Mercurial > hg > openttd
annotate src/economy.cpp @ 15744:f9e8032ac213 draft
(svn r20411) -Codechange: rename unmovables as quite a lot of them are actually movable; e.g. HQ and owned land are pretty movable.
author | rubidium <rubidium@openttd.org> |
---|---|
date | Sun, 08 Aug 2010 10:59:30 +0000 |
parents | f6078460c5b1 |
children | 56dcb448bdfb |
rev | line source |
---|---|
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1 /* $Id$ */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2 |
12778
bc7926153e19
(svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents:
12756
diff
changeset
|
3 /* |
bc7926153e19
(svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents:
12756
diff
changeset
|
4 * This file is part of OpenTTD. |
bc7926153e19
(svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents:
12756
diff
changeset
|
5 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. |
bc7926153e19
(svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents:
12756
diff
changeset
|
6 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
bc7926153e19
(svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents:
12756
diff
changeset
|
7 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>. |
bc7926153e19
(svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents:
12756
diff
changeset
|
8 */ |
bc7926153e19
(svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents:
12756
diff
changeset
|
9 |
9111
d48433370037
(svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium <rubidium@openttd.org>
parents:
9058
diff
changeset
|
10 /** @file economy.cpp Handling of the economy. */ |
6125
46d001ebacf6
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents:
6119
diff
changeset
|
11 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
12 #include "stdafx.h" |
10208
39cf8eebfda5
(svn r14422) -Codechange: also reflect the changes of r14421 in the filenames.
rubidium <rubidium@openttd.org>
parents:
10207
diff
changeset
|
13 #include "company_func.h" |
8116
9cc845deddfe
(svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium <rubidium@openttd.org>
parents:
8114
diff
changeset
|
14 #include "command_func.h" |
12826
c2f3eaf3b353
(svn r17316) -Codechange: use Industry::GetByTile() instead of GetIndustryByTile()
smatz <smatz@openttd.org>
parents:
12778
diff
changeset
|
15 #include "industry.h" |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
16 #include "town.h" |
8763
d6e363672edb
(svn r12459) -Codechange: split news.h into news_type.h and news_func.h.
rubidium <rubidium@openttd.org>
parents:
8626
diff
changeset
|
17 #include "news_func.h" |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
18 #include "network/network.h" |
9428
ba7cdcf21f4c
(svn r13343) -Codechange: reorder/move variable/functions in the network headers so that nothing from the network directory needs to include basically all network headers.
rubidium <rubidium@openttd.org>
parents:
9413
diff
changeset
|
19 #include "network/network_func.h" |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
20 #include "vehicle_gui.h" |
10696
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
10647
diff
changeset
|
21 #include "ai/ai.hpp" |
5854
b52317eb405c
(svn r8428) -Codechange: Add proper names to aircraft subtypes instead of magic numbers and add a function IsNormalAircraft() which tells us whether the aircraft is in fact some flying device or a rotor/shadow.
Darkvater <Darkvater@openttd.org>
parents:
5683
diff
changeset
|
22 #include "aircraft.h" |
11987
81554d4e6d76
(svn r16393) -Codechange: move VehicleRail to Train.
rubidium <rubidium@openttd.org>
parents:
11956
diff
changeset
|
23 #include "train.h" |
13466
a6e569a5cc14
(svn r17976) -Codechange: Move CargoClass to cargotype.h and clean up including of newgrf_cargo.h
frosch <frosch@openttd.org>
parents:
13325
diff
changeset
|
24 #include "newgrf_cargo.h" |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
25 #include "newgrf_engine.h" |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
26 #include "newgrf_sound.h" |
7168
f0216e74951d
(svn r10442) -Codechange: implement the industry production callback.
rubidium <rubidium@openttd.org>
parents:
7167
diff
changeset
|
27 #include "newgrf_industries.h" |
7229
39b4e2291424
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium <rubidium@openttd.org>
parents:
7199
diff
changeset
|
28 #include "newgrf_industrytiles.h" |
9003
ac23e012c9d7
(svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents:
8885
diff
changeset
|
29 #include "newgrf_station.h" |
14620
a2d95ade0e87
(svn r19197) -Codechange: introduce animation callbacks for airport tiles
yexo <yexo@openttd.org>
parents:
14353
diff
changeset
|
30 #include "newgrf_airporttiles.h" |
15744
f9e8032ac213
(svn r20411) -Codechange: rename unmovables as quite a lot of them are actually movable; e.g. HQ and owned land are pretty movable.
rubidium <rubidium@openttd.org>
parents:
15729
diff
changeset
|
31 #include "object.h" |
6643
18d58b36b9b3
(svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium <rubidium@openttd.org>
parents:
6639
diff
changeset
|
32 #include "group.h" |
8114
2d6af5d7a142
(svn r11675) -Codechange: split the string types from the string functions.
rubidium <rubidium@openttd.org>
parents:
8106
diff
changeset
|
33 #include "strings_func.h" |
8131
e300ac8001ae
(svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium <rubidium@openttd.org>
parents:
8121
diff
changeset
|
34 #include "functions.h" |
e300ac8001ae
(svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium <rubidium@openttd.org>
parents:
8121
diff
changeset
|
35 #include "window_func.h" |
8140
fb8a05d579da
(svn r11702) -Codechange: move all date related stuff to date*.
rubidium <rubidium@openttd.org>
parents:
8139
diff
changeset
|
36 #include "date_func.h" |
8144
d18c8a0bb638
(svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium <rubidium@openttd.org>
parents:
8140
diff
changeset
|
37 #include "vehicle_func.h" |
8157
019833e42fda
(svn r11719) -Codechange: split sound.h in a header with types and one with functions.
rubidium <rubidium@openttd.org>
parents:
8155
diff
changeset
|
38 #include "sound_func.h" |
9058
c73011639858
(svn r12906) -Fix: vehicle groups, engine replacement rules and player/company names were not properly reset/freed after bankrupt (before new player start)
smatz <smatz@openttd.org>
parents:
9043
diff
changeset
|
39 #include "autoreplace_func.h" |
10208
39cf8eebfda5
(svn r14422) -Codechange: also reflect the changes of r14421 in the filenames.
rubidium <rubidium@openttd.org>
parents:
10207
diff
changeset
|
40 #include "company_gui.h" |
10158
c429fccf1aea
(svn r14348) -Fix (r1667): signs were not updated on company bankrupcy/sell, they have colour of invalid player
smatz <smatz@openttd.org>
parents:
10146
diff
changeset
|
41 #include "signs_base.h" |
12297
39ea618c207e
(svn r16714) -Codechange: use pool-like accessors for Subsidy
smatz <smatz@openttd.org>
parents:
12294
diff
changeset
|
42 #include "subsidy_base.h" |
11997
e2187548a5e4
(svn r16403) -Codechange: move code related to subsidies to separate file
smatz <smatz@openttd.org>
parents:
11987
diff
changeset
|
43 #include "subsidy_func.h" |
12228
240adc64d01a
(svn r16643) -Codechange: replace GetStationByTile() by Station::GetByTile()
smatz <smatz@openttd.org>
parents:
12143
diff
changeset
|
44 #include "station_base.h" |
12475
c133b51890f4
(svn r16912) -Codechange: split waypoint.h in waypoint_base.h and waypoint_func.h
rubidium <rubidium@openttd.org>
parents:
12467
diff
changeset
|
45 #include "waypoint_base.h" |
12268
3a97d4e6f918
(svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents:
12267
diff
changeset
|
46 #include "economy_base.h" |
12279
329b186db8cd
(svn r16694) -Fix [FS#2995] (rgradual loading, rnewindustries): only pay for whatever has been actually unloaded and perform the payment when unloading has finished. This fixes, amongst others:
rubidium <rubidium@openttd.org>
parents:
12278
diff
changeset
|
47 #include "core/pool_func.hpp" |
14258
a899d4e5ee1a
(svn r18809) -Codechange/Cleanup: remove unneeded headers from some files, if a header require a header make it include that header
rubidium <rubidium@openttd.org>
parents:
14213
diff
changeset
|
48 #include "newgrf.h" |
a899d4e5ee1a
(svn r18809) -Codechange/Cleanup: remove unneeded headers from some files, if a header require a header make it include that header
rubidium <rubidium@openttd.org>
parents:
14213
diff
changeset
|
49 #include "engine_base.h" |
15279
4e1862aebea2
(svn r19914) -Codechange: Wrap a helper class around temporary assignments of _current_company to ensure proper restoration.
frosch <frosch@openttd.org>
parents:
15050
diff
changeset
|
50 #include "core/backup_type.hpp" |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
51 |
8264
2495310e220f
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium <rubidium@openttd.org>
parents:
8254
diff
changeset
|
52 #include "table/strings.h" |
2495310e220f
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium <rubidium@openttd.org>
parents:
8254
diff
changeset
|
53 #include "table/sprites.h" |
12593
73b580ddf33f
(svn r17036) -Codechange: Split price bases from economy.cpp to table/pricebase.h.
frosch <frosch@openttd.org>
parents:
12496
diff
changeset
|
54 #include "table/pricebase.h" |
8264
2495310e220f
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium <rubidium@openttd.org>
parents:
8254
diff
changeset
|
55 |
12279
329b186db8cd
(svn r16694) -Fix [FS#2995] (rgradual loading, rnewindustries): only pay for whatever has been actually unloaded and perform the payment when unloading has finished. This fixes, amongst others:
rubidium <rubidium@openttd.org>
parents:
12278
diff
changeset
|
56 |
329b186db8cd
(svn r16694) -Fix [FS#2995] (rgradual loading, rnewindustries): only pay for whatever has been actually unloaded and perform the payment when unloading has finished. This fixes, amongst others:
rubidium <rubidium@openttd.org>
parents:
12278
diff
changeset
|
57 /* Initialize the cargo payment-pool */ |
329b186db8cd
(svn r16694) -Fix [FS#2995] (rgradual loading, rnewindustries): only pay for whatever has been actually unloaded and perform the payment when unloading has finished. This fixes, amongst others:
rubidium <rubidium@openttd.org>
parents:
12278
diff
changeset
|
58 CargoPaymentPool _cargo_payment_pool("CargoPayment"); |
329b186db8cd
(svn r16694) -Fix [FS#2995] (rgradual loading, rnewindustries): only pay for whatever has been actually unloaded and perform the payment when unloading has finished. This fixes, amongst others:
rubidium <rubidium@openttd.org>
parents:
12278
diff
changeset
|
59 INSTANTIATE_POOL_METHODS(CargoPayment) |
329b186db8cd
(svn r16694) -Fix [FS#2995] (rgradual loading, rnewindustries): only pay for whatever has been actually unloaded and perform the payment when unloading has finished. This fixes, amongst others:
rubidium <rubidium@openttd.org>
parents:
12278
diff
changeset
|
60 |
7926
e8ce9f6469d1
(svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents:
7922
diff
changeset
|
61 /** |
e8ce9f6469d1
(svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents:
7922
diff
changeset
|
62 * Multiply two integer values and shift the results to right. |
e8ce9f6469d1
(svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents:
7922
diff
changeset
|
63 * |
e8ce9f6469d1
(svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents:
7922
diff
changeset
|
64 * This function multiplies two integer values. The result is |
e8ce9f6469d1
(svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents:
7922
diff
changeset
|
65 * shifted by the amount of shift to right. |
e8ce9f6469d1
(svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents:
7922
diff
changeset
|
66 * |
e8ce9f6469d1
(svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents:
7922
diff
changeset
|
67 * @param a The first integer |
e8ce9f6469d1
(svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents:
7922
diff
changeset
|
68 * @param b The second integer |
e8ce9f6469d1
(svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents:
7922
diff
changeset
|
69 * @param shift The amount to shift the value to right. |
e8ce9f6469d1
(svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents:
7922
diff
changeset
|
70 * @return The shifted result |
e8ce9f6469d1
(svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents:
7922
diff
changeset
|
71 */ |
e8ce9f6469d1
(svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents:
7922
diff
changeset
|
72 static inline int32 BigMulS(const int32 a, const int32 b, const uint8 shift) |
e8ce9f6469d1
(svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents:
7922
diff
changeset
|
73 { |
e8ce9f6469d1
(svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents:
7922
diff
changeset
|
74 return (int32)((int64)a * (int64)b >> shift); |
e8ce9f6469d1
(svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents:
7922
diff
changeset
|
75 } |
e8ce9f6469d1
(svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents:
7922
diff
changeset
|
76 |
e8ce9f6469d1
(svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents:
7922
diff
changeset
|
77 /** |
e8ce9f6469d1
(svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents:
7922
diff
changeset
|
78 * Multiply two unsigned integers and shift the results to right. |
e8ce9f6469d1
(svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents:
7922
diff
changeset
|
79 * |
e8ce9f6469d1
(svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents:
7922
diff
changeset
|
80 * This function multiplies two unsigned integers. The result is |
e8ce9f6469d1
(svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents:
7922
diff
changeset
|
81 * shifted by the amount of shift to right. |
e8ce9f6469d1
(svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents:
7922
diff
changeset
|
82 * |
e8ce9f6469d1
(svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents:
7922
diff
changeset
|
83 * @param a The first unsigned integer |
e8ce9f6469d1
(svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents:
7922
diff
changeset
|
84 * @param b The second unsigned integer |
e8ce9f6469d1
(svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents:
7922
diff
changeset
|
85 * @param shift The amount to shift the value to right. |
e8ce9f6469d1
(svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents:
7922
diff
changeset
|
86 * @return The shifted result |
e8ce9f6469d1
(svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents:
7922
diff
changeset
|
87 */ |
e8ce9f6469d1
(svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents:
7922
diff
changeset
|
88 static inline uint32 BigMulSU(const uint32 a, const uint32 b, const uint8 shift) |
e8ce9f6469d1
(svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents:
7922
diff
changeset
|
89 { |
e8ce9f6469d1
(svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents:
7922
diff
changeset
|
90 return (uint32)((uint64)a * (uint64)b >> shift); |
e8ce9f6469d1
(svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents:
7922
diff
changeset
|
91 } |
e8ce9f6469d1
(svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents:
7922
diff
changeset
|
92 |
10450
e3e68b2c143c
(svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents:
10419
diff
changeset
|
93 typedef SmallVector<Industry *, 16> SmallIndustryList; |
e3e68b2c143c
(svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents:
10419
diff
changeset
|
94 |
15601
4d1a28b41236
(svn r20262) -Codechange: Remove unused ScoreInfo::id field, and doxyment the data structures.
alberth <alberth@openttd.org>
parents:
15552
diff
changeset
|
95 /** |
4d1a28b41236
(svn r20262) -Codechange: Remove unused ScoreInfo::id field, and doxyment the data structures.
alberth <alberth@openttd.org>
parents:
15552
diff
changeset
|
96 * Score info, values used for computing the detailed performance rating. |
4d1a28b41236
(svn r20262) -Codechange: Remove unused ScoreInfo::id field, and doxyment the data structures.
alberth <alberth@openttd.org>
parents:
15552
diff
changeset
|
97 */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
98 const ScoreInfo _score_info[] = { |
15601
4d1a28b41236
(svn r20262) -Codechange: Remove unused ScoreInfo::id field, and doxyment the data structures.
alberth <alberth@openttd.org>
parents:
15552
diff
changeset
|
99 { 120, 100}, // SCORE_VEHICLES |
4d1a28b41236
(svn r20262) -Codechange: Remove unused ScoreInfo::id field, and doxyment the data structures.
alberth <alberth@openttd.org>
parents:
15552
diff
changeset
|
100 { 80, 100}, // SCORE_STATIONS |
4d1a28b41236
(svn r20262) -Codechange: Remove unused ScoreInfo::id field, and doxyment the data structures.
alberth <alberth@openttd.org>
parents:
15552
diff
changeset
|
101 { 10000, 100}, // SCORE_MIN_PROFIT |
4d1a28b41236
(svn r20262) -Codechange: Remove unused ScoreInfo::id field, and doxyment the data structures.
alberth <alberth@openttd.org>
parents:
15552
diff
changeset
|
102 { 50000, 50}, // SCORE_MIN_INCOME |
4d1a28b41236
(svn r20262) -Codechange: Remove unused ScoreInfo::id field, and doxyment the data structures.
alberth <alberth@openttd.org>
parents:
15552
diff
changeset
|
103 { 100000, 100}, // SCORE_MAX_INCOME |
4d1a28b41236
(svn r20262) -Codechange: Remove unused ScoreInfo::id field, and doxyment the data structures.
alberth <alberth@openttd.org>
parents:
15552
diff
changeset
|
104 { 40000, 400}, // SCORE_DELIVERED |
4d1a28b41236
(svn r20262) -Codechange: Remove unused ScoreInfo::id field, and doxyment the data structures.
alberth <alberth@openttd.org>
parents:
15552
diff
changeset
|
105 { 8, 50}, // SCORE_CARGO |
4d1a28b41236
(svn r20262) -Codechange: Remove unused ScoreInfo::id field, and doxyment the data structures.
alberth <alberth@openttd.org>
parents:
15552
diff
changeset
|
106 {10000000, 50}, // SCORE_MONEY |
4d1a28b41236
(svn r20262) -Codechange: Remove unused ScoreInfo::id field, and doxyment the data structures.
alberth <alberth@openttd.org>
parents:
15552
diff
changeset
|
107 { 250000, 50}, // SCORE_LOAN |
4d1a28b41236
(svn r20262) -Codechange: Remove unused ScoreInfo::id field, and doxyment the data structures.
alberth <alberth@openttd.org>
parents:
15552
diff
changeset
|
108 { 0, 0} // SCORE_TOTAL |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
109 }; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
110 |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
111 int _score_part[MAX_COMPANIES][SCORE_END]; |
8116
9cc845deddfe
(svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium <rubidium@openttd.org>
parents:
8114
diff
changeset
|
112 Economy _economy; |
9cc845deddfe
(svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium <rubidium@openttd.org>
parents:
8114
diff
changeset
|
113 Prices _price; |
8119
b6ec923e9fa8
(svn r11680) -Codechange: refactor more out of openttd.h and functions.h.
rubidium <rubidium@openttd.org>
parents:
8116
diff
changeset
|
114 Money _additional_cash_required; |
13743
c84d609b6877
(svn r18268) -Feature: [NewGRF] Make price base multipliers related to vehicles only apply to the GRF locally, if it defines engines of that type itself.
frosch <frosch@openttd.org>
parents:
13741
diff
changeset
|
115 static PriceMultipliers _price_base_multiplier; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
116 |
14353
098ac3e84f3b
(svn r18908) -Fix [FS#3561]: on bankruptcy the company value did include the loan and as such the value at which you bought the company was too low
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
117 /** |
098ac3e84f3b
(svn r18908) -Fix [FS#3561]: on bankruptcy the company value did include the loan and as such the value at which you bought the company was too low
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
118 * Calculate the value of the company. That is the value of all |
098ac3e84f3b
(svn r18908) -Fix [FS#3561]: on bankruptcy the company value did include the loan and as such the value at which you bought the company was too low
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
119 * assets (vehicles, stations, etc) and money minus the loan, |
098ac3e84f3b
(svn r18908) -Fix [FS#3561]: on bankruptcy the company value did include the loan and as such the value at which you bought the company was too low
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
120 * except when including_loan is \c false which is useful when |
098ac3e84f3b
(svn r18908) -Fix [FS#3561]: on bankruptcy the company value did include the loan and as such the value at which you bought the company was too low
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
121 * we want to calculate the value for bankruptcy. |
098ac3e84f3b
(svn r18908) -Fix [FS#3561]: on bankruptcy the company value did include the loan and as such the value at which you bought the company was too low
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
122 * @param c the company to get the value of. |
098ac3e84f3b
(svn r18908) -Fix [FS#3561]: on bankruptcy the company value did include the loan and as such the value at which you bought the company was too low
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
123 * @param including_loan include the loan in the company value. |
098ac3e84f3b
(svn r18908) -Fix [FS#3561]: on bankruptcy the company value did include the loan and as such the value at which you bought the company was too low
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
124 * @return the value of the company. |
098ac3e84f3b
(svn r18908) -Fix [FS#3561]: on bankruptcy the company value did include the loan and as such the value at which you bought the company was too low
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
125 */ |
098ac3e84f3b
(svn r18908) -Fix [FS#3561]: on bankruptcy the company value did include the loan and as such the value at which you bought the company was too low
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
126 Money CalculateCompanyValue(const Company *c, bool including_loan) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
127 { |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
128 Owner owner = c->index; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
129 |
7781
67423408cf20
(svn r11331) -Fix: do not misuse CommandCost for overflow safe stuff as Money supports that now too.
rubidium <rubidium@openttd.org>
parents:
7763
diff
changeset
|
130 Station *st; |
67423408cf20
(svn r11331) -Fix: do not misuse CommandCost for overflow safe stuff as Money supports that now too.
rubidium <rubidium@openttd.org>
parents:
7763
diff
changeset
|
131 uint num = 0; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
132 |
7781
67423408cf20
(svn r11331) -Fix: do not misuse CommandCost for overflow safe stuff as Money supports that now too.
rubidium <rubidium@openttd.org>
parents:
7763
diff
changeset
|
133 FOR_ALL_STATIONS(st) { |
12319
712bfd1aca6c
(svn r16736) -Codechange: give some station enums a name and use that instead of 'byte'.
rubidium <rubidium@openttd.org>
parents:
12297
diff
changeset
|
134 if (st->owner == owner) num += CountBits((byte)st->facilities); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
135 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
136 |
15652
354307d245e5
(svn r20317) -Codechange: Move variable declaration to their first use.
alberth <alberth@openttd.org>
parents:
15623
diff
changeset
|
137 Money value = num * _price[PR_STATION_VALUE] * 25; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
138 |
7781
67423408cf20
(svn r11331) -Fix: do not misuse CommandCost for overflow safe stuff as Money supports that now too.
rubidium <rubidium@openttd.org>
parents:
7763
diff
changeset
|
139 Vehicle *v; |
67423408cf20
(svn r11331) -Fix: do not misuse CommandCost for overflow safe stuff as Money supports that now too.
rubidium <rubidium@openttd.org>
parents:
7763
diff
changeset
|
140 FOR_ALL_VEHICLES(v) { |
67423408cf20
(svn r11331) -Fix: do not misuse CommandCost for overflow safe stuff as Money supports that now too.
rubidium <rubidium@openttd.org>
parents:
7763
diff
changeset
|
141 if (v->owner != owner) continue; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
142 |
7781
67423408cf20
(svn r11331) -Fix: do not misuse CommandCost for overflow safe stuff as Money supports that now too.
rubidium <rubidium@openttd.org>
parents:
7763
diff
changeset
|
143 if (v->type == VEH_TRAIN || |
67423408cf20
(svn r11331) -Fix: do not misuse CommandCost for overflow safe stuff as Money supports that now too.
rubidium <rubidium@openttd.org>
parents:
7763
diff
changeset
|
144 v->type == VEH_ROAD || |
12384
d4b73a406cf3
(svn r16814) -Codechange: make IsNormalAircraft() member of Aircraft
smatz <smatz@openttd.org>
parents:
12383
diff
changeset
|
145 (v->type == VEH_AIRCRAFT && Aircraft::From(v)->IsNormalAircraft()) || |
7781
67423408cf20
(svn r11331) -Fix: do not misuse CommandCost for overflow safe stuff as Money supports that now too.
rubidium <rubidium@openttd.org>
parents:
7763
diff
changeset
|
146 v->type == VEH_SHIP) { |
67423408cf20
(svn r11331) -Fix: do not misuse CommandCost for overflow safe stuff as Money supports that now too.
rubidium <rubidium@openttd.org>
parents:
7763
diff
changeset
|
147 value += v->value * 3 >> 1; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
148 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
149 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
150 |
6953
41fd36025784
(svn r10208) -Codechange: replace int32 with Money where appropriate.
rubidium <rubidium@openttd.org>
parents:
6952
diff
changeset
|
151 /* Add real money value */ |
14353
098ac3e84f3b
(svn r18908) -Fix [FS#3561]: on bankruptcy the company value did include the loan and as such the value at which you bought the company was too low
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
152 if (including_loan) value -= c->current_loan; |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
153 value += c->money; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
154 |
7781
67423408cf20
(svn r11331) -Fix: do not misuse CommandCost for overflow safe stuff as Money supports that now too.
rubidium <rubidium@openttd.org>
parents:
7763
diff
changeset
|
155 return max(value, (Money)1); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
156 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
157 |
15620
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15616
diff
changeset
|
158 /** |
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15616
diff
changeset
|
159 * if update is set to true, the economy is updated with this score |
6125
46d001ebacf6
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents:
6119
diff
changeset
|
160 * (also the house is updated, should only be true in the on-tick event) |
46d001ebacf6
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents:
6119
diff
changeset
|
161 * @param update the economy with calculated score |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
162 * @param c company been evaluated |
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
163 * @return actual score of this company |
15623
c62577640878
(svn r20286) -Codechange: Unify end of doxygen comments.
frosch <frosch@openttd.org>
parents:
15620
diff
changeset
|
164 * |
c62577640878
(svn r20286) -Codechange: Unify end of doxygen comments.
frosch <frosch@openttd.org>
parents:
15620
diff
changeset
|
165 */ |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
166 int UpdateCompanyRatingAndValue(Company *c, bool update) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
167 { |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
168 Owner owner = c->index; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
169 int score = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
170 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
171 memset(_score_part[owner], 0, sizeof(_score_part[owner])); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
172 |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
173 /* Count vehicles */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
174 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
175 Vehicle *v; |
6990
a19700261804
(svn r10246) -Fix (r10297): some forgotten money conversions and truncation issues. Thanks to benc for providing the patch.
rubidium <rubidium@openttd.org>
parents:
6957
diff
changeset
|
176 Money min_profit = 0; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
177 bool min_profit_first = true; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
178 uint num = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
179 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
180 FOR_ALL_VEHICLES(v) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
181 if (v->owner != owner) continue; |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
182 if (IsCompanyBuildableVehicleType(v->type) && v->IsPrimaryVehicle()) { |
12991
d3df6e84bf71
(svn r17485) -Change [FS2459]: make the performance ratings harder to exploit; only count profitable vehicles and recently serviced stations.
rubidium <rubidium@openttd.org>
parents:
12956
diff
changeset
|
183 if (v->profit_last_year > 0) num++; // For the vehicle score only count profitable vehicles |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
184 if (v->age > 730) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
185 /* Find the vehicle with the lowest amount of profit */ |
8614
36bb76188638
(svn r12197) -Fix [FS#1788](r12134): show correct last year profit when the train had negative income
smatz <smatz@openttd.org>
parents:
8556
diff
changeset
|
186 if (min_profit_first || min_profit > v->profit_last_year) { |
36bb76188638
(svn r12197) -Fix [FS#1788](r12134): show correct last year profit when the train had negative income
smatz <smatz@openttd.org>
parents:
8556
diff
changeset
|
187 min_profit = v->profit_last_year; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
188 min_profit_first = false; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
189 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
190 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
191 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
192 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
193 |
8614
36bb76188638
(svn r12197) -Fix [FS#1788](r12134): show correct last year profit when the train had negative income
smatz <smatz@openttd.org>
parents:
8556
diff
changeset
|
194 min_profit >>= 8; // remove the fract part |
36bb76188638
(svn r12197) -Fix [FS#1788](r12134): show correct last year profit when the train had negative income
smatz <smatz@openttd.org>
parents:
8556
diff
changeset
|
195 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
196 _score_part[owner][SCORE_VEHICLES] = num; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
197 /* Don't allow negative min_profit to show */ |
15552
683f2dbe75bb
(svn r20211) -Codechange: Indented code should have curly braces around it.
alberth <alberth@openttd.org>
parents:
15511
diff
changeset
|
198 if (min_profit > 0) { |
6990
a19700261804
(svn r10246) -Fix (r10297): some forgotten money conversions and truncation issues. Thanks to benc for providing the patch.
rubidium <rubidium@openttd.org>
parents:
6957
diff
changeset
|
199 _score_part[owner][SCORE_MIN_PROFIT] = ClampToI32(min_profit); |
15552
683f2dbe75bb
(svn r20211) -Codechange: Indented code should have curly braces around it.
alberth <alberth@openttd.org>
parents:
15511
diff
changeset
|
200 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
201 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
202 |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
203 /* Count stations */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
204 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
205 uint num = 0; |
10647
592ae9307430
(svn r14949) -Cleanup: pointer coding style
rubidium <rubidium@openttd.org>
parents:
10571
diff
changeset
|
206 const Station *st; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
207 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
208 FOR_ALL_STATIONS(st) { |
12991
d3df6e84bf71
(svn r17485) -Change [FS2459]: make the performance ratings harder to exploit; only count profitable vehicles and recently serviced stations.
rubidium <rubidium@openttd.org>
parents:
12956
diff
changeset
|
209 /* Only count stations that are actually serviced */ |
d3df6e84bf71
(svn r17485) -Change [FS2459]: make the performance ratings harder to exploit; only count profitable vehicles and recently serviced stations.
rubidium <rubidium@openttd.org>
parents:
12956
diff
changeset
|
210 if (st->owner == owner && (st->time_since_load <= 20 || st->time_since_unload <= 20)) num += CountBits((byte)st->facilities); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
211 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
212 _score_part[owner][SCORE_STATIONS] = num; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
213 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
214 |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
215 /* Generate statistics depending on recent income statistics */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
216 { |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
217 int numec = min(c->num_valid_stat_ent, 12); |
6953
41fd36025784
(svn r10208) -Codechange: replace int32 with Money where appropriate.
rubidium <rubidium@openttd.org>
parents:
6952
diff
changeset
|
218 if (numec != 0) { |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
219 const CompanyEconomyEntry *cee = c->old_economy; |
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
220 Money min_income = cee->income + cee->expenses; |
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
221 Money max_income = cee->income + cee->expenses; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
222 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
223 do { |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
224 min_income = min(min_income, cee->income + cee->expenses); |
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
225 max_income = max(max_income, cee->income + cee->expenses); |
11361
02313cc6114e
(svn r15711) -Codechange: lots of whitespace cleanup/fixes
rubidium <rubidium@openttd.org>
parents:
11234
diff
changeset
|
226 } while (++cee, --numec); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
227 |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
228 if (min_income > 0) { |
6990
a19700261804
(svn r10246) -Fix (r10297): some forgotten money conversions and truncation issues. Thanks to benc for providing the patch.
rubidium <rubidium@openttd.org>
parents:
6957
diff
changeset
|
229 _score_part[owner][SCORE_MIN_INCOME] = ClampToI32(min_income); |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
230 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
231 |
6990
a19700261804
(svn r10246) -Fix (r10297): some forgotten money conversions and truncation issues. Thanks to benc for providing the patch.
rubidium <rubidium@openttd.org>
parents:
6957
diff
changeset
|
232 _score_part[owner][SCORE_MAX_INCOME] = ClampToI32(max_income); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
233 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
234 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
235 |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
236 /* Generate score depending on amount of transported cargo */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
237 { |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
238 const CompanyEconomyEntry *cee; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
239 int numec; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
240 uint32 total_delivered; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
241 |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
242 numec = min(c->num_valid_stat_ent, 4); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
243 if (numec != 0) { |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
244 cee = c->old_economy; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
245 total_delivered = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
246 do { |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
247 total_delivered += cee->delivered_cargo; |
11361
02313cc6114e
(svn r15711) -Codechange: lots of whitespace cleanup/fixes
rubidium <rubidium@openttd.org>
parents:
11234
diff
changeset
|
248 } while (++cee, --numec); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
249 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
250 _score_part[owner][SCORE_DELIVERED] = total_delivered; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
251 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
252 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
253 |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
254 /* Generate score for variety of cargo */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
255 { |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
256 uint num = CountBits(c->cargo_types); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
257 _score_part[owner][SCORE_CARGO] = num; |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
258 if (update) c->cargo_types = 0; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
259 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
260 |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
261 /* Generate score for company's money */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
262 { |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
263 if (c->money > 0) { |
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
264 _score_part[owner][SCORE_MONEY] = ClampToI32(c->money); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
265 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
266 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
267 |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
268 /* Generate score for loan */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
269 { |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
270 _score_part[owner][SCORE_LOAN] = ClampToI32(_score_info[SCORE_LOAN].needed - c->current_loan); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
271 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
272 |
6125
46d001ebacf6
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents:
6119
diff
changeset
|
273 /* Now we calculate the score for each item.. */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
274 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
275 int total_score = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
276 int s; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
277 score = 0; |
5587
c44c070c5032
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium <rubidium@openttd.org>
parents:
5584
diff
changeset
|
278 for (ScoreID i = SCORE_BEGIN; i < SCORE_END; i++) { |
6125
46d001ebacf6
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents:
6119
diff
changeset
|
279 /* Skip the total */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
280 if (i == SCORE_TOTAL) continue; |
6125
46d001ebacf6
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents:
6119
diff
changeset
|
281 /* Check the score */ |
7922
ff1975ced735
(svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
skidd13 <skidd13@openttd.org>
parents:
7860
diff
changeset
|
282 s = Clamp(_score_part[owner][i], 0, _score_info[i].needed) * _score_info[i].score / _score_info[i].needed; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
283 score += s; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
284 total_score += _score_info[i].score; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
285 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
286 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
287 _score_part[owner][SCORE_TOTAL] = score; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
288 |
6125
46d001ebacf6
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents:
6119
diff
changeset
|
289 /* We always want the score scaled to SCORE_MAX (1000) */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
290 if (total_score != SCORE_MAX) score = score * SCORE_MAX / total_score; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
291 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
292 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
293 if (update) { |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
294 c->old_economy[0].performance_history = score; |
15676
87f2261652e1
(svn r20341) -Codechange: pass the tile of the HQ instead of the company to UpdateCompanyHQ
rubidium <rubidium@openttd.org>
parents:
15655
diff
changeset
|
295 UpdateCompanyHQ(c->location_of_HQ, score); |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
296 c->old_economy[0].company_value = CalculateCompanyValue(c); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
297 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
298 |
13034
6eb3f749890a
(svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents:
12991
diff
changeset
|
299 SetWindowDirty(WC_PERFORMANCE_DETAIL, 0); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
300 return score; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
301 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
302 |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
303 /* use INVALID_OWNER as new_owner to delete the company. */ |
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
304 void ChangeOwnershipOfCompanyItems(Owner old_owner, Owner new_owner) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
305 { |
15035
cd12f24222ac
(svn r19651) -Fix [FS#3745]: when a company is sold, move connected clients to spectators
smatz <smatz@openttd.org>
parents:
15002
diff
changeset
|
306 #ifdef ENABLE_NETWORK |
cd12f24222ac
(svn r19651) -Fix [FS#3745]: when a company is sold, move connected clients to spectators
smatz <smatz@openttd.org>
parents:
15002
diff
changeset
|
307 /* In all cases, make spectators of clients connected to that company */ |
cd12f24222ac
(svn r19651) -Fix [FS#3745]: when a company is sold, move connected clients to spectators
smatz <smatz@openttd.org>
parents:
15002
diff
changeset
|
308 if (_networking) NetworkClientsToSpectators(old_owner); |
cd12f24222ac
(svn r19651) -Fix [FS#3745]: when a company is sold, move connected clients to spectators
smatz <smatz@openttd.org>
parents:
15002
diff
changeset
|
309 #endif /* ENABLE_NETWORK */ |
cd12f24222ac
(svn r19651) -Fix [FS#3745]: when a company is sold, move connected clients to spectators
smatz <smatz@openttd.org>
parents:
15002
diff
changeset
|
310 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
311 Town *t; |
15292
e2c62d70dfcf
(svn r19931) -Fix (r19914): Convert assertion in Backup<> destructor into DEBUG() output. It was triggered on exceptions, especially when aborting world generation.
frosch <frosch@openttd.org>
parents:
15279
diff
changeset
|
312 Backup<CompanyByte> cur_company(_current_company, old_owner, FILE_LINE); |
6403
8c022dabd50e
(svn r9533) -Fix [FS#274]: when a company is removed (either via auto-clean, bankrupt, or take over), sell all the shares he has first, then sell the shares all people have on this company, and then remove the company.
truelight <truelight@openttd.org>
parents:
6369
diff
changeset
|
313 |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
314 assert(old_owner != new_owner); |
6405
3f3b30a14c26
(svn r9541) -Codechange: Safeguard the company-buying routines so that the buying player and the bought player need to be two different entities
celestar <celestar@openttd.org>
parents:
6403
diff
changeset
|
315 |
6403
8c022dabd50e
(svn r9533) -Fix [FS#274]: when a company is removed (either via auto-clean, bankrupt, or take over), sell all the shares he has first, then sell the shares all people have on this company, and then remove the company.
truelight <truelight@openttd.org>
parents:
6369
diff
changeset
|
316 { |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
317 Company *c; |
6403
8c022dabd50e
(svn r9533) -Fix [FS#274]: when a company is removed (either via auto-clean, bankrupt, or take over), sell all the shares he has first, then sell the shares all people have on this company, and then remove the company.
truelight <truelight@openttd.org>
parents:
6369
diff
changeset
|
318 uint i; |
8c022dabd50e
(svn r9533) -Fix [FS#274]: when a company is removed (either via auto-clean, bankrupt, or take over), sell all the shares he has first, then sell the shares all people have on this company, and then remove the company.
truelight <truelight@openttd.org>
parents:
6369
diff
changeset
|
319 |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
320 /* See if the old_owner had shares in other companies */ |
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
321 FOR_ALL_COMPANIES(c) { |
6403
8c022dabd50e
(svn r9533) -Fix [FS#274]: when a company is removed (either via auto-clean, bankrupt, or take over), sell all the shares he has first, then sell the shares all people have on this company, and then remove the company.
truelight <truelight@openttd.org>
parents:
6369
diff
changeset
|
322 for (i = 0; i < 4; i++) { |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
323 if (c->share_owners[i] == old_owner) { |
6403
8c022dabd50e
(svn r9533) -Fix [FS#274]: when a company is removed (either via auto-clean, bankrupt, or take over), sell all the shares he has first, then sell the shares all people have on this company, and then remove the company.
truelight <truelight@openttd.org>
parents:
6369
diff
changeset
|
324 /* Sell his shares */ |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
325 CommandCost res = DoCommand(0, c->index, 0, DC_EXEC, CMD_SELL_SHARE_IN_COMPANY); |
14136
54dfd3720fa1
(svn r18683) -Fix: it's not an other
rubidium <rubidium@openttd.org>
parents:
13998
diff
changeset
|
326 /* Because we are in a DoCommand, we can't just execute another one and |
6403
8c022dabd50e
(svn r9533) -Fix [FS#274]: when a company is removed (either via auto-clean, bankrupt, or take over), sell all the shares he has first, then sell the shares all people have on this company, and then remove the company.
truelight <truelight@openttd.org>
parents:
6369
diff
changeset
|
327 * expect the money to be removed. We need to do it ourself! */ |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
328 SubtractMoneyFromCompany(res); |
6403
8c022dabd50e
(svn r9533) -Fix [FS#274]: when a company is removed (either via auto-clean, bankrupt, or take over), sell all the shares he has first, then sell the shares all people have on this company, and then remove the company.
truelight <truelight@openttd.org>
parents:
6369
diff
changeset
|
329 } |
8c022dabd50e
(svn r9533) -Fix [FS#274]: when a company is removed (either via auto-clean, bankrupt, or take over), sell all the shares he has first, then sell the shares all people have on this company, and then remove the company.
truelight <truelight@openttd.org>
parents:
6369
diff
changeset
|
330 } |
8c022dabd50e
(svn r9533) -Fix [FS#274]: when a company is removed (either via auto-clean, bankrupt, or take over), sell all the shares he has first, then sell the shares all people have on this company, and then remove the company.
truelight <truelight@openttd.org>
parents:
6369
diff
changeset
|
331 } |
8c022dabd50e
(svn r9533) -Fix [FS#274]: when a company is removed (either via auto-clean, bankrupt, or take over), sell all the shares he has first, then sell the shares all people have on this company, and then remove the company.
truelight <truelight@openttd.org>
parents:
6369
diff
changeset
|
332 |
8c022dabd50e
(svn r9533) -Fix [FS#274]: when a company is removed (either via auto-clean, bankrupt, or take over), sell all the shares he has first, then sell the shares all people have on this company, and then remove the company.
truelight <truelight@openttd.org>
parents:
6369
diff
changeset
|
333 /* Sell all the shares that people have on this company */ |
15292
e2c62d70dfcf
(svn r19931) -Fix (r19914): Convert assertion in Backup<> destructor into DEBUG() output. It was triggered on exceptions, especially when aborting world generation.
frosch <frosch@openttd.org>
parents:
15279
diff
changeset
|
334 Backup<CompanyByte> cur_company2(_current_company, FILE_LINE); |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11730
diff
changeset
|
335 c = Company::Get(old_owner); |
6403
8c022dabd50e
(svn r9533) -Fix [FS#274]: when a company is removed (either via auto-clean, bankrupt, or take over), sell all the shares he has first, then sell the shares all people have on this company, and then remove the company.
truelight <truelight@openttd.org>
parents:
6369
diff
changeset
|
336 for (i = 0; i < 4; i++) { |
15279
4e1862aebea2
(svn r19914) -Codechange: Wrap a helper class around temporary assignments of _current_company to ensure proper restoration.
frosch <frosch@openttd.org>
parents:
15050
diff
changeset
|
337 cur_company2.Change(c->share_owners[i]); |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
338 if (_current_company != INVALID_OWNER) { |
6403
8c022dabd50e
(svn r9533) -Fix [FS#274]: when a company is removed (either via auto-clean, bankrupt, or take over), sell all the shares he has first, then sell the shares all people have on this company, and then remove the company.
truelight <truelight@openttd.org>
parents:
6369
diff
changeset
|
339 /* Sell the shares */ |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
340 CommandCost res = DoCommand(0, old_owner, 0, DC_EXEC, CMD_SELL_SHARE_IN_COMPANY); |
14136
54dfd3720fa1
(svn r18683) -Fix: it's not an other
rubidium <rubidium@openttd.org>
parents:
13998
diff
changeset
|
341 /* Because we are in a DoCommand, we can't just execute another one and |
6403
8c022dabd50e
(svn r9533) -Fix [FS#274]: when a company is removed (either via auto-clean, bankrupt, or take over), sell all the shares he has first, then sell the shares all people have on this company, and then remove the company.
truelight <truelight@openttd.org>
parents:
6369
diff
changeset
|
342 * expect the money to be removed. We need to do it ourself! */ |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
343 SubtractMoneyFromCompany(res); |
6403
8c022dabd50e
(svn r9533) -Fix [FS#274]: when a company is removed (either via auto-clean, bankrupt, or take over), sell all the shares he has first, then sell the shares all people have on this company, and then remove the company.
truelight <truelight@openttd.org>
parents:
6369
diff
changeset
|
344 } |
8c022dabd50e
(svn r9533) -Fix [FS#274]: when a company is removed (either via auto-clean, bankrupt, or take over), sell all the shares he has first, then sell the shares all people have on this company, and then remove the company.
truelight <truelight@openttd.org>
parents:
6369
diff
changeset
|
345 } |
15279
4e1862aebea2
(svn r19914) -Codechange: Wrap a helper class around temporary assignments of _current_company to ensure proper restoration.
frosch <frosch@openttd.org>
parents:
15050
diff
changeset
|
346 cur_company2.Restore(); |
6403
8c022dabd50e
(svn r9533) -Fix [FS#274]: when a company is removed (either via auto-clean, bankrupt, or take over), sell all the shares he has first, then sell the shares all people have on this company, and then remove the company.
truelight <truelight@openttd.org>
parents:
6369
diff
changeset
|
347 } |
8c022dabd50e
(svn r9533) -Fix [FS#274]: when a company is removed (either via auto-clean, bankrupt, or take over), sell all the shares he has first, then sell the shares all people have on this company, and then remove the company.
truelight <truelight@openttd.org>
parents:
6369
diff
changeset
|
348 |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
349 /* Temporarily increase the company's money, to be sure that |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
350 * removing his/her property doesn't fail because of lack of money. |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
351 * Not too drastically though, because it could overflow */ |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
352 if (new_owner == INVALID_OWNER) { |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11730
diff
changeset
|
353 Company::Get(old_owner)->money = UINT64_MAX >> 2; // jackpot ;p |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
354 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
355 |
12658
b75d8c6681bd
(svn r17113) -Change [FS#265][FS#2094][FS#2589]: apply the subsidy when subsidy's destination is in station's catchment area and cargo packets originate from subsidy's source
smatz <smatz@openttd.org>
parents:
12652
diff
changeset
|
356 Subsidy *s; |
b75d8c6681bd
(svn r17113) -Change [FS#265][FS#2094][FS#2589]: apply the subsidy when subsidy's destination is in station's catchment area and cargo packets originate from subsidy's source
smatz <smatz@openttd.org>
parents:
12652
diff
changeset
|
357 FOR_ALL_SUBSIDIES(s) { |
b75d8c6681bd
(svn r17113) -Change [FS#265][FS#2094][FS#2589]: apply the subsidy when subsidy's destination is in station's catchment area and cargo packets originate from subsidy's source
smatz <smatz@openttd.org>
parents:
12652
diff
changeset
|
358 if (s->awarded == old_owner) { |
b75d8c6681bd
(svn r17113) -Change [FS#265][FS#2094][FS#2589]: apply the subsidy when subsidy's destination is in station's catchment area and cargo packets originate from subsidy's source
smatz <smatz@openttd.org>
parents:
12652
diff
changeset
|
359 if (new_owner == INVALID_OWNER) { |
12669
406f4ae1e2ca
(svn r17124) -Codechange: store subsidies in a pool (instead of an array)
smatz <smatz@openttd.org>
parents:
12658
diff
changeset
|
360 delete s; |
12658
b75d8c6681bd
(svn r17113) -Change [FS#265][FS#2094][FS#2589]: apply the subsidy when subsidy's destination is in station's catchment area and cargo packets originate from subsidy's source
smatz <smatz@openttd.org>
parents:
12652
diff
changeset
|
361 } else { |
b75d8c6681bd
(svn r17113) -Change [FS#265][FS#2094][FS#2589]: apply the subsidy when subsidy's destination is in station's catchment area and cargo packets originate from subsidy's source
smatz <smatz@openttd.org>
parents:
12652
diff
changeset
|
362 s->awarded = new_owner; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
363 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
364 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
365 } |
12669
406f4ae1e2ca
(svn r17124) -Codechange: store subsidies in a pool (instead of an array)
smatz <smatz@openttd.org>
parents:
12658
diff
changeset
|
366 if (new_owner == INVALID_OWNER) RebuildSubsidisedSourceAndDestinationCache(); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
367 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
368 /* Take care of rating in towns */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
369 FOR_ALL_TOWNS(t) { |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
370 /* If a company takes over, give the ratings to that company. */ |
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
371 if (new_owner != INVALID_OWNER) { |
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
372 if (HasBit(t->have_ratings, old_owner)) { |
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
373 if (HasBit(t->have_ratings, new_owner)) { |
11368
82c90cd591ab
(svn r15718) -Cleanup: apply some comment coding style on the rest of the sources too
rubidium <rubidium@openttd.org>
parents:
11361
diff
changeset
|
374 /* use max of the two ratings. */ |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
375 t->ratings[new_owner] = max(t->ratings[new_owner], t->ratings[old_owner]); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
376 } else { |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
377 SetBit(t->have_ratings, new_owner); |
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
378 t->ratings[new_owner] = t->ratings[old_owner]; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
379 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
380 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
381 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
382 |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
383 /* Reset the ratings for the old owner */ |
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
384 t->ratings[old_owner] = RATING_INITIAL; |
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
385 ClrBit(t->have_ratings, old_owner); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
386 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
387 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
388 { |
10498
730117b172e1
(svn r14753) -Fix (r1): after buying a company, one could have more vehicles with the same UnitID
smatz <smatz@openttd.org>
parents:
10495
diff
changeset
|
389 FreeUnitIDGenerator unitidgen[] = { |
730117b172e1
(svn r14753) -Fix (r1): after buying a company, one could have more vehicles with the same UnitID
smatz <smatz@openttd.org>
parents:
10495
diff
changeset
|
390 FreeUnitIDGenerator(VEH_TRAIN, new_owner), FreeUnitIDGenerator(VEH_ROAD, new_owner), |
730117b172e1
(svn r14753) -Fix (r1): after buying a company, one could have more vehicles with the same UnitID
smatz <smatz@openttd.org>
parents:
10495
diff
changeset
|
391 FreeUnitIDGenerator(VEH_SHIP, new_owner), FreeUnitIDGenerator(VEH_AIRCRAFT, new_owner) |
730117b172e1
(svn r14753) -Fix (r1): after buying a company, one could have more vehicles with the same UnitID
smatz <smatz@openttd.org>
parents:
10495
diff
changeset
|
392 }; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
393 |
10498
730117b172e1
(svn r14753) -Fix (r1): after buying a company, one could have more vehicles with the same UnitID
smatz <smatz@openttd.org>
parents:
10495
diff
changeset
|
394 Vehicle *v; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
395 FOR_ALL_VEHICLES(v) { |
10492
28fa021b003c
(svn r14747) -Codechange: remove DeleteVehicleChain in favour of the vehicle destructor as that was already doing the same for a few vehicle types.
rubidium <rubidium@openttd.org>
parents:
10479
diff
changeset
|
396 if (v->owner == old_owner && IsCompanyBuildableVehicleType(v->type)) { |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
397 if (new_owner == INVALID_OWNER) { |
10492
28fa021b003c
(svn r14747) -Codechange: remove DeleteVehicleChain in favour of the vehicle destructor as that was already doing the same for a few vehicle types.
rubidium <rubidium@openttd.org>
parents:
10479
diff
changeset
|
398 if (v->Previous() == NULL) delete v; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
399 } else { |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
400 v->owner = new_owner; |
11085
8da1855e9f14
(svn r15428) -Codechange: consistently use colour instead of having both color and colour.
rubidium <rubidium@openttd.org>
parents:
11056
diff
changeset
|
401 v->colourmap = PAL_NONE; |
12383
3c7e93b91c73
(svn r16813) -Codechange: make IsEngineCountable() member of Vehicle
smatz <smatz@openttd.org>
parents:
12319
diff
changeset
|
402 if (v->IsEngineCountable()) Company::Get(new_owner)->num_engines[v->engine_type]++; |
10498
730117b172e1
(svn r14753) -Fix (r1): after buying a company, one could have more vehicles with the same UnitID
smatz <smatz@openttd.org>
parents:
10495
diff
changeset
|
403 if (v->IsPrimaryVehicle()) v->unitnumber = unitidgen[v->type].NextID(); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
404 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
405 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
406 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
407 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
408 |
6125
46d001ebacf6
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents:
6119
diff
changeset
|
409 /* Change ownership of tiles */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
410 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
411 TileIndex tile = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
412 do { |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
413 ChangeTileOwner(tile, old_owner, new_owner); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
414 } while (++tile != MapSize()); |
8200
f7f49622b3e0
(svn r11763) -Fix: update signal states after merging a company
smatz <smatz@openttd.org>
parents:
8186
diff
changeset
|
415 |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
416 if (new_owner != INVALID_OWNER) { |
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
417 /* Update all signals because there can be new segment that was owned by two companies |
8342
441cda3cfbdb
(svn r11908) -Fix: update crossing when merging a company, when building a crossing and after loading older savegame
smatz <smatz@openttd.org>
parents:
8306
diff
changeset
|
418 * and signals were not propagated |
441cda3cfbdb
(svn r11908) -Fix: update crossing when merging a company, when building a crossing and after loading older savegame
smatz <smatz@openttd.org>
parents:
8306
diff
changeset
|
419 * Similiar with crossings - it is needed to bar crossings that weren't before |
441cda3cfbdb
(svn r11908) -Fix: update crossing when merging a company, when building a crossing and after loading older savegame
smatz <smatz@openttd.org>
parents:
8306
diff
changeset
|
420 * because of different owner of crossing and approaching train */ |
8200
f7f49622b3e0
(svn r11763) -Fix: update signal states after merging a company
smatz <smatz@openttd.org>
parents:
8186
diff
changeset
|
421 tile = 0; |
f7f49622b3e0
(svn r11763) -Fix: update signal states after merging a company
smatz <smatz@openttd.org>
parents:
8186
diff
changeset
|
422 |
f7f49622b3e0
(svn r11763) -Fix: update signal states after merging a company
smatz <smatz@openttd.org>
parents:
8186
diff
changeset
|
423 do { |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
424 if (IsTileType(tile, MP_RAILWAY) && IsTileOwner(tile, new_owner) && HasSignals(tile)) { |
8200
f7f49622b3e0
(svn r11763) -Fix: update signal states after merging a company
smatz <smatz@openttd.org>
parents:
8186
diff
changeset
|
425 TrackBits tracks = GetTrackBits(tile); |
f7f49622b3e0
(svn r11763) -Fix: update signal states after merging a company
smatz <smatz@openttd.org>
parents:
8186
diff
changeset
|
426 do { // there may be two tracks with signals for TRACK_BIT_HORZ and TRACK_BIT_VERT |
f7f49622b3e0
(svn r11763) -Fix: update signal states after merging a company
smatz <smatz@openttd.org>
parents:
8186
diff
changeset
|
427 Track track = RemoveFirstTrack(&tracks); |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
428 if (HasSignalOnTrack(tile, track)) AddTrackToSignalBuffer(tile, track, new_owner); |
8200
f7f49622b3e0
(svn r11763) -Fix: update signal states after merging a company
smatz <smatz@openttd.org>
parents:
8186
diff
changeset
|
429 } while (tracks != TRACK_BIT_NONE); |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
430 } else if (IsLevelCrossingTile(tile) && IsTileOwner(tile, new_owner)) { |
8342
441cda3cfbdb
(svn r11908) -Fix: update crossing when merging a company, when building a crossing and after loading older savegame
smatz <smatz@openttd.org>
parents:
8306
diff
changeset
|
431 UpdateLevelCrossing(tile); |
8200
f7f49622b3e0
(svn r11763) -Fix: update signal states after merging a company
smatz <smatz@openttd.org>
parents:
8186
diff
changeset
|
432 } |
f7f49622b3e0
(svn r11763) -Fix: update signal states after merging a company
smatz <smatz@openttd.org>
parents:
8186
diff
changeset
|
433 } while (++tile != MapSize()); |
8347
a83dd50f52f9
(svn r11913) -Fix (r11871): update signals after company bankrupt and disaster too
smatz <smatz@openttd.org>
parents:
8342
diff
changeset
|
434 } |
8306
ea2c123b3655
(svn r11871) -Fix [FS#1074]: do not update signals after each tile when building/removing a large block of track/signals/station
smatz <smatz@openttd.org>
parents:
8302
diff
changeset
|
435 |
8347
a83dd50f52f9
(svn r11913) -Fix (r11871): update signals after company bankrupt and disaster too
smatz <smatz@openttd.org>
parents:
8342
diff
changeset
|
436 /* update signals in buffer */ |
a83dd50f52f9
(svn r11913) -Fix (r11871): update signals after company bankrupt and disaster too
smatz <smatz@openttd.org>
parents:
8342
diff
changeset
|
437 UpdateSignalsInBuffer(); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
438 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
439 |
11234
6ebdffe6e5e6
(svn r15588) -Fix: change owner of waypoints and deleted stations when merging companies or when a company benkrupts
smatz <smatz@openttd.org>
parents:
11221
diff
changeset
|
440 /* convert owner of stations (including deleted ones, but excluding buoys) */ |
6ebdffe6e5e6
(svn r15588) -Fix: change owner of waypoints and deleted stations when merging companies or when a company benkrupts
smatz <smatz@openttd.org>
parents:
11221
diff
changeset
|
441 Station *st; |
6ebdffe6e5e6
(svn r15588) -Fix: change owner of waypoints and deleted stations when merging companies or when a company benkrupts
smatz <smatz@openttd.org>
parents:
11221
diff
changeset
|
442 FOR_ALL_STATIONS(st) { |
6ebdffe6e5e6
(svn r15588) -Fix: change owner of waypoints and deleted stations when merging companies or when a company benkrupts
smatz <smatz@openttd.org>
parents:
11221
diff
changeset
|
443 if (st->owner == old_owner) { |
6ebdffe6e5e6
(svn r15588) -Fix: change owner of waypoints and deleted stations when merging companies or when a company benkrupts
smatz <smatz@openttd.org>
parents:
11221
diff
changeset
|
444 /* if a company goes bankrupt, set owner to OWNER_NONE so the sign doesn't disappear immediately |
6ebdffe6e5e6
(svn r15588) -Fix: change owner of waypoints and deleted stations when merging companies or when a company benkrupts
smatz <smatz@openttd.org>
parents:
11221
diff
changeset
|
445 * also, drawing station window would cause reading invalid company's colour */ |
6ebdffe6e5e6
(svn r15588) -Fix: change owner of waypoints and deleted stations when merging companies or when a company benkrupts
smatz <smatz@openttd.org>
parents:
11221
diff
changeset
|
446 st->owner = new_owner == INVALID_OWNER ? OWNER_NONE : new_owner; |
6ebdffe6e5e6
(svn r15588) -Fix: change owner of waypoints and deleted stations when merging companies or when a company benkrupts
smatz <smatz@openttd.org>
parents:
11221
diff
changeset
|
447 } |
6ebdffe6e5e6
(svn r15588) -Fix: change owner of waypoints and deleted stations when merging companies or when a company benkrupts
smatz <smatz@openttd.org>
parents:
11221
diff
changeset
|
448 } |
6ebdffe6e5e6
(svn r15588) -Fix: change owner of waypoints and deleted stations when merging companies or when a company benkrupts
smatz <smatz@openttd.org>
parents:
11221
diff
changeset
|
449 |
6ebdffe6e5e6
(svn r15588) -Fix: change owner of waypoints and deleted stations when merging companies or when a company benkrupts
smatz <smatz@openttd.org>
parents:
11221
diff
changeset
|
450 /* do the same for waypoints (we need to do this here so deleted waypoints are converted too) */ |
6ebdffe6e5e6
(svn r15588) -Fix: change owner of waypoints and deleted stations when merging companies or when a company benkrupts
smatz <smatz@openttd.org>
parents:
11221
diff
changeset
|
451 Waypoint *wp; |
6ebdffe6e5e6
(svn r15588) -Fix: change owner of waypoints and deleted stations when merging companies or when a company benkrupts
smatz <smatz@openttd.org>
parents:
11221
diff
changeset
|
452 FOR_ALL_WAYPOINTS(wp) { |
6ebdffe6e5e6
(svn r15588) -Fix: change owner of waypoints and deleted stations when merging companies or when a company benkrupts
smatz <smatz@openttd.org>
parents:
11221
diff
changeset
|
453 if (wp->owner == old_owner) { |
6ebdffe6e5e6
(svn r15588) -Fix: change owner of waypoints and deleted stations when merging companies or when a company benkrupts
smatz <smatz@openttd.org>
parents:
11221
diff
changeset
|
454 wp->owner = new_owner == INVALID_OWNER ? OWNER_NONE : new_owner; |
6ebdffe6e5e6
(svn r15588) -Fix: change owner of waypoints and deleted stations when merging companies or when a company benkrupts
smatz <smatz@openttd.org>
parents:
11221
diff
changeset
|
455 } |
6ebdffe6e5e6
(svn r15588) -Fix: change owner of waypoints and deleted stations when merging companies or when a company benkrupts
smatz <smatz@openttd.org>
parents:
11221
diff
changeset
|
456 } |
6ebdffe6e5e6
(svn r15588) -Fix: change owner of waypoints and deleted stations when merging companies or when a company benkrupts
smatz <smatz@openttd.org>
parents:
11221
diff
changeset
|
457 |
9058
c73011639858
(svn r12906) -Fix: vehicle groups, engine replacement rules and player/company names were not properly reset/freed after bankrupt (before new player start)
smatz <smatz@openttd.org>
parents:
9043
diff
changeset
|
458 /* In all cases clear replace engine rules. |
c73011639858
(svn r12906) -Fix: vehicle groups, engine replacement rules and player/company names were not properly reset/freed after bankrupt (before new player start)
smatz <smatz@openttd.org>
parents:
9043
diff
changeset
|
459 * Even if it was copied, it could interfere with new owner's rules */ |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11730
diff
changeset
|
460 RemoveAllEngineReplacementForCompany(Company::Get(old_owner)); |
9058
c73011639858
(svn r12906) -Fix: vehicle groups, engine replacement rules and player/company names were not properly reset/freed after bankrupt (before new player start)
smatz <smatz@openttd.org>
parents:
9043
diff
changeset
|
461 |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
462 if (new_owner == INVALID_OWNER) { |
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
463 RemoveAllGroupsForCompany(old_owner); |
9058
c73011639858
(svn r12906) -Fix: vehicle groups, engine replacement rules and player/company names were not properly reset/freed after bankrupt (before new player start)
smatz <smatz@openttd.org>
parents:
9043
diff
changeset
|
464 } else { |
c73011639858
(svn r12906) -Fix: vehicle groups, engine replacement rules and player/company names were not properly reset/freed after bankrupt (before new player start)
smatz <smatz@openttd.org>
parents:
9043
diff
changeset
|
465 Group *g; |
c73011639858
(svn r12906) -Fix: vehicle groups, engine replacement rules and player/company names were not properly reset/freed after bankrupt (before new player start)
smatz <smatz@openttd.org>
parents:
9043
diff
changeset
|
466 FOR_ALL_GROUPS(g) { |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
467 if (g->owner == old_owner) g->owner = new_owner; |
9058
c73011639858
(svn r12906) -Fix: vehicle groups, engine replacement rules and player/company names were not properly reset/freed after bankrupt (before new player start)
smatz <smatz@openttd.org>
parents:
9043
diff
changeset
|
468 } |
c73011639858
(svn r12906) -Fix: vehicle groups, engine replacement rules and player/company names were not properly reset/freed after bankrupt (before new player start)
smatz <smatz@openttd.org>
parents:
9043
diff
changeset
|
469 } |
c73011639858
(svn r12906) -Fix: vehicle groups, engine replacement rules and player/company names were not properly reset/freed after bankrupt (before new player start)
smatz <smatz@openttd.org>
parents:
9043
diff
changeset
|
470 |
10158
c429fccf1aea
(svn r14348) -Fix (r1667): signs were not updated on company bankrupcy/sell, they have colour of invalid player
smatz <smatz@openttd.org>
parents:
10146
diff
changeset
|
471 Sign *si; |
c429fccf1aea
(svn r14348) -Fix (r1667): signs were not updated on company bankrupcy/sell, they have colour of invalid player
smatz <smatz@openttd.org>
parents:
10146
diff
changeset
|
472 FOR_ALL_SIGNS(si) { |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
473 if (si->owner == old_owner) si->owner = new_owner == INVALID_OWNER ? OWNER_NONE : new_owner; |
10158
c429fccf1aea
(svn r14348) -Fix (r1667): signs were not updated on company bankrupcy/sell, they have colour of invalid player
smatz <smatz@openttd.org>
parents:
10146
diff
changeset
|
474 } |
c429fccf1aea
(svn r14348) -Fix (r1667): signs were not updated on company bankrupcy/sell, they have colour of invalid player
smatz <smatz@openttd.org>
parents:
10146
diff
changeset
|
475 |
11085
8da1855e9f14
(svn r15428) -Codechange: consistently use colour instead of having both color and colour.
rubidium <rubidium@openttd.org>
parents:
11056
diff
changeset
|
476 /* Change colour of existing windows */ |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
477 if (new_owner != INVALID_OWNER) ChangeWindowOwner(old_owner, new_owner); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
478 |
15279
4e1862aebea2
(svn r19914) -Codechange: Wrap a helper class around temporary assignments of _current_company to ensure proper restoration.
frosch <frosch@openttd.org>
parents:
15050
diff
changeset
|
479 cur_company.Restore(); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
480 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
481 MarkWholeScreenDirty(); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
482 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
483 |
15653
930fc2895ced
(svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents:
15652
diff
changeset
|
484 /** |
930fc2895ced
(svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents:
15652
diff
changeset
|
485 * Check for bankruptcy of a company. Called every three months. |
930fc2895ced
(svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents:
15652
diff
changeset
|
486 * @param c Company to check. |
930fc2895ced
(svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents:
15652
diff
changeset
|
487 */ |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
488 static void CompanyCheckBankrupt(Company *c) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
489 { |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
490 /* If the company has money again, it does not go bankrupt */ |
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
491 if (c->money >= 0) { |
12853
a1d8c582ef59
(svn r17343) -Codechange: it's bankruptcy, not bankrupcy, according to my Oxford Dictionary of English and Merriam-Webster.
rubidium <rubidium@openttd.org>
parents:
12852
diff
changeset
|
492 c->quarters_of_bankruptcy = 0; |
12852
c8f80b97fd61
(svn r17342) -Fix: reset bankruptcy checks when bankruptcy has been averted and don't set an unused timeout with a magic number
rubidium <rubidium@openttd.org>
parents:
12851
diff
changeset
|
493 c->bankrupt_asked = 0; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
494 return; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
495 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
496 |
12853
a1d8c582ef59
(svn r17343) -Codechange: it's bankruptcy, not bankrupcy, according to my Oxford Dictionary of English and Merriam-Webster.
rubidium <rubidium@openttd.org>
parents:
12852
diff
changeset
|
497 c->quarters_of_bankruptcy++; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
498 |
9658
27697e657d2e
(svn r13730) -Fix: make a copy of the names for news messages about the deletion of companies as the removal of a company could lead to wrong names in the news messages.
rubidium <rubidium@openttd.org>
parents:
9652
diff
changeset
|
499 CompanyNewsInformation *cni = MallocT<CompanyNewsInformation>(1); |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
500 cni->FillData(c); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
501 |
12853
a1d8c582ef59
(svn r17343) -Codechange: it's bankruptcy, not bankrupcy, according to my Oxford Dictionary of English and Merriam-Webster.
rubidium <rubidium@openttd.org>
parents:
12852
diff
changeset
|
502 switch (c->quarters_of_bankruptcy) { |
10495
dd7d08e0ff23
(svn r14750) -Fix [FS#1993]: in an MP game in SP mode no company would go bankrupt. Furthermore companies that passed the "bankrupt" period (4 quarters) wouldn't go bankrupt when loading the game back in MP. Now any company that is in MP or not "currently controlled by the player" in SP will bankrupt.
rubidium <rubidium@openttd.org>
parents:
10493
diff
changeset
|
503 case 0: |
dd7d08e0ff23
(svn r14750) -Fix [FS#1993]: in an MP game in SP mode no company would go bankrupt. Furthermore companies that passed the "bankrupt" period (4 quarters) wouldn't go bankrupt when loading the game back in MP. Now any company that is in MP or not "currently controlled by the player" in SP will bankrupt.
rubidium <rubidium@openttd.org>
parents:
10493
diff
changeset
|
504 case 1: |
9658
27697e657d2e
(svn r13730) -Fix: make a copy of the names for news messages about the deletion of companies as the removal of a company could lead to wrong names in the news messages.
rubidium <rubidium@openttd.org>
parents:
9652
diff
changeset
|
505 free(cni); |
27697e657d2e
(svn r13730) -Fix: make a copy of the names for news messages about the deletion of companies as the removal of a company could lead to wrong names in the news messages.
rubidium <rubidium@openttd.org>
parents:
9652
diff
changeset
|
506 break; |
27697e657d2e
(svn r13730) -Fix: make a copy of the names for news messages about the deletion of companies as the removal of a company could lead to wrong names in the news messages.
rubidium <rubidium@openttd.org>
parents:
9652
diff
changeset
|
507 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
508 case 2: |
11730
a39da1e4c1f5
(svn r16118) -Change/cleanup: remove the hexadecimal 'in TTD the string had this ID' from 'some' strings and replace the string name with something more sensible.
rubidium <rubidium@openttd.org>
parents:
11376
diff
changeset
|
509 SetDParam(0, STR_NEWS_COMPANY_IN_TROUBLE_TITLE); |
a39da1e4c1f5
(svn r16118) -Change/cleanup: remove the hexadecimal 'in TTD the string had this ID' from 'some' strings and replace the string name with something more sensible.
rubidium <rubidium@openttd.org>
parents:
11376
diff
changeset
|
510 SetDParam(1, STR_NEWS_COMPANY_IN_TROUBLE_DESCRIPTION); |
9658
27697e657d2e
(svn r13730) -Fix: make a copy of the names for news messages about the deletion of companies as the removal of a company could lead to wrong names in the news messages.
rubidium <rubidium@openttd.org>
parents:
9652
diff
changeset
|
511 SetDParamStr(2, cni->company_name); |
12632
e41943276802
(svn r17075) -Codechange: rename ~750 strings to be more uniform with their relatives
rubidium <rubidium@openttd.org>
parents:
12615
diff
changeset
|
512 AddCompanyNewsItem(STR_MESSAGE_NEWS_FORMAT, NS_COMPANY_TROUBLE, cni); |
10696
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
10647
diff
changeset
|
513 AI::BroadcastNewEvent(new AIEventCompanyInTrouble(c->index)); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
514 break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
515 case 3: { |
6125
46d001ebacf6
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents:
6119
diff
changeset
|
516 /* Check if the company has any value.. if not, declare it bankrupt |
46d001ebacf6
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents:
6119
diff
changeset
|
517 * right now */ |
14353
098ac3e84f3b
(svn r18908) -Fix [FS#3561]: on bankruptcy the company value did include the loan and as such the value at which you bought the company was too low
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
518 Money val = CalculateCompanyValue(c, false); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
519 if (val > 0) { |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
520 c->bankrupt_value = val; |
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
521 c->bankrupt_asked = 1 << c->index; // Don't ask the owner |
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
522 c->bankrupt_timeout = 0; |
9658
27697e657d2e
(svn r13730) -Fix: make a copy of the names for news messages about the deletion of companies as the removal of a company could lead to wrong names in the news messages.
rubidium <rubidium@openttd.org>
parents:
9652
diff
changeset
|
523 free(cni); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
524 break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
525 } |
15655
0be6e9a4ca0b
(svn r20320) -Doc: Small Doxygen and normal comment fixes, and an missed addition.
alberth <alberth@openttd.org>
parents:
15654
diff
changeset
|
526 /* FALL THROUGH to case 4... */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
527 } |
10495
dd7d08e0ff23
(svn r14750) -Fix [FS#1993]: in an MP game in SP mode no company would go bankrupt. Furthermore companies that passed the "bankrupt" period (4 quarters) wouldn't go bankrupt when loading the game back in MP. Now any company that is in MP or not "currently controlled by the player" in SP will bankrupt.
rubidium <rubidium@openttd.org>
parents:
10493
diff
changeset
|
528 default: |
dd7d08e0ff23
(svn r14750) -Fix [FS#1993]: in an MP game in SP mode no company would go bankrupt. Furthermore companies that passed the "bankrupt" period (4 quarters) wouldn't go bankrupt when loading the game back in MP. Now any company that is in MP or not "currently controlled by the player" in SP will bankrupt.
rubidium <rubidium@openttd.org>
parents:
10493
diff
changeset
|
529 case 4: |
dd7d08e0ff23
(svn r14750) -Fix [FS#1993]: in an MP game in SP mode no company would go bankrupt. Furthermore companies that passed the "bankrupt" period (4 quarters) wouldn't go bankrupt when loading the game back in MP. Now any company that is in MP or not "currently controlled by the player" in SP will bankrupt.
rubidium <rubidium@openttd.org>
parents:
10493
diff
changeset
|
530 if (!_networking && _local_company == c->index) { |
dd7d08e0ff23
(svn r14750) -Fix [FS#1993]: in an MP game in SP mode no company would go bankrupt. Furthermore companies that passed the "bankrupt" period (4 quarters) wouldn't go bankrupt when loading the game back in MP. Now any company that is in MP or not "currently controlled by the player" in SP will bankrupt.
rubidium <rubidium@openttd.org>
parents:
10493
diff
changeset
|
531 /* If we are in offline mode, leave the company playing. Eg. there |
dd7d08e0ff23
(svn r14750) -Fix [FS#1993]: in an MP game in SP mode no company would go bankrupt. Furthermore companies that passed the "bankrupt" period (4 quarters) wouldn't go bankrupt when loading the game back in MP. Now any company that is in MP or not "currently controlled by the player" in SP will bankrupt.
rubidium <rubidium@openttd.org>
parents:
10493
diff
changeset
|
532 * is no THE-END, otherwise mark the client as spectator to make sure |
dd7d08e0ff23
(svn r14750) -Fix [FS#1993]: in an MP game in SP mode no company would go bankrupt. Furthermore companies that passed the "bankrupt" period (4 quarters) wouldn't go bankrupt when loading the game back in MP. Now any company that is in MP or not "currently controlled by the player" in SP will bankrupt.
rubidium <rubidium@openttd.org>
parents:
10493
diff
changeset
|
533 * he/she is no long in control of this company. However... when you |
dd7d08e0ff23
(svn r14750) -Fix [FS#1993]: in an MP game in SP mode no company would go bankrupt. Furthermore companies that passed the "bankrupt" period (4 quarters) wouldn't go bankrupt when loading the game back in MP. Now any company that is in MP or not "currently controlled by the player" in SP will bankrupt.
rubidium <rubidium@openttd.org>
parents:
10493
diff
changeset
|
534 * join another company (cheat) the "unowned" company can bankrupt. */ |
dd7d08e0ff23
(svn r14750) -Fix [FS#1993]: in an MP game in SP mode no company would go bankrupt. Furthermore companies that passed the "bankrupt" period (4 quarters) wouldn't go bankrupt when loading the game back in MP. Now any company that is in MP or not "currently controlled by the player" in SP will bankrupt.
rubidium <rubidium@openttd.org>
parents:
10493
diff
changeset
|
535 c->bankrupt_asked = MAX_UVALUE(CompanyMask); |
12851
a398faeb024e
(svn r17341) -Fix: memory leak when trying to bankrupt the local company
rubidium <rubidium@openttd.org>
parents:
12826
diff
changeset
|
536 free(cni); |
10495
dd7d08e0ff23
(svn r14750) -Fix [FS#1993]: in an MP game in SP mode no company would go bankrupt. Furthermore companies that passed the "bankrupt" period (4 quarters) wouldn't go bankrupt when loading the game back in MP. Now any company that is in MP or not "currently controlled by the player" in SP will bankrupt.
rubidium <rubidium@openttd.org>
parents:
10493
diff
changeset
|
537 break; |
dd7d08e0ff23
(svn r14750) -Fix [FS#1993]: in an MP game in SP mode no company would go bankrupt. Furthermore companies that passed the "bankrupt" period (4 quarters) wouldn't go bankrupt when loading the game back in MP. Now any company that is in MP or not "currently controlled by the player" in SP will bankrupt.
rubidium <rubidium@openttd.org>
parents:
10493
diff
changeset
|
538 } |
dd7d08e0ff23
(svn r14750) -Fix [FS#1993]: in an MP game in SP mode no company would go bankrupt. Furthermore companies that passed the "bankrupt" period (4 quarters) wouldn't go bankrupt when loading the game back in MP. Now any company that is in MP or not "currently controlled by the player" in SP will bankrupt.
rubidium <rubidium@openttd.org>
parents:
10493
diff
changeset
|
539 |
6125
46d001ebacf6
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents:
6119
diff
changeset
|
540 /* Close everything the owner has open */ |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
541 DeleteCompanyWindows(c->index); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
542 |
6125
46d001ebacf6
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents:
6119
diff
changeset
|
543 /* Show bankrupt news */ |
11730
a39da1e4c1f5
(svn r16118) -Change/cleanup: remove the hexadecimal 'in TTD the string had this ID' from 'some' strings and replace the string name with something more sensible.
rubidium <rubidium@openttd.org>
parents:
11376
diff
changeset
|
544 SetDParam(0, STR_NEWS_COMPANY_BANKRUPT_TITLE); |
a39da1e4c1f5
(svn r16118) -Change/cleanup: remove the hexadecimal 'in TTD the string had this ID' from 'some' strings and replace the string name with something more sensible.
rubidium <rubidium@openttd.org>
parents:
11376
diff
changeset
|
545 SetDParam(1, STR_NEWS_COMPANY_BANKRUPT_DESCRIPTION); |
9658
27697e657d2e
(svn r13730) -Fix: make a copy of the names for news messages about the deletion of companies as the removal of a company could lead to wrong names in the news messages.
rubidium <rubidium@openttd.org>
parents:
9652
diff
changeset
|
546 SetDParamStr(2, cni->company_name); |
12632
e41943276802
(svn r17075) -Codechange: rename ~750 strings to be more uniform with their relatives
rubidium <rubidium@openttd.org>
parents:
12615
diff
changeset
|
547 AddCompanyNewsItem(STR_MESSAGE_NEWS_FORMAT, NS_COMPANY_BANKRUPT, cni); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
548 |
10495
dd7d08e0ff23
(svn r14750) -Fix [FS#1993]: in an MP game in SP mode no company would go bankrupt. Furthermore companies that passed the "bankrupt" period (4 quarters) wouldn't go bankrupt when loading the game back in MP. Now any company that is in MP or not "currently controlled by the player" in SP will bankrupt.
rubidium <rubidium@openttd.org>
parents:
10493
diff
changeset
|
549 ChangeOwnershipOfCompanyItems(c->index, INVALID_OWNER); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
550 |
12143
20abba1d6d18
(svn r16559) -Codechange: introduce Company::IsValidAiID() and Company::IsValidHumanID(), don't use IsHumanCompany() where possible
smatz <smatz@openttd.org>
parents:
12114
diff
changeset
|
551 if (c->is_ai) AI::Stop(c->index); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
552 |
10696
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
10647
diff
changeset
|
553 CompanyID c_index = c->index; |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
554 delete c; |
10696
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
10647
diff
changeset
|
555 AI::BroadcastNewEvent(new AIEventCompanyBankrupt(c_index)); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
556 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
557 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
558 |
15653
930fc2895ced
(svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents:
15652
diff
changeset
|
559 /** |
930fc2895ced
(svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents:
15652
diff
changeset
|
560 * Update the finances of all companies. |
930fc2895ced
(svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents:
15652
diff
changeset
|
561 * Pay for the stations, update the history graph, update ratings and company values, and deal with bankruptcy. |
930fc2895ced
(svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents:
15652
diff
changeset
|
562 */ |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
563 static void CompaniesGenStatistics() |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
564 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
565 Station *st; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
566 |
15292
e2c62d70dfcf
(svn r19931) -Fix (r19914): Convert assertion in Backup<> destructor into DEBUG() output. It was triggered on exceptions, especially when aborting world generation.
frosch <frosch@openttd.org>
parents:
15279
diff
changeset
|
567 Backup<CompanyByte> cur_company(_current_company, FILE_LINE); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
568 FOR_ALL_STATIONS(st) { |
15279
4e1862aebea2
(svn r19914) -Codechange: Wrap a helper class around temporary assignments of _current_company to ensure proper restoration.
frosch <frosch@openttd.org>
parents:
15050
diff
changeset
|
569 cur_company.Change(st->owner); |
13486
f2535c5098a0
(svn r18005) -Codechange: Convert the Prices struct into an array and an enum.
frosch <frosch@openttd.org>
parents:
13466
diff
changeset
|
570 CommandCost cost(EXPENSES_PROPERTY, _price[PR_STATION_VALUE] >> 1); |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
571 SubtractMoneyFromCompany(cost); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
572 } |
15279
4e1862aebea2
(svn r19914) -Codechange: Wrap a helper class around temporary assignments of _current_company to ensure proper restoration.
frosch <frosch@openttd.org>
parents:
15050
diff
changeset
|
573 cur_company.Restore(); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
574 |
15552
683f2dbe75bb
(svn r20211) -Codechange: Indented code should have curly braces around it.
alberth <alberth@openttd.org>
parents:
15511
diff
changeset
|
575 if (!HasBit(1 << 0 | 1 << 3 | 1 << 6 | 1 << 9, _cur_month)) return; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
576 |
15652
354307d245e5
(svn r20317) -Codechange: Move variable declaration to their first use.
alberth <alberth@openttd.org>
parents:
15623
diff
changeset
|
577 Company *c; |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
578 FOR_ALL_COMPANIES(c) { |
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
579 memmove(&c->old_economy[1], &c->old_economy[0], sizeof(c->old_economy) - sizeof(c->old_economy[0])); |
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
580 c->old_economy[0] = c->cur_economy; |
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
581 memset(&c->cur_economy, 0, sizeof(c->cur_economy)); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
582 |
12615
5f44b757d251
(svn r17058) -Codechange: magic numbers removal.
belugas <belugas@openttd.org>
parents:
12594
diff
changeset
|
583 if (c->num_valid_stat_ent != MAX_HISTORY_MONTHS) c->num_valid_stat_ent++; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
584 |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
585 UpdateCompanyRatingAndValue(c, true); |
12046
da0c682ff327
(svn r16453) -Fix: Move some code around so a company is no longer used after deleting it
yexo <yexo@openttd.org>
parents:
12010
diff
changeset
|
586 if (c->block_preview != 0) c->block_preview--; |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
587 CompanyCheckBankrupt(c); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
588 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
589 |
13034
6eb3f749890a
(svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents:
12991
diff
changeset
|
590 SetWindowDirty(WC_INCOME_GRAPH, 0); |
6eb3f749890a
(svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents:
12991
diff
changeset
|
591 SetWindowDirty(WC_OPERATING_PROFIT, 0); |
6eb3f749890a
(svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents:
12991
diff
changeset
|
592 SetWindowDirty(WC_DELIVERED_CARGO, 0); |
6eb3f749890a
(svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents:
12991
diff
changeset
|
593 SetWindowDirty(WC_PERFORMANCE_HISTORY, 0); |
6eb3f749890a
(svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents:
12991
diff
changeset
|
594 SetWindowDirty(WC_COMPANY_VALUE, 0); |
6eb3f749890a
(svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents:
12991
diff
changeset
|
595 SetWindowDirty(WC_COMPANY_LEAGUE, 0); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
596 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
597 |
12940
1b090e0c4f93
(svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents:
12933
diff
changeset
|
598 /** |
1b090e0c4f93
(svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents:
12933
diff
changeset
|
599 * Add monthly inflation |
1b090e0c4f93
(svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents:
12933
diff
changeset
|
600 * @param check_year Shall the inflation get stopped after 170 years? |
1b090e0c4f93
(svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents:
12933
diff
changeset
|
601 */ |
1b090e0c4f93
(svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents:
12933
diff
changeset
|
602 void AddInflation(bool check_year) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
603 { |
7244
00f3d8da22e4
(svn r10541) -Fix [FS#1028]: cargo payment rates overflow.
rubidium <rubidium@openttd.org>
parents:
7229
diff
changeset
|
604 /* The cargo payment inflation differs from the normal inflation, so the |
00f3d8da22e4
(svn r10541) -Fix [FS#1028]: cargo payment rates overflow.
rubidium <rubidium@openttd.org>
parents:
7229
diff
changeset
|
605 * relative amount of money you make with a transport decreases slowly over |
00f3d8da22e4
(svn r10541) -Fix [FS#1028]: cargo payment rates overflow.
rubidium <rubidium@openttd.org>
parents:
7229
diff
changeset
|
606 * the 170 years. After a few hundred years we reach a level in which the |
00f3d8da22e4
(svn r10541) -Fix [FS#1028]: cargo payment rates overflow.
rubidium <rubidium@openttd.org>
parents:
7229
diff
changeset
|
607 * games will become unplayable as the maximum income will be less than |
00f3d8da22e4
(svn r10541) -Fix [FS#1028]: cargo payment rates overflow.
rubidium <rubidium@openttd.org>
parents:
7229
diff
changeset
|
608 * the minimum running cost. |
00f3d8da22e4
(svn r10541) -Fix [FS#1028]: cargo payment rates overflow.
rubidium <rubidium@openttd.org>
parents:
7229
diff
changeset
|
609 * |
00f3d8da22e4
(svn r10541) -Fix [FS#1028]: cargo payment rates overflow.
rubidium <rubidium@openttd.org>
parents:
7229
diff
changeset
|
610 * Furthermore there are a lot of inflation related overflows all over the |
00f3d8da22e4
(svn r10541) -Fix [FS#1028]: cargo payment rates overflow.
rubidium <rubidium@openttd.org>
parents:
7229
diff
changeset
|
611 * place. Solving them is hardly possible because inflation will always |
00f3d8da22e4
(svn r10541) -Fix [FS#1028]: cargo payment rates overflow.
rubidium <rubidium@openttd.org>
parents:
7229
diff
changeset
|
612 * reach the overflow threshold some day. So we'll just perform the |
00f3d8da22e4
(svn r10541) -Fix [FS#1028]: cargo payment rates overflow.
rubidium <rubidium@openttd.org>
parents:
7229
diff
changeset
|
613 * inflation mechanism during the first 170 years (the amount of years that |
00f3d8da22e4
(svn r10541) -Fix [FS#1028]: cargo payment rates overflow.
rubidium <rubidium@openttd.org>
parents:
7229
diff
changeset
|
614 * one had in the original TTD) and stop doing the inflation after that |
00f3d8da22e4
(svn r10541) -Fix [FS#1028]: cargo payment rates overflow.
rubidium <rubidium@openttd.org>
parents:
7229
diff
changeset
|
615 * because it only causes problems that can't be solved nicely and the |
00f3d8da22e4
(svn r10541) -Fix [FS#1028]: cargo payment rates overflow.
rubidium <rubidium@openttd.org>
parents:
7229
diff
changeset
|
616 * inflation doesn't add anything after that either; it even makes playing |
00f3d8da22e4
(svn r10541) -Fix [FS#1028]: cargo payment rates overflow.
rubidium <rubidium@openttd.org>
parents:
7229
diff
changeset
|
617 * it impossible due to the diverging cost and income rates. |
00f3d8da22e4
(svn r10541) -Fix [FS#1028]: cargo payment rates overflow.
rubidium <rubidium@openttd.org>
parents:
7229
diff
changeset
|
618 */ |
9717
57549f1e5133
(svn r13836) -Fix [FS#2074]: Automatically recalculate inflation if NewGRFs are changed and cargo types are added, so that cargo payment rates are correct.
peter1138 <peter1138@openttd.org>
parents:
9659
diff
changeset
|
619 if (check_year && (_cur_year - _settings_game.game_creation.starting_year) >= (ORIGINAL_MAX_YEAR - ORIGINAL_BASE_YEAR)) return; |
7244
00f3d8da22e4
(svn r10541) -Fix [FS#1028]: cargo payment rates overflow.
rubidium <rubidium@openttd.org>
parents:
7229
diff
changeset
|
620 |
6119 | 621 /* Approximation for (100 + infl_amount)% ** (1 / 12) - 100% |
622 * scaled by 65536 | |
623 * 12 -> months per year | |
624 * This is only a good approxiamtion for small values | |
625 */ | |
12940
1b090e0c4f93
(svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents:
12933
diff
changeset
|
626 _economy.inflation_prices += min((_economy.inflation_prices * _economy.infl_amount * 54) >> 16, MAX_INFLATION); |
1b090e0c4f93
(svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents:
12933
diff
changeset
|
627 _economy.inflation_payment += min((_economy.inflation_payment * _economy.infl_amount_pr * 54) >> 16, MAX_INFLATION); |
1b090e0c4f93
(svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents:
12933
diff
changeset
|
628 } |
1b090e0c4f93
(svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents:
12933
diff
changeset
|
629 |
1b090e0c4f93
(svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents:
12933
diff
changeset
|
630 /** |
1b090e0c4f93
(svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents:
12933
diff
changeset
|
631 * Computes all prices, payments and maximum loan. |
1b090e0c4f93
(svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents:
12933
diff
changeset
|
632 */ |
1b090e0c4f93
(svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents:
12933
diff
changeset
|
633 void RecomputePrices() |
1b090e0c4f93
(svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents:
12933
diff
changeset
|
634 { |
1b090e0c4f93
(svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents:
12933
diff
changeset
|
635 /* Setup maximum loan */ |
1b090e0c4f93
(svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents:
12933
diff
changeset
|
636 _economy.max_loan = (_settings_game.difficulty.max_loan * _economy.inflation_prices >> 16) / 50000 * 50000; |
1b090e0c4f93
(svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents:
12933
diff
changeset
|
637 |
1b090e0c4f93
(svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents:
12933
diff
changeset
|
638 /* Setup price bases */ |
13489
afa5c1a70640
(svn r18008) -Codechange: Rename NUM_PRICES to PR_END, and use the Price enum some more.
frosch <frosch@openttd.org>
parents:
13486
diff
changeset
|
639 for (Price i = PR_BEGIN; i < PR_END; i++) { |
12940
1b090e0c4f93
(svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents:
12933
diff
changeset
|
640 Money price = _price_base_specs[i].start_price; |
1b090e0c4f93
(svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents:
12933
diff
changeset
|
641 |
1b090e0c4f93
(svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents:
12933
diff
changeset
|
642 /* Apply difficulty settings */ |
1b090e0c4f93
(svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents:
12933
diff
changeset
|
643 uint mod = 1; |
1b090e0c4f93
(svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents:
12933
diff
changeset
|
644 switch (_price_base_specs[i].category) { |
1b090e0c4f93
(svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents:
12933
diff
changeset
|
645 case PCAT_RUNNING: |
1b090e0c4f93
(svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents:
12933
diff
changeset
|
646 mod = _settings_game.difficulty.vehicle_costs; |
1b090e0c4f93
(svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents:
12933
diff
changeset
|
647 break; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
648 |
12940
1b090e0c4f93
(svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents:
12933
diff
changeset
|
649 case PCAT_CONSTRUCTION: |
1b090e0c4f93
(svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents:
12933
diff
changeset
|
650 mod = _settings_game.difficulty.construction_cost; |
1b090e0c4f93
(svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents:
12933
diff
changeset
|
651 break; |
1b090e0c4f93
(svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents:
12933
diff
changeset
|
652 |
1b090e0c4f93
(svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents:
12933
diff
changeset
|
653 default: break; |
1b090e0c4f93
(svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents:
12933
diff
changeset
|
654 } |
1b090e0c4f93
(svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents:
12933
diff
changeset
|
655 if (mod < 1) { |
1b090e0c4f93
(svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents:
12933
diff
changeset
|
656 price = price * 3 >> 2; |
1b090e0c4f93
(svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents:
12933
diff
changeset
|
657 } else if (mod > 1) { |
1b090e0c4f93
(svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents:
12933
diff
changeset
|
658 price = price * 9 >> 3; |
1b090e0c4f93
(svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents:
12933
diff
changeset
|
659 } |
1b090e0c4f93
(svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents:
12933
diff
changeset
|
660 |
1b090e0c4f93
(svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents:
12933
diff
changeset
|
661 /* Apply inflation */ |
1b090e0c4f93
(svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents:
12933
diff
changeset
|
662 price = (int64)price * _economy.inflation_prices; |
1b090e0c4f93
(svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents:
12933
diff
changeset
|
663 |
1b090e0c4f93
(svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents:
12933
diff
changeset
|
664 /* Apply newgrf modifiers, and remove fractional part of inflation */ |
13497
a378bbea4ddb
(svn r18016) -Codechange: Move the arbitrary basecost multiplier offset (8) to newgrf loading and make the internal state zero-based instead.
frosch <frosch@openttd.org>
parents:
13489
diff
changeset
|
665 int shift = _price_base_multiplier[i] - 16; |
12940
1b090e0c4f93
(svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents:
12933
diff
changeset
|
666 if (shift >= 0) { |
1b090e0c4f93
(svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents:
12933
diff
changeset
|
667 price <<= shift; |
1b090e0c4f93
(svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents:
12933
diff
changeset
|
668 } else { |
1b090e0c4f93
(svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents:
12933
diff
changeset
|
669 price >>= -shift; |
1b090e0c4f93
(svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents:
12933
diff
changeset
|
670 } |
1b090e0c4f93
(svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents:
12933
diff
changeset
|
671 |
14695
4d9574aa8b7a
(svn r19277) -Fix [FS#3646]: [NewGRF] Ensure prices can't be set to zero. Zero prices break a lot of the internal logic to determine whether something has been done.
rubidium <rubidium@openttd.org>
parents:
14620
diff
changeset
|
672 /* Make sure the price does not get reduced to zero. |
4d9574aa8b7a
(svn r19277) -Fix [FS#3646]: [NewGRF] Ensure prices can't be set to zero. Zero prices break a lot of the internal logic to determine whether something has been done.
rubidium <rubidium@openttd.org>
parents:
14620
diff
changeset
|
673 * Zero breaks quite a few commands that use a zero |
4d9574aa8b7a
(svn r19277) -Fix [FS#3646]: [NewGRF] Ensure prices can't be set to zero. Zero prices break a lot of the internal logic to determine whether something has been done.
rubidium <rubidium@openttd.org>
parents:
14620
diff
changeset
|
674 * cost to see whether something got changed or not |
4d9574aa8b7a
(svn r19277) -Fix [FS#3646]: [NewGRF] Ensure prices can't be set to zero. Zero prices break a lot of the internal logic to determine whether something has been done.
rubidium <rubidium@openttd.org>
parents:
14620
diff
changeset
|
675 * and based on that cause an error. When the price |
4d9574aa8b7a
(svn r19277) -Fix [FS#3646]: [NewGRF] Ensure prices can't be set to zero. Zero prices break a lot of the internal logic to determine whether something has been done.
rubidium <rubidium@openttd.org>
parents:
14620
diff
changeset
|
676 * is zero that fails even when things are done. */ |
4d9574aa8b7a
(svn r19277) -Fix [FS#3646]: [NewGRF] Ensure prices can't be set to zero. Zero prices break a lot of the internal logic to determine whether something has been done.
rubidium <rubidium@openttd.org>
parents:
14620
diff
changeset
|
677 if (price == 0) { |
4d9574aa8b7a
(svn r19277) -Fix [FS#3646]: [NewGRF] Ensure prices can't be set to zero. Zero prices break a lot of the internal logic to determine whether something has been done.
rubidium <rubidium@openttd.org>
parents:
14620
diff
changeset
|
678 price = Clamp(_price_base_specs[i].start_price, -1, 1); |
4d9574aa8b7a
(svn r19277) -Fix [FS#3646]: [NewGRF] Ensure prices can't be set to zero. Zero prices break a lot of the internal logic to determine whether something has been done.
rubidium <rubidium@openttd.org>
parents:
14620
diff
changeset
|
679 /* No base price should be zero, but be sure. */ |
4d9574aa8b7a
(svn r19277) -Fix [FS#3646]: [NewGRF] Ensure prices can't be set to zero. Zero prices break a lot of the internal logic to determine whether something has been done.
rubidium <rubidium@openttd.org>
parents:
14620
diff
changeset
|
680 assert(price != 0); |
4d9574aa8b7a
(svn r19277) -Fix [FS#3646]: [NewGRF] Ensure prices can't be set to zero. Zero prices break a lot of the internal logic to determine whether something has been done.
rubidium <rubidium@openttd.org>
parents:
14620
diff
changeset
|
681 } |
12940
1b090e0c4f93
(svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents:
12933
diff
changeset
|
682 /* Store value */ |
13489
afa5c1a70640
(svn r18008) -Codechange: Rename NUM_PRICES to PR_END, and use the Price enum some more.
frosch <frosch@openttd.org>
parents:
13486
diff
changeset
|
683 _price[i] = price; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
684 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
685 |
12940
1b090e0c4f93
(svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents:
12933
diff
changeset
|
686 /* Setup cargo payment */ |
12942
e762f0b0f0b1
(svn r17435) -Codechange: Move _cargo_payment_rates[] to CargoSpec::current_payment.
frosch <frosch@openttd.org>
parents:
12940
diff
changeset
|
687 CargoSpec *cs; |
12940
1b090e0c4f93
(svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents:
12933
diff
changeset
|
688 FOR_ALL_CARGOSPECS(cs) { |
12942
e762f0b0f0b1
(svn r17435) -Codechange: Move _cargo_payment_rates[] to CargoSpec::current_payment.
frosch <frosch@openttd.org>
parents:
12940
diff
changeset
|
689 cs->current_payment = ((int64)cs->initial_payment * _economy.inflation_payment) >> 16; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
690 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
691 |
13034
6eb3f749890a
(svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents:
12991
diff
changeset
|
692 SetWindowClassesDirty(WC_BUILD_VEHICLE); |
6eb3f749890a
(svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents:
12991
diff
changeset
|
693 SetWindowClassesDirty(WC_REPLACE_VEHICLE); |
6eb3f749890a
(svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents:
12991
diff
changeset
|
694 SetWindowClassesDirty(WC_VEHICLE_DETAILS); |
6eb3f749890a
(svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents:
12991
diff
changeset
|
695 SetWindowDirty(WC_PAYMENT_RATES, 0); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
696 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
697 |
15655
0be6e9a4ca0b
(svn r20320) -Doc: Small Doxygen and normal comment fixes, and an missed addition.
alberth <alberth@openttd.org>
parents:
15654
diff
changeset
|
698 /** Let all companies pay the monthly interest on their loan. */ |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
699 static void CompaniesPayInterest() |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
700 { |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
701 const Company *c; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
702 |
15292
e2c62d70dfcf
(svn r19931) -Fix (r19914): Convert assertion in Backup<> destructor into DEBUG() output. It was triggered on exceptions, especially when aborting world generation.
frosch <frosch@openttd.org>
parents:
15279
diff
changeset
|
703 Backup<CompanyByte> cur_company(_current_company, FILE_LINE); |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
704 FOR_ALL_COMPANIES(c) { |
15279
4e1862aebea2
(svn r19914) -Codechange: Wrap a helper class around temporary assignments of _current_company to ensure proper restoration.
frosch <frosch@openttd.org>
parents:
15050
diff
changeset
|
705 cur_company.Change(c->index); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
706 |
10568
35171d182079
(svn r14825) -Fix: pay the correct amount of interest instead of a few percent too little a year
rubidium <rubidium@openttd.org>
parents:
10550
diff
changeset
|
707 /* Over a year the paid interest should be "loan * interest percentage", |
35171d182079
(svn r14825) -Fix: pay the correct amount of interest instead of a few percent too little a year
rubidium <rubidium@openttd.org>
parents:
10550
diff
changeset
|
708 * but... as that number is likely not dividable by 12 (pay each month), |
35171d182079
(svn r14825) -Fix: pay the correct amount of interest instead of a few percent too little a year
rubidium <rubidium@openttd.org>
parents:
10550
diff
changeset
|
709 * one needs to account for that in the monthly fee calculations. |
35171d182079
(svn r14825) -Fix: pay the correct amount of interest instead of a few percent too little a year
rubidium <rubidium@openttd.org>
parents:
10550
diff
changeset
|
710 * To easily calculate what one should pay "this" month, you calculate |
15604
ca959eb5d431
(svn r20266) -Doc: Mostly typo fixes, a few doxygen-related improvements.
alberth <alberth@openttd.org>
parents:
15601
diff
changeset
|
711 * what (total) should have been paid up to this month and you subtract |
10568
35171d182079
(svn r14825) -Fix: pay the correct amount of interest instead of a few percent too little a year
rubidium <rubidium@openttd.org>
parents:
10550
diff
changeset
|
712 * whatever has been paid in the previous months. This will mean one month |
35171d182079
(svn r14825) -Fix: pay the correct amount of interest instead of a few percent too little a year
rubidium <rubidium@openttd.org>
parents:
10550
diff
changeset
|
713 * it'll be a bit more and the other it'll be a bit less than the average |
35171d182079
(svn r14825) -Fix: pay the correct amount of interest instead of a few percent too little a year
rubidium <rubidium@openttd.org>
parents:
10550
diff
changeset
|
714 * monthly fee, but on average it will be exact. */ |
35171d182079
(svn r14825) -Fix: pay the correct amount of interest instead of a few percent too little a year
rubidium <rubidium@openttd.org>
parents:
10550
diff
changeset
|
715 Money yearly_fee = c->current_loan * _economy.interest_rate / 100; |
35171d182079
(svn r14825) -Fix: pay the correct amount of interest instead of a few percent too little a year
rubidium <rubidium@openttd.org>
parents:
10550
diff
changeset
|
716 Money up_to_previous_month = yearly_fee * _cur_month / 12; |
35171d182079
(svn r14825) -Fix: pay the correct amount of interest instead of a few percent too little a year
rubidium <rubidium@openttd.org>
parents:
10550
diff
changeset
|
717 Money up_to_this_month = yearly_fee * (_cur_month + 1) / 12; |
35171d182079
(svn r14825) -Fix: pay the correct amount of interest instead of a few percent too little a year
rubidium <rubidium@openttd.org>
parents:
10550
diff
changeset
|
718 |
35171d182079
(svn r14825) -Fix: pay the correct amount of interest instead of a few percent too little a year
rubidium <rubidium@openttd.org>
parents:
10550
diff
changeset
|
719 SubtractMoneyFromCompany(CommandCost(EXPENSES_LOAN_INT, up_to_this_month - up_to_previous_month)); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
720 |
13486
f2535c5098a0
(svn r18005) -Codechange: Convert the Prices struct into an array and an enum.
frosch <frosch@openttd.org>
parents:
13466
diff
changeset
|
721 SubtractMoneyFromCompany(CommandCost(EXPENSES_OTHER, _price[PR_STATION_VALUE] >> 2)); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
722 } |
15279
4e1862aebea2
(svn r19914) -Codechange: Wrap a helper class around temporary assignments of _current_company to ensure proper restoration.
frosch <frosch@openttd.org>
parents:
15050
diff
changeset
|
723 cur_company.Restore(); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
724 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
725 |
6247
57363e064324
(svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents:
6227
diff
changeset
|
726 static void HandleEconomyFluctuations() |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
727 { |
12933
23e2eb186b4d
(svn r17426) -Fix (r1): economy recession would never end when economy is set to Steady while in recession
smatz <smatz@openttd.org>
parents:
12927
diff
changeset
|
728 if (_settings_game.difficulty.economy != 0) { |
23e2eb186b4d
(svn r17426) -Fix (r1): economy recession would never end when economy is set to Steady while in recession
smatz <smatz@openttd.org>
parents:
12927
diff
changeset
|
729 /* When economy is Fluctuating, decrease counter */ |
23e2eb186b4d
(svn r17426) -Fix (r1): economy recession would never end when economy is set to Steady while in recession
smatz <smatz@openttd.org>
parents:
12927
diff
changeset
|
730 _economy.fluct--; |
23e2eb186b4d
(svn r17426) -Fix (r1): economy recession would never end when economy is set to Steady while in recession
smatz <smatz@openttd.org>
parents:
12927
diff
changeset
|
731 } else if (_economy.fluct <= 0) { |
23e2eb186b4d
(svn r17426) -Fix (r1): economy recession would never end when economy is set to Steady while in recession
smatz <smatz@openttd.org>
parents:
12927
diff
changeset
|
732 /* When it's Steady and we are in recession, end it now */ |
23e2eb186b4d
(svn r17426) -Fix (r1): economy recession would never end when economy is set to Steady while in recession
smatz <smatz@openttd.org>
parents:
12927
diff
changeset
|
733 _economy.fluct = -12; |
23e2eb186b4d
(svn r17426) -Fix (r1): economy recession would never end when economy is set to Steady while in recession
smatz <smatz@openttd.org>
parents:
12927
diff
changeset
|
734 } else { |
23e2eb186b4d
(svn r17426) -Fix (r1): economy recession would never end when economy is set to Steady while in recession
smatz <smatz@openttd.org>
parents:
12927
diff
changeset
|
735 /* No need to do anything else in other cases */ |
23e2eb186b4d
(svn r17426) -Fix (r1): economy recession would never end when economy is set to Steady while in recession
smatz <smatz@openttd.org>
parents:
12927
diff
changeset
|
736 return; |
23e2eb186b4d
(svn r17426) -Fix (r1): economy recession would never end when economy is set to Steady while in recession
smatz <smatz@openttd.org>
parents:
12927
diff
changeset
|
737 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
738 |
12933
23e2eb186b4d
(svn r17426) -Fix (r1): economy recession would never end when economy is set to Steady while in recession
smatz <smatz@openttd.org>
parents:
12927
diff
changeset
|
739 if (_economy.fluct == 0) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
740 _economy.fluct = -(int)GB(Random(), 0, 2); |
12010
d0bf08a7c260
(svn r16416) -Fix [FS#2912]: Rework deleting of news when referenced vehicles/stations/industries are deleted.
frosch <frosch@openttd.org>
parents:
12001
diff
changeset
|
741 AddNewsItem(STR_NEWS_BEGIN_OF_RECESSION, NS_ECONOMY); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
742 } else if (_economy.fluct == -12) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
743 _economy.fluct = GB(Random(), 0, 8) + 312; |
12010
d0bf08a7c260
(svn r16416) -Fix [FS#2912]: Rework deleting of news when referenced vehicles/stations/industries are deleted.
frosch <frosch@openttd.org>
parents:
12001
diff
changeset
|
744 AddNewsItem(STR_NEWS_END_OF_RECESSION, NS_ECONOMY); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
745 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
746 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
747 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
748 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
749 /** |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
750 * Reset changes to the price base multipliers. |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
751 */ |
6247
57363e064324
(svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents:
6227
diff
changeset
|
752 void ResetPriceBaseMultipliers() |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
753 { |
13497
a378bbea4ddb
(svn r18016) -Codechange: Move the arbitrary basecost multiplier offset (8) to newgrf loading and make the internal state zero-based instead.
frosch <frosch@openttd.org>
parents:
13489
diff
changeset
|
754 memset(_price_base_multiplier, 0, sizeof(_price_base_multiplier)); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
755 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
756 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
757 /** |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
758 * Change a price base by the given factor. |
13497
a378bbea4ddb
(svn r18016) -Codechange: Move the arbitrary basecost multiplier offset (8) to newgrf loading and make the internal state zero-based instead.
frosch <frosch@openttd.org>
parents:
13489
diff
changeset
|
759 * The price base is altered by factors of two. |
a378bbea4ddb
(svn r18016) -Codechange: Move the arbitrary basecost multiplier offset (8) to newgrf loading and make the internal state zero-based instead.
frosch <frosch@openttd.org>
parents:
13489
diff
changeset
|
760 * NewBaseCost = OldBaseCost * 2^n |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
761 * @param price Index of price base to change. |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
762 * @param factor Amount to change by. |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
763 */ |
13497
a378bbea4ddb
(svn r18016) -Codechange: Move the arbitrary basecost multiplier offset (8) to newgrf loading and make the internal state zero-based instead.
frosch <frosch@openttd.org>
parents:
13489
diff
changeset
|
764 void SetPriceBaseMultiplier(Price price, int factor) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
765 { |
13489
afa5c1a70640
(svn r18008) -Codechange: Rename NUM_PRICES to PR_END, and use the Price enum some more.
frosch <frosch@openttd.org>
parents:
13486
diff
changeset
|
766 assert(price < PR_END); |
13497
a378bbea4ddb
(svn r18016) -Codechange: Move the arbitrary basecost multiplier offset (8) to newgrf loading and make the internal state zero-based instead.
frosch <frosch@openttd.org>
parents:
13489
diff
changeset
|
767 _price_base_multiplier[price] = Clamp(factor, MIN_PRICE_MODIFIER, MAX_PRICE_MODIFIER); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
768 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
769 |
10146
f5ef198f917d
(svn r14332) -Fix[FS#1885]: Balance the monthly random industry changes, by introducing a daily random industry change.
belugas <belugas@openttd.org>
parents:
10080
diff
changeset
|
770 /** |
f5ef198f917d
(svn r14332) -Fix[FS#1885]: Balance the monthly random industry changes, by introducing a daily random industry change.
belugas <belugas@openttd.org>
parents:
10080
diff
changeset
|
771 * Initialize the variables that will maintain the daily industry change system. |
f5ef198f917d
(svn r14332) -Fix[FS#1885]: Balance the monthly random industry changes, by introducing a daily random industry change.
belugas <belugas@openttd.org>
parents:
10080
diff
changeset
|
772 * @param init_counter specifies if the counter is required to be initialized |
f5ef198f917d
(svn r14332) -Fix[FS#1885]: Balance the monthly random industry changes, by introducing a daily random industry change.
belugas <belugas@openttd.org>
parents:
10080
diff
changeset
|
773 */ |
10571
b6779abf2e96
(svn r14828) -Codechange: move most of save/load-specific code to separate files
smatz <smatz@openttd.org>
parents:
10568
diff
changeset
|
774 void StartupIndustryDailyChanges(bool init_counter) |
10146
f5ef198f917d
(svn r14332) -Fix[FS#1885]: Balance the monthly random industry changes, by introducing a daily random industry change.
belugas <belugas@openttd.org>
parents:
10080
diff
changeset
|
775 { |
f5ef198f917d
(svn r14332) -Fix[FS#1885]: Balance the monthly random industry changes, by introducing a daily random industry change.
belugas <belugas@openttd.org>
parents:
10080
diff
changeset
|
776 uint map_size = MapLogX() + MapLogY(); |
f5ef198f917d
(svn r14332) -Fix[FS#1885]: Balance the monthly random industry changes, by introducing a daily random industry change.
belugas <belugas@openttd.org>
parents:
10080
diff
changeset
|
777 /* After getting map size, it needs to be scaled appropriately and divided by 31, |
f5ef198f917d
(svn r14332) -Fix[FS#1885]: Balance the monthly random industry changes, by introducing a daily random industry change.
belugas <belugas@openttd.org>
parents:
10080
diff
changeset
|
778 * which stands for the days in a month. |
f5ef198f917d
(svn r14332) -Fix[FS#1885]: Balance the monthly random industry changes, by introducing a daily random industry change.
belugas <belugas@openttd.org>
parents:
10080
diff
changeset
|
779 * Using just 31 will make it so that a monthly reset (based on the real number of days of that month) |
f5ef198f917d
(svn r14332) -Fix[FS#1885]: Balance the monthly random industry changes, by introducing a daily random industry change.
belugas <belugas@openttd.org>
parents:
10080
diff
changeset
|
780 * would not be needed. |
f5ef198f917d
(svn r14332) -Fix[FS#1885]: Balance the monthly random industry changes, by introducing a daily random industry change.
belugas <belugas@openttd.org>
parents:
10080
diff
changeset
|
781 * Since it is based on "fractionnal parts", the leftover days will not make much of a difference |
f5ef198f917d
(svn r14332) -Fix[FS#1885]: Balance the monthly random industry changes, by introducing a daily random industry change.
belugas <belugas@openttd.org>
parents:
10080
diff
changeset
|
782 * on the overall total number of changes performed */ |
f5ef198f917d
(svn r14332) -Fix[FS#1885]: Balance the monthly random industry changes, by introducing a daily random industry change.
belugas <belugas@openttd.org>
parents:
10080
diff
changeset
|
783 _economy.industry_daily_increment = (1 << map_size) / 31; |
f5ef198f917d
(svn r14332) -Fix[FS#1885]: Balance the monthly random industry changes, by introducing a daily random industry change.
belugas <belugas@openttd.org>
parents:
10080
diff
changeset
|
784 |
f5ef198f917d
(svn r14332) -Fix[FS#1885]: Balance the monthly random industry changes, by introducing a daily random industry change.
belugas <belugas@openttd.org>
parents:
10080
diff
changeset
|
785 if (init_counter) { |
f5ef198f917d
(svn r14332) -Fix[FS#1885]: Balance the monthly random industry changes, by introducing a daily random industry change.
belugas <belugas@openttd.org>
parents:
10080
diff
changeset
|
786 /* A new game or a savegame from an older version will require the counter to be initialized */ |
f5ef198f917d
(svn r14332) -Fix[FS#1885]: Balance the monthly random industry changes, by introducing a daily random industry change.
belugas <belugas@openttd.org>
parents:
10080
diff
changeset
|
787 _economy.industry_daily_change_counter = 0; |
f5ef198f917d
(svn r14332) -Fix[FS#1885]: Balance the monthly random industry changes, by introducing a daily random industry change.
belugas <belugas@openttd.org>
parents:
10080
diff
changeset
|
788 } |
f5ef198f917d
(svn r14332) -Fix[FS#1885]: Balance the monthly random industry changes, by introducing a daily random industry change.
belugas <belugas@openttd.org>
parents:
10080
diff
changeset
|
789 } |
f5ef198f917d
(svn r14332) -Fix[FS#1885]: Balance the monthly random industry changes, by introducing a daily random industry change.
belugas <belugas@openttd.org>
parents:
10080
diff
changeset
|
790 |
6247
57363e064324
(svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents:
6227
diff
changeset
|
791 void StartupEconomy() |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
792 { |
9413
512ea64da840
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium <rubidium@openttd.org>
parents:
9359
diff
changeset
|
793 _economy.interest_rate = _settings_game.difficulty.initial_interest; |
512ea64da840
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium <rubidium@openttd.org>
parents:
9359
diff
changeset
|
794 _economy.infl_amount = _settings_game.difficulty.initial_interest; |
512ea64da840
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium <rubidium@openttd.org>
parents:
9359
diff
changeset
|
795 _economy.infl_amount_pr = max(0, _settings_game.difficulty.initial_interest - 1); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
796 _economy.fluct = GB(Random(), 0, 8) + 168; |
10146
f5ef198f917d
(svn r14332) -Fix[FS#1885]: Balance the monthly random industry changes, by introducing a daily random industry change.
belugas <belugas@openttd.org>
parents:
10080
diff
changeset
|
797 |
12940
1b090e0c4f93
(svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents:
12933
diff
changeset
|
798 /* Set up prices */ |
1b090e0c4f93
(svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents:
12933
diff
changeset
|
799 RecomputePrices(); |
1b090e0c4f93
(svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents:
12933
diff
changeset
|
800 |
10146
f5ef198f917d
(svn r14332) -Fix[FS#1885]: Balance the monthly random industry changes, by introducing a daily random industry change.
belugas <belugas@openttd.org>
parents:
10080
diff
changeset
|
801 StartupIndustryDailyChanges(true); // As we are starting a new game, initialize the counter too |
f5ef198f917d
(svn r14332) -Fix[FS#1885]: Balance the monthly random industry changes, by introducing a daily random industry change.
belugas <belugas@openttd.org>
parents:
10080
diff
changeset
|
802 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
803 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
804 |
12940
1b090e0c4f93
(svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents:
12933
diff
changeset
|
805 /** |
1b090e0c4f93
(svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents:
12933
diff
changeset
|
806 * Resets economy to initial values |
1b090e0c4f93
(svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents:
12933
diff
changeset
|
807 */ |
1b090e0c4f93
(svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents:
12933
diff
changeset
|
808 void InitializeEconomy() |
9717
57549f1e5133
(svn r13836) -Fix [FS#2074]: Automatically recalculate inflation if NewGRFs are changed and cargo types are added, so that cargo payment rates are correct.
peter1138 <peter1138@openttd.org>
parents:
9659
diff
changeset
|
809 { |
12940
1b090e0c4f93
(svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents:
12933
diff
changeset
|
810 _economy.inflation_prices = _economy.inflation_payment = 1 << 16; |
9717
57549f1e5133
(svn r13836) -Fix [FS#2074]: Automatically recalculate inflation if NewGRFs are changed and cargo types are added, so that cargo payment rates are correct.
peter1138 <peter1138@openttd.org>
parents:
9659
diff
changeset
|
811 } |
8626
e6ad3a9cdfcb
(svn r12209) -Fix: [NewGRF] Support using any base price for rail and road vehicles' running cost, and show running cost of wagons if they have it.
peter1138 <peter1138@openttd.org>
parents:
8624
diff
changeset
|
812 |
13486
f2535c5098a0
(svn r18005) -Codechange: Convert the Prices struct into an array and an enum.
frosch <frosch@openttd.org>
parents:
13466
diff
changeset
|
813 /** |
13741
775d368aa2b0
(svn r18266) -Codechange: Add a function to compute prices from price base and cost factor and use it consistently for vehicle purchase, running cost, and refit cost.
frosch <frosch@openttd.org>
parents:
13497
diff
changeset
|
814 * Determine a certain price |
775d368aa2b0
(svn r18266) -Codechange: Add a function to compute prices from price base and cost factor and use it consistently for vehicle purchase, running cost, and refit cost.
frosch <frosch@openttd.org>
parents:
13497
diff
changeset
|
815 * @param index Price base |
775d368aa2b0
(svn r18266) -Codechange: Add a function to compute prices from price base and cost factor and use it consistently for vehicle purchase, running cost, and refit cost.
frosch <frosch@openttd.org>
parents:
13497
diff
changeset
|
816 * @param cost_factor Price factor |
13743
c84d609b6877
(svn r18268) -Feature: [NewGRF] Make price base multipliers related to vehicles only apply to the GRF locally, if it defines engines of that type itself.
frosch <frosch@openttd.org>
parents:
13741
diff
changeset
|
817 * @param grf_file NewGRF to use local price multipliers from. |
13741
775d368aa2b0
(svn r18266) -Codechange: Add a function to compute prices from price base and cost factor and use it consistently for vehicle purchase, running cost, and refit cost.
frosch <frosch@openttd.org>
parents:
13497
diff
changeset
|
818 * @param shift Extra bit shifting after the computation |
775d368aa2b0
(svn r18266) -Codechange: Add a function to compute prices from price base and cost factor and use it consistently for vehicle purchase, running cost, and refit cost.
frosch <frosch@openttd.org>
parents:
13497
diff
changeset
|
819 * @return Price |
13486
f2535c5098a0
(svn r18005) -Codechange: Convert the Prices struct into an array and an enum.
frosch <frosch@openttd.org>
parents:
13466
diff
changeset
|
820 */ |
13743
c84d609b6877
(svn r18268) -Feature: [NewGRF] Make price base multipliers related to vehicles only apply to the GRF locally, if it defines engines of that type itself.
frosch <frosch@openttd.org>
parents:
13741
diff
changeset
|
821 Money GetPrice(Price index, uint cost_factor, const GRFFile *grf_file, int shift) |
8626
e6ad3a9cdfcb
(svn r12209) -Fix: [NewGRF] Support using any base price for rail and road vehicles' running cost, and show running cost of wagons if they have it.
peter1138 <peter1138@openttd.org>
parents:
8624
diff
changeset
|
822 { |
13489
afa5c1a70640
(svn r18008) -Codechange: Rename NUM_PRICES to PR_END, and use the Price enum some more.
frosch <frosch@openttd.org>
parents:
13486
diff
changeset
|
823 if (index >= PR_END) return 0; |
8626
e6ad3a9cdfcb
(svn r12209) -Fix: [NewGRF] Support using any base price for rail and road vehicles' running cost, and show running cost of wagons if they have it.
peter1138 <peter1138@openttd.org>
parents:
8624
diff
changeset
|
824 |
13741
775d368aa2b0
(svn r18266) -Codechange: Add a function to compute prices from price base and cost factor and use it consistently for vehicle purchase, running cost, and refit cost.
frosch <frosch@openttd.org>
parents:
13497
diff
changeset
|
825 Money cost = _price[index] * cost_factor; |
13743
c84d609b6877
(svn r18268) -Feature: [NewGRF] Make price base multipliers related to vehicles only apply to the GRF locally, if it defines engines of that type itself.
frosch <frosch@openttd.org>
parents:
13741
diff
changeset
|
826 if (grf_file != NULL) shift += grf_file->price_base_multipliers[index]; |
13741
775d368aa2b0
(svn r18266) -Codechange: Add a function to compute prices from price base and cost factor and use it consistently for vehicle purchase, running cost, and refit cost.
frosch <frosch@openttd.org>
parents:
13497
diff
changeset
|
827 |
775d368aa2b0
(svn r18266) -Codechange: Add a function to compute prices from price base and cost factor and use it consistently for vehicle purchase, running cost, and refit cost.
frosch <frosch@openttd.org>
parents:
13497
diff
changeset
|
828 if (shift >= 0) { |
775d368aa2b0
(svn r18266) -Codechange: Add a function to compute prices from price base and cost factor and use it consistently for vehicle purchase, running cost, and refit cost.
frosch <frosch@openttd.org>
parents:
13497
diff
changeset
|
829 cost <<= shift; |
775d368aa2b0
(svn r18266) -Codechange: Add a function to compute prices from price base and cost factor and use it consistently for vehicle purchase, running cost, and refit cost.
frosch <frosch@openttd.org>
parents:
13497
diff
changeset
|
830 } else { |
775d368aa2b0
(svn r18266) -Codechange: Add a function to compute prices from price base and cost factor and use it consistently for vehicle purchase, running cost, and refit cost.
frosch <frosch@openttd.org>
parents:
13497
diff
changeset
|
831 cost >>= -shift; |
775d368aa2b0
(svn r18266) -Codechange: Add a function to compute prices from price base and cost factor and use it consistently for vehicle purchase, running cost, and refit cost.
frosch <frosch@openttd.org>
parents:
13497
diff
changeset
|
832 } |
775d368aa2b0
(svn r18266) -Codechange: Add a function to compute prices from price base and cost factor and use it consistently for vehicle purchase, running cost, and refit cost.
frosch <frosch@openttd.org>
parents:
13497
diff
changeset
|
833 |
775d368aa2b0
(svn r18266) -Codechange: Add a function to compute prices from price base and cost factor and use it consistently for vehicle purchase, running cost, and refit cost.
frosch <frosch@openttd.org>
parents:
13497
diff
changeset
|
834 return cost; |
8626
e6ad3a9cdfcb
(svn r12209) -Fix: [NewGRF] Support using any base price for rail and road vehicles' running cost, and show running cost of wagons if they have it.
peter1138 <peter1138@openttd.org>
parents:
8624
diff
changeset
|
835 } |
e6ad3a9cdfcb
(svn r12209) -Fix: [NewGRF] Support using any base price for rail and road vehicles' running cost, and show running cost of wagons if they have it.
peter1138 <peter1138@openttd.org>
parents:
8624
diff
changeset
|
836 |
6954
3aa54e38394f
(svn r10209) -Fix/Codechange: forgot a few changes of int32 -> Money in the previous commit
rubidium <rubidium@openttd.org>
parents:
6953
diff
changeset
|
837 Money GetTransportedGoodsIncome(uint num_pieces, uint dist, byte transit_days, CargoID cargo_type) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
838 { |
12415
6a77d1df56e2
(svn r16849) -Codechange: replace GetCargo() by CargoSpec::Get()
smatz <smatz@openttd.org>
parents:
12384
diff
changeset
|
839 const CargoSpec *cs = CargoSpec::Get(cargo_type); |
12942
e762f0b0f0b1
(svn r17435) -Codechange: Move _cargo_payment_rates[] to CargoSpec::current_payment.
frosch <frosch@openttd.org>
parents:
12940
diff
changeset
|
840 if (!cs->IsValid()) { |
e762f0b0f0b1
(svn r17435) -Codechange: Move _cargo_payment_rates[] to CargoSpec::current_payment.
frosch <frosch@openttd.org>
parents:
12940
diff
changeset
|
841 /* User changed newgrfs and some vehicle still carries some cargo which is no longer available. */ |
e762f0b0f0b1
(svn r17435) -Codechange: Move _cargo_payment_rates[] to CargoSpec::current_payment.
frosch <frosch@openttd.org>
parents:
12940
diff
changeset
|
842 return 0; |
e762f0b0f0b1
(svn r17435) -Codechange: Move _cargo_payment_rates[] to CargoSpec::current_payment.
frosch <frosch@openttd.org>
parents:
12940
diff
changeset
|
843 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
844 |
6458
57cfff4ac608
(svn r9617) -Codechange: Implement callback for cargo profit calculation
peter1138 <peter1138@openttd.org>
parents:
6453
diff
changeset
|
845 /* Use callback to calculate cargo profit, if available */ |
7928
4e8dfd103163
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7926
diff
changeset
|
846 if (HasBit(cs->callback_mask, CBM_CARGO_PROFIT_CALC)) { |
6458
57cfff4ac608
(svn r9617) -Codechange: Implement callback for cargo profit calculation
peter1138 <peter1138@openttd.org>
parents:
6453
diff
changeset
|
847 uint32 var18 = min(dist, 0xFFFF) | (min(num_pieces, 0xFF) << 16) | (transit_days << 24); |
57cfff4ac608
(svn r9617) -Codechange: Implement callback for cargo profit calculation
peter1138 <peter1138@openttd.org>
parents:
6453
diff
changeset
|
848 uint16 callback = GetCargoCallback(CBID_CARGO_PROFIT_CALC, 0, var18, cs); |
57cfff4ac608
(svn r9617) -Codechange: Implement callback for cargo profit calculation
peter1138 <peter1138@openttd.org>
parents:
6453
diff
changeset
|
849 if (callback != CALLBACK_FAILED) { |
57cfff4ac608
(svn r9617) -Codechange: Implement callback for cargo profit calculation
peter1138 <peter1138@openttd.org>
parents:
6453
diff
changeset
|
850 int result = GB(callback, 0, 14); |
57cfff4ac608
(svn r9617) -Codechange: Implement callback for cargo profit calculation
peter1138 <peter1138@openttd.org>
parents:
6453
diff
changeset
|
851 |
57cfff4ac608
(svn r9617) -Codechange: Implement callback for cargo profit calculation
peter1138 <peter1138@openttd.org>
parents:
6453
diff
changeset
|
852 /* Simulate a 15 bit signed value */ |
13048
f9399c64435f
(svn r17546) -Fix (r9617): sign extending of profit calculation didn't work
rubidium <rubidium@openttd.org>
parents:
13044
diff
changeset
|
853 if (HasBit(callback, 14)) result -= 0x4000; |
6458
57cfff4ac608
(svn r9617) -Codechange: Implement callback for cargo profit calculation
peter1138 <peter1138@openttd.org>
parents:
6453
diff
changeset
|
854 |
57cfff4ac608
(svn r9617) -Codechange: Implement callback for cargo profit calculation
peter1138 <peter1138@openttd.org>
parents:
6453
diff
changeset
|
855 /* "The result should be a signed multiplier that gets multiplied |
57cfff4ac608
(svn r9617) -Codechange: Implement callback for cargo profit calculation
peter1138 <peter1138@openttd.org>
parents:
6453
diff
changeset
|
856 * by the amount of cargo moved and the price factor, then gets |
57cfff4ac608
(svn r9617) -Codechange: Implement callback for cargo profit calculation
peter1138 <peter1138@openttd.org>
parents:
6453
diff
changeset
|
857 * divided by 8192." */ |
12942
e762f0b0f0b1
(svn r17435) -Codechange: Move _cargo_payment_rates[] to CargoSpec::current_payment.
frosch <frosch@openttd.org>
parents:
12940
diff
changeset
|
858 return result * num_pieces * cs->current_payment / 8192; |
6458
57cfff4ac608
(svn r9617) -Codechange: Implement callback for cargo profit calculation
peter1138 <peter1138@openttd.org>
parents:
6453
diff
changeset
|
859 } |
57cfff4ac608
(svn r9617) -Codechange: Implement callback for cargo profit calculation
peter1138 <peter1138@openttd.org>
parents:
6453
diff
changeset
|
860 } |
57cfff4ac608
(svn r9617) -Codechange: Implement callback for cargo profit calculation
peter1138 <peter1138@openttd.org>
parents:
6453
diff
changeset
|
861 |
7328
35cf803fe4b9
(svn r10691) -Codechange [FS#509]: simplify GetTransportedGoodsIncome to make it more obvious and less hidden what actually happens. Based on a patch by rfalke.
rubidium <rubidium@openttd.org>
parents:
7287
diff
changeset
|
862 static const int MIN_TIME_FACTOR = 31; |
35cf803fe4b9
(svn r10691) -Codechange [FS#509]: simplify GetTransportedGoodsIncome to make it more obvious and less hidden what actually happens. Based on a patch by rfalke.
rubidium <rubidium@openttd.org>
parents:
7287
diff
changeset
|
863 static const int MAX_TIME_FACTOR = 255; |
35cf803fe4b9
(svn r10691) -Codechange [FS#509]: simplify GetTransportedGoodsIncome to make it more obvious and less hidden what actually happens. Based on a patch by rfalke.
rubidium <rubidium@openttd.org>
parents:
7287
diff
changeset
|
864 |
35cf803fe4b9
(svn r10691) -Codechange [FS#509]: simplify GetTransportedGoodsIncome to make it more obvious and less hidden what actually happens. Based on a patch by rfalke.
rubidium <rubidium@openttd.org>
parents:
7287
diff
changeset
|
865 const int days1 = cs->transit_days[0]; |
35cf803fe4b9
(svn r10691) -Codechange [FS#509]: simplify GetTransportedGoodsIncome to make it more obvious and less hidden what actually happens. Based on a patch by rfalke.
rubidium <rubidium@openttd.org>
parents:
7287
diff
changeset
|
866 const int days2 = cs->transit_days[1]; |
10417
844e13224bd1
(svn r14670) -Codechange: use better readable (I hope) and branchless (for some archs/compilers) code for cargo value computation
smatz <smatz@openttd.org>
parents:
10297
diff
changeset
|
867 const int days_over_days1 = max( transit_days - days1, 0); |
844e13224bd1
(svn r14670) -Codechange: use better readable (I hope) and branchless (for some archs/compilers) code for cargo value computation
smatz <smatz@openttd.org>
parents:
10297
diff
changeset
|
868 const int days_over_days2 = max(days_over_days1 - days2, 0); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
869 |
7328
35cf803fe4b9
(svn r10691) -Codechange [FS#509]: simplify GetTransportedGoodsIncome to make it more obvious and less hidden what actually happens. Based on a patch by rfalke.
rubidium <rubidium@openttd.org>
parents:
7287
diff
changeset
|
870 /* |
35cf803fe4b9
(svn r10691) -Codechange [FS#509]: simplify GetTransportedGoodsIncome to make it more obvious and less hidden what actually happens. Based on a patch by rfalke.
rubidium <rubidium@openttd.org>
parents:
7287
diff
changeset
|
871 * The time factor is calculated based on the time it took |
35cf803fe4b9
(svn r10691) -Codechange [FS#509]: simplify GetTransportedGoodsIncome to make it more obvious and less hidden what actually happens. Based on a patch by rfalke.
rubidium <rubidium@openttd.org>
parents:
7287
diff
changeset
|
872 * (transit_days) compared two cargo-depending values. The |
35cf803fe4b9
(svn r10691) -Codechange [FS#509]: simplify GetTransportedGoodsIncome to make it more obvious and less hidden what actually happens. Based on a patch by rfalke.
rubidium <rubidium@openttd.org>
parents:
7287
diff
changeset
|
873 * range is divided into three parts: |
35cf803fe4b9
(svn r10691) -Codechange [FS#509]: simplify GetTransportedGoodsIncome to make it more obvious and less hidden what actually happens. Based on a patch by rfalke.
rubidium <rubidium@openttd.org>
parents:
7287
diff
changeset
|
874 * |
35cf803fe4b9
(svn r10691) -Codechange [FS#509]: simplify GetTransportedGoodsIncome to make it more obvious and less hidden what actually happens. Based on a patch by rfalke.
rubidium <rubidium@openttd.org>
parents:
7287
diff
changeset
|
875 * - constant for fast transits |
35cf803fe4b9
(svn r10691) -Codechange [FS#509]: simplify GetTransportedGoodsIncome to make it more obvious and less hidden what actually happens. Based on a patch by rfalke.
rubidium <rubidium@openttd.org>
parents:
7287
diff
changeset
|
876 * - linear decreasing with time with a slope of -1 for medium transports |
35cf803fe4b9
(svn r10691) -Codechange [FS#509]: simplify GetTransportedGoodsIncome to make it more obvious and less hidden what actually happens. Based on a patch by rfalke.
rubidium <rubidium@openttd.org>
parents:
7287
diff
changeset
|
877 * - linear decreasing with time with a slope of -2 for slow transports |
35cf803fe4b9
(svn r10691) -Codechange [FS#509]: simplify GetTransportedGoodsIncome to make it more obvious and less hidden what actually happens. Based on a patch by rfalke.
rubidium <rubidium@openttd.org>
parents:
7287
diff
changeset
|
878 * |
35cf803fe4b9
(svn r10691) -Codechange [FS#509]: simplify GetTransportedGoodsIncome to make it more obvious and less hidden what actually happens. Based on a patch by rfalke.
rubidium <rubidium@openttd.org>
parents:
7287
diff
changeset
|
879 */ |
10417
844e13224bd1
(svn r14670) -Codechange: use better readable (I hope) and branchless (for some archs/compilers) code for cargo value computation
smatz <smatz@openttd.org>
parents:
10297
diff
changeset
|
880 const int time_factor = max(MAX_TIME_FACTOR - days_over_days1 - days_over_days2, MIN_TIME_FACTOR); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
881 |
12942
e762f0b0f0b1
(svn r17435) -Codechange: Move _cargo_payment_rates[] to CargoSpec::current_payment.
frosch <frosch@openttd.org>
parents:
12940
diff
changeset
|
882 return BigMulS(dist * time_factor * num_pieces, cs->current_payment, 21); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
883 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
884 |
12267
fe4287ad4243
(svn r16682) -Codechange: make (static) industry list used to trigger the industries' production compile unit static instead of passing it around as pointer
rubidium <rubidium@openttd.org>
parents:
12266
diff
changeset
|
885 /** The industries we've currently brought cargo to. */ |
fe4287ad4243
(svn r16682) -Codechange: make (static) industry list used to trigger the industries' production compile unit static instead of passing it around as pointer
rubidium <rubidium@openttd.org>
parents:
12266
diff
changeset
|
886 static SmallIndustryList _cargo_delivery_destinations; |
12239
b1d30d9d4025
(svn r16654) -Codechange: cache industries in station's coverage area instead of searching them everytime payment is made
smatz <smatz@openttd.org>
parents:
12228
diff
changeset
|
887 |
b1d30d9d4025
(svn r16654) -Codechange: cache industries in station's coverage area instead of searching them everytime payment is made
smatz <smatz@openttd.org>
parents:
12228
diff
changeset
|
888 /** |
b1d30d9d4025
(svn r16654) -Codechange: cache industries in station's coverage area instead of searching them everytime payment is made
smatz <smatz@openttd.org>
parents:
12228
diff
changeset
|
889 * Transfer goods from station to industry. |
b1d30d9d4025
(svn r16654) -Codechange: cache industries in station's coverage area instead of searching them everytime payment is made
smatz <smatz@openttd.org>
parents:
12228
diff
changeset
|
890 * All cargo is delivered to the nearest (Manhattan) industry to the station sign, which is inside the acceptance rectangle and actually accepts the cargo. |
b1d30d9d4025
(svn r16654) -Codechange: cache industries in station's coverage area instead of searching them everytime payment is made
smatz <smatz@openttd.org>
parents:
12228
diff
changeset
|
891 * @param st The station that accepted the cargo |
b1d30d9d4025
(svn r16654) -Codechange: cache industries in station's coverage area instead of searching them everytime payment is made
smatz <smatz@openttd.org>
parents:
12228
diff
changeset
|
892 * @param cargo_type Type of cargo delivered |
13070
1c4c4ae8d716
(svn r17570) -Fix: a number of Doxygen warnings about missing parameters, which were sometimes missing and sometimes just typos
rubidium <rubidium@openttd.org>
parents:
13067
diff
changeset
|
893 * @param num_pieces Amount of cargo delivered |
1c4c4ae8d716
(svn r17570) -Fix: a number of Doxygen warnings about missing parameters, which were sometimes missing and sometimes just typos
rubidium <rubidium@openttd.org>
parents:
13067
diff
changeset
|
894 * @param source The source of the cargo |
12943
049765007dc0
(svn r17436) -Change: pay only for cargo actually delivered, not for all cargo unloaded at station (can differ with 'stockpiling' industries)
smatz <smatz@openttd.org>
parents:
12942
diff
changeset
|
895 * @return actually accepted pieces of cargo |
12239
b1d30d9d4025
(svn r16654) -Codechange: cache industries in station's coverage area instead of searching them everytime payment is made
smatz <smatz@openttd.org>
parents:
12228
diff
changeset
|
896 */ |
12944
75ae91d09b03
(svn r17437) -Change: don't accept cargo produced in the same industry (generalise and improve the check used only for valuables)
smatz <smatz@openttd.org>
parents:
12943
diff
changeset
|
897 static uint DeliverGoodsToIndustry(const Station *st, CargoID cargo_type, uint num_pieces, IndustryID source) |
12239
b1d30d9d4025
(svn r16654) -Codechange: cache industries in station's coverage area instead of searching them everytime payment is made
smatz <smatz@openttd.org>
parents:
12228
diff
changeset
|
898 { |
b1d30d9d4025
(svn r16654) -Codechange: cache industries in station's coverage area instead of searching them everytime payment is made
smatz <smatz@openttd.org>
parents:
12228
diff
changeset
|
899 /* Find the nearest industrytile to the station sign inside the catchment area, whose industry accepts the cargo. |
b1d30d9d4025
(svn r16654) -Codechange: cache industries in station's coverage area instead of searching them everytime payment is made
smatz <smatz@openttd.org>
parents:
12228
diff
changeset
|
900 * This fails in three cases: |
b1d30d9d4025
(svn r16654) -Codechange: cache industries in station's coverage area instead of searching them everytime payment is made
smatz <smatz@openttd.org>
parents:
12228
diff
changeset
|
901 * 1) The station accepts the cargo because there are enough houses around it accepting the cargo. |
b1d30d9d4025
(svn r16654) -Codechange: cache industries in station's coverage area instead of searching them everytime payment is made
smatz <smatz@openttd.org>
parents:
12228
diff
changeset
|
902 * 2) The industries in the catchment area temporarily reject the cargo, and the daily station loop has not yet updated station acceptance. |
b1d30d9d4025
(svn r16654) -Codechange: cache industries in station's coverage area instead of searching them everytime payment is made
smatz <smatz@openttd.org>
parents:
12228
diff
changeset
|
903 * 3) The results of callbacks CBID_INDUSTRY_REFUSE_CARGO and CBID_INDTILE_CARGO_ACCEPTANCE are inconsistent. (documented behaviour) |
b1d30d9d4025
(svn r16654) -Codechange: cache industries in station's coverage area instead of searching them everytime payment is made
smatz <smatz@openttd.org>
parents:
12228
diff
changeset
|
904 */ |
b1d30d9d4025
(svn r16654) -Codechange: cache industries in station's coverage area instead of searching them everytime payment is made
smatz <smatz@openttd.org>
parents:
12228
diff
changeset
|
905 |
12943
049765007dc0
(svn r17436) -Change: pay only for cargo actually delivered, not for all cargo unloaded at station (can differ with 'stockpiling' industries)
smatz <smatz@openttd.org>
parents:
12942
diff
changeset
|
906 uint accepted = 0; |
049765007dc0
(svn r17436) -Change: pay only for cargo actually delivered, not for all cargo unloaded at station (can differ with 'stockpiling' industries)
smatz <smatz@openttd.org>
parents:
12942
diff
changeset
|
907 |
049765007dc0
(svn r17436) -Change: pay only for cargo actually delivered, not for all cargo unloaded at station (can differ with 'stockpiling' industries)
smatz <smatz@openttd.org>
parents:
12942
diff
changeset
|
908 for (uint i = 0; i < st->industries_near.Length() && num_pieces != 0; i++) { |
12239
b1d30d9d4025
(svn r16654) -Codechange: cache industries in station's coverage area instead of searching them everytime payment is made
smatz <smatz@openttd.org>
parents:
12228
diff
changeset
|
909 Industry *ind = st->industries_near[i]; |
12944
75ae91d09b03
(svn r17437) -Change: don't accept cargo produced in the same industry (generalise and improve the check used only for valuables)
smatz <smatz@openttd.org>
parents:
12943
diff
changeset
|
910 if (ind->index == source) continue; |
75ae91d09b03
(svn r17437) -Change: don't accept cargo produced in the same industry (generalise and improve the check used only for valuables)
smatz <smatz@openttd.org>
parents:
12943
diff
changeset
|
911 |
12239
b1d30d9d4025
(svn r16654) -Codechange: cache industries in station's coverage area instead of searching them everytime payment is made
smatz <smatz@openttd.org>
parents:
12228
diff
changeset
|
912 uint cargo_index; |
b1d30d9d4025
(svn r16654) -Codechange: cache industries in station's coverage area instead of searching them everytime payment is made
smatz <smatz@openttd.org>
parents:
12228
diff
changeset
|
913 for (cargo_index = 0; cargo_index < lengthof(ind->accepts_cargo); cargo_index++) { |
b1d30d9d4025
(svn r16654) -Codechange: cache industries in station's coverage area instead of searching them everytime payment is made
smatz <smatz@openttd.org>
parents:
12228
diff
changeset
|
914 if (cargo_type == ind->accepts_cargo[cargo_index]) break; |
b1d30d9d4025
(svn r16654) -Codechange: cache industries in station's coverage area instead of searching them everytime payment is made
smatz <smatz@openttd.org>
parents:
12228
diff
changeset
|
915 } |
b1d30d9d4025
(svn r16654) -Codechange: cache industries in station's coverage area instead of searching them everytime payment is made
smatz <smatz@openttd.org>
parents:
12228
diff
changeset
|
916 /* Check if matching cargo has been found */ |
b1d30d9d4025
(svn r16654) -Codechange: cache industries in station's coverage area instead of searching them everytime payment is made
smatz <smatz@openttd.org>
parents:
12228
diff
changeset
|
917 if (cargo_index >= lengthof(ind->accepts_cargo)) continue; |
b1d30d9d4025
(svn r16654) -Codechange: cache industries in station's coverage area instead of searching them everytime payment is made
smatz <smatz@openttd.org>
parents:
12228
diff
changeset
|
918 |
b1d30d9d4025
(svn r16654) -Codechange: cache industries in station's coverage area instead of searching them everytime payment is made
smatz <smatz@openttd.org>
parents:
12228
diff
changeset
|
919 /* Check if industry temporarily refuses acceptance */ |
15729
f6078460c5b1
(svn r20396) -Codechange: introduce a helper function to test whether an industry temporarily refues to accept some cargo
yexo <yexo@openttd.org>
parents:
15726
diff
changeset
|
920 if (IndustryTemporarilyRefusesCargo(ind, cargo_type)) continue; |
7165
c3b231638b80
(svn r10439) -Codechange: initial steps for customized industry productions.
rubidium <rubidium@openttd.org>
parents:
7124
diff
changeset
|
921 |
12267
fe4287ad4243
(svn r16682) -Codechange: make (static) industry list used to trigger the industries' production compile unit static instead of passing it around as pointer
rubidium <rubidium@openttd.org>
parents:
12266
diff
changeset
|
922 /* Insert the industry into _cargo_delivery_destinations, if not yet contained */ |
fe4287ad4243
(svn r16682) -Codechange: make (static) industry list used to trigger the industries' production compile unit static instead of passing it around as pointer
rubidium <rubidium@openttd.org>
parents:
12266
diff
changeset
|
923 _cargo_delivery_destinations.Include(ind); |
12239
b1d30d9d4025
(svn r16654) -Codechange: cache industries in station's coverage area instead of searching them everytime payment is made
smatz <smatz@openttd.org>
parents:
12228
diff
changeset
|
924 |
12956
3a0bbffd1a58
(svn r17449) -Fix (r17436): MSVC compile warning about comparing signed and unsigned values
rubidium <rubidium@openttd.org>
parents:
12946
diff
changeset
|
925 uint amount = min(num_pieces, 0xFFFFU - ind->incoming_cargo_waiting[cargo_index]); |
12943
049765007dc0
(svn r17436) -Change: pay only for cargo actually delivered, not for all cargo unloaded at station (can differ with 'stockpiling' industries)
smatz <smatz@openttd.org>
parents:
12942
diff
changeset
|
926 ind->incoming_cargo_waiting[cargo_index] += amount; |
049765007dc0
(svn r17436) -Change: pay only for cargo actually delivered, not for all cargo unloaded at station (can differ with 'stockpiling' industries)
smatz <smatz@openttd.org>
parents:
12942
diff
changeset
|
927 num_pieces -= amount; |
049765007dc0
(svn r17436) -Change: pay only for cargo actually delivered, not for all cargo unloaded at station (can differ with 'stockpiling' industries)
smatz <smatz@openttd.org>
parents:
12942
diff
changeset
|
928 accepted += amount; |
049765007dc0
(svn r17436) -Change: pay only for cargo actually delivered, not for all cargo unloaded at station (can differ with 'stockpiling' industries)
smatz <smatz@openttd.org>
parents:
12942
diff
changeset
|
929 } |
12239
b1d30d9d4025
(svn r16654) -Codechange: cache industries in station's coverage area instead of searching them everytime payment is made
smatz <smatz@openttd.org>
parents:
12228
diff
changeset
|
930 |
12943
049765007dc0
(svn r17436) -Change: pay only for cargo actually delivered, not for all cargo unloaded at station (can differ with 'stockpiling' industries)
smatz <smatz@openttd.org>
parents:
12942
diff
changeset
|
931 return accepted; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
932 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
933 |
10450
e3e68b2c143c
(svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents:
10419
diff
changeset
|
934 /** |
e3e68b2c143c
(svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents:
10419
diff
changeset
|
935 * Delivers goods to industries/towns and calculates the payment |
e3e68b2c143c
(svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents:
10419
diff
changeset
|
936 * @param num_pieces amount of cargo delivered |
13070
1c4c4ae8d716
(svn r17570) -Fix: a number of Doxygen warnings about missing parameters, which were sometimes missing and sometimes just typos
rubidium <rubidium@openttd.org>
parents:
13067
diff
changeset
|
937 * @param cargo_type the type of cargo that is delivered |
10450
e3e68b2c143c
(svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents:
10419
diff
changeset
|
938 * @param dest Station the cargo has been unloaded |
e3e68b2c143c
(svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents:
10419
diff
changeset
|
939 * @param source_tile The origin of the cargo for distance calculation |
e3e68b2c143c
(svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents:
10419
diff
changeset
|
940 * @param days_in_transit Travel time |
12266
c9e7d3ec5c1a
(svn r16681) -Codechange: only resolve the company once for vehicle payment instead of each time a cargo packet is delivered
rubidium <rubidium@openttd.org>
parents:
12265
diff
changeset
|
941 * @param company The company delivering the cargo |
12658
b75d8c6681bd
(svn r17113) -Change [FS#265][FS#2094][FS#2589]: apply the subsidy when subsidy's destination is in station's catchment area and cargo packets originate from subsidy's source
smatz <smatz@openttd.org>
parents:
12652
diff
changeset
|
942 * @param src_type Type of source of cargo (industry, town, headquarters) |
b75d8c6681bd
(svn r17113) -Change [FS#265][FS#2094][FS#2589]: apply the subsidy when subsidy's destination is in station's catchment area and cargo packets originate from subsidy's source
smatz <smatz@openttd.org>
parents:
12652
diff
changeset
|
943 * @param src Index of source of cargo |
b75d8c6681bd
(svn r17113) -Change [FS#265][FS#2094][FS#2589]: apply the subsidy when subsidy's destination is in station's catchment area and cargo packets originate from subsidy's source
smatz <smatz@openttd.org>
parents:
12652
diff
changeset
|
944 * @return Revenue for delivering cargo |
b75d8c6681bd
(svn r17113) -Change [FS#265][FS#2094][FS#2589]: apply the subsidy when subsidy's destination is in station's catchment area and cargo packets originate from subsidy's source
smatz <smatz@openttd.org>
parents:
12652
diff
changeset
|
945 * @note The cargo is just added to the stockpile of the industry. It is due to the caller to trigger the industry's production machinery |
10450
e3e68b2c143c
(svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents:
10419
diff
changeset
|
946 */ |
12658
b75d8c6681bd
(svn r17113) -Change [FS#265][FS#2094][FS#2589]: apply the subsidy when subsidy's destination is in station's catchment area and cargo packets originate from subsidy's source
smatz <smatz@openttd.org>
parents:
12652
diff
changeset
|
947 static Money DeliverGoods(int num_pieces, CargoID cargo_type, StationID dest, TileIndex source_tile, byte days_in_transit, Company *company, SourceType src_type, SourceID src) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
948 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
949 assert(num_pieces > 0); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
950 |
12658
b75d8c6681bd
(svn r17113) -Change [FS#265][FS#2094][FS#2589]: apply the subsidy when subsidy's destination is in station's catchment area and cargo packets originate from subsidy's source
smatz <smatz@openttd.org>
parents:
12652
diff
changeset
|
951 const Station *st = Station::Get(dest); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
952 |
6125
46d001ebacf6
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents:
6119
diff
changeset
|
953 /* Give the goods to the industry. */ |
12944
75ae91d09b03
(svn r17437) -Change: don't accept cargo produced in the same industry (generalise and improve the check used only for valuables)
smatz <smatz@openttd.org>
parents:
12943
diff
changeset
|
954 uint accepted = DeliverGoodsToIndustry(st, cargo_type, num_pieces, src_type == ST_INDUSTRY ? src : INVALID_INDUSTRY); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
955 |
13092
d755cf7553ef
(svn r17592) -Fix [FS#3212](r17436): force all cargo being accepted when industry tiles accept it but industry itself doesn't
smatz <smatz@openttd.org>
parents:
13089
diff
changeset
|
956 /* If this cargo type is always accepted, accept all */ |
13089
559dafab3ecb
(svn r17589) -Codechange: rename town_acc to always_accepted
smatz <smatz@openttd.org>
parents:
13079
diff
changeset
|
957 if (HasBit(st->always_accepted, cargo_type)) accepted = num_pieces; |
12946
560c26f15688
(svn r17439) -Fix (r17436): you weren't paid for cargo delivered to houses and headquarters anymore
smatz <smatz@openttd.org>
parents:
12944
diff
changeset
|
958 |
13995
bc8b836e1fb9
(svn r18537) -Fix (r17436): Also do not account cargo in statistics, if it was not accepted.
frosch <frosch@openttd.org>
parents:
13804
diff
changeset
|
959 /* Update company statistics */ |
bc8b836e1fb9
(svn r18537) -Fix (r17436): Also do not account cargo in statistics, if it was not accepted.
frosch <frosch@openttd.org>
parents:
13804
diff
changeset
|
960 company->cur_economy.delivered_cargo += accepted; |
bc8b836e1fb9
(svn r18537) -Fix (r17436): Also do not account cargo in statistics, if it was not accepted.
frosch <frosch@openttd.org>
parents:
13804
diff
changeset
|
961 if (accepted > 0) SetBit(company->cargo_types, cargo_type); |
bc8b836e1fb9
(svn r18537) -Fix (r17436): Also do not account cargo in statistics, if it was not accepted.
frosch <frosch@openttd.org>
parents:
13804
diff
changeset
|
962 |
bc8b836e1fb9
(svn r18537) -Fix (r17436): Also do not account cargo in statistics, if it was not accepted.
frosch <frosch@openttd.org>
parents:
13804
diff
changeset
|
963 /* Increase town's counter for some special goods types */ |
bc8b836e1fb9
(svn r18537) -Fix (r17436): Also do not account cargo in statistics, if it was not accepted.
frosch <frosch@openttd.org>
parents:
13804
diff
changeset
|
964 const CargoSpec *cs = CargoSpec::Get(cargo_type); |
bc8b836e1fb9
(svn r18537) -Fix (r17436): Also do not account cargo in statistics, if it was not accepted.
frosch <frosch@openttd.org>
parents:
13804
diff
changeset
|
965 if (cs->town_effect == TE_FOOD) st->town->new_act_food += accepted; |
bc8b836e1fb9
(svn r18537) -Fix (r17436): Also do not account cargo in statistics, if it was not accepted.
frosch <frosch@openttd.org>
parents:
13804
diff
changeset
|
966 if (cs->town_effect == TE_WATER) st->town->new_act_water += accepted; |
bc8b836e1fb9
(svn r18537) -Fix (r17436): Also do not account cargo in statistics, if it was not accepted.
frosch <frosch@openttd.org>
parents:
13804
diff
changeset
|
967 |
6125
46d001ebacf6
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents:
6119
diff
changeset
|
968 /* Determine profit */ |
12943
049765007dc0
(svn r17436) -Change: pay only for cargo actually delivered, not for all cargo unloaded at station (can differ with 'stockpiling' industries)
smatz <smatz@openttd.org>
parents:
12942
diff
changeset
|
969 Money profit = GetTransportedGoodsIncome(accepted, DistanceManhattan(source_tile, st->xy), days_in_transit, cargo_type); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
970 |
6125
46d001ebacf6
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents:
6119
diff
changeset
|
971 /* Modify profit if a subsidy is in effect */ |
12658
b75d8c6681bd
(svn r17113) -Change [FS#265][FS#2094][FS#2589]: apply the subsidy when subsidy's destination is in station's catchment area and cargo packets originate from subsidy's source
smatz <smatz@openttd.org>
parents:
12652
diff
changeset
|
972 if (CheckSubsidised(cargo_type, company->index, src_type, src, st)) { |
9413
512ea64da840
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium <rubidium@openttd.org>
parents:
9359
diff
changeset
|
973 switch (_settings_game.difficulty.subsidy_multiplier) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
974 case 0: profit += profit >> 1; break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
975 case 1: profit *= 2; break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
976 case 2: profit *= 3; break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
977 default: profit *= 4; break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
978 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
979 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
980 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
981 return profit; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
982 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
983 |
6559
b680e3433ca2
(svn r9761) -Codechange: refactor cargo payment out of LoadUnloadVehicle.
rubidium <rubidium@openttd.org>
parents:
6500
diff
changeset
|
984 /** |
10450
e3e68b2c143c
(svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents:
10419
diff
changeset
|
985 * Inform the industry about just delivered cargo |
e3e68b2c143c
(svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents:
10419
diff
changeset
|
986 * DeliverGoodsToIndustry() silently incremented incoming_cargo_waiting, now it is time to do something with the new cargo. |
e3e68b2c143c
(svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents:
10419
diff
changeset
|
987 * @param i The industry to process |
e3e68b2c143c
(svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents:
10419
diff
changeset
|
988 */ |
e3e68b2c143c
(svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents:
10419
diff
changeset
|
989 static void TriggerIndustryProduction(Industry *i) |
e3e68b2c143c
(svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents:
10419
diff
changeset
|
990 { |
e3e68b2c143c
(svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents:
10419
diff
changeset
|
991 const IndustrySpec *indspec = GetIndustrySpec(i->type); |
13036
8e2a0e8fa275
(svn r17534) -Codechange: unify the naming of callback masks/flags
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
992 uint16 callback = indspec->callback_mask; |
10450
e3e68b2c143c
(svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents:
10419
diff
changeset
|
993 |
e3e68b2c143c
(svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents:
10419
diff
changeset
|
994 i->was_cargo_delivered = true; |
e3e68b2c143c
(svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents:
10419
diff
changeset
|
995 i->last_cargo_accepted_at = _date; |
e3e68b2c143c
(svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents:
10419
diff
changeset
|
996 |
e3e68b2c143c
(svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents:
10419
diff
changeset
|
997 if (HasBit(callback, CBM_IND_PRODUCTION_CARGO_ARRIVAL) || HasBit(callback, CBM_IND_PRODUCTION_256_TICKS)) { |
e3e68b2c143c
(svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents:
10419
diff
changeset
|
998 if (HasBit(callback, CBM_IND_PRODUCTION_CARGO_ARRIVAL)) { |
e3e68b2c143c
(svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents:
10419
diff
changeset
|
999 IndustryProductionCallback(i, 0); |
e3e68b2c143c
(svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents:
10419
diff
changeset
|
1000 } else { |
13034
6eb3f749890a
(svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents:
12991
diff
changeset
|
1001 SetWindowDirty(WC_INDUSTRY_VIEW, i->index); |
10450
e3e68b2c143c
(svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents:
10419
diff
changeset
|
1002 } |
e3e68b2c143c
(svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents:
10419
diff
changeset
|
1003 } else { |
e3e68b2c143c
(svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents:
10419
diff
changeset
|
1004 for (uint cargo_index = 0; cargo_index < lengthof(i->incoming_cargo_waiting); cargo_index++) { |
e3e68b2c143c
(svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents:
10419
diff
changeset
|
1005 uint cargo_waiting = i->incoming_cargo_waiting[cargo_index]; |
e3e68b2c143c
(svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents:
10419
diff
changeset
|
1006 if (cargo_waiting == 0) continue; |
e3e68b2c143c
(svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents:
10419
diff
changeset
|
1007 |
e3e68b2c143c
(svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents:
10419
diff
changeset
|
1008 i->produced_cargo_waiting[0] = min(i->produced_cargo_waiting[0] + (cargo_waiting * indspec->input_cargo_multiplier[cargo_index][0] / 256), 0xFFFF); |
e3e68b2c143c
(svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents:
10419
diff
changeset
|
1009 i->produced_cargo_waiting[1] = min(i->produced_cargo_waiting[1] + (cargo_waiting * indspec->input_cargo_multiplier[cargo_index][1] / 256), 0xFFFF); |
e3e68b2c143c
(svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents:
10419
diff
changeset
|
1010 |
e3e68b2c143c
(svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents:
10419
diff
changeset
|
1011 i->incoming_cargo_waiting[cargo_index] = 0; |
e3e68b2c143c
(svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents:
10419
diff
changeset
|
1012 } |
e3e68b2c143c
(svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents:
10419
diff
changeset
|
1013 } |
e3e68b2c143c
(svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents:
10419
diff
changeset
|
1014 |
e3e68b2c143c
(svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents:
10419
diff
changeset
|
1015 TriggerIndustry(i, INDUSTRY_TRIGGER_RECEIVED_CARGO); |
e3e68b2c143c
(svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents:
10419
diff
changeset
|
1016 StartStopIndustryTileAnimation(i, IAT_INDUSTRY_RECEIVED_CARGO); |
e3e68b2c143c
(svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents:
10419
diff
changeset
|
1017 } |
e3e68b2c143c
(svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents:
10419
diff
changeset
|
1018 |
e3e68b2c143c
(svn r14705) -Fix [FS#2460]: First transfer the whole load of a vehicle chain to industries before triggering any processing.
frosch <frosch@openttd.org>
parents:
10419
diff
changeset
|
1019 /** |
12268
3a97d4e6f918
(svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents:
12267
diff
changeset
|
1020 * Makes us a new cargo payment helper. |
3a97d4e6f918
(svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents:
12267
diff
changeset
|
1021 * @param front The front of the train |
3a97d4e6f918
(svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents:
12267
diff
changeset
|
1022 */ |
3a97d4e6f918
(svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents:
12267
diff
changeset
|
1023 CargoPayment::CargoPayment(Vehicle *front) : |
3a97d4e6f918
(svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents:
12267
diff
changeset
|
1024 front(front), |
3a97d4e6f918
(svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents:
12267
diff
changeset
|
1025 current_station(front->last_station_visited) |
3a97d4e6f918
(svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents:
12267
diff
changeset
|
1026 { |
3a97d4e6f918
(svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents:
12267
diff
changeset
|
1027 } |
3a97d4e6f918
(svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents:
12267
diff
changeset
|
1028 |
3a97d4e6f918
(svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents:
12267
diff
changeset
|
1029 CargoPayment::~CargoPayment() |
3a97d4e6f918
(svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents:
12267
diff
changeset
|
1030 { |
12279
329b186db8cd
(svn r16694) -Fix [FS#2995] (rgradual loading, rnewindustries): only pay for whatever has been actually unloaded and perform the payment when unloading has finished. This fixes, amongst others:
rubidium <rubidium@openttd.org>
parents:
12278
diff
changeset
|
1031 if (this->CleaningPool()) return; |
329b186db8cd
(svn r16694) -Fix [FS#2995] (rgradual loading, rnewindustries): only pay for whatever has been actually unloaded and perform the payment when unloading has finished. This fixes, amongst others:
rubidium <rubidium@openttd.org>
parents:
12278
diff
changeset
|
1032 |
329b186db8cd
(svn r16694) -Fix [FS#2995] (rgradual loading, rnewindustries): only pay for whatever has been actually unloaded and perform the payment when unloading has finished. This fixes, amongst others:
rubidium <rubidium@openttd.org>
parents:
12278
diff
changeset
|
1033 this->front->cargo_payment = NULL; |
329b186db8cd
(svn r16694) -Fix [FS#2995] (rgradual loading, rnewindustries): only pay for whatever has been actually unloaded and perform the payment when unloading has finished. This fixes, amongst others:
rubidium <rubidium@openttd.org>
parents:
12278
diff
changeset
|
1034 |
12268
3a97d4e6f918
(svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents:
12267
diff
changeset
|
1035 if (this->visual_profit == 0) return; |
3a97d4e6f918
(svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents:
12267
diff
changeset
|
1036 |
15292
e2c62d70dfcf
(svn r19931) -Fix (r19914): Convert assertion in Backup<> destructor into DEBUG() output. It was triggered on exceptions, especially when aborting world generation.
frosch <frosch@openttd.org>
parents:
15279
diff
changeset
|
1037 Backup<CompanyByte> cur_company(_current_company, this->front->owner, FILE_LINE); |
12268
3a97d4e6f918
(svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents:
12267
diff
changeset
|
1038 |
3a97d4e6f918
(svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents:
12267
diff
changeset
|
1039 SubtractMoneyFromCompany(CommandCost(this->front->GetExpenseType(true), -this->route_profit)); |
12278
492621950e1a
(svn r16693) -Fix [FS#3004] (r16883): cargo income was not added to the vehicle's profit.
rubidium <rubidium@openttd.org>
parents:
12268
diff
changeset
|
1040 this->front->profit_this_year += this->visual_profit << 8; |
12268
3a97d4e6f918
(svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents:
12267
diff
changeset
|
1041 |
3a97d4e6f918
(svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents:
12267
diff
changeset
|
1042 if (this->route_profit != 0) { |
3a97d4e6f918
(svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents:
12267
diff
changeset
|
1043 if (IsLocalCompany() && !PlayVehicleSound(this->front, VSE_LOAD_UNLOAD)) { |
3a97d4e6f918
(svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents:
12267
diff
changeset
|
1044 SndPlayVehicleFx(SND_14_CASHTILL, this->front); |
3a97d4e6f918
(svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents:
12267
diff
changeset
|
1045 } |
3a97d4e6f918
(svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents:
12267
diff
changeset
|
1046 |
3a97d4e6f918
(svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents:
12267
diff
changeset
|
1047 ShowCostOrIncomeAnimation(this->front->x_pos, this->front->y_pos, this->front->z_pos, -this->visual_profit); |
3a97d4e6f918
(svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents:
12267
diff
changeset
|
1048 } else { |
3a97d4e6f918
(svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents:
12267
diff
changeset
|
1049 ShowFeederIncomeAnimation(this->front->x_pos, this->front->y_pos, this->front->z_pos, this->visual_profit); |
3a97d4e6f918
(svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents:
12267
diff
changeset
|
1050 } |
3a97d4e6f918
(svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents:
12267
diff
changeset
|
1051 |
15279
4e1862aebea2
(svn r19914) -Codechange: Wrap a helper class around temporary assignments of _current_company to ensure proper restoration.
frosch <frosch@openttd.org>
parents:
15050
diff
changeset
|
1052 cur_company.Restore(); |
12268
3a97d4e6f918
(svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents:
12267
diff
changeset
|
1053 } |
3a97d4e6f918
(svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents:
12267
diff
changeset
|
1054 |
3a97d4e6f918
(svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents:
12267
diff
changeset
|
1055 /** |
3a97d4e6f918
(svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents:
12267
diff
changeset
|
1056 * Handle payment for final delivery of the given cargo packet. |
3a97d4e6f918
(svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents:
12267
diff
changeset
|
1057 * @param cp The cargo packet to pay for. |
3a97d4e6f918
(svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents:
12267
diff
changeset
|
1058 * @param count The number of packets to pay for. |
3a97d4e6f918
(svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents:
12267
diff
changeset
|
1059 */ |
13213
cbc7f8fe50ee
(svn r17720) -Codechange: guard the CargoPacket variables that are cached in CargoLists so they cannot be written from outside the CargoList class (based on patch by fonsinchen)
rubidium <rubidium@openttd.org>
parents:
13092
diff
changeset
|
1060 void CargoPayment::PayFinalDelivery(const CargoPacket *cp, uint count) |
12268
3a97d4e6f918
(svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents:
12267
diff
changeset
|
1061 { |
3a97d4e6f918
(svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents:
12267
diff
changeset
|
1062 if (this->owner == NULL) { |
3a97d4e6f918
(svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents:
12267
diff
changeset
|
1063 this->owner = Company::Get(this->front->owner); |
3a97d4e6f918
(svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents:
12267
diff
changeset
|
1064 } |
3a97d4e6f918
(svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents:
12267
diff
changeset
|
1065 |
3a97d4e6f918
(svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents:
12267
diff
changeset
|
1066 /* Handle end of route payment */ |
13325
2cac520633fc
(svn r17834) -Fix [FS#3274] (r17808): you got paid a bit too much... ofcourse the index of the source station generally doesn't equal the location of said station.
rubidium <rubidium@openttd.org>
parents:
13299
diff
changeset
|
1067 Money profit = DeliverGoods(count, this->ct, this->current_station, cp->SourceStationXY(), cp->DaysInTransit(), this->owner, cp->SourceSubsidyType(), cp->SourceSubsidyID()); |
12268
3a97d4e6f918
(svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents:
12267
diff
changeset
|
1068 this->route_profit += profit; |
3a97d4e6f918
(svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents:
12267
diff
changeset
|
1069 |
3a97d4e6f918
(svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents:
12267
diff
changeset
|
1070 /* The vehicle's profit is whatever route profit there is minus feeder shares. */ |
13213
cbc7f8fe50ee
(svn r17720) -Codechange: guard the CargoPacket variables that are cached in CargoLists so they cannot be written from outside the CargoList class (based on patch by fonsinchen)
rubidium <rubidium@openttd.org>
parents:
13092
diff
changeset
|
1071 this->visual_profit += profit - cp->FeederShare(); |
12268
3a97d4e6f918
(svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents:
12267
diff
changeset
|
1072 } |
3a97d4e6f918
(svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents:
12267
diff
changeset
|
1073 |
3a97d4e6f918
(svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents:
12267
diff
changeset
|
1074 /** |
3a97d4e6f918
(svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents:
12267
diff
changeset
|
1075 * Handle payment for transfer of the given cargo packet. |
13213
cbc7f8fe50ee
(svn r17720) -Codechange: guard the CargoPacket variables that are cached in CargoLists so they cannot be written from outside the CargoList class (based on patch by fonsinchen)
rubidium <rubidium@openttd.org>
parents:
13092
diff
changeset
|
1076 * @param cp The cargo packet to pay for; actual payment won't be made!. |
12268
3a97d4e6f918
(svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents:
12267
diff
changeset
|
1077 * @param count The number of packets to pay for. |
13213
cbc7f8fe50ee
(svn r17720) -Codechange: guard the CargoPacket variables that are cached in CargoLists so they cannot be written from outside the CargoList class (based on patch by fonsinchen)
rubidium <rubidium@openttd.org>
parents:
13092
diff
changeset
|
1078 * @return The amount of money paid for the transfer. |
12268
3a97d4e6f918
(svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents:
12267
diff
changeset
|
1079 */ |
13213
cbc7f8fe50ee
(svn r17720) -Codechange: guard the CargoPacket variables that are cached in CargoLists so they cannot be written from outside the CargoList class (based on patch by fonsinchen)
rubidium <rubidium@openttd.org>
parents:
13092
diff
changeset
|
1080 Money CargoPayment::PayTransfer(const CargoPacket *cp, uint count) |
12268
3a97d4e6f918
(svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents:
12267
diff
changeset
|
1081 { |
3a97d4e6f918
(svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents:
12267
diff
changeset
|
1082 Money profit = GetTransportedGoodsIncome( |
15654
22d1a4dbf678
(svn r20319) -Codechange: Align comments, add indent to a function call.
alberth <alberth@openttd.org>
parents:
15653
diff
changeset
|
1083 count, |
22d1a4dbf678
(svn r20319) -Codechange: Align comments, add indent to a function call.
alberth <alberth@openttd.org>
parents:
15653
diff
changeset
|
1084 /* pay transfer vehicle for only the part of transfer it has done: ie. cargo_loaded_at_xy to here */ |
22d1a4dbf678
(svn r20319) -Codechange: Align comments, add indent to a function call.
alberth <alberth@openttd.org>
parents:
15653
diff
changeset
|
1085 DistanceManhattan(cp->LoadedAtXY(), Station::Get(this->current_station)->xy), |
22d1a4dbf678
(svn r20319) -Codechange: Align comments, add indent to a function call.
alberth <alberth@openttd.org>
parents:
15653
diff
changeset
|
1086 cp->DaysInTransit(), |
22d1a4dbf678
(svn r20319) -Codechange: Align comments, add indent to a function call.
alberth <alberth@openttd.org>
parents:
15653
diff
changeset
|
1087 this->ct); |
12268
3a97d4e6f918
(svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents:
12267
diff
changeset
|
1088 |
14155
96be446af436
(svn r18703) -Feature-ish: allow virtually paying a percentage of the leg profit in feeder chains. This to give the user a better chance to get a feeder system without "losses".
rubidium <rubidium@openttd.org>
parents:
14136
diff
changeset
|
1089 profit = profit * _settings_game.economy.feeder_payment_share / 100; |
96be446af436
(svn r18703) -Feature-ish: allow virtually paying a percentage of the leg profit in feeder chains. This to give the user a better chance to get a feeder system without "losses".
rubidium <rubidium@openttd.org>
parents:
14136
diff
changeset
|
1090 |
12268
3a97d4e6f918
(svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents:
12267
diff
changeset
|
1091 this->visual_profit += profit; // accumulate transfer profits for whole vehicle |
13213
cbc7f8fe50ee
(svn r17720) -Codechange: guard the CargoPacket variables that are cached in CargoLists so they cannot be written from outside the CargoList class (based on patch by fonsinchen)
rubidium <rubidium@openttd.org>
parents:
13092
diff
changeset
|
1092 return profit; // account for the (virtual) profit already made for the cargo packet |
12268
3a97d4e6f918
(svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents:
12267
diff
changeset
|
1093 } |
3a97d4e6f918
(svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents:
12267
diff
changeset
|
1094 |
3a97d4e6f918
(svn r16683) -Codechange: move the cargo payment handling to a seperate class. Based on ideas of fonso/fonsinchen.
rubidium <rubidium@openttd.org>
parents:
12267
diff
changeset
|
1095 /** |
12279
329b186db8cd
(svn r16694) -Fix [FS#2995] (rgradual loading, rnewindustries): only pay for whatever has been actually unloaded and perform the payment when unloading has finished. This fixes, amongst others:
rubidium <rubidium@openttd.org>
parents:
12278
diff
changeset
|
1096 * Prepare the vehicle to be unloaded. |
6559
b680e3433ca2
(svn r9761) -Codechange: refactor cargo payment out of LoadUnloadVehicle.
rubidium <rubidium@openttd.org>
parents:
6500
diff
changeset
|
1097 * @param front_v the vehicle to be unloaded |
b680e3433ca2
(svn r9761) -Codechange: refactor cargo payment out of LoadUnloadVehicle.
rubidium <rubidium@openttd.org>
parents:
6500
diff
changeset
|
1098 */ |
12279
329b186db8cd
(svn r16694) -Fix [FS#2995] (rgradual loading, rnewindustries): only pay for whatever has been actually unloaded and perform the payment when unloading has finished. This fixes, amongst others:
rubidium <rubidium@openttd.org>
parents:
12278
diff
changeset
|
1099 void PrepareUnload(Vehicle *front_v) |
6559
b680e3433ca2
(svn r9761) -Codechange: refactor cargo payment out of LoadUnloadVehicle.
rubidium <rubidium@openttd.org>
parents:
6500
diff
changeset
|
1100 { |
6565
547b0171c3a9
(svn r9770) -Codechange: perform the payment of cargo when loading/unloading, but when arriving at the station.
rubidium <rubidium@openttd.org>
parents:
6559
diff
changeset
|
1101 /* At this moment loading cannot be finished */ |
7929
4d13dbed828c
(svn r11482) -Codechange: Remove the doubled function ClrBitT and rename the remaining to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7928
diff
changeset
|
1102 ClrBit(front_v->vehicle_flags, VF_LOADING_FINISHED); |
6565
547b0171c3a9
(svn r9770) -Codechange: perform the payment of cargo when loading/unloading, but when arriving at the station.
rubidium <rubidium@openttd.org>
parents:
6559
diff
changeset
|
1103 |
547b0171c3a9
(svn r9770) -Codechange: perform the payment of cargo when loading/unloading, but when arriving at the station.
rubidium <rubidium@openttd.org>
parents:
6559
diff
changeset
|
1104 /* Start unloading in at the first possible moment */ |
14213
41b2e7bf03da
(svn r18764) -Fix [FS#3422]: split the (un)load ticks counter and signal wait counter; sometimes they might get into eachother's way
rubidium <rubidium@openttd.org>
parents:
14169
diff
changeset
|
1105 front_v->load_unload_ticks = 1; |
6565
547b0171c3a9
(svn r9770) -Codechange: perform the payment of cargo when loading/unloading, but when arriving at the station.
rubidium <rubidium@openttd.org>
parents:
6559
diff
changeset
|
1106 |
12279
329b186db8cd
(svn r16694) -Fix [FS#2995] (rgradual loading, rnewindustries): only pay for whatever has been actually unloaded and perform the payment when unloading has finished. This fixes, amongst others:
rubidium <rubidium@openttd.org>
parents:
12278
diff
changeset
|
1107 if ((front_v->current_order.GetUnloadType() & OUFB_NO_UNLOAD) == 0) { |
329b186db8cd
(svn r16694) -Fix [FS#2995] (rgradual loading, rnewindustries): only pay for whatever has been actually unloaded and perform the payment when unloading has finished. This fixes, amongst others:
rubidium <rubidium@openttd.org>
parents:
12278
diff
changeset
|
1108 for (Vehicle *v = front_v; v != NULL; v = v->Next()) { |
329b186db8cd
(svn r16694) -Fix [FS#2995] (rgradual loading, rnewindustries): only pay for whatever has been actually unloaded and perform the payment when unloading has finished. This fixes, amongst others:
rubidium <rubidium@openttd.org>
parents:
12278
diff
changeset
|
1109 if (v->cargo_cap > 0 && !v->cargo.Empty()) { |
7931
44ff7a6d801f
(svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7929
diff
changeset
|
1110 SetBit(v->vehicle_flags, VF_CARGO_UNLOADING); |
6559
b680e3433ca2
(svn r9761) -Codechange: refactor cargo payment out of LoadUnloadVehicle.
rubidium <rubidium@openttd.org>
parents:
6500
diff
changeset
|
1111 } |
b680e3433ca2
(svn r9761) -Codechange: refactor cargo payment out of LoadUnloadVehicle.
rubidium <rubidium@openttd.org>
parents:
6500
diff
changeset
|
1112 } |
b680e3433ca2
(svn r9761) -Codechange: refactor cargo payment out of LoadUnloadVehicle.
rubidium <rubidium@openttd.org>
parents:
6500
diff
changeset
|
1113 } |
b680e3433ca2
(svn r9761) -Codechange: refactor cargo payment out of LoadUnloadVehicle.
rubidium <rubidium@openttd.org>
parents:
6500
diff
changeset
|
1114 |
12279
329b186db8cd
(svn r16694) -Fix [FS#2995] (rgradual loading, rnewindustries): only pay for whatever has been actually unloaded and perform the payment when unloading has finished. This fixes, amongst others:
rubidium <rubidium@openttd.org>
parents:
12278
diff
changeset
|
1115 assert(front_v->cargo_payment == NULL); |
329b186db8cd
(svn r16694) -Fix [FS#2995] (rgradual loading, rnewindustries): only pay for whatever has been actually unloaded and perform the payment when unloading has finished. This fixes, amongst others:
rubidium <rubidium@openttd.org>
parents:
12278
diff
changeset
|
1116 front_v->cargo_payment = new CargoPayment(front_v); |
6559
b680e3433ca2
(svn r9761) -Codechange: refactor cargo payment out of LoadUnloadVehicle.
rubidium <rubidium@openttd.org>
parents:
6500
diff
changeset
|
1117 } |
b680e3433ca2
(svn r9761) -Codechange: refactor cargo payment out of LoadUnloadVehicle.
rubidium <rubidium@openttd.org>
parents:
6500
diff
changeset
|
1118 |
6580
e1cdf0b1265b
(svn r9794) -Codechange: refactor the question whether a vehicle can be loaded into LoadUnloadVehicle instead of duplicating it for each vehicle.
rubidium <rubidium@openttd.org>
parents:
6565
diff
changeset
|
1119 /** |
e1cdf0b1265b
(svn r9794) -Codechange: refactor the question whether a vehicle can be loaded into LoadUnloadVehicle instead of duplicating it for each vehicle.
rubidium <rubidium@openttd.org>
parents:
6565
diff
changeset
|
1120 * Loads/unload the vehicle if possible. |
e1cdf0b1265b
(svn r9794) -Codechange: refactor the question whether a vehicle can be loaded into LoadUnloadVehicle instead of duplicating it for each vehicle.
rubidium <rubidium@openttd.org>
parents:
6565
diff
changeset
|
1121 * @param v the vehicle to be (un)loaded |
6618
a0ebb1506656
(svn r9838) -Fix: make "improved loading" a proper improved loading instead of loading one (semi-)random vehicle at a time:
rubidium <rubidium@openttd.org>
parents:
6616
diff
changeset
|
1122 * @param cargo_left the amount of each cargo type that is |
a0ebb1506656
(svn r9838) -Fix: make "improved loading" a proper improved loading instead of loading one (semi-)random vehicle at a time:
rubidium <rubidium@openttd.org>
parents:
6616
diff
changeset
|
1123 * virtually left on the platform to be |
a0ebb1506656
(svn r9838) -Fix: make "improved loading" a proper improved loading instead of loading one (semi-)random vehicle at a time:
rubidium <rubidium@openttd.org>
parents:
6616
diff
changeset
|
1124 * picked up by another vehicle when all |
a0ebb1506656
(svn r9838) -Fix: make "improved loading" a proper improved loading instead of loading one (semi-)random vehicle at a time:
rubidium <rubidium@openttd.org>
parents:
6616
diff
changeset
|
1125 * previous vehicles have loaded. |
6580
e1cdf0b1265b
(svn r9794) -Codechange: refactor the question whether a vehicle can be loaded into LoadUnloadVehicle instead of duplicating it for each vehicle.
rubidium <rubidium@openttd.org>
parents:
6565
diff
changeset
|
1126 */ |
6618
a0ebb1506656
(svn r9838) -Fix: make "improved loading" a proper improved loading instead of loading one (semi-)random vehicle at a time:
rubidium <rubidium@openttd.org>
parents:
6616
diff
changeset
|
1127 static void LoadUnloadVehicle(Vehicle *v, int *cargo_left) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1128 { |
8837
bdaf8866039c
(svn r12585) -Fix (r12584): assumption that assertions were enabled during compilation/testing was flawed.
rubidium <rubidium@openttd.org>
parents:
8814
diff
changeset
|
1129 assert(v->current_order.IsType(OT_LOADING)); |
12756
7e6255798f4e
(svn r17222) -Fix [FS#3129, FS#3130]: with time tables vehicles would stay in the 'loading' state after they have finished loading
rubidium <rubidium@openttd.org>
parents:
12669
diff
changeset
|
1130 |
14213
41b2e7bf03da
(svn r18764) -Fix [FS#3422]: split the (un)load ticks counter and signal wait counter; sometimes they might get into eachother's way
rubidium <rubidium@openttd.org>
parents:
14169
diff
changeset
|
1131 assert(v->load_unload_ticks != 0); |
6616
ce5601a32593
(svn r9836) -Codechange: make non-improved loading happen FIFO-ish; generally loading/unloading will happen fifo, but there are no guarantees on the FIFO-ness. For (better) FIFO guarantees you still need to use improved loading.
rubidium <rubidium@openttd.org>
parents:
6611
diff
changeset
|
1132 |
ce5601a32593
(svn r9836) -Codechange: make non-improved loading happen FIFO-ish; generally loading/unloading will happen fifo, but there are no guarantees on the FIFO-ness. For (better) FIFO guarantees you still need to use improved loading.
rubidium <rubidium@openttd.org>
parents:
6611
diff
changeset
|
1133 /* We have not waited enough time till the next round of loading/unloading */ |
14213
41b2e7bf03da
(svn r18764) -Fix [FS#3422]: split the (un)load ticks counter and signal wait counter; sometimes they might get into eachother's way
rubidium <rubidium@openttd.org>
parents:
14169
diff
changeset
|
1134 if (--v->load_unload_ticks != 0) { |
9413
512ea64da840
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium <rubidium@openttd.org>
parents:
9359
diff
changeset
|
1135 if (_settings_game.order.improved_load && (v->current_order.GetLoadType() & OLFB_FULL_LOAD)) { |
6618
a0ebb1506656
(svn r9838) -Fix: make "improved loading" a proper improved loading instead of loading one (semi-)random vehicle at a time:
rubidium <rubidium@openttd.org>
parents:
6616
diff
changeset
|
1136 /* 'Reserve' this cargo for this vehicle, because we were first. */ |
7492
09743324277c
(svn r11003) -Codechange: replace Vehicle->next to Vehicle->Next() and Vehicle->SetNext() so we can trap instances that change a next pointer and (in the future) update the first/previous pointers based on that.
rubidium <rubidium@openttd.org>
parents:
7474
diff
changeset
|
1137 for (; v != NULL; v = v->Next()) { |
11194
1c56a71f2bb1
(svn r15547) -Codechange: Eliminate all == and != comparisons between v->cargo_cap and v->cargo.Count() to improve behaviour wrt. broken/incompatible grfs.
frosch <frosch@openttd.org>
parents:
11090
diff
changeset
|
1138 int cap_left = v->cargo_cap - v->cargo.Count(); |
1c56a71f2bb1
(svn r15547) -Codechange: Eliminate all == and != comparisons between v->cargo_cap and v->cargo.Count() to improve behaviour wrt. broken/incompatible grfs.
frosch <frosch@openttd.org>
parents:
11090
diff
changeset
|
1139 if (cap_left > 0) cargo_left[v->cargo_type] -= cap_left; |
6618
a0ebb1506656
(svn r9838) -Fix: make "improved loading" a proper improved loading instead of loading one (semi-)random vehicle at a time:
rubidium <rubidium@openttd.org>
parents:
6616
diff
changeset
|
1140 } |
a0ebb1506656
(svn r9838) -Fix: make "improved loading" a proper improved loading instead of loading one (semi-)random vehicle at a time:
rubidium <rubidium@openttd.org>
parents:
6616
diff
changeset
|
1141 } |
a0ebb1506656
(svn r9838) -Fix: make "improved loading" a proper improved loading instead of loading one (semi-)random vehicle at a time:
rubidium <rubidium@openttd.org>
parents:
6616
diff
changeset
|
1142 return; |
a0ebb1506656
(svn r9838) -Fix: make "improved loading" a proper improved loading instead of loading one (semi-)random vehicle at a time:
rubidium <rubidium@openttd.org>
parents:
6616
diff
changeset
|
1143 } |
6616
ce5601a32593
(svn r9836) -Codechange: make non-improved loading happen FIFO-ish; generally loading/unloading will happen fifo, but there are no guarantees on the FIFO-ness. For (better) FIFO guarantees you still need to use improved loading.
rubidium <rubidium@openttd.org>
parents:
6611
diff
changeset
|
1144 |
8231
7002fda5bb72
(svn r11794) -Fix [FS#1632]: reversing a train when loading at a station with an adjacent station in the same axis crashed.
glx <glx@openttd.org>
parents:
8230
diff
changeset
|
1145 StationID last_visited = v->last_station_visited; |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11730
diff
changeset
|
1146 Station *st = Station::Get(last_visited); |
8231
7002fda5bb72
(svn r11794) -Fix [FS#1632]: reversing a train when loading at a station with an adjacent station in the same axis crashed.
glx <glx@openttd.org>
parents:
8230
diff
changeset
|
1147 |
7002fda5bb72
(svn r11794) -Fix [FS#1632]: reversing a train when loading at a station with an adjacent station in the same axis crashed.
glx <glx@openttd.org>
parents:
8230
diff
changeset
|
1148 if (v->type == VEH_TRAIN && (!IsTileType(v->tile, MP_STATION) || GetStationIndex(v->tile) != st->index)) { |
6844
70d60b0104c1
(svn r10084) -Fix [FS#855]: reversing a train when loading at a station crashed.
rubidium <rubidium@openttd.org>
parents:
6823
diff
changeset
|
1149 /* The train reversed in the station. Take the "easy" way |
70d60b0104c1
(svn r10084) -Fix [FS#855]: reversing a train when loading at a station crashed.
rubidium <rubidium@openttd.org>
parents:
6823
diff
changeset
|
1150 * out and let the train just leave as it always did. */ |
7931
44ff7a6d801f
(svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7929
diff
changeset
|
1151 SetBit(v->vehicle_flags, VF_LOADING_FINISHED); |
14213
41b2e7bf03da
(svn r18764) -Fix [FS#3422]: split the (un)load ticks counter and signal wait counter; sometimes they might get into eachother's way
rubidium <rubidium@openttd.org>
parents:
14169
diff
changeset
|
1152 v->load_unload_ticks = 1; |
6844
70d60b0104c1
(svn r10084) -Fix [FS#855]: reversing a train when loading at a station crashed.
rubidium <rubidium@openttd.org>
parents:
6823
diff
changeset
|
1153 return; |
70d60b0104c1
(svn r10084) -Fix [FS#855]: reversing a train when loading at a station crashed.
rubidium <rubidium@openttd.org>
parents:
6823
diff
changeset
|
1154 } |
70d60b0104c1
(svn r10084) -Fix [FS#855]: reversing a train when loading at a station crashed.
rubidium <rubidium@openttd.org>
parents:
6823
diff
changeset
|
1155 |
6611
461107df1c8f
(svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents:
6609
diff
changeset
|
1156 int unloading_time = 0; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1157 Vehicle *u = v; |
13998
3d6fd0265851
(svn r18540) -Codechange: resulting in better name for 'result'.
frosch <frosch@openttd.org>
parents:
13995
diff
changeset
|
1158 bool dirty_vehicle = false; |
3d6fd0265851
(svn r18540) -Codechange: resulting in better name for 'result'.
frosch <frosch@openttd.org>
parents:
13995
diff
changeset
|
1159 bool dirty_station = false; |
6565
547b0171c3a9
(svn r9770) -Codechange: perform the payment of cargo when loading/unloading, but when arriving at the station.
rubidium <rubidium@openttd.org>
parents:
6559
diff
changeset
|
1160 |
8241
4648f777da55
(svn r11805) -Fix [FS#1620]: VEHICLE_TRIGGER_EMPTY was triggered continuously while train waiting in station.
frosch <frosch@openttd.org>
parents:
8238
diff
changeset
|
1161 bool completely_emptied = true; |
6611
461107df1c8f
(svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents:
6609
diff
changeset
|
1162 bool anything_unloaded = false; |
461107df1c8f
(svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents:
6609
diff
changeset
|
1163 bool anything_loaded = false; |
461107df1c8f
(svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents:
6609
diff
changeset
|
1164 uint32 cargo_not_full = 0; |
461107df1c8f
(svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents:
6609
diff
changeset
|
1165 uint32 cargo_full = 0; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1166 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1167 v->cur_speed = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1168 |
12279
329b186db8cd
(svn r16694) -Fix [FS#2995] (rgradual loading, rnewindustries): only pay for whatever has been actually unloaded and perform the payment when unloading has finished. This fixes, amongst others:
rubidium <rubidium@openttd.org>
parents:
12278
diff
changeset
|
1169 CargoPayment *payment = v->cargo_payment; |
329b186db8cd
(svn r16694) -Fix [FS#2995] (rgradual loading, rnewindustries): only pay for whatever has been actually unloaded and perform the payment when unloading has finished. This fixes, amongst others:
rubidium <rubidium@openttd.org>
parents:
12278
diff
changeset
|
1170 |
7492
09743324277c
(svn r11003) -Codechange: replace Vehicle->next to Vehicle->Next() and Vehicle->SetNext() so we can trap instances that change a next pointer and (in the future) update the first/previous pointers based on that.
rubidium <rubidium@openttd.org>
parents:
7474
diff
changeset
|
1171 for (; v != NULL; v = v->Next()) { |
6609
e78f5516e040
(svn r9829) -Codechange: more refactoring of the unloading algorithm.
rubidium <rubidium@openttd.org>
parents:
6601
diff
changeset
|
1172 if (v->cargo_cap == 0) continue; |
e78f5516e040
(svn r9829) -Codechange: more refactoring of the unloading algorithm.
rubidium <rubidium@openttd.org>
parents:
6601
diff
changeset
|
1173 |
13218
03a409fa4c29
(svn r17725) -Codechange: Reduce usage of EngInfo and XxxVehInfo, esp. when a Engine * is already present.
frosch <frosch@openttd.org>
parents:
13213
diff
changeset
|
1174 const Engine *e = Engine::Get(v->engine_type); |
03a409fa4c29
(svn r17725) -Codechange: Reduce usage of EngInfo and XxxVehInfo, esp. when a Engine * is already present.
frosch <frosch@openttd.org>
parents:
13213
diff
changeset
|
1175 byte load_amount = e->info.load_amount; |
10419
e723ec01b3a6
(svn r14672) -Fix [FS#2444]: Property 7 and callback 12 were broken for aircraft.
frosch <frosch@openttd.org>
parents:
10417
diff
changeset
|
1176 |
e723ec01b3a6
(svn r14672) -Fix [FS#2444]: Property 7 and callback 12 were broken for aircraft.
frosch <frosch@openttd.org>
parents:
10417
diff
changeset
|
1177 /* The default loadamount for mail is 1/4 of the load amount for passengers */ |
15050
73f4e0e490b7
(svn r19670) -Codechange: Add CeilDiv() and RoundDiv() to simplify integer divisions with rounding.
frosch <frosch@openttd.org>
parents:
15038
diff
changeset
|
1178 if (v->type == VEH_AIRCRAFT && !Aircraft::From(v)->IsNormalAircraft()) load_amount = CeilDiv(load_amount, 4); |
10419
e723ec01b3a6
(svn r14672) -Fix [FS#2444]: Property 7 and callback 12 were broken for aircraft.
frosch <frosch@openttd.org>
parents:
10417
diff
changeset
|
1179 |
13218
03a409fa4c29
(svn r17725) -Codechange: Reduce usage of EngInfo and XxxVehInfo, esp. when a Engine * is already present.
frosch <frosch@openttd.org>
parents:
13213
diff
changeset
|
1180 if (_settings_game.order.gradual_loading && HasBit(e->info.callback_mask, CBM_VEHICLE_LOAD_AMOUNT)) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1181 uint16 cb_load_amount = GetVehicleCallback(CBID_VEHICLE_LOAD_AMOUNT, 0, 0, v->engine_type, v); |
9020
94bb527c979f
(svn r12819) -Codechange: handle more NewGRFs in the same way as TTDP does it, i.e. testing the low bits for 0xFF or 0 instead of all bits.
rubidium <rubidium@openttd.org>
parents:
9003
diff
changeset
|
1182 if (cb_load_amount != CALLBACK_FAILED && GB(cb_load_amount, 0, 8) != 0) load_amount = GB(cb_load_amount, 0, 8); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1183 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1184 |
6609
e78f5516e040
(svn r9829) -Codechange: more refactoring of the unloading algorithm.
rubidium <rubidium@openttd.org>
parents:
6601
diff
changeset
|
1185 GoodsEntry *ge = &st->goods[v->cargo_type]; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1186 |
8883
23eea6824c4b
(svn r12650) -Feature: ability to force a vehicle to not load at a station.
rubidium <rubidium@openttd.org>
parents:
8873
diff
changeset
|
1187 if (HasBit(v->vehicle_flags, VF_CARGO_UNLOADING) && (u->current_order.GetUnloadType() & OUFB_NO_UNLOAD) == 0) { |
7010
f0f87c5a431e
(svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium <rubidium@openttd.org>
parents:
7002
diff
changeset
|
1188 uint cargo_count = v->cargo.Count(); |
9413
512ea64da840
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium <rubidium@openttd.org>
parents:
9359
diff
changeset
|
1189 uint amount_unloaded = _settings_game.order.gradual_loading ? min(cargo_count, load_amount) : cargo_count; |
11221
6205ed0337b2
(svn r15574) -Fix [FS#2680]: force unload not working when trying to force unload at the station where you received the cargo
rubidium <rubidium@openttd.org>
parents:
11194
diff
changeset
|
1190 bool remaining = false; // Are there cargo entities in this vehicle that can still be unloaded here? |
6205ed0337b2
(svn r15574) -Fix [FS#2680]: force unload not working when trying to force unload at the station where you received the cargo
rubidium <rubidium@openttd.org>
parents:
11194
diff
changeset
|
1191 bool accepted = false; // Is the cargo accepted by the station? |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1192 |
12279
329b186db8cd
(svn r16694) -Fix [FS#2995] (rgradual loading, rnewindustries): only pay for whatever has been actually unloaded and perform the payment when unloading has finished. This fixes, amongst others:
rubidium <rubidium@openttd.org>
parents:
12278
diff
changeset
|
1193 payment->SetCargo(v->cargo_type); |
329b186db8cd
(svn r16694) -Fix [FS#2995] (rgradual loading, rnewindustries): only pay for whatever has been actually unloaded and perform the payment when unloading has finished. This fixes, amongst others:
rubidium <rubidium@openttd.org>
parents:
12278
diff
changeset
|
1194 |
8855
2acce887e7ec
(svn r12617) -Codechange: add type safety to the Order's load and unload types.
rubidium <rubidium@openttd.org>
parents:
8843
diff
changeset
|
1195 if (HasBit(ge->acceptance_pickup, GoodsEntry::ACCEPTANCE) && !(u->current_order.GetUnloadType() & OUFB_TRANSFER)) { |
15002
baf0e12ad2b4
(svn r19614) -Codechange: "it's" => "its" where appropriate
smatz <smatz@openttd.org>
parents:
14695
diff
changeset
|
1196 /* The cargo has reached its final destination, the packets may now be destroyed */ |
13291
07fc7c78b30b
(svn r17800) -Codechange: first steps into making CargoList a template
rubidium <rubidium@openttd.org>
parents:
13218
diff
changeset
|
1197 remaining = v->cargo.MoveTo<StationCargoList>(NULL, amount_unloaded, VehicleCargoList::MTA_FINAL_DELIVERY, payment, last_visited); |
7010
f0f87c5a431e
(svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium <rubidium@openttd.org>
parents:
7002
diff
changeset
|
1198 |
13998
3d6fd0265851
(svn r18540) -Codechange: resulting in better name for 'result'.
frosch <frosch@openttd.org>
parents:
13995
diff
changeset
|
1199 dirty_vehicle = true; |
11221
6205ed0337b2
(svn r15574) -Fix [FS#2680]: force unload not working when trying to force unload at the station where you received the cargo
rubidium <rubidium@openttd.org>
parents:
11194
diff
changeset
|
1200 accepted = true; |
6205ed0337b2
(svn r15574) -Fix [FS#2680]: force unload not working when trying to force unload at the station where you received the cargo
rubidium <rubidium@openttd.org>
parents:
11194
diff
changeset
|
1201 } |
6205ed0337b2
(svn r15574) -Fix [FS#2680]: force unload not working when trying to force unload at the station where you received the cargo
rubidium <rubidium@openttd.org>
parents:
11194
diff
changeset
|
1202 |
6205ed0337b2
(svn r15574) -Fix [FS#2680]: force unload not working when trying to force unload at the station where you received the cargo
rubidium <rubidium@openttd.org>
parents:
11194
diff
changeset
|
1203 /* The !accepted || v->cargo.Count == cargo_count clause is there |
6205ed0337b2
(svn r15574) -Fix [FS#2680]: force unload not working when trying to force unload at the station where you received the cargo
rubidium <rubidium@openttd.org>
parents:
11194
diff
changeset
|
1204 * to make it possible to force unload vehicles at the station where |
6205ed0337b2
(svn r15574) -Fix [FS#2680]: force unload not working when trying to force unload at the station where you received the cargo
rubidium <rubidium@openttd.org>
parents:
11194
diff
changeset
|
1205 * they were loaded, but to not force unload the vehicle when the |
6205ed0337b2
(svn r15574) -Fix [FS#2680]: force unload not working when trying to force unload at the station where you received the cargo
rubidium <rubidium@openttd.org>
parents:
11194
diff
changeset
|
1206 * station is still accepting the cargo in the vehicle. It doesn't |
6205ed0337b2
(svn r15574) -Fix [FS#2680]: force unload not working when trying to force unload at the station where you received the cargo
rubidium <rubidium@openttd.org>
parents:
11194
diff
changeset
|
1207 * accept cargo that was loaded at the same station. */ |
12082
d092f17a921d
(svn r16491) -Codechange: Added parentheses around bitwise operators for code style.
alberth <alberth@openttd.org>
parents:
12046
diff
changeset
|
1208 if ((u->current_order.GetUnloadType() & (OUFB_UNLOAD | OUFB_TRANSFER)) && (!accepted || v->cargo.Count() == cargo_count)) { |
13291
07fc7c78b30b
(svn r17800) -Codechange: first steps into making CargoList a template
rubidium <rubidium@openttd.org>
parents:
13218
diff
changeset
|
1209 remaining = v->cargo.MoveTo(&ge->cargo, amount_unloaded, u->current_order.GetUnloadType() & OUFB_TRANSFER ? VehicleCargoList::MTA_TRANSFER : VehicleCargoList::MTA_UNLOAD, payment); |
7931
44ff7a6d801f
(svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7929
diff
changeset
|
1210 SetBit(ge->acceptance_pickup, GoodsEntry::PICKUP); |
6198
a2cdd211d091
(svn r8978) -Feature: Rewrite of transfer system.
richk <richk@openttd.org>
parents:
6190
diff
changeset
|
1211 |
13998
3d6fd0265851
(svn r18540) -Codechange: resulting in better name for 'result'.
frosch <frosch@openttd.org>
parents:
13995
diff
changeset
|
1212 dirty_vehicle = dirty_station = true; |
11221
6205ed0337b2
(svn r15574) -Fix [FS#2680]: force unload not working when trying to force unload at the station where you received the cargo
rubidium <rubidium@openttd.org>
parents:
11194
diff
changeset
|
1213 } else if (!accepted) { |
6609
e78f5516e040
(svn r9829) -Codechange: more refactoring of the unloading algorithm.
rubidium <rubidium@openttd.org>
parents:
6601
diff
changeset
|
1214 /* The order changed while unloading (unset unload/transfer) or the |
12290
3ba19b02f30e
(svn r16707) -Fix [FS#3007] (r16693): under some circumstances vehicles would skip loading as they thought nothing could be unloaded or loaded.
rubidium <rubidium@openttd.org>
parents:
12289
diff
changeset
|
1215 * station does not accept our goods. */ |
7929
4d13dbed828c
(svn r11482) -Codechange: Remove the doubled function ClrBitT and rename the remaining to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7928
diff
changeset
|
1216 ClrBit(v->vehicle_flags, VF_CARGO_UNLOADING); |
12290
3ba19b02f30e
(svn r16707) -Fix [FS#3007] (r16693): under some circumstances vehicles would skip loading as they thought nothing could be unloaded or loaded.
rubidium <rubidium@openttd.org>
parents:
12289
diff
changeset
|
1217 |
3ba19b02f30e
(svn r16707) -Fix [FS#3007] (r16693): under some circumstances vehicles would skip loading as they thought nothing could be unloaded or loaded.
rubidium <rubidium@openttd.org>
parents:
12289
diff
changeset
|
1218 /* Say we loaded something, otherwise we'll think we didn't unload |
3ba19b02f30e
(svn r16707) -Fix [FS#3007] (r16693): under some circumstances vehicles would skip loading as they thought nothing could be unloaded or loaded.
rubidium <rubidium@openttd.org>
parents:
12289
diff
changeset
|
1219 * something and we didn't load something, so we must be finished |
3ba19b02f30e
(svn r16707) -Fix [FS#3007] (r16693): under some circumstances vehicles would skip loading as they thought nothing could be unloaded or loaded.
rubidium <rubidium@openttd.org>
parents:
12289
diff
changeset
|
1220 * at this station. Setting the unloaded means that we will get a |
3ba19b02f30e
(svn r16707) -Fix [FS#3007] (r16693): under some circumstances vehicles would skip loading as they thought nothing could be unloaded or loaded.
rubidium <rubidium@openttd.org>
parents:
12289
diff
changeset
|
1221 * retry for loading in the next cycle. */ |
3ba19b02f30e
(svn r16707) -Fix [FS#3007] (r16693): under some circumstances vehicles would skip loading as they thought nothing could be unloaded or loaded.
rubidium <rubidium@openttd.org>
parents:
12289
diff
changeset
|
1222 anything_unloaded = true; |
6609
e78f5516e040
(svn r9829) -Codechange: more refactoring of the unloading algorithm.
rubidium <rubidium@openttd.org>
parents:
6601
diff
changeset
|
1223 continue; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1224 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1225 |
6609
e78f5516e040
(svn r9829) -Codechange: more refactoring of the unloading algorithm.
rubidium <rubidium@openttd.org>
parents:
6601
diff
changeset
|
1226 /* Deliver goods to the station */ |
e78f5516e040
(svn r9829) -Codechange: more refactoring of the unloading algorithm.
rubidium <rubidium@openttd.org>
parents:
6601
diff
changeset
|
1227 st->time_since_unload = 0; |
e78f5516e040
(svn r9829) -Codechange: more refactoring of the unloading algorithm.
rubidium <rubidium@openttd.org>
parents:
6601
diff
changeset
|
1228 |
e78f5516e040
(svn r9829) -Codechange: more refactoring of the unloading algorithm.
rubidium <rubidium@openttd.org>
parents:
6601
diff
changeset
|
1229 unloading_time += amount_unloaded; |
e78f5516e040
(svn r9829) -Codechange: more refactoring of the unloading algorithm.
rubidium <rubidium@openttd.org>
parents:
6601
diff
changeset
|
1230 |
6611
461107df1c8f
(svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents:
6609
diff
changeset
|
1231 anything_unloaded = true; |
9413
512ea64da840
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium <rubidium@openttd.org>
parents:
9359
diff
changeset
|
1232 if (_settings_game.order.gradual_loading && remaining) { |
8241
4648f777da55
(svn r11805) -Fix [FS#1620]: VEHICLE_TRIGGER_EMPTY was triggered continuously while train waiting in station.
frosch <frosch@openttd.org>
parents:
8238
diff
changeset
|
1233 completely_emptied = false; |
6609
e78f5516e040
(svn r9829) -Codechange: more refactoring of the unloading algorithm.
rubidium <rubidium@openttd.org>
parents:
6601
diff
changeset
|
1234 } else { |
e78f5516e040
(svn r9829) -Codechange: more refactoring of the unloading algorithm.
rubidium <rubidium@openttd.org>
parents:
6601
diff
changeset
|
1235 /* We have finished unloading (cargo count == 0) */ |
7929
4d13dbed828c
(svn r11482) -Codechange: Remove the doubled function ClrBitT and rename the remaining to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7928
diff
changeset
|
1236 ClrBit(v->vehicle_flags, VF_CARGO_UNLOADING); |
6609
e78f5516e040
(svn r9829) -Codechange: more refactoring of the unloading algorithm.
rubidium <rubidium@openttd.org>
parents:
6601
diff
changeset
|
1237 } |
e78f5516e040
(svn r9829) -Codechange: more refactoring of the unloading algorithm.
rubidium <rubidium@openttd.org>
parents:
6601
diff
changeset
|
1238 |
e78f5516e040
(svn r9829) -Codechange: more refactoring of the unloading algorithm.
rubidium <rubidium@openttd.org>
parents:
6601
diff
changeset
|
1239 continue; |
e78f5516e040
(svn r9829) -Codechange: more refactoring of the unloading algorithm.
rubidium <rubidium@openttd.org>
parents:
6601
diff
changeset
|
1240 } |
5888
11683122ef51
(svn r8501) -Fix (r7377) [FS#539]: Keep track of how much cargo has been paid for, so that cargo cannot be paid for more than once.
maedhros <maedhros@openttd.org>
parents:
5854
diff
changeset
|
1241 |
8885
2d7e1a978a1a
(svn r12652) -Codechange: rework the order GUI a little more to make it a little more clear that 'transfer' is just an unload type.
rubidium <rubidium@openttd.org>
parents:
8883
diff
changeset
|
1242 /* Do not pick up goods when we have no-load set. */ |
2d7e1a978a1a
(svn r12652) -Codechange: rework the order GUI a little more to make it a little more clear that 'transfer' is just an unload type.
rubidium <rubidium@openttd.org>
parents:
8883
diff
changeset
|
1243 if (u->current_order.GetLoadType() & OLFB_NO_LOAD) continue; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1244 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1245 /* update stats */ |
6609
e78f5516e040
(svn r9829) -Codechange: more refactoring of the unloading algorithm.
rubidium <rubidium@openttd.org>
parents:
6601
diff
changeset
|
1246 int t; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1247 switch (u->type) { |
13052
6dba8bf1c036
(svn r17550) -Fix (r8973): Aircraft are good enough, don't make them even better.
frosch <frosch@openttd.org>
parents:
13048
diff
changeset
|
1248 case VEH_TRAIN: t = Train::From(u)->tcache.cached_max_speed; break; |
6dba8bf1c036
(svn r17550) -Fix (r8973): Aircraft are good enough, don't make them even better.
frosch <frosch@openttd.org>
parents:
13048
diff
changeset
|
1249 case VEH_ROAD: t = u->max_speed / 2; break; |
6dba8bf1c036
(svn r17550) -Fix (r8973): Aircraft are good enough, don't make them even better.
frosch <frosch@openttd.org>
parents:
13048
diff
changeset
|
1250 case VEH_SHIP: t = u->max_speed; break; |
15511
fbbbb2791756
(svn r20164) -Fix [FS#3870]: inconsistencies w.r.t. to km/h vs km-ish/h as "base" unit for aircraft speeds
rubidium <rubidium@openttd.org>
parents:
15292
diff
changeset
|
1251 case VEH_AIRCRAFT: t = u->max_speed * 10 / 128; break; // convert to old units |
13052
6dba8bf1c036
(svn r17550) -Fix (r8973): Aircraft are good enough, don't make them even better.
frosch <frosch@openttd.org>
parents:
13048
diff
changeset
|
1252 default: NOT_REACHED(); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1253 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1254 |
6125
46d001ebacf6
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents:
6119
diff
changeset
|
1255 /* if last speed is 0, we treat that as if no vehicle has ever visited the station. */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1256 ge->last_speed = min(t, 255); |
6990
a19700261804
(svn r10246) -Fix (r10297): some forgotten money conversions and truncation issues. Thanks to benc for providing the patch.
rubidium <rubidium@openttd.org>
parents:
6957
diff
changeset
|
1257 ge->last_age = _cur_year - u->build_year; |
7458
7e4d907043ef
(svn r10953) -Fix [FS#1139, FS#1143]: stations would not get a rating when there were already two stations with a "more than default" rating as no cargo would be moved to the station to be picked up.
rubidium <rubidium@openttd.org>
parents:
7447
diff
changeset
|
1258 ge->days_since_pickup = 0; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1259 |
6125
46d001ebacf6
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents:
6119
diff
changeset
|
1260 /* If there's goods waiting at the station, and the vehicle |
46d001ebacf6
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents:
6119
diff
changeset
|
1261 * has capacity for it, load it on the vehicle. */ |
11194
1c56a71f2bb1
(svn r15547) -Codechange: Eliminate all == and != comparisons between v->cargo_cap and v->cargo.Count() to improve behaviour wrt. broken/incompatible grfs.
frosch <frosch@openttd.org>
parents:
11090
diff
changeset
|
1262 int cap_left = v->cargo_cap - v->cargo.Count(); |
1c56a71f2bb1
(svn r15547) -Codechange: Eliminate all == and != comparisons between v->cargo_cap and v->cargo.Count() to improve behaviour wrt. broken/incompatible grfs.
frosch <frosch@openttd.org>
parents:
11090
diff
changeset
|
1263 if (!ge->cargo.Empty() && cap_left > 0) { |
1c56a71f2bb1
(svn r15547) -Codechange: Eliminate all == and != comparisons between v->cargo_cap and v->cargo.Count() to improve behaviour wrt. broken/incompatible grfs.
frosch <frosch@openttd.org>
parents:
11090
diff
changeset
|
1264 uint cap = cap_left; |
7010
f0f87c5a431e
(svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium <rubidium@openttd.org>
parents:
7002
diff
changeset
|
1265 uint count = ge->cargo.Count(); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1266 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1267 /* Skip loading this vehicle if another train/vehicle is already handling |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1268 * the same cargo type at this station */ |
9413
512ea64da840
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium <rubidium@openttd.org>
parents:
9359
diff
changeset
|
1269 if (_settings_game.order.improved_load && cargo_left[v->cargo_type] <= 0) { |
7931
44ff7a6d801f
(svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7929
diff
changeset
|
1270 SetBit(cargo_not_full, v->cargo_type); |
6565
547b0171c3a9
(svn r9770) -Codechange: perform the payment of cargo when loading/unloading, but when arriving at the station.
rubidium <rubidium@openttd.org>
parents:
6559
diff
changeset
|
1271 continue; |
547b0171c3a9
(svn r9770) -Codechange: perform the payment of cargo when loading/unloading, but when arriving at the station.
rubidium <rubidium@openttd.org>
parents:
6559
diff
changeset
|
1272 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1273 |
6618
a0ebb1506656
(svn r9838) -Fix: make "improved loading" a proper improved loading instead of loading one (semi-)random vehicle at a time:
rubidium <rubidium@openttd.org>
parents:
6616
diff
changeset
|
1274 if (cap > count) cap = count; |
9413
512ea64da840
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium <rubidium@openttd.org>
parents:
9359
diff
changeset
|
1275 if (_settings_game.order.gradual_loading) cap = min(cap, load_amount); |
512ea64da840
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium <rubidium@openttd.org>
parents:
9359
diff
changeset
|
1276 if (_settings_game.order.improved_load) { |
6618
a0ebb1506656
(svn r9838) -Fix: make "improved loading" a proper improved loading instead of loading one (semi-)random vehicle at a time:
rubidium <rubidium@openttd.org>
parents:
6616
diff
changeset
|
1277 /* Don't load stuff that is already 'reserved' for other vehicles */ |
7023
1997a5b53cec
(svn r10287) -Fix (r10266): some surprises from that (almost always) complaining compiler...
rubidium <rubidium@openttd.org>
parents:
7014
diff
changeset
|
1278 cap = min((uint)cargo_left[v->cargo_type], cap); |
6618
a0ebb1506656
(svn r9838) -Fix: make "improved loading" a proper improved loading instead of loading one (semi-)random vehicle at a time:
rubidium <rubidium@openttd.org>
parents:
6616
diff
changeset
|
1279 cargo_left[v->cargo_type] -= cap; |
a0ebb1506656
(svn r9838) -Fix: make "improved loading" a proper improved loading instead of loading one (semi-)random vehicle at a time:
rubidium <rubidium@openttd.org>
parents:
6616
diff
changeset
|
1280 } |
a0ebb1506656
(svn r9838) -Fix: make "improved loading" a proper improved loading instead of loading one (semi-)random vehicle at a time:
rubidium <rubidium@openttd.org>
parents:
6616
diff
changeset
|
1281 |
7010
f0f87c5a431e
(svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium <rubidium@openttd.org>
parents:
7002
diff
changeset
|
1282 if (v->cargo.Empty()) TriggerVehicle(v, VEHICLE_TRIGGER_NEW_CARGO); |
6618
a0ebb1506656
(svn r9838) -Fix: make "improved loading" a proper improved loading instead of loading one (semi-)random vehicle at a time:
rubidium <rubidium@openttd.org>
parents:
6616
diff
changeset
|
1283 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1284 /* TODO: Regarding this, when we do gradual loading, we |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1285 * should first unload all vehicles and then start |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1286 * loading them. Since this will cause |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1287 * VEHICLE_TRIGGER_EMPTY to be called at the time when |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1288 * the whole vehicle chain is really totally empty, the |
8241
4648f777da55
(svn r11805) -Fix [FS#1620]: VEHICLE_TRIGGER_EMPTY was triggered continuously while train waiting in station.
frosch <frosch@openttd.org>
parents:
8238
diff
changeset
|
1289 * completely_emptied assignment can then be safely |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1290 * removed; that's how TTDPatch behaves too. --pasky */ |
8241
4648f777da55
(svn r11805) -Fix [FS#1620]: VEHICLE_TRIGGER_EMPTY was triggered continuously while train waiting in station.
frosch <frosch@openttd.org>
parents:
8238
diff
changeset
|
1291 completely_emptied = false; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1292 anything_loaded = true; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1293 |
13291
07fc7c78b30b
(svn r17800) -Codechange: first steps into making CargoList a template
rubidium <rubidium@openttd.org>
parents:
13218
diff
changeset
|
1294 ge->cargo.MoveTo(&v->cargo, cap, StationCargoList::MTA_CARGO_LOAD, NULL, st->xy); |
6198
a2cdd211d091
(svn r8978) -Feature: Rewrite of transfer system.
richk <richk@openttd.org>
parents:
6190
diff
changeset
|
1295 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1296 st->time_since_load = 0; |
7010
f0f87c5a431e
(svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium <rubidium@openttd.org>
parents:
7002
diff
changeset
|
1297 st->last_vehicle_type = v->type; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1298 |
9003
ac23e012c9d7
(svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents:
8885
diff
changeset
|
1299 StationAnimationTrigger(st, st->xy, STAT_ANIM_CARGO_TAKEN, v->cargo_type); |
14620
a2d95ade0e87
(svn r19197) -Codechange: introduce animation callbacks for airport tiles
yexo <yexo@openttd.org>
parents:
14353
diff
changeset
|
1300 AirportAnimationTrigger(st, AAT_STATION_CARGO_TAKEN, v->cargo_type); |
9003
ac23e012c9d7
(svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents:
8885
diff
changeset
|
1301 |
7474
7b35fd1cc99d
(svn r10981) -Fix [FS#1156] (r10970): stations gave ratings for accepted cargo too.
rubidium <rubidium@openttd.org>
parents:
7458
diff
changeset
|
1302 unloading_time += cap; |
7b35fd1cc99d
(svn r10981) -Fix [FS#1156] (r10970): stations gave ratings for accepted cargo too.
rubidium <rubidium@openttd.org>
parents:
7458
diff
changeset
|
1303 |
13998
3d6fd0265851
(svn r18540) -Codechange: resulting in better name for 'result'.
frosch <frosch@openttd.org>
parents:
13995
diff
changeset
|
1304 dirty_vehicle = dirty_station = true; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1305 } |
6611
461107df1c8f
(svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents:
6609
diff
changeset
|
1306 |
11194
1c56a71f2bb1
(svn r15547) -Codechange: Eliminate all == and != comparisons between v->cargo_cap and v->cargo.Count() to improve behaviour wrt. broken/incompatible grfs.
frosch <frosch@openttd.org>
parents:
11090
diff
changeset
|
1307 if (v->cargo.Count() >= v->cargo_cap) { |
7931
44ff7a6d801f
(svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7929
diff
changeset
|
1308 SetBit(cargo_full, v->cargo_type); |
6611
461107df1c8f
(svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents:
6609
diff
changeset
|
1309 } else { |
7931
44ff7a6d801f
(svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7929
diff
changeset
|
1310 SetBit(cargo_not_full, v->cargo_type); |
6611
461107df1c8f
(svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents:
6609
diff
changeset
|
1311 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1312 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1313 |
15604
ca959eb5d431
(svn r20266) -Doc: Mostly typo fixes, a few doxygen-related improvements.
alberth <alberth@openttd.org>
parents:
15601
diff
changeset
|
1314 /* Only set completely_emptied, if we just unloaded all remaining cargo */ |
8241
4648f777da55
(svn r11805) -Fix [FS#1620]: VEHICLE_TRIGGER_EMPTY was triggered continuously while train waiting in station.
frosch <frosch@openttd.org>
parents:
8238
diff
changeset
|
1315 completely_emptied &= anything_unloaded; |
4648f777da55
(svn r11805) -Fix [FS#1620]: VEHICLE_TRIGGER_EMPTY was triggered continuously while train waiting in station.
frosch <frosch@openttd.org>
parents:
8238
diff
changeset
|
1316 |
6618
a0ebb1506656
(svn r9838) -Fix: make "improved loading" a proper improved loading instead of loading one (semi-)random vehicle at a time:
rubidium <rubidium@openttd.org>
parents:
6616
diff
changeset
|
1317 /* We update these variables here, so gradual loading still fills |
a0ebb1506656
(svn r9838) -Fix: make "improved loading" a proper improved loading instead of loading one (semi-)random vehicle at a time:
rubidium <rubidium@openttd.org>
parents:
6616
diff
changeset
|
1318 * all wagons at the same time instead of using the same 'improved' |
a0ebb1506656
(svn r9838) -Fix: make "improved loading" a proper improved loading instead of loading one (semi-)random vehicle at a time:
rubidium <rubidium@openttd.org>
parents:
6616
diff
changeset
|
1319 * loading algorithm for the wagons (only fill wagon when there is |
a0ebb1506656
(svn r9838) -Fix: make "improved loading" a proper improved loading instead of loading one (semi-)random vehicle at a time:
rubidium <rubidium@openttd.org>
parents:
6616
diff
changeset
|
1320 * enough to fill the previous wagons) */ |
9413
512ea64da840
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium <rubidium@openttd.org>
parents:
9359
diff
changeset
|
1321 if (_settings_game.order.improved_load && (u->current_order.GetLoadType() & OLFB_FULL_LOAD)) { |
6618
a0ebb1506656
(svn r9838) -Fix: make "improved loading" a proper improved loading instead of loading one (semi-)random vehicle at a time:
rubidium <rubidium@openttd.org>
parents:
6616
diff
changeset
|
1322 /* Update left cargo */ |
7492
09743324277c
(svn r11003) -Codechange: replace Vehicle->next to Vehicle->Next() and Vehicle->SetNext() so we can trap instances that change a next pointer and (in the future) update the first/previous pointers based on that.
rubidium <rubidium@openttd.org>
parents:
7474
diff
changeset
|
1323 for (v = u; v != NULL; v = v->Next()) { |
11194
1c56a71f2bb1
(svn r15547) -Codechange: Eliminate all == and != comparisons between v->cargo_cap and v->cargo.Count() to improve behaviour wrt. broken/incompatible grfs.
frosch <frosch@openttd.org>
parents:
11090
diff
changeset
|
1324 int cap_left = v->cargo_cap - v->cargo.Count(); |
1c56a71f2bb1
(svn r15547) -Codechange: Eliminate all == and != comparisons between v->cargo_cap and v->cargo.Count() to improve behaviour wrt. broken/incompatible grfs.
frosch <frosch@openttd.org>
parents:
11090
diff
changeset
|
1325 if (cap_left > 0) cargo_left[v->cargo_type] -= cap_left; |
6618
a0ebb1506656
(svn r9838) -Fix: make "improved loading" a proper improved loading instead of loading one (semi-)random vehicle at a time:
rubidium <rubidium@openttd.org>
parents:
6616
diff
changeset
|
1326 } |
a0ebb1506656
(svn r9838) -Fix: make "improved loading" a proper improved loading instead of loading one (semi-)random vehicle at a time:
rubidium <rubidium@openttd.org>
parents:
6616
diff
changeset
|
1327 } |
a0ebb1506656
(svn r9838) -Fix: make "improved loading" a proper improved loading instead of loading one (semi-)random vehicle at a time:
rubidium <rubidium@openttd.org>
parents:
6616
diff
changeset
|
1328 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1329 v = u; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1330 |
12279
329b186db8cd
(svn r16694) -Fix [FS#2995] (rgradual loading, rnewindustries): only pay for whatever has been actually unloaded and perform the payment when unloading has finished. This fixes, amongst others:
rubidium <rubidium@openttd.org>
parents:
12278
diff
changeset
|
1331 if (!anything_unloaded) delete payment; |
329b186db8cd
(svn r16694) -Fix [FS#2995] (rgradual loading, rnewindustries): only pay for whatever has been actually unloaded and perform the payment when unloading has finished. This fixes, amongst others:
rubidium <rubidium@openttd.org>
parents:
12278
diff
changeset
|
1332 |
6611
461107df1c8f
(svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents:
6609
diff
changeset
|
1333 if (anything_loaded || anything_unloaded) { |
9413
512ea64da840
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium <rubidium@openttd.org>
parents:
9359
diff
changeset
|
1334 if (_settings_game.order.gradual_loading) { |
6611
461107df1c8f
(svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents:
6609
diff
changeset
|
1335 /* The time it takes to load one 'slice' of cargo or passengers depends |
11361
02313cc6114e
(svn r15711) -Codechange: lots of whitespace cleanup/fixes
rubidium <rubidium@openttd.org>
parents:
11234
diff
changeset
|
1336 * on the vehicle type - the values here are those found in TTDPatch */ |
6611
461107df1c8f
(svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents:
6609
diff
changeset
|
1337 const uint gradual_loading_wait_time[] = { 40, 20, 10, 20 }; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1338 |
6611
461107df1c8f
(svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents:
6609
diff
changeset
|
1339 unloading_time = gradual_loading_wait_time[v->type]; |
461107df1c8f
(svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents:
6609
diff
changeset
|
1340 } |
461107df1c8f
(svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents:
6609
diff
changeset
|
1341 } else { |
461107df1c8f
(svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents:
6609
diff
changeset
|
1342 bool finished_loading = true; |
8855
2acce887e7ec
(svn r12617) -Codechange: add type safety to the Order's load and unload types.
rubidium <rubidium@openttd.org>
parents:
8843
diff
changeset
|
1343 if (v->current_order.GetLoadType() & OLFB_FULL_LOAD) { |
8873
9780f2a6cd20
(svn r12640) -Codechange: let GetLoadType make a difference between full load and full load any based on the patch setting instead of using the patch setting directly.
rubidium <rubidium@openttd.org>
parents:
8855
diff
changeset
|
1344 if (v->current_order.GetLoadType() == OLF_FULL_LOAD_ANY) { |
6611
461107df1c8f
(svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents:
6609
diff
changeset
|
1345 /* if the aircraft carries passengers and is NOT full, then |
461107df1c8f
(svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents:
6609
diff
changeset
|
1346 * continue loading, no matter how much mail is in */ |
11194
1c56a71f2bb1
(svn r15547) -Codechange: Eliminate all == and != comparisons between v->cargo_cap and v->cargo.Count() to improve behaviour wrt. broken/incompatible grfs.
frosch <frosch@openttd.org>
parents:
11090
diff
changeset
|
1347 if ((v->type == VEH_AIRCRAFT && IsCargoInClass(v->cargo_type, CC_PASSENGERS) && v->cargo_cap > v->cargo.Count()) || |
15655
0be6e9a4ca0b
(svn r20320) -Doc: Small Doxygen and normal comment fixes, and an missed addition.
alberth <alberth@openttd.org>
parents:
15654
diff
changeset
|
1348 (cargo_not_full && (cargo_full & ~cargo_not_full) == 0)) { // There are still non-full cargoes |
6611
461107df1c8f
(svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents:
6609
diff
changeset
|
1349 finished_loading = false; |
461107df1c8f
(svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents:
6609
diff
changeset
|
1350 } |
461107df1c8f
(svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents:
6609
diff
changeset
|
1351 } else if (cargo_not_full != 0) { |
461107df1c8f
(svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents:
6609
diff
changeset
|
1352 finished_loading = false; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1353 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1354 } |
6611
461107df1c8f
(svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents:
6609
diff
changeset
|
1355 unloading_time = 20; |
461107df1c8f
(svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents:
6609
diff
changeset
|
1356 |
461107df1c8f
(svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents:
6609
diff
changeset
|
1357 SB(v->vehicle_flags, VF_LOADING_FINISHED, 1, finished_loading); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1358 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1359 |
6259
4a39d6291d58
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium <rubidium@openttd.org>
parents:
6248
diff
changeset
|
1360 if (v->type == VEH_TRAIN) { |
6125
46d001ebacf6
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents:
6119
diff
changeset
|
1361 /* Each platform tile is worth 2 rail vehicles. */ |
12114
f020ec6be498
(svn r16527) -Codechange: use static member functions instead of simple casts when converting Vehicle to specialised vehicle types. Includes safety check
smatz <smatz@openttd.org>
parents:
12082
diff
changeset
|
1362 int overhang = Train::From(v)->tcache.cached_total_length - st->GetPlatformLength(v->tile) * TILE_SIZE; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1363 if (overhang > 0) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1364 unloading_time <<= 1; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1365 unloading_time += (overhang * unloading_time) / 8; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1366 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1367 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1368 |
7543
2e26b732a29b
(svn r11063) -Codechange: make it possible for people to view the loading indicators of everyone. Patch by SmatZ.
rubidium <rubidium@openttd.org>
parents:
7520
diff
changeset
|
1369 /* Calculate the loading indicator fill percent and display |
2e26b732a29b
(svn r11063) -Codechange: make it possible for people to view the loading indicators of everyone. Patch by SmatZ.
rubidium <rubidium@openttd.org>
parents:
7520
diff
changeset
|
1370 * In the Game Menu do not display indicators |
9413
512ea64da840
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium <rubidium@openttd.org>
parents:
9359
diff
changeset
|
1371 * If _settings_client.gui.loading_indicators == 2, show indicators (bool can be promoted to int as 0 or 1 - results in 2 > 0,1 ) |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
1372 * if _settings_client.gui.loading_indicators == 1, _local_company must be the owner or must be a spectator to show ind., so 1 > 0 |
9413
512ea64da840
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium <rubidium@openttd.org>
parents:
9359
diff
changeset
|
1373 * if _settings_client.gui.loading_indicators == 0, do not display indicators ... 0 is never greater than anything |
7543
2e26b732a29b
(svn r11063) -Codechange: make it possible for people to view the loading indicators of everyone. Patch by SmatZ.
rubidium <rubidium@openttd.org>
parents:
7520
diff
changeset
|
1374 */ |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
1375 if (_game_mode != GM_MENU && (_settings_client.gui.loading_indicators > (uint)(v->owner != _local_company && _local_company != COMPANY_SPECTATOR))) { |
7014
d03670858cef
(svn r10270) -Add: prefixed the loading indicator with an arrow, up meaning vehicle is loading, down meaning vehicle is unloading
truelight <truelight@openttd.org>
parents:
7010
diff
changeset
|
1376 StringID percent_up_down = STR_NULL; |
d03670858cef
(svn r10270) -Add: prefixed the loading indicator with an arrow, up meaning vehicle is loading, down meaning vehicle is unloading
truelight <truelight@openttd.org>
parents:
7010
diff
changeset
|
1377 int percent = CalcPercentVehicleFilled(v, &percent_up_down); |
6998
13ea0d5f8acf
(svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight <truelight@openttd.org>
parents:
6991
diff
changeset
|
1378 if (v->fill_percent_te_id == INVALID_TE_ID) { |
7014
d03670858cef
(svn r10270) -Add: prefixed the loading indicator with an arrow, up meaning vehicle is loading, down meaning vehicle is unloading
truelight <truelight@openttd.org>
parents:
7010
diff
changeset
|
1379 v->fill_percent_te_id = ShowFillingPercent(v->x_pos, v->y_pos, v->z_pos + 20, percent, percent_up_down); |
6998
13ea0d5f8acf
(svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight <truelight@openttd.org>
parents:
6991
diff
changeset
|
1380 } else { |
7014
d03670858cef
(svn r10270) -Add: prefixed the loading indicator with an arrow, up meaning vehicle is loading, down meaning vehicle is unloading
truelight <truelight@openttd.org>
parents:
7010
diff
changeset
|
1381 UpdateFillingPercent(v->fill_percent_te_id, percent, percent_up_down); |
6998
13ea0d5f8acf
(svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight <truelight@openttd.org>
parents:
6991
diff
changeset
|
1382 } |
13ea0d5f8acf
(svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight <truelight@openttd.org>
parents:
6991
diff
changeset
|
1383 } |
13ea0d5f8acf
(svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight <truelight@openttd.org>
parents:
6991
diff
changeset
|
1384 |
12496
99f1ec9a1940
(svn r16933) -Fix [FS#3054] (r16694): vehicles would wait "very long" when they had nothing to unload and gradual loading was disabled.
rubidium <rubidium@openttd.org>
parents:
12475
diff
changeset
|
1385 /* Always wait at least 1, otherwise we'll wait 'infinitively' long. */ |
14213
41b2e7bf03da
(svn r18764) -Fix [FS#3422]: split the (un)load ticks counter and signal wait counter; sometimes they might get into eachother's way
rubidium <rubidium@openttd.org>
parents:
14169
diff
changeset
|
1386 v->load_unload_ticks = max(1, unloading_time); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1387 |
8241
4648f777da55
(svn r11805) -Fix [FS#1620]: VEHICLE_TRIGGER_EMPTY was triggered continuously while train waiting in station.
frosch <frosch@openttd.org>
parents:
8238
diff
changeset
|
1388 if (completely_emptied) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1389 TriggerVehicle(v, VEHICLE_TRIGGER_EMPTY); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1390 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1391 |
13998
3d6fd0265851
(svn r18540) -Codechange: resulting in better name for 'result'.
frosch <frosch@openttd.org>
parents:
13995
diff
changeset
|
1392 if (dirty_vehicle) { |
13034
6eb3f749890a
(svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents:
12991
diff
changeset
|
1393 SetWindowDirty(GetWindowClassForVehicleType(v->type), v->owner); |
6eb3f749890a
(svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents:
12991
diff
changeset
|
1394 SetWindowDirty(WC_VEHICLE_DETAILS, v->index); |
13998
3d6fd0265851
(svn r18540) -Codechange: resulting in better name for 'result'.
frosch <frosch@openttd.org>
parents:
13995
diff
changeset
|
1395 v->MarkDirty(); |
3d6fd0265851
(svn r18540) -Codechange: resulting in better name for 'result'.
frosch <frosch@openttd.org>
parents:
13995
diff
changeset
|
1396 } |
3d6fd0265851
(svn r18540) -Codechange: resulting in better name for 'result'.
frosch <frosch@openttd.org>
parents:
13995
diff
changeset
|
1397 if (dirty_station) { |
6823
afa9c0a81fda
(svn r10062) -Codechange: Don't redraw all station tiles when cargo is added or removed if the station has no custom graphics.
peter1138 <peter1138@openttd.org>
parents:
6819
diff
changeset
|
1398 st->MarkTilesDirty(true); |
13998
3d6fd0265851
(svn r18540) -Codechange: resulting in better name for 'result'.
frosch <frosch@openttd.org>
parents:
13995
diff
changeset
|
1399 SetWindowDirty(WC_STATION_VIEW, last_visited); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1400 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1401 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1402 |
6616
ce5601a32593
(svn r9836) -Codechange: make non-improved loading happen FIFO-ish; generally loading/unloading will happen fifo, but there are no guarantees on the FIFO-ness. For (better) FIFO guarantees you still need to use improved loading.
rubidium <rubidium@openttd.org>
parents:
6611
diff
changeset
|
1403 /** |
ce5601a32593
(svn r9836) -Codechange: make non-improved loading happen FIFO-ish; generally loading/unloading will happen fifo, but there are no guarantees on the FIFO-ness. For (better) FIFO guarantees you still need to use improved loading.
rubidium <rubidium@openttd.org>
parents:
6611
diff
changeset
|
1404 * Load/unload the vehicles in this station according to the order |
ce5601a32593
(svn r9836) -Codechange: make non-improved loading happen FIFO-ish; generally loading/unloading will happen fifo, but there are no guarantees on the FIFO-ness. For (better) FIFO guarantees you still need to use improved loading.
rubidium <rubidium@openttd.org>
parents:
6611
diff
changeset
|
1405 * they entered. |
ce5601a32593
(svn r9836) -Codechange: make non-improved loading happen FIFO-ish; generally loading/unloading will happen fifo, but there are no guarantees on the FIFO-ness. For (better) FIFO guarantees you still need to use improved loading.
rubidium <rubidium@openttd.org>
parents:
6611
diff
changeset
|
1406 * @param st the station to do the loading/unloading for |
ce5601a32593
(svn r9836) -Codechange: make non-improved loading happen FIFO-ish; generally loading/unloading will happen fifo, but there are no guarantees on the FIFO-ness. For (better) FIFO guarantees you still need to use improved loading.
rubidium <rubidium@openttd.org>
parents:
6611
diff
changeset
|
1407 */ |
ce5601a32593
(svn r9836) -Codechange: make non-improved loading happen FIFO-ish; generally loading/unloading will happen fifo, but there are no guarantees on the FIFO-ness. For (better) FIFO guarantees you still need to use improved loading.
rubidium <rubidium@openttd.org>
parents:
6611
diff
changeset
|
1408 void LoadUnloadStation(Station *st) |
ce5601a32593
(svn r9836) -Codechange: make non-improved loading happen FIFO-ish; generally loading/unloading will happen fifo, but there are no guarantees on the FIFO-ness. For (better) FIFO guarantees you still need to use improved loading.
rubidium <rubidium@openttd.org>
parents:
6611
diff
changeset
|
1409 { |
12265
10c7609e2d4b
(svn r16680) -Codechange: don't go through all the station unloading stuff when there is no vehicle at the station
rubidium <rubidium@openttd.org>
parents:
12239
diff
changeset
|
1410 /* No vehicle is here... */ |
10c7609e2d4b
(svn r16680) -Codechange: don't go through all the station unloading stuff when there is no vehicle at the station
rubidium <rubidium@openttd.org>
parents:
12239
diff
changeset
|
1411 if (st->loading_vehicles.empty()) return; |
10c7609e2d4b
(svn r16680) -Codechange: don't go through all the station unloading stuff when there is no vehicle at the station
rubidium <rubidium@openttd.org>
parents:
12239
diff
changeset
|
1412 |
6618
a0ebb1506656
(svn r9838) -Fix: make "improved loading" a proper improved loading instead of loading one (semi-)random vehicle at a time:
rubidium <rubidium@openttd.org>
parents:
6616
diff
changeset
|
1413 int cargo_left[NUM_CARGO]; |
a0ebb1506656
(svn r9838) -Fix: make "improved loading" a proper improved loading instead of loading one (semi-)random vehicle at a time:
rubidium <rubidium@openttd.org>
parents:
6616
diff
changeset
|
1414 |
7010
f0f87c5a431e
(svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium <rubidium@openttd.org>
parents:
7002
diff
changeset
|
1415 for (uint i = 0; i < NUM_CARGO; i++) cargo_left[i] = st->goods[i].cargo.Count(); |
6618
a0ebb1506656
(svn r9838) -Fix: make "improved loading" a proper improved loading instead of loading one (semi-)random vehicle at a time:
rubidium <rubidium@openttd.org>
parents:
6616
diff
changeset
|
1416 |
6616
ce5601a32593
(svn r9836) -Codechange: make non-improved loading happen FIFO-ish; generally loading/unloading will happen fifo, but there are no guarantees on the FIFO-ness. For (better) FIFO guarantees you still need to use improved loading.
rubidium <rubidium@openttd.org>
parents:
6611
diff
changeset
|
1417 std::list<Vehicle *>::iterator iter; |
ce5601a32593
(svn r9836) -Codechange: make non-improved loading happen FIFO-ish; generally loading/unloading will happen fifo, but there are no guarantees on the FIFO-ness. For (better) FIFO guarantees you still need to use improved loading.
rubidium <rubidium@openttd.org>
parents:
6611
diff
changeset
|
1418 for (iter = st->loading_vehicles.begin(); iter != st->loading_vehicles.end(); ++iter) { |
ce5601a32593
(svn r9836) -Codechange: make non-improved loading happen FIFO-ish; generally loading/unloading will happen fifo, but there are no guarantees on the FIFO-ness. For (better) FIFO guarantees you still need to use improved loading.
rubidium <rubidium@openttd.org>
parents:
6611
diff
changeset
|
1419 Vehicle *v = *iter; |
6618
a0ebb1506656
(svn r9838) -Fix: make "improved loading" a proper improved loading instead of loading one (semi-)random vehicle at a time:
rubidium <rubidium@openttd.org>
parents:
6616
diff
changeset
|
1420 if (!(v->vehstatus & (VS_STOPPED | VS_CRASHED))) LoadUnloadVehicle(v, cargo_left); |
6616
ce5601a32593
(svn r9836) -Codechange: make non-improved loading happen FIFO-ish; generally loading/unloading will happen fifo, but there are no guarantees on the FIFO-ness. For (better) FIFO guarantees you still need to use improved loading.
rubidium <rubidium@openttd.org>
parents:
6611
diff
changeset
|
1421 } |
12279
329b186db8cd
(svn r16694) -Fix [FS#2995] (rgradual loading, rnewindustries): only pay for whatever has been actually unloaded and perform the payment when unloading has finished. This fixes, amongst others:
rubidium <rubidium@openttd.org>
parents:
12278
diff
changeset
|
1422 |
329b186db8cd
(svn r16694) -Fix [FS#2995] (rgradual loading, rnewindustries): only pay for whatever has been actually unloaded and perform the payment when unloading has finished. This fixes, amongst others:
rubidium <rubidium@openttd.org>
parents:
12278
diff
changeset
|
1423 /* Call the production machinery of industries */ |
329b186db8cd
(svn r16694) -Fix [FS#2995] (rgradual loading, rnewindustries): only pay for whatever has been actually unloaded and perform the payment when unloading has finished. This fixes, amongst others:
rubidium <rubidium@openttd.org>
parents:
12278
diff
changeset
|
1424 const Industry * const *isend = _cargo_delivery_destinations.End(); |
329b186db8cd
(svn r16694) -Fix [FS#2995] (rgradual loading, rnewindustries): only pay for whatever has been actually unloaded and perform the payment when unloading has finished. This fixes, amongst others:
rubidium <rubidium@openttd.org>
parents:
12278
diff
changeset
|
1425 for (Industry **iid = _cargo_delivery_destinations.Begin(); iid != isend; iid++) { |
329b186db8cd
(svn r16694) -Fix [FS#2995] (rgradual loading, rnewindustries): only pay for whatever has been actually unloaded and perform the payment when unloading has finished. This fixes, amongst others:
rubidium <rubidium@openttd.org>
parents:
12278
diff
changeset
|
1426 TriggerIndustryProduction(*iid); |
329b186db8cd
(svn r16694) -Fix [FS#2995] (rgradual loading, rnewindustries): only pay for whatever has been actually unloaded and perform the payment when unloading has finished. This fixes, amongst others:
rubidium <rubidium@openttd.org>
parents:
12278
diff
changeset
|
1427 } |
329b186db8cd
(svn r16694) -Fix [FS#2995] (rgradual loading, rnewindustries): only pay for whatever has been actually unloaded and perform the payment when unloading has finished. This fixes, amongst others:
rubidium <rubidium@openttd.org>
parents:
12278
diff
changeset
|
1428 _cargo_delivery_destinations.Clear(); |
6616
ce5601a32593
(svn r9836) -Codechange: make non-improved loading happen FIFO-ish; generally loading/unloading will happen fifo, but there are no guarantees on the FIFO-ness. For (better) FIFO guarantees you still need to use improved loading.
rubidium <rubidium@openttd.org>
parents:
6611
diff
changeset
|
1429 } |
ce5601a32593
(svn r9836) -Codechange: make non-improved loading happen FIFO-ish; generally loading/unloading will happen fifo, but there are no guarantees on the FIFO-ness. For (better) FIFO guarantees you still need to use improved loading.
rubidium <rubidium@openttd.org>
parents:
6611
diff
changeset
|
1430 |
15616
d76890d16808
(svn r20279) -Doc: Doxygen additions/improvements.
alberth <alberth@openttd.org>
parents:
15604
diff
changeset
|
1431 /** |
d76890d16808
(svn r20279) -Doc: Doxygen additions/improvements.
alberth <alberth@openttd.org>
parents:
15604
diff
changeset
|
1432 * Monthly update of the economic data (of the companies as well as economic fluctuations). |
d76890d16808
(svn r20279) -Doc: Doxygen additions/improvements.
alberth <alberth@openttd.org>
parents:
15604
diff
changeset
|
1433 */ |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
1434 void CompaniesMonthlyLoop() |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1435 { |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
1436 CompaniesGenStatistics(); |
12940
1b090e0c4f93
(svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents:
12933
diff
changeset
|
1437 if (_settings_game.economy.inflation) { |
1b090e0c4f93
(svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents:
12933
diff
changeset
|
1438 AddInflation(); |
1b090e0c4f93
(svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents:
12933
diff
changeset
|
1439 RecomputePrices(); |
1b090e0c4f93
(svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
frosch <frosch@openttd.org>
parents:
12933
diff
changeset
|
1440 } |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
1441 CompaniesPayInterest(); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1442 HandleEconomyFluctuations(); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1443 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1444 |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
1445 static void DoAcquireCompany(Company *c) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1446 { |
10696
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
10647
diff
changeset
|
1447 CompanyID ci = c->index; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1448 |
9658
27697e657d2e
(svn r13730) -Fix: make a copy of the names for news messages about the deletion of companies as the removal of a company could lead to wrong names in the news messages.
rubidium <rubidium@openttd.org>
parents:
9652
diff
changeset
|
1449 CompanyNewsInformation *cni = MallocT<CompanyNewsInformation>(1); |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11730
diff
changeset
|
1450 cni->FillData(c, Company::Get(_current_company)); |
9658
27697e657d2e
(svn r13730) -Fix: make a copy of the names for news messages about the deletion of companies as the removal of a company could lead to wrong names in the news messages.
rubidium <rubidium@openttd.org>
parents:
9652
diff
changeset
|
1451 |
11730
a39da1e4c1f5
(svn r16118) -Change/cleanup: remove the hexadecimal 'in TTD the string had this ID' from 'some' strings and replace the string name with something more sensible.
rubidium <rubidium@openttd.org>
parents:
11376
diff
changeset
|
1452 SetDParam(0, STR_NEWS_COMPANY_MERGER_TITLE); |
a39da1e4c1f5
(svn r16118) -Change/cleanup: remove the hexadecimal 'in TTD the string had this ID' from 'some' strings and replace the string name with something more sensible.
rubidium <rubidium@openttd.org>
parents:
11376
diff
changeset
|
1453 SetDParam(1, c->bankrupt_value == 0 ? STR_NEWS_MERGER_TAKEOVER_TITLE : STR_NEWS_COMPANY_MERGER_DESCRIPTION); |
9658
27697e657d2e
(svn r13730) -Fix: make a copy of the names for news messages about the deletion of companies as the removal of a company could lead to wrong names in the news messages.
rubidium <rubidium@openttd.org>
parents:
9652
diff
changeset
|
1454 SetDParamStr(2, cni->company_name); |
27697e657d2e
(svn r13730) -Fix: make a copy of the names for news messages about the deletion of companies as the removal of a company could lead to wrong names in the news messages.
rubidium <rubidium@openttd.org>
parents:
9652
diff
changeset
|
1455 SetDParamStr(3, cni->other_company_name); |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
1456 SetDParam(4, c->bankrupt_value); |
12632
e41943276802
(svn r17075) -Codechange: rename ~750 strings to be more uniform with their relatives
rubidium <rubidium@openttd.org>
parents:
12615
diff
changeset
|
1457 AddCompanyNewsItem(STR_MESSAGE_NEWS_FORMAT, NS_COMPANY_MERGER, cni); |
10696
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
10647
diff
changeset
|
1458 AI::BroadcastNewEvent(new AIEventCompanyMerger(ci, _current_company)); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1459 |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
1460 ChangeOwnershipOfCompanyItems(ci, _current_company); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1461 |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
1462 if (c->bankrupt_value == 0) { |
15652
354307d245e5
(svn r20317) -Codechange: Move variable declaration to their first use.
alberth <alberth@openttd.org>
parents:
15623
diff
changeset
|
1463 Company *owner = Company::Get(_current_company); |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
1464 owner->current_loan += c->current_loan; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1465 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1466 |
15652
354307d245e5
(svn r20317) -Codechange: Move variable declaration to their first use.
alberth <alberth@openttd.org>
parents:
15623
diff
changeset
|
1467 Money value = CalculateCompanyValue(c) >> 2; |
15292
e2c62d70dfcf
(svn r19931) -Fix (r19914): Convert assertion in Backup<> destructor into DEBUG() output. It was triggered on exceptions, especially when aborting world generation.
frosch <frosch@openttd.org>
parents:
15279
diff
changeset
|
1468 Backup<CompanyByte> cur_company(_current_company, FILE_LINE); |
15652
354307d245e5
(svn r20317) -Codechange: Move variable declaration to their first use.
alberth <alberth@openttd.org>
parents:
15623
diff
changeset
|
1469 for (int i = 0; i != 4; i++) { |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
1470 if (c->share_owners[i] != COMPANY_SPECTATOR) { |
15279
4e1862aebea2
(svn r19914) -Codechange: Wrap a helper class around temporary assignments of _current_company to ensure proper restoration.
frosch <frosch@openttd.org>
parents:
15050
diff
changeset
|
1471 cur_company.Change(c->share_owners[i]); |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
1472 SubtractMoneyFromCompany(CommandCost(EXPENSES_OTHER, -value)); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1473 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1474 } |
15279
4e1862aebea2
(svn r19914) -Codechange: Wrap a helper class around temporary assignments of _current_company to ensure proper restoration.
frosch <frosch@openttd.org>
parents:
15050
diff
changeset
|
1475 cur_company.Restore(); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1476 |
12143
20abba1d6d18
(svn r16559) -Codechange: introduce Company::IsValidAiID() and Company::IsValidHumanID(), don't use IsHumanCompany() where possible
smatz <smatz@openttd.org>
parents:
12114
diff
changeset
|
1477 if (c->is_ai) AI::Stop(c->index); |
10696
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
10647
diff
changeset
|
1478 |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
1479 DeleteCompanyWindows(ci); |
9297
add307f2e6ea
(svn r13165) -Codechange: replace some RebuildXXXList/ResortXXXList+InvalidateWindowXXX with InvalidateWindowXXXData.
rubidium <rubidium@openttd.org>
parents:
9281
diff
changeset
|
1480 InvalidateWindowClassesData(WC_TRAINS_LIST, 0); |
add307f2e6ea
(svn r13165) -Codechange: replace some RebuildXXXList/ResortXXXList+InvalidateWindowXXX with InvalidateWindowXXXData.
rubidium <rubidium@openttd.org>
parents:
9281
diff
changeset
|
1481 InvalidateWindowClassesData(WC_SHIPS_LIST, 0); |
add307f2e6ea
(svn r13165) -Codechange: replace some RebuildXXXList/ResortXXXList+InvalidateWindowXXX with InvalidateWindowXXXData.
rubidium <rubidium@openttd.org>
parents:
9281
diff
changeset
|
1482 InvalidateWindowClassesData(WC_ROADVEH_LIST, 0); |
add307f2e6ea
(svn r13165) -Codechange: replace some RebuildXXXList/ResortXXXList+InvalidateWindowXXX with InvalidateWindowXXXData.
rubidium <rubidium@openttd.org>
parents:
9281
diff
changeset
|
1483 InvalidateWindowClassesData(WC_AIRCRAFT_LIST, 0); |
9659
14e241fadc66
(svn r13731) -Codechange: make a pool of the array of players.
rubidium <rubidium@openttd.org>
parents:
9658
diff
changeset
|
1484 |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
1485 delete c; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1486 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1487 |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
1488 extern int GetAmountOwnedBy(const Company *c, Owner owner); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1489 |
15620
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15616
diff
changeset
|
1490 /** |
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15616
diff
changeset
|
1491 * Acquire shares in an opposing company. |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1492 * @param tile unused |
6432
fc703c6dc92c
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas <belugas@openttd.org>
parents:
6405
diff
changeset
|
1493 * @param flags type of operation |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
1494 * @param p1 company to buy the shares from |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1495 * @param p2 unused |
13067
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13054
diff
changeset
|
1496 * @param text unused |
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13054
diff
changeset
|
1497 * @return the cost of this operation or an error |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1498 */ |
11090
df23c4e04638
(svn r15434) -Codechange: bit of type safety for the DC_xxx flags.
rubidium <rubidium@openttd.org>
parents:
11085
diff
changeset
|
1499 CommandCost CmdBuyShareInCompany(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1500 { |
8230
5b61305fcdd4
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium <rubidium@openttd.org>
parents:
8224
diff
changeset
|
1501 CommandCost cost(EXPENSES_OTHER); |
15038
80e8104bac11
(svn r19655) -Codechange: Reduce usage magic p1 parameter.
frosch <frosch@openttd.org>
parents:
15035
diff
changeset
|
1502 CompanyID target_company = (CompanyID)p1; |
80e8104bac11
(svn r19655) -Codechange: Reduce usage magic p1 parameter.
frosch <frosch@openttd.org>
parents:
15035
diff
changeset
|
1503 Company *c = Company::GetIfValid(target_company); |
11949
c89301974eb8
(svn r16352) -Codechange: use PoolItem::GetIfValid() instead of PoolItem::IsValidID() and PoolItem::Get()
smatz <smatz@openttd.org>
parents:
11924
diff
changeset
|
1504 |
11368
82c90cd591ab
(svn r15718) -Cleanup: apply some comment coding style on the rest of the sources too
rubidium <rubidium@openttd.org>
parents:
11361
diff
changeset
|
1505 /* Check if buying shares is allowed (protection against modified clients) |
82c90cd591ab
(svn r15718) -Cleanup: apply some comment coding style on the rest of the sources too
rubidium <rubidium@openttd.org>
parents:
11361
diff
changeset
|
1506 * Cannot buy own shares */ |
15038
80e8104bac11
(svn r19655) -Codechange: Reduce usage magic p1 parameter.
frosch <frosch@openttd.org>
parents:
15035
diff
changeset
|
1507 if (c == NULL || !_settings_game.economy.allow_shares || _current_company == target_company) return CMD_ERROR; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1508 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1509 /* Protect new companies from hostile takeovers */ |
12632
e41943276802
(svn r17075) -Codechange: rename ~750 strings to be more uniform with their relatives
rubidium <rubidium@openttd.org>
parents:
12615
diff
changeset
|
1510 if (_cur_year - c->inaugurated_year < 6) return_cmd_error(STR_ERROR_PROTECTED); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1511 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1512 /* Those lines are here for network-protection (clients can be slow) */ |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
1513 if (GetAmountOwnedBy(c, COMPANY_SPECTATOR) == 0) return cost; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1514 |
15726
88dadfb384f8
(svn r20393) -Fix [FS#3993]: Prevent taking over competitors when you'd get too many vehicles.
alberth <alberth@openttd.org>
parents:
15725
diff
changeset
|
1515 if (GetAmountOwnedBy(c, COMPANY_SPECTATOR) == 1) { |
88dadfb384f8
(svn r20393) -Fix [FS#3993]: Prevent taking over competitors when you'd get too many vehicles.
alberth <alberth@openttd.org>
parents:
15725
diff
changeset
|
1516 if (!c->is_ai) return cost; // We can not buy out a real company (temporarily). TODO: well, enable it obviously. |
88dadfb384f8
(svn r20393) -Fix [FS#3993]: Prevent taking over competitors when you'd get too many vehicles.
alberth <alberth@openttd.org>
parents:
15725
diff
changeset
|
1517 |
88dadfb384f8
(svn r20393) -Fix [FS#3993]: Prevent taking over competitors when you'd get too many vehicles.
alberth <alberth@openttd.org>
parents:
15725
diff
changeset
|
1518 if (GetAmountOwnedBy(c, _current_company) == 3 && !MayCompanyTakeOver(_current_company, target_company)) return_cmd_error(STR_ERROR_TOO_MANY_VEHICLES_IN_GAME); |
88dadfb384f8
(svn r20393) -Fix [FS#3993]: Prevent taking over competitors when you'd get too many vehicles.
alberth <alberth@openttd.org>
parents:
15725
diff
changeset
|
1519 } |
88dadfb384f8
(svn r20393) -Fix [FS#3993]: Prevent taking over competitors when you'd get too many vehicles.
alberth <alberth@openttd.org>
parents:
15725
diff
changeset
|
1520 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1521 |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
1522 cost.AddCost(CalculateCompanyValue(c) >> 2); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1523 if (flags & DC_EXEC) { |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
1524 OwnerByte *b = c->share_owners; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1525 |
11368
82c90cd591ab
(svn r15718) -Cleanup: apply some comment coding style on the rest of the sources too
rubidium <rubidium@openttd.org>
parents:
11361
diff
changeset
|
1526 while (*b != COMPANY_SPECTATOR) b++; // share owners is guaranteed to contain at least one COMPANY_SPECTATOR |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
1527 *b = _current_company; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1528 |
15652
354307d245e5
(svn r20317) -Codechange: Move variable declaration to their first use.
alberth <alberth@openttd.org>
parents:
15623
diff
changeset
|
1529 for (int i = 0; c->share_owners[i] == _current_company;) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1530 if (++i == 4) { |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
1531 c->bankrupt_value = 0; |
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
1532 DoAcquireCompany(c); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1533 break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1534 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1535 } |
15038
80e8104bac11
(svn r19655) -Codechange: Reduce usage magic p1 parameter.
frosch <frosch@openttd.org>
parents:
15035
diff
changeset
|
1536 SetWindowDirty(WC_COMPANY, target_company); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1537 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1538 return cost; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1539 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1540 |
15620
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15616
diff
changeset
|
1541 /** |
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15616
diff
changeset
|
1542 * Sell shares in an opposing company. |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1543 * @param tile unused |
6432
fc703c6dc92c
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas <belugas@openttd.org>
parents:
6405
diff
changeset
|
1544 * @param flags type of operation |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
1545 * @param p1 company to sell the shares from |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1546 * @param p2 unused |
13067
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13054
diff
changeset
|
1547 * @param text unused |
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13054
diff
changeset
|
1548 * @return the cost of this operation or an error |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1549 */ |
11090
df23c4e04638
(svn r15434) -Codechange: bit of type safety for the DC_xxx flags.
rubidium <rubidium@openttd.org>
parents:
11085
diff
changeset
|
1550 CommandCost CmdSellShareInCompany(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1551 { |
15038
80e8104bac11
(svn r19655) -Codechange: Reduce usage magic p1 parameter.
frosch <frosch@openttd.org>
parents:
15035
diff
changeset
|
1552 CompanyID target_company = (CompanyID)p1; |
80e8104bac11
(svn r19655) -Codechange: Reduce usage magic p1 parameter.
frosch <frosch@openttd.org>
parents:
15035
diff
changeset
|
1553 Company *c = Company::GetIfValid(target_company); |
11949
c89301974eb8
(svn r16352) -Codechange: use PoolItem::GetIfValid() instead of PoolItem::IsValidID() and PoolItem::Get()
smatz <smatz@openttd.org>
parents:
11924
diff
changeset
|
1554 |
11368
82c90cd591ab
(svn r15718) -Cleanup: apply some comment coding style on the rest of the sources too
rubidium <rubidium@openttd.org>
parents:
11361
diff
changeset
|
1555 /* Check if selling shares is allowed (protection against modified clients) |
82c90cd591ab
(svn r15718) -Cleanup: apply some comment coding style on the rest of the sources too
rubidium <rubidium@openttd.org>
parents:
11361
diff
changeset
|
1556 * Cannot sell own shares */ |
15038
80e8104bac11
(svn r19655) -Codechange: Reduce usage magic p1 parameter.
frosch <frosch@openttd.org>
parents:
15035
diff
changeset
|
1557 if (c == NULL || !_settings_game.economy.allow_shares || _current_company == target_company) return CMD_ERROR; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1558 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1559 /* Those lines are here for network-protection (clients can be slow) */ |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
1560 if (GetAmountOwnedBy(c, _current_company) == 0) return CommandCost(); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1561 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1562 /* adjust it a little to make it less profitable to sell and buy */ |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
1563 Money cost = CalculateCompanyValue(c) >> 2; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1564 cost = -(cost - (cost >> 7)); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1565 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1566 if (flags & DC_EXEC) { |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
1567 OwnerByte *b = c->share_owners; |
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
1568 while (*b != _current_company) b++; // share owners is guaranteed to contain company |
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
1569 *b = COMPANY_SPECTATOR; |
15038
80e8104bac11
(svn r19655) -Codechange: Reduce usage magic p1 parameter.
frosch <frosch@openttd.org>
parents:
15035
diff
changeset
|
1570 SetWindowDirty(WC_COMPANY, target_company); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1571 } |
8230
5b61305fcdd4
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium <rubidium@openttd.org>
parents:
8224
diff
changeset
|
1572 return CommandCost(EXPENSES_OTHER, cost); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1573 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1574 |
15620
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15616
diff
changeset
|
1575 /** |
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15616
diff
changeset
|
1576 * Buy up another company. |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1577 * When a competing company is gone bankrupt you get the chance to purchase |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1578 * that company. |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
1579 * @todo currently this only works for AI companies |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1580 * @param tile unused |
6432
fc703c6dc92c
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas <belugas@openttd.org>
parents:
6405
diff
changeset
|
1581 * @param flags type of operation |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
1582 * @param p1 company to buy up |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1583 * @param p2 unused |
13067
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13054
diff
changeset
|
1584 * @param text unused |
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13054
diff
changeset
|
1585 * @return the cost of this operation or an error |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1586 */ |
11090
df23c4e04638
(svn r15434) -Codechange: bit of type safety for the DC_xxx flags.
rubidium <rubidium@openttd.org>
parents:
11085
diff
changeset
|
1587 CommandCost CmdBuyCompany(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1588 { |
15038
80e8104bac11
(svn r19655) -Codechange: Reduce usage magic p1 parameter.
frosch <frosch@openttd.org>
parents:
15035
diff
changeset
|
1589 CompanyID target_company = (CompanyID)p1; |
80e8104bac11
(svn r19655) -Codechange: Reduce usage magic p1 parameter.
frosch <frosch@openttd.org>
parents:
15035
diff
changeset
|
1590 Company *c = Company::GetIfValid(target_company); |
12855
7c31785657c1
(svn r17345) -Fix [FS#2769]: one wasn't offered to take over bankrupt companies anymore; caused by the introduction NoAI, although NewAI had the same problem too.
rubidium <rubidium@openttd.org>
parents:
12853
diff
changeset
|
1591 if (c == NULL) return CMD_ERROR; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1592 |
12855
7c31785657c1
(svn r17345) -Fix [FS#2769]: one wasn't offered to take over bankrupt companies anymore; caused by the introduction NoAI, although NewAI had the same problem too.
rubidium <rubidium@openttd.org>
parents:
12853
diff
changeset
|
1593 /* Disable takeovers when not asked */ |
7c31785657c1
(svn r17345) -Fix [FS#2769]: one wasn't offered to take over bankrupt companies anymore; caused by the introduction NoAI, although NewAI had the same problem too.
rubidium <rubidium@openttd.org>
parents:
12853
diff
changeset
|
1594 if (!HasBit(c->bankrupt_asked, _current_company)) return CMD_ERROR; |
7c31785657c1
(svn r17345) -Fix [FS#2769]: one wasn't offered to take over bankrupt companies anymore; caused by the introduction NoAI, although NewAI had the same problem too.
rubidium <rubidium@openttd.org>
parents:
12853
diff
changeset
|
1595 |
7c31785657c1
(svn r17345) -Fix [FS#2769]: one wasn't offered to take over bankrupt companies anymore; caused by the introduction NoAI, although NewAI had the same problem too.
rubidium <rubidium@openttd.org>
parents:
12853
diff
changeset
|
1596 /* Disable taking over the local company in single player */ |
7c31785657c1
(svn r17345) -Fix [FS#2769]: one wasn't offered to take over bankrupt companies anymore; caused by the introduction NoAI, although NewAI had the same problem too.
rubidium <rubidium@openttd.org>
parents:
12853
diff
changeset
|
1597 if (!_networking && _local_company == c->index) return CMD_ERROR; |
6405
3f3b30a14c26
(svn r9541) -Codechange: Safeguard the company-buying routines so that the buying player and the bought player need to be two different entities
celestar <celestar@openttd.org>
parents:
6403
diff
changeset
|
1598 |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
1599 /* Do not allow companies to take over themselves */ |
15038
80e8104bac11
(svn r19655) -Codechange: Reduce usage magic p1 parameter.
frosch <frosch@openttd.org>
parents:
15035
diff
changeset
|
1600 if (target_company == _current_company) return CMD_ERROR; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1601 |
15725
597cad644741
(svn r20392) -Fix [FS#3993]: Prevent buying bankrupt companies when you'd get too many vehicles.
alberth <alberth@openttd.org>
parents:
15676
diff
changeset
|
1602 /* Disable taking over when not allowed. */ |
597cad644741
(svn r20392) -Fix [FS#3993]: Prevent buying bankrupt companies when you'd get too many vehicles.
alberth <alberth@openttd.org>
parents:
15676
diff
changeset
|
1603 if (!MayCompanyTakeOver(_current_company, target_company)) return CMD_ERROR; |
597cad644741
(svn r20392) -Fix [FS#3993]: Prevent buying bankrupt companies when you'd get too many vehicles.
alberth <alberth@openttd.org>
parents:
15676
diff
changeset
|
1604 |
13044
1f4a5608aba5
(svn r17542) -Fix: don't access variables in the company struct after it has been deleted
yexo <yexo@openttd.org>
parents:
13036
diff
changeset
|
1605 /* Get the cost here as the company is deleted in DoAcquireCompany. */ |
1f4a5608aba5
(svn r17542) -Fix: don't access variables in the company struct after it has been deleted
yexo <yexo@openttd.org>
parents:
13036
diff
changeset
|
1606 CommandCost cost(EXPENSES_OTHER, c->bankrupt_value); |
1f4a5608aba5
(svn r17542) -Fix: don't access variables in the company struct after it has been deleted
yexo <yexo@openttd.org>
parents:
13036
diff
changeset
|
1607 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1608 if (flags & DC_EXEC) { |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10158
diff
changeset
|
1609 DoAcquireCompany(c); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1610 } |
13044
1f4a5608aba5
(svn r17542) -Fix: don't access variables in the company struct after it has been deleted
yexo <yexo@openttd.org>
parents:
13036
diff
changeset
|
1611 return cost; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1612 } |