Mercurial > hg > openttd
annotate src/economy.cpp @ 18692:90d395fc678d draft
(svn r23540) -Codechange: unify and document vehicle widgets
author | rubidium <rubidium@openttd.org> |
---|---|
date | Fri, 16 Dec 2011 16:58:55 +0000 |
parents | ac23ced64c4b |
children | 1fa19d70aea9 |
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" |
17152
c62cecf4dade
(svn r21890) -Cleanup: remove some unneeded includes
rubidium <rubidium@openttd.org>
parents:
16923
diff
changeset
|
23 #include "newgrf_engine.h" |
c62cecf4dade
(svn r21890) -Cleanup: remove some unneeded includes
rubidium <rubidium@openttd.org>
parents:
16923
diff
changeset
|
24 #include "engine_base.h" |
c62cecf4dade
(svn r21890) -Cleanup: remove some unneeded includes
rubidium <rubidium@openttd.org>
parents:
16923
diff
changeset
|
25 #include "ground_vehicle.hpp" |
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
|
26 #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
|
27 #include "newgrf_sound.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 "window_func.h" |
8140
fb8a05d579da
(svn r11702) -Codechange: move all date related stuff to date*.
rubidium <rubidium@openttd.org>
parents:
8139
diff
changeset
|
35 #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
|
36 #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
|
37 #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
|
38 #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
|
39 #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
|
40 #include "signs_base.h" |
12297
39ea618c207e
(svn r16714) -Codechange: use pool-like accessors for Subsidy
smatz <smatz@openttd.org>
parents:
12294
diff
changeset
|
41 #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
|
42 #include "subsidy_func.h" |
12228
240adc64d01a
(svn r16643) -Codechange: replace GetStationByTile() by Station::GetByTile()
smatz <smatz@openttd.org>
parents:
12143
diff
changeset
|
43 #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
|
44 #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
|
45 #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
|
46 #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
|
47 #include "newgrf.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
|
48 #include "core/backup_type.hpp" |
18570
bbdb2c13eb92
(svn r23415) -Feature: Infrastructure maintenance costs.
michi_cc <michi_cc@openttd.org>
parents:
18511
diff
changeset
|
49 #include "water.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
|
50 |
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
|
51 #include "table/strings.h" |
12593
73b580ddf33f
(svn r17036) -Codechange: Split price bases from economy.cpp to table/pricebase.h.
frosch <frosch@openttd.org>
parents:
12496
diff
changeset
|
52 #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
|
53 |
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
|
54 |
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
|
55 /* 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
|
56 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
|
57 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
|
58 |
7926
e8ce9f6469d1
(svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents:
7922
diff
changeset
|
59 /** |
e8ce9f6469d1
(svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents:
7922
diff
changeset
|
60 * 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
|
61 * |
e8ce9f6469d1
(svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents:
7922
diff
changeset
|
62 * 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
|
63 * 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
|
64 * |
e8ce9f6469d1
(svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents:
7922
diff
changeset
|
65 * @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
|
66 * @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
|
67 * @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
|
68 * @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
|
69 */ |
e8ce9f6469d1
(svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents:
7922
diff
changeset
|
70 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
|
71 { |
e8ce9f6469d1
(svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents:
7922
diff
changeset
|
72 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
|
73 } |
e8ce9f6469d1
(svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents:
7922
diff
changeset
|
74 |
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
|
75 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
|
76 |
15601
4d1a28b41236
(svn r20262) -Codechange: Remove unused ScoreInfo::id field, and doxyment the data structures.
alberth <alberth@openttd.org>
parents:
15552
diff
changeset
|
77 /** |
4d1a28b41236
(svn r20262) -Codechange: Remove unused ScoreInfo::id field, and doxyment the data structures.
alberth <alberth@openttd.org>
parents:
15552
diff
changeset
|
78 * 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
|
79 */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
80 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
|
81 { 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
|
82 { 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
|
83 { 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
|
84 { 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
|
85 { 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
|
86 { 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
|
87 { 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
|
88 {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
|
89 { 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
|
90 { 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
|
91 }; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
92 |
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
|
93 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
|
94 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
|
95 Prices _price; |
8119
b6ec923e9fa8
(svn r11680) -Codechange: refactor more out of openttd.h and functions.h.
rubidium <rubidium@openttd.org>
parents:
8116
diff
changeset
|
96 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
|
97 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
|
98 |
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
|
99 /** |
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
|
100 * 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
|
101 * 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
|
102 * 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
|
103 * 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
|
104 * @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
|
105 * @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
|
106 * @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
|
107 */ |
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
|
108 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
|
109 { |
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
|
110 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
|
111 |
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
|
112 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
|
113 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
|
114 |
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
|
115 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
|
116 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
|
117 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
118 |
15652
354307d245e5
(svn r20317) -Codechange: Move variable declaration to their first use.
alberth <alberth@openttd.org>
parents:
15623
diff
changeset
|
119 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
|
120 |
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
|
121 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
|
122 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
|
123 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
|
124 |
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
|
125 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
|
126 v->type == VEH_ROAD || |
12384
d4b73a406cf3
(svn r16814) -Codechange: make IsNormalAircraft() member of Aircraft
smatz <smatz@openttd.org>
parents:
12383
diff
changeset
|
127 (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
|
128 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
|
129 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
|
130 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
131 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
132 |
6953
41fd36025784
(svn r10208) -Codechange: replace int32 with Money where appropriate.
rubidium <rubidium@openttd.org>
parents:
6952
diff
changeset
|
133 /* 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
|
134 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
|
135 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
|
136 |
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
|
137 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
|
138 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
139 |
15620
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15616
diff
changeset
|
140 /** |
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15616
diff
changeset
|
141 * 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
|
142 * (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
|
143 * @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
|
144 * @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
|
145 * @return actual score of this company |
15623
c62577640878
(svn r20286) -Codechange: Unify end of doxygen comments.
frosch <frosch@openttd.org>
parents:
15620
diff
changeset
|
146 * |
c62577640878
(svn r20286) -Codechange: Unify end of doxygen comments.
frosch <frosch@openttd.org>
parents:
15620
diff
changeset
|
147 */ |
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
|
148 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
|
149 { |
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
|
150 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
|
151 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
|
152 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
153 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
|
154 |
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
|
155 /* 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
|
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 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
|
158 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
|
159 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
|
160 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
|
161 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
162 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
|
163 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
|
164 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
|
165 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
|
166 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
|
167 /* 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
|
168 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
|
169 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
|
170 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
|
171 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
172 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
173 } |
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 |
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
|
176 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
|
177 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
178 _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
|
179 /* 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
|
180 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
|
181 _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
|
182 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
183 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
184 |
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
|
185 /* 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
|
186 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
187 uint num = 0; |
10647
592ae9307430
(svn r14949) -Cleanup: pointer coding style
rubidium <rubidium@openttd.org>
parents:
10571
diff
changeset
|
188 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
|
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 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
|
191 /* 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
|
192 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
|
193 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
194 _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
|
195 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
196 |
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
|
197 /* 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
|
198 { |
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
|
199 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
|
200 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
|
201 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
|
202 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
|
203 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
|
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 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
|
206 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
|
207 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
|
208 } 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
|
209 |
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
|
210 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
|
211 _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
|
212 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
213 |
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
|
214 _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
|
215 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
216 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
217 |
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
|
218 /* 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
|
219 { |
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
|
220 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
|
221 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
|
222 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
|
223 |
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 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
|
225 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
|
226 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
|
227 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
|
228 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
|
229 total_delivered += cee->delivered_cargo; |
11361
02313cc6114e
(svn r15711) -Codechange: lots of whitespace cleanup/fixes
rubidium <rubidium@openttd.org>
parents:
11234
diff
changeset
|
230 } 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
|
231 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
232 _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
|
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 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
|
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 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
|
239 _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
|
240 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
|
241 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
242 |
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
|
243 /* 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
|
244 { |
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
|
245 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
|
246 _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
|
247 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
248 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
249 |
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
|
250 /* 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
|
251 { |
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
|
252 _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
|
253 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
254 |
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
|
255 /* 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
|
256 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
257 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
|
258 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
|
259 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
|
260 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
|
261 /* 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
|
262 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
|
263 /* 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
|
264 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
|
265 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
|
266 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
|
267 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
268 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
269 _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
|
270 |
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
|
271 /* 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
|
272 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
|
273 } |
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 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
|
276 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
|
277 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
|
278 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
|
279 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
280 |
13034
6eb3f749890a
(svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents:
12991
diff
changeset
|
281 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
|
282 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
|
283 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
284 |
17642
d8caba096f22
(svn r22413) -Document: even more stuff
rubidium <rubidium@openttd.org>
parents:
17340
diff
changeset
|
285 /** |
d8caba096f22
(svn r22413) -Document: even more stuff
rubidium <rubidium@openttd.org>
parents:
17340
diff
changeset
|
286 * Change the ownership of all the items of a company. |
d8caba096f22
(svn r22413) -Document: even more stuff
rubidium <rubidium@openttd.org>
parents:
17340
diff
changeset
|
287 * @param old_owner The company that gets removed. |
d8caba096f22
(svn r22413) -Document: even more stuff
rubidium <rubidium@openttd.org>
parents:
17340
diff
changeset
|
288 * @param new_owner The company to merge to, or INVALID_OWNER to remove the company. |
d8caba096f22
(svn r22413) -Document: even more stuff
rubidium <rubidium@openttd.org>
parents:
17340
diff
changeset
|
289 */ |
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
|
290 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
|
291 { |
17230
2933d0e4edcb
(svn r21970) -Fix [FS#4464]: Crash when a multiplayer company goes bankrupt with 'you' in it
rubidium <rubidium@openttd.org>
parents:
17218
diff
changeset
|
292 /* We need to set _current_company to old_owner before we try to move |
2933d0e4edcb
(svn r21970) -Fix [FS#4464]: Crash when a multiplayer company goes bankrupt with 'you' in it
rubidium <rubidium@openttd.org>
parents:
17218
diff
changeset
|
293 * the client. This is needed as it needs to know whether "you" really |
2933d0e4edcb
(svn r21970) -Fix [FS#4464]: Crash when a multiplayer company goes bankrupt with 'you' in it
rubidium <rubidium@openttd.org>
parents:
17218
diff
changeset
|
294 * are the current local company. */ |
2933d0e4edcb
(svn r21970) -Fix [FS#4464]: Crash when a multiplayer company goes bankrupt with 'you' in it
rubidium <rubidium@openttd.org>
parents:
17218
diff
changeset
|
295 Backup<CompanyByte> cur_company(_current_company, old_owner, FILE_LINE); |
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
|
296 #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
|
297 /* 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
|
298 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
|
299 #endif /* ENABLE_NETWORK */ |
17833
22216d88b87b
(svn r22624) -Fix [FS#4654]: When closing an AI company the local player cheated to, we need to cheat him to another company.
frosch <frosch@openttd.org>
parents:
17832
diff
changeset
|
300 if (old_owner == _local_company) { |
22216d88b87b
(svn r22624) -Fix [FS#4654]: When closing an AI company the local player cheated to, we need to cheat him to another company.
frosch <frosch@openttd.org>
parents:
17832
diff
changeset
|
301 /* Single player cheated to AI company. |
22216d88b87b
(svn r22624) -Fix [FS#4654]: When closing an AI company the local player cheated to, we need to cheat him to another company.
frosch <frosch@openttd.org>
parents:
17832
diff
changeset
|
302 * There are no specatators in single player, so we must pick some other company. */ |
22216d88b87b
(svn r22624) -Fix [FS#4654]: When closing an AI company the local player cheated to, we need to cheat him to another company.
frosch <frosch@openttd.org>
parents:
17832
diff
changeset
|
303 assert(!_networking); |
22216d88b87b
(svn r22624) -Fix [FS#4654]: When closing an AI company the local player cheated to, we need to cheat him to another company.
frosch <frosch@openttd.org>
parents:
17832
diff
changeset
|
304 Backup<CompanyByte> cur_company(_current_company, FILE_LINE); |
22216d88b87b
(svn r22624) -Fix [FS#4654]: When closing an AI company the local player cheated to, we need to cheat him to another company.
frosch <frosch@openttd.org>
parents:
17832
diff
changeset
|
305 Company *c; |
22216d88b87b
(svn r22624) -Fix [FS#4654]: When closing an AI company the local player cheated to, we need to cheat him to another company.
frosch <frosch@openttd.org>
parents:
17832
diff
changeset
|
306 FOR_ALL_COMPANIES(c) { |
22216d88b87b
(svn r22624) -Fix [FS#4654]: When closing an AI company the local player cheated to, we need to cheat him to another company.
frosch <frosch@openttd.org>
parents:
17832
diff
changeset
|
307 if (c->index != old_owner) { |
22216d88b87b
(svn r22624) -Fix [FS#4654]: When closing an AI company the local player cheated to, we need to cheat him to another company.
frosch <frosch@openttd.org>
parents:
17832
diff
changeset
|
308 SetLocalCompany(c->index); |
22216d88b87b
(svn r22624) -Fix [FS#4654]: When closing an AI company the local player cheated to, we need to cheat him to another company.
frosch <frosch@openttd.org>
parents:
17832
diff
changeset
|
309 break; |
22216d88b87b
(svn r22624) -Fix [FS#4654]: When closing an AI company the local player cheated to, we need to cheat him to another company.
frosch <frosch@openttd.org>
parents:
17832
diff
changeset
|
310 } |
22216d88b87b
(svn r22624) -Fix [FS#4654]: When closing an AI company the local player cheated to, we need to cheat him to another company.
frosch <frosch@openttd.org>
parents:
17832
diff
changeset
|
311 } |
22216d88b87b
(svn r22624) -Fix [FS#4654]: When closing an AI company the local player cheated to, we need to cheat him to another company.
frosch <frosch@openttd.org>
parents:
17832
diff
changeset
|
312 cur_company.Restore(); |
22216d88b87b
(svn r22624) -Fix [FS#4654]: When closing an AI company the local player cheated to, we need to cheat him to another company.
frosch <frosch@openttd.org>
parents:
17832
diff
changeset
|
313 assert(old_owner != _local_company); |
22216d88b87b
(svn r22624) -Fix [FS#4654]: When closing an AI company the local player cheated to, we need to cheat him to another company.
frosch <frosch@openttd.org>
parents:
17832
diff
changeset
|
314 } |
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
|
315 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
316 Town *t; |
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
|
317 |
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
|
318 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
|
319 |
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
|
320 { |
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
|
321 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
|
322 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
|
323 |
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
|
324 /* 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
|
325 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
|
326 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
|
327 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
|
328 /* Sell his shares */ |
17831
7c8f4c06bbc1
(svn r22622) -Fix: When closing down companies their shares in other companies must be sold even if share trading is disabled at that point of time.
frosch <frosch@openttd.org>
parents:
17758
diff
changeset
|
329 CommandCost res = DoCommand(0, c->index, 0, DC_EXEC | DC_BANKRUPT, CMD_SELL_SHARE_IN_COMPANY); |
14136
54dfd3720fa1
(svn r18683) -Fix: it's not an other
rubidium <rubidium@openttd.org>
parents:
13998
diff
changeset
|
330 /* 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
|
331 * 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
|
332 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
|
333 } |
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
|
334 } |
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
|
335 } |
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 |
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
|
337 /* 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
|
338 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
|
339 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
|
340 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
|
341 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
|
342 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
|
343 /* Sell the shares */ |
17831
7c8f4c06bbc1
(svn r22622) -Fix: When closing down companies their shares in other companies must be sold even if share trading is disabled at that point of time.
frosch <frosch@openttd.org>
parents:
17758
diff
changeset
|
344 CommandCost res = DoCommand(0, old_owner, 0, DC_EXEC | DC_BANKRUPT, CMD_SELL_SHARE_IN_COMPANY); |
14136
54dfd3720fa1
(svn r18683) -Fix: it's not an other
rubidium <rubidium@openttd.org>
parents:
13998
diff
changeset
|
345 /* 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
|
346 * 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
|
347 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
|
348 } |
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
|
349 } |
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
|
350 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
|
351 } |
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
|
352 |
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
|
353 /* 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
|
354 * 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
|
355 * 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
|
356 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
|
357 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
|
358 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
359 |
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
|
360 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
|
361 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
|
362 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
|
363 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
|
364 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
|
365 } 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
|
366 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
|
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 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
369 } |
12669
406f4ae1e2ca
(svn r17124) -Codechange: store subsidies in a pool (instead of an array)
smatz <smatz@openttd.org>
parents:
12658
diff
changeset
|
370 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
|
371 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
372 /* 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
|
373 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
|
374 /* 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
|
375 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
|
376 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
|
377 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
|
378 /* 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
|
379 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
|
380 } 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
|
381 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
|
382 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
|
383 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
384 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
385 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
386 |
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
|
387 /* 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
|
388 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
|
389 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
|
390 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
391 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
392 { |
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
|
393 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
|
394 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
|
395 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
|
396 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
|
397 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
|
398 } else { |
18155
a7b36ae3de21
(svn r22980) -Add: GroupStatistics for DEFAULT_GROUP.
frosch <frosch@openttd.org>
parents:
17941
diff
changeset
|
399 if (v->IsEngineCountable()) GroupStatistics::CountEngine(v, -1); |
a7b36ae3de21
(svn r22980) -Add: GroupStatistics for DEFAULT_GROUP.
frosch <frosch@openttd.org>
parents:
17941
diff
changeset
|
400 if (v->IsPrimaryVehicle()) GroupStatistics::CountVehicle(v, -1); |
18231
013a4175f4c4
(svn r23067) -Fix [FS#4812]: updating the group statistics got more strict checks, so there was some trouble moving a vehicles and groups from one company to another
rubidium <rubidium@openttd.org>
parents:
18202
diff
changeset
|
401 } |
013a4175f4c4
(svn r23067) -Fix [FS#4812]: updating the group statistics got more strict checks, so there was some trouble moving a vehicles and groups from one company to another
rubidium <rubidium@openttd.org>
parents:
18202
diff
changeset
|
402 } |
013a4175f4c4
(svn r23067) -Fix [FS#4812]: updating the group statistics got more strict checks, so there was some trouble moving a vehicles and groups from one company to another
rubidium <rubidium@openttd.org>
parents:
18202
diff
changeset
|
403 } |
013a4175f4c4
(svn r23067) -Fix [FS#4812]: updating the group statistics got more strict checks, so there was some trouble moving a vehicles and groups from one company to another
rubidium <rubidium@openttd.org>
parents:
18202
diff
changeset
|
404 } |
18155
a7b36ae3de21
(svn r22980) -Add: GroupStatistics for DEFAULT_GROUP.
frosch <frosch@openttd.org>
parents:
17941
diff
changeset
|
405 |
18231
013a4175f4c4
(svn r23067) -Fix [FS#4812]: updating the group statistics got more strict checks, so there was some trouble moving a vehicles and groups from one company to another
rubidium <rubidium@openttd.org>
parents:
18202
diff
changeset
|
406 /* In all cases clear replace engine rules. |
013a4175f4c4
(svn r23067) -Fix [FS#4812]: updating the group statistics got more strict checks, so there was some trouble moving a vehicles and groups from one company to another
rubidium <rubidium@openttd.org>
parents:
18202
diff
changeset
|
407 * Even if it was copied, it could interfere with new owner's rules */ |
013a4175f4c4
(svn r23067) -Fix [FS#4812]: updating the group statistics got more strict checks, so there was some trouble moving a vehicles and groups from one company to another
rubidium <rubidium@openttd.org>
parents:
18202
diff
changeset
|
408 RemoveAllEngineReplacementForCompany(Company::Get(old_owner)); |
013a4175f4c4
(svn r23067) -Fix [FS#4812]: updating the group statistics got more strict checks, so there was some trouble moving a vehicles and groups from one company to another
rubidium <rubidium@openttd.org>
parents:
18202
diff
changeset
|
409 |
013a4175f4c4
(svn r23067) -Fix [FS#4812]: updating the group statistics got more strict checks, so there was some trouble moving a vehicles and groups from one company to another
rubidium <rubidium@openttd.org>
parents:
18202
diff
changeset
|
410 if (new_owner == INVALID_OWNER) { |
013a4175f4c4
(svn r23067) -Fix [FS#4812]: updating the group statistics got more strict checks, so there was some trouble moving a vehicles and groups from one company to another
rubidium <rubidium@openttd.org>
parents:
18202
diff
changeset
|
411 RemoveAllGroupsForCompany(old_owner); |
013a4175f4c4
(svn r23067) -Fix [FS#4812]: updating the group statistics got more strict checks, so there was some trouble moving a vehicles and groups from one company to another
rubidium <rubidium@openttd.org>
parents:
18202
diff
changeset
|
412 } else { |
013a4175f4c4
(svn r23067) -Fix [FS#4812]: updating the group statistics got more strict checks, so there was some trouble moving a vehicles and groups from one company to another
rubidium <rubidium@openttd.org>
parents:
18202
diff
changeset
|
413 Group *g; |
013a4175f4c4
(svn r23067) -Fix [FS#4812]: updating the group statistics got more strict checks, so there was some trouble moving a vehicles and groups from one company to another
rubidium <rubidium@openttd.org>
parents:
18202
diff
changeset
|
414 FOR_ALL_GROUPS(g) { |
013a4175f4c4
(svn r23067) -Fix [FS#4812]: updating the group statistics got more strict checks, so there was some trouble moving a vehicles and groups from one company to another
rubidium <rubidium@openttd.org>
parents:
18202
diff
changeset
|
415 if (g->owner == old_owner) g->owner = new_owner; |
013a4175f4c4
(svn r23067) -Fix [FS#4812]: updating the group statistics got more strict checks, so there was some trouble moving a vehicles and groups from one company to another
rubidium <rubidium@openttd.org>
parents:
18202
diff
changeset
|
416 } |
013a4175f4c4
(svn r23067) -Fix [FS#4812]: updating the group statistics got more strict checks, so there was some trouble moving a vehicles and groups from one company to another
rubidium <rubidium@openttd.org>
parents:
18202
diff
changeset
|
417 } |
18155
a7b36ae3de21
(svn r22980) -Add: GroupStatistics for DEFAULT_GROUP.
frosch <frosch@openttd.org>
parents:
17941
diff
changeset
|
418 |
18231
013a4175f4c4
(svn r23067) -Fix [FS#4812]: updating the group statistics got more strict checks, so there was some trouble moving a vehicles and groups from one company to another
rubidium <rubidium@openttd.org>
parents:
18202
diff
changeset
|
419 { |
013a4175f4c4
(svn r23067) -Fix [FS#4812]: updating the group statistics got more strict checks, so there was some trouble moving a vehicles and groups from one company to another
rubidium <rubidium@openttd.org>
parents:
18202
diff
changeset
|
420 FreeUnitIDGenerator unitidgen[] = { |
013a4175f4c4
(svn r23067) -Fix [FS#4812]: updating the group statistics got more strict checks, so there was some trouble moving a vehicles and groups from one company to another
rubidium <rubidium@openttd.org>
parents:
18202
diff
changeset
|
421 FreeUnitIDGenerator(VEH_TRAIN, new_owner), FreeUnitIDGenerator(VEH_ROAD, new_owner), |
013a4175f4c4
(svn r23067) -Fix [FS#4812]: updating the group statistics got more strict checks, so there was some trouble moving a vehicles and groups from one company to another
rubidium <rubidium@openttd.org>
parents:
18202
diff
changeset
|
422 FreeUnitIDGenerator(VEH_SHIP, new_owner), FreeUnitIDGenerator(VEH_AIRCRAFT, new_owner) |
013a4175f4c4
(svn r23067) -Fix [FS#4812]: updating the group statistics got more strict checks, so there was some trouble moving a vehicles and groups from one company to another
rubidium <rubidium@openttd.org>
parents:
18202
diff
changeset
|
423 }; |
013a4175f4c4
(svn r23067) -Fix [FS#4812]: updating the group statistics got more strict checks, so there was some trouble moving a vehicles and groups from one company to another
rubidium <rubidium@openttd.org>
parents:
18202
diff
changeset
|
424 |
013a4175f4c4
(svn r23067) -Fix [FS#4812]: updating the group statistics got more strict checks, so there was some trouble moving a vehicles and groups from one company to another
rubidium <rubidium@openttd.org>
parents:
18202
diff
changeset
|
425 Vehicle *v; |
013a4175f4c4
(svn r23067) -Fix [FS#4812]: updating the group statistics got more strict checks, so there was some trouble moving a vehicles and groups from one company to another
rubidium <rubidium@openttd.org>
parents:
18202
diff
changeset
|
426 FOR_ALL_VEHICLES(v) { |
013a4175f4c4
(svn r23067) -Fix [FS#4812]: updating the group statistics got more strict checks, so there was some trouble moving a vehicles and groups from one company to another
rubidium <rubidium@openttd.org>
parents:
18202
diff
changeset
|
427 if (v->owner == old_owner && IsCompanyBuildableVehicleType(v->type)) { |
013a4175f4c4
(svn r23067) -Fix [FS#4812]: updating the group statistics got more strict checks, so there was some trouble moving a vehicles and groups from one company to another
rubidium <rubidium@openttd.org>
parents:
18202
diff
changeset
|
428 assert(new_owner != INVALID_OWNER); |
16871
39e28608198f
(svn r21605) -Fix [FS#4324]: crash due to cargo payments belonging to an non-existing company
rubidium <rubidium@openttd.org>
parents:
16788
diff
changeset
|
429 |
18231
013a4175f4c4
(svn r23067) -Fix [FS#4812]: updating the group statistics got more strict checks, so there was some trouble moving a vehicles and groups from one company to another
rubidium <rubidium@openttd.org>
parents:
18202
diff
changeset
|
430 v->owner = new_owner; |
013a4175f4c4
(svn r23067) -Fix [FS#4812]: updating the group statistics got more strict checks, so there was some trouble moving a vehicles and groups from one company to another
rubidium <rubidium@openttd.org>
parents:
18202
diff
changeset
|
431 v->colourmap = PAL_NONE; |
013a4175f4c4
(svn r23067) -Fix [FS#4812]: updating the group statistics got more strict checks, so there was some trouble moving a vehicles and groups from one company to another
rubidium <rubidium@openttd.org>
parents:
18202
diff
changeset
|
432 |
013a4175f4c4
(svn r23067) -Fix [FS#4812]: updating the group statistics got more strict checks, so there was some trouble moving a vehicles and groups from one company to another
rubidium <rubidium@openttd.org>
parents:
18202
diff
changeset
|
433 if (v->IsEngineCountable()) { |
013a4175f4c4
(svn r23067) -Fix [FS#4812]: updating the group statistics got more strict checks, so there was some trouble moving a vehicles and groups from one company to another
rubidium <rubidium@openttd.org>
parents:
18202
diff
changeset
|
434 GroupStatistics::CountEngine(v, 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
|
435 } |
18231
013a4175f4c4
(svn r23067) -Fix [FS#4812]: updating the group statistics got more strict checks, so there was some trouble moving a vehicles and groups from one company to another
rubidium <rubidium@openttd.org>
parents:
18202
diff
changeset
|
436 if (v->IsPrimaryVehicle()) { |
013a4175f4c4
(svn r23067) -Fix [FS#4812]: updating the group statistics got more strict checks, so there was some trouble moving a vehicles and groups from one company to another
rubidium <rubidium@openttd.org>
parents:
18202
diff
changeset
|
437 GroupStatistics::CountVehicle(v, 1); |
013a4175f4c4
(svn r23067) -Fix [FS#4812]: updating the group statistics got more strict checks, so there was some trouble moving a vehicles and groups from one company to another
rubidium <rubidium@openttd.org>
parents:
18202
diff
changeset
|
438 v->unitnumber = unitidgen[v->type].NextID(); |
013a4175f4c4
(svn r23067) -Fix [FS#4812]: updating the group statistics got more strict checks, so there was some trouble moving a vehicles and groups from one company to another
rubidium <rubidium@openttd.org>
parents:
18202
diff
changeset
|
439 } |
013a4175f4c4
(svn r23067) -Fix [FS#4812]: updating the group statistics got more strict checks, so there was some trouble moving a vehicles and groups from one company to another
rubidium <rubidium@openttd.org>
parents:
18202
diff
changeset
|
440 |
013a4175f4c4
(svn r23067) -Fix [FS#4812]: updating the group statistics got more strict checks, so there was some trouble moving a vehicles and groups from one company to another
rubidium <rubidium@openttd.org>
parents:
18202
diff
changeset
|
441 /* Invalidate the vehicle's cargo payment "owner cache". */ |
013a4175f4c4
(svn r23067) -Fix [FS#4812]: updating the group statistics got more strict checks, so there was some trouble moving a vehicles and groups from one company to another
rubidium <rubidium@openttd.org>
parents:
18202
diff
changeset
|
442 if (v->cargo_payment != NULL) v->cargo_payment->owner = NULL; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
443 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
444 } |
18160
9fd018e89254
(svn r22985) -Feature: Display autoreplace status in group GUI.
frosch <frosch@openttd.org>
parents:
18156
diff
changeset
|
445 |
9fd018e89254
(svn r22985) -Feature: Display autoreplace status in group GUI.
frosch <frosch@openttd.org>
parents:
18156
diff
changeset
|
446 if (new_owner != INVALID_OWNER) GroupStatistics::UpdateAutoreplace(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
|
447 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
448 |
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
|
449 /* 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
|
450 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
451 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
|
452 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
|
453 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
|
454 } while (++tile != MapSize()); |
8200
f7f49622b3e0
(svn r11763) -Fix: update signal states after merging a company
smatz <smatz@openttd.org>
parents:
8186
diff
changeset
|
455 |
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
|
456 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
|
457 /* 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
|
458 * 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
|
459 * 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
|
460 * 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
|
461 tile = 0; |
f7f49622b3e0
(svn r11763) -Fix: update signal states after merging a company
smatz <smatz@openttd.org>
parents:
8186
diff
changeset
|
462 |
f7f49622b3e0
(svn r11763) -Fix: update signal states after merging a company
smatz <smatz@openttd.org>
parents:
8186
diff
changeset
|
463 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
|
464 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
|
465 TrackBits tracks = GetTrackBits(tile); |
f7f49622b3e0
(svn r11763) -Fix: update signal states after merging a company
smatz <smatz@openttd.org>
parents:
8186
diff
changeset
|
466 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
|
467 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
|
468 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
|
469 } 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
|
470 } 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
|
471 UpdateLevelCrossing(tile); |
8200
f7f49622b3e0
(svn r11763) -Fix: update signal states after merging a company
smatz <smatz@openttd.org>
parents:
8186
diff
changeset
|
472 } |
f7f49622b3e0
(svn r11763) -Fix: update signal states after merging a company
smatz <smatz@openttd.org>
parents:
8186
diff
changeset
|
473 } 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
|
474 } |
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
|
475 |
8347
a83dd50f52f9
(svn r11913) -Fix (r11871): update signals after company bankrupt and disaster too
smatz <smatz@openttd.org>
parents:
8342
diff
changeset
|
476 /* 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
|
477 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
|
478 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
479 |
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
|
480 /* 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
|
481 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
|
482 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
|
483 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
|
484 /* 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
|
485 * 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
|
486 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
|
487 } |
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
|
488 } |
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
|
489 |
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
|
490 /* 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
|
491 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
|
492 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
|
493 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
|
494 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
|
495 } |
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
|
496 } |
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
|
497 |
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
|
498 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
|
499 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
|
500 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
|
501 } |
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
|
502 |
11085
8da1855e9f14
(svn r15428) -Codechange: consistently use colour instead of having both color and colour.
rubidium <rubidium@openttd.org>
parents:
11056
diff
changeset
|
503 /* 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
|
504 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
|
505 |
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
|
506 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
|
507 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
508 MarkWholeScreenDirty(); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
509 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
510 |
15653
930fc2895ced
(svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents:
15652
diff
changeset
|
511 /** |
930fc2895ced
(svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents:
15652
diff
changeset
|
512 * Check for bankruptcy of a company. Called every three months. |
930fc2895ced
(svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents:
15652
diff
changeset
|
513 * @param c Company to check. |
930fc2895ced
(svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents:
15652
diff
changeset
|
514 */ |
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
|
515 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
|
516 { |
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
|
517 /* 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
|
518 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
|
519 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
|
520 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
|
521 return; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
522 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
523 |
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
|
524 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
|
525 |
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
|
526 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
|
527 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
|
528 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
|
529 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
|
530 |
17213
4111445c818e
(svn r21952) -Codechange: unify the company clearing code for bankruptcy with the command to remove companies
rubidium <rubidium@openttd.org>
parents:
17152
diff
changeset
|
531 case 2: { |
4111445c818e
(svn r21952) -Codechange: unify the company clearing code for bankruptcy with the command to remove companies
rubidium <rubidium@openttd.org>
parents:
17152
diff
changeset
|
532 CompanyNewsInformation *cni = MallocT<CompanyNewsInformation>(1); |
4111445c818e
(svn r21952) -Codechange: unify the company clearing code for bankruptcy with the command to remove companies
rubidium <rubidium@openttd.org>
parents:
17152
diff
changeset
|
533 cni->FillData(c); |
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
|
534 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
|
535 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
|
536 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
|
537 AddCompanyNewsItem(STR_MESSAGE_NEWS_FORMAT, NS_COMPANY_TROUBLE, cni); |
18511
f1214da4c397
(svn r23355) -Codechange: rename all AI* to Script* (Rubidium)
truebrain <truebrain@openttd.org>
parents:
18454
diff
changeset
|
538 AI::BroadcastNewEvent(new ScriptEventCompanyInTrouble(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
|
539 break; |
17213
4111445c818e
(svn r21952) -Codechange: unify the company clearing code for bankruptcy with the command to remove companies
rubidium <rubidium@openttd.org>
parents:
17152
diff
changeset
|
540 } |
4111445c818e
(svn r21952) -Codechange: unify the company clearing code for bankruptcy with the command to remove companies
rubidium <rubidium@openttd.org>
parents:
17152
diff
changeset
|
541 |
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 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
|
543 /* 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
|
544 * 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
|
545 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
|
546 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
|
547 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
|
548 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
|
549 c->bankrupt_timeout = 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
|
550 break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
551 } |
15655
0be6e9a4ca0b
(svn r20320) -Doc: Small Doxygen and normal comment fixes, and an missed addition.
alberth <alberth@openttd.org>
parents:
15654
diff
changeset
|
552 /* 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
|
553 } |
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
|
554 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
|
555 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
|
556 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
|
557 /* 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
|
558 * 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
|
559 * 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
|
560 * 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
|
561 c->bankrupt_asked = MAX_UVALUE(CompanyMask); |
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
|
562 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
|
563 } |
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
|
564 |
17230
2933d0e4edcb
(svn r21970) -Fix [FS#4464]: Crash when a multiplayer company goes bankrupt with 'you' in it
rubidium <rubidium@openttd.org>
parents:
17218
diff
changeset
|
565 /* Actually remove the company, but not when we're a network client. |
2933d0e4edcb
(svn r21970) -Fix [FS#4464]: Crash when a multiplayer company goes bankrupt with 'you' in it
rubidium <rubidium@openttd.org>
parents:
17218
diff
changeset
|
566 * In case of network clients we will be getting a command from the |
2933d0e4edcb
(svn r21970) -Fix [FS#4464]: Crash when a multiplayer company goes bankrupt with 'you' in it
rubidium <rubidium@openttd.org>
parents:
17218
diff
changeset
|
567 * server. It is done in this way as we are called from the |
2933d0e4edcb
(svn r21970) -Fix [FS#4464]: Crash when a multiplayer company goes bankrupt with 'you' in it
rubidium <rubidium@openttd.org>
parents:
17218
diff
changeset
|
568 * StateGameLoop which can't change the current company, and thus |
2933d0e4edcb
(svn r21970) -Fix [FS#4464]: Crash when a multiplayer company goes bankrupt with 'you' in it
rubidium <rubidium@openttd.org>
parents:
17218
diff
changeset
|
569 * updating the local company triggers an assert later on. In the |
2933d0e4edcb
(svn r21970) -Fix [FS#4464]: Crash when a multiplayer company goes bankrupt with 'you' in it
rubidium <rubidium@openttd.org>
parents:
17218
diff
changeset
|
570 * case of a network game the command will be processed at a time |
2933d0e4edcb
(svn r21970) -Fix [FS#4464]: Crash when a multiplayer company goes bankrupt with 'you' in it
rubidium <rubidium@openttd.org>
parents:
17218
diff
changeset
|
571 * that changing the current company is okay. In case of single |
2933d0e4edcb
(svn r21970) -Fix [FS#4464]: Crash when a multiplayer company goes bankrupt with 'you' in it
rubidium <rubidium@openttd.org>
parents:
17218
diff
changeset
|
572 * player we are sure (the above check) that we are not the local |
2933d0e4edcb
(svn r21970) -Fix [FS#4464]: Crash when a multiplayer company goes bankrupt with 'you' in it
rubidium <rubidium@openttd.org>
parents:
17218
diff
changeset
|
573 * company and thus we won't be moved. */ |
18202
f5b712935c89
(svn r23031) -Fix [FS#4804]: for the admin "bots" there was no distinction between bankruptcy and manual removal of companies even though the API suggested that
rubidium <rubidium@openttd.org>
parents:
18160
diff
changeset
|
574 if (!_networking || _network_server) DoCommandP(0, 2 | (c->index << 16), CRR_BANKRUPT, CMD_COMPANY_CTRL); |
17213
4111445c818e
(svn r21952) -Codechange: unify the company clearing code for bankruptcy with the command to remove companies
rubidium <rubidium@openttd.org>
parents:
17152
diff
changeset
|
575 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
|
576 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
577 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
578 |
15653
930fc2895ced
(svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents:
15652
diff
changeset
|
579 /** |
930fc2895ced
(svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents:
15652
diff
changeset
|
580 * Update the finances of all companies. |
930fc2895ced
(svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents:
15652
diff
changeset
|
581 * 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
|
582 */ |
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
|
583 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
|
584 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
585 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
|
586 |
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
|
587 Backup<CompanyByte> cur_company(_current_company, FILE_LINE); |
18570
bbdb2c13eb92
(svn r23415) -Feature: Infrastructure maintenance costs.
michi_cc <michi_cc@openttd.org>
parents:
18511
diff
changeset
|
588 Company *c; |
bbdb2c13eb92
(svn r23415) -Feature: Infrastructure maintenance costs.
michi_cc <michi_cc@openttd.org>
parents:
18511
diff
changeset
|
589 |
bbdb2c13eb92
(svn r23415) -Feature: Infrastructure maintenance costs.
michi_cc <michi_cc@openttd.org>
parents:
18511
diff
changeset
|
590 if (!_settings_game.economy.infrastructure_maintenance) { |
bbdb2c13eb92
(svn r23415) -Feature: Infrastructure maintenance costs.
michi_cc <michi_cc@openttd.org>
parents:
18511
diff
changeset
|
591 FOR_ALL_STATIONS(st) { |
bbdb2c13eb92
(svn r23415) -Feature: Infrastructure maintenance costs.
michi_cc <michi_cc@openttd.org>
parents:
18511
diff
changeset
|
592 cur_company.Change(st->owner); |
bbdb2c13eb92
(svn r23415) -Feature: Infrastructure maintenance costs.
michi_cc <michi_cc@openttd.org>
parents:
18511
diff
changeset
|
593 CommandCost cost(EXPENSES_PROPERTY, _price[PR_STATION_VALUE] >> 1); |
bbdb2c13eb92
(svn r23415) -Feature: Infrastructure maintenance costs.
michi_cc <michi_cc@openttd.org>
parents:
18511
diff
changeset
|
594 SubtractMoneyFromCompany(cost); |
bbdb2c13eb92
(svn r23415) -Feature: Infrastructure maintenance costs.
michi_cc <michi_cc@openttd.org>
parents:
18511
diff
changeset
|
595 } |
bbdb2c13eb92
(svn r23415) -Feature: Infrastructure maintenance costs.
michi_cc <michi_cc@openttd.org>
parents:
18511
diff
changeset
|
596 } else { |
bbdb2c13eb92
(svn r23415) -Feature: Infrastructure maintenance costs.
michi_cc <michi_cc@openttd.org>
parents:
18511
diff
changeset
|
597 /* Improved monthly infrastructure costs. */ |
bbdb2c13eb92
(svn r23415) -Feature: Infrastructure maintenance costs.
michi_cc <michi_cc@openttd.org>
parents:
18511
diff
changeset
|
598 FOR_ALL_COMPANIES(c) { |
bbdb2c13eb92
(svn r23415) -Feature: Infrastructure maintenance costs.
michi_cc <michi_cc@openttd.org>
parents:
18511
diff
changeset
|
599 cur_company.Change(c->index); |
bbdb2c13eb92
(svn r23415) -Feature: Infrastructure maintenance costs.
michi_cc <michi_cc@openttd.org>
parents:
18511
diff
changeset
|
600 |
bbdb2c13eb92
(svn r23415) -Feature: Infrastructure maintenance costs.
michi_cc <michi_cc@openttd.org>
parents:
18511
diff
changeset
|
601 CommandCost cost(EXPENSES_PROPERTY); |
bbdb2c13eb92
(svn r23415) -Feature: Infrastructure maintenance costs.
michi_cc <michi_cc@openttd.org>
parents:
18511
diff
changeset
|
602 for (RailType rt = RAILTYPE_BEGIN; rt < RAILTYPE_END; rt++) { |
bbdb2c13eb92
(svn r23415) -Feature: Infrastructure maintenance costs.
michi_cc <michi_cc@openttd.org>
parents:
18511
diff
changeset
|
603 if (c->infrastructure.rail[rt] != 0) cost.AddCost(RailMaintenanceCost(rt, c->infrastructure.rail[rt])); |
bbdb2c13eb92
(svn r23415) -Feature: Infrastructure maintenance costs.
michi_cc <michi_cc@openttd.org>
parents:
18511
diff
changeset
|
604 } |
bbdb2c13eb92
(svn r23415) -Feature: Infrastructure maintenance costs.
michi_cc <michi_cc@openttd.org>
parents:
18511
diff
changeset
|
605 cost.AddCost(SignalMaintenanceCost(c->infrastructure.signal)); |
bbdb2c13eb92
(svn r23415) -Feature: Infrastructure maintenance costs.
michi_cc <michi_cc@openttd.org>
parents:
18511
diff
changeset
|
606 for (RoadType rt = ROADTYPE_BEGIN; rt < ROADTYPE_END; rt++) { |
bbdb2c13eb92
(svn r23415) -Feature: Infrastructure maintenance costs.
michi_cc <michi_cc@openttd.org>
parents:
18511
diff
changeset
|
607 if (c->infrastructure.road[rt] != 0) cost.AddCost(RoadMaintenanceCost(rt, c->infrastructure.road[rt])); |
bbdb2c13eb92
(svn r23415) -Feature: Infrastructure maintenance costs.
michi_cc <michi_cc@openttd.org>
parents:
18511
diff
changeset
|
608 } |
bbdb2c13eb92
(svn r23415) -Feature: Infrastructure maintenance costs.
michi_cc <michi_cc@openttd.org>
parents:
18511
diff
changeset
|
609 cost.AddCost(CanalMaintenanceCost(c->infrastructure.water)); |
bbdb2c13eb92
(svn r23415) -Feature: Infrastructure maintenance costs.
michi_cc <michi_cc@openttd.org>
parents:
18511
diff
changeset
|
610 cost.AddCost(StationMaintenanceCost(c->infrastructure.station)); |
bbdb2c13eb92
(svn r23415) -Feature: Infrastructure maintenance costs.
michi_cc <michi_cc@openttd.org>
parents:
18511
diff
changeset
|
611 cost.AddCost(AirportMaintenanceCost(c->index)); |
bbdb2c13eb92
(svn r23415) -Feature: Infrastructure maintenance costs.
michi_cc <michi_cc@openttd.org>
parents:
18511
diff
changeset
|
612 |
bbdb2c13eb92
(svn r23415) -Feature: Infrastructure maintenance costs.
michi_cc <michi_cc@openttd.org>
parents:
18511
diff
changeset
|
613 SubtractMoneyFromCompany(cost); |
bbdb2c13eb92
(svn r23415) -Feature: Infrastructure maintenance costs.
michi_cc <michi_cc@openttd.org>
parents:
18511
diff
changeset
|
614 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
615 } |
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
|
616 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
|
617 |
17340
ed1445ee6e5f
(svn r22080) -Doc: Add doxygen comments to a few functions and improve a few existing comments
planetmaker <planetmaker@openttd.org>
parents:
17283
diff
changeset
|
618 /* Only run the economic statics and update company stats every 3rd month (1st of quarter). */ |
15552
683f2dbe75bb
(svn r20211) -Codechange: Indented code should have curly braces around it.
alberth <alberth@openttd.org>
parents:
15511
diff
changeset
|
619 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
|
620 |
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
|
621 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
|
622 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
|
623 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
|
624 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
|
625 |
17699
74a00ba15e7d
(svn r22479) -Codechange/Fix: Months != quarters. (xi)
frosch <frosch@openttd.org>
parents:
17642
diff
changeset
|
626 if (c->num_valid_stat_ent != MAX_HISTORY_QUARTERS) 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
|
627 |
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
|
628 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
|
629 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
|
630 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
|
631 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
632 |
13034
6eb3f749890a
(svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents:
12991
diff
changeset
|
633 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
|
634 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
|
635 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
|
636 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
|
637 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
|
638 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
|
639 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
640 |
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
|
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 * 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
|
643 * @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
|
644 */ |
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 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
|
646 { |
7244
00f3d8da22e4
(svn r10541) -Fix [FS#1028]: cargo payment rates overflow.
rubidium <rubidium@openttd.org>
parents:
7229
diff
changeset
|
647 /* 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
|
648 * 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
|
649 * 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
|
650 * 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
|
651 * the minimum running cost. |
00f3d8da22e4
(svn r10541) -Fix [FS#1028]: cargo payment rates overflow.
rubidium <rubidium@openttd.org>
parents:
7229
diff
changeset
|
652 * |
00f3d8da22e4
(svn r10541) -Fix [FS#1028]: cargo payment rates overflow.
rubidium <rubidium@openttd.org>
parents:
7229
diff
changeset
|
653 * 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
|
654 * 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
|
655 * 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
|
656 * 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
|
657 * 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
|
658 * 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
|
659 * 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
|
660 * 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
|
661 */ |
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
|
662 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
|
663 |
6119 | 664 /* Approximation for (100 + infl_amount)% ** (1 / 12) - 100% |
665 * scaled by 65536 | |
666 * 12 -> months per year | |
667 * This is only a good approxiamtion for small values | |
668 */ | |
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
|
669 _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
|
670 _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
|
671 } |
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
|
672 |
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
|
673 /** |
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
|
674 * 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
|
675 */ |
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
|
676 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
|
677 { |
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
|
678 /* 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
|
679 _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
|
680 |
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
|
681 /* 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
|
682 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
|
683 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
|
684 |
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
|
685 /* 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
|
686 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
|
687 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
|
688 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
|
689 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
|
690 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
|
691 |
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
|
692 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
|
693 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
|
694 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
|
695 |
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
|
696 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
|
697 } |
17903
62089c39f660
(svn r22707) -Codechange: Simplify applying the difficulty settings to prices, and reduce computational errors. (Eddi)
frosch <frosch@openttd.org>
parents:
17833
diff
changeset
|
698 switch (mod) { |
62089c39f660
(svn r22707) -Codechange: Simplify applying the difficulty settings to prices, and reduce computational errors. (Eddi)
frosch <frosch@openttd.org>
parents:
17833
diff
changeset
|
699 case 0: price *= 6; break; |
62089c39f660
(svn r22707) -Codechange: Simplify applying the difficulty settings to prices, and reduce computational errors. (Eddi)
frosch <frosch@openttd.org>
parents:
17833
diff
changeset
|
700 case 1: price *= 8; break; // normalised to 1 below |
62089c39f660
(svn r22707) -Codechange: Simplify applying the difficulty settings to prices, and reduce computational errors. (Eddi)
frosch <frosch@openttd.org>
parents:
17833
diff
changeset
|
701 case 2: price *= 9; break; |
62089c39f660
(svn r22707) -Codechange: Simplify applying the difficulty settings to prices, and reduce computational errors. (Eddi)
frosch <frosch@openttd.org>
parents:
17833
diff
changeset
|
702 default: NOT_REACHED(); |
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
|
703 } |
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
|
704 |
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
|
705 /* 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
|
706 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
|
707 |
17903
62089c39f660
(svn r22707) -Codechange: Simplify applying the difficulty settings to prices, and reduce computational errors. (Eddi)
frosch <frosch@openttd.org>
parents:
17833
diff
changeset
|
708 /* Apply newgrf modifiers, remove fractional part of inflation, and normalise on medium difficulty. */ |
62089c39f660
(svn r22707) -Codechange: Simplify applying the difficulty settings to prices, and reduce computational errors. (Eddi)
frosch <frosch@openttd.org>
parents:
17833
diff
changeset
|
709 int shift = _price_base_multiplier[i] - 16 - 3; |
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
|
710 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
|
711 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
|
712 } 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
|
713 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
|
714 } |
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
|
715 |
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
|
716 /* 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
|
717 * 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
|
718 * 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
|
719 * 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
|
720 * 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
|
721 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
|
722 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
|
723 /* 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
|
724 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
|
725 } |
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
|
726 /* 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
|
727 _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
|
728 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
729 |
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
|
730 /* Setup cargo payment */ |
12942
e762f0b0f0b1
(svn r17435) -Codechange: Move _cargo_payment_rates[] to CargoSpec::current_payment.
frosch <frosch@openttd.org>
parents:
12940
diff
changeset
|
731 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
|
732 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
|
733 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
|
734 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
735 |
13034
6eb3f749890a
(svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents:
12991
diff
changeset
|
736 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
|
737 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
|
738 SetWindowClassesDirty(WC_VEHICLE_DETAILS); |
18570
bbdb2c13eb92
(svn r23415) -Feature: Infrastructure maintenance costs.
michi_cc <michi_cc@openttd.org>
parents:
18511
diff
changeset
|
739 SetWindowClassesDirty(WC_COMPANY_INFRASTRUCTURE); |
16923
047786b50538
(svn r21658) -Fix [FS#4351]: cargo payment window wasn't properly invalidated when payment changed
rubidium <rubidium@openttd.org>
parents:
16871
diff
changeset
|
740 InvalidateWindowData(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
|
741 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
742 |
15655
0be6e9a4ca0b
(svn r20320) -Doc: Small Doxygen and normal comment fixes, and an missed addition.
alberth <alberth@openttd.org>
parents:
15654
diff
changeset
|
743 /** 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
|
744 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
|
745 { |
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
|
746 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
|
747 |
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
|
748 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
|
749 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
|
750 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
|
751 |
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
|
752 /* 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
|
753 * 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
|
754 * 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
|
755 * 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
|
756 * 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
|
757 * 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
|
758 * 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
|
759 * 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
|
760 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
|
761 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
|
762 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
|
763 |
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
|
764 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
|
765 |
13486
f2535c5098a0
(svn r18005) -Codechange: Convert the Prices struct into an array and an enum.
frosch <frosch@openttd.org>
parents:
13466
diff
changeset
|
766 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
|
767 } |
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
|
768 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
|
769 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
770 |
6247
57363e064324
(svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents:
6227
diff
changeset
|
771 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
|
772 { |
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
|
773 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
|
774 /* 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
|
775 _economy.fluct--; |
16440
c776a99ce938
(svn r21156) -Codechange: Introduce EconomyIsInRecession().
alberth <alberth@openttd.org>
parents:
16429
diff
changeset
|
776 } else if (EconomyIsInRecession()) { |
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
|
777 /* 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
|
778 _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
|
779 } 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
|
780 /* 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
|
781 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
|
782 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
783 |
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
|
784 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
|
785 _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
|
786 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
|
787 } 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
|
788 _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
|
789 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
|
790 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
791 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
792 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
793 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
794 /** |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
795 * 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
|
796 */ |
6247
57363e064324
(svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents:
6227
diff
changeset
|
797 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
|
798 { |
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
|
799 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
|
800 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
801 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
802 /** |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
803 * 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
|
804 * 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
|
805 * 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
|
806 * @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
|
807 * @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
|
808 */ |
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
|
809 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
|
810 { |
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
|
811 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
|
812 _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
|
813 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
814 |
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
|
815 /** |
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
|
816 * 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
|
817 * @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
|
818 */ |
10571
b6779abf2e96
(svn r14828) -Codechange: move most of save/load-specific code to separate files
smatz <smatz@openttd.org>
parents:
10568
diff
changeset
|
819 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
|
820 { |
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
|
821 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
|
822 /* 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
|
823 * 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
|
824 * 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
|
825 * 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
|
826 * 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
|
827 * 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
|
828 _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
|
829 |
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
|
830 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
|
831 /* 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
|
832 _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
|
833 } |
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
|
834 } |
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
|
835 |
6247
57363e064324
(svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents:
6227
diff
changeset
|
836 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
|
837 { |
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
|
838 _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
|
839 _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
|
840 _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
|
841 _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
|
842 |
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
|
843 /* 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
|
844 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
|
845 |
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
|
846 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
|
847 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
848 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
849 |
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
|
850 /** |
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
|
851 * 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
|
852 */ |
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
|
853 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
|
854 { |
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
|
855 _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
|
856 } |
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
|
857 |
13486
f2535c5098a0
(svn r18005) -Codechange: Convert the Prices struct into an array and an enum.
frosch <frosch@openttd.org>
parents:
13466
diff
changeset
|
858 /** |
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
|
859 * 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
|
860 * @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
|
861 * @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
|
862 * @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
|
863 * @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
|
864 * @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
|
865 */ |
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
|
866 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
|
867 { |
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
|
868 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
|
869 |
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
|
870 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
|
871 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
|
872 |
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
|
873 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
|
874 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
|
875 } 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
|
876 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
|
877 } |
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
|
878 |
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
|
879 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
|
880 } |
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
|
881 |
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
|
882 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
|
883 { |
12415
6a77d1df56e2
(svn r16849) -Codechange: replace GetCargo() by CargoSpec::Get()
smatz <smatz@openttd.org>
parents:
12384
diff
changeset
|
884 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
|
885 if (!cs->IsValid()) { |
e762f0b0f0b1
(svn r17435) -Codechange: Move _cargo_payment_rates[] to CargoSpec::current_payment.
frosch <frosch@openttd.org>
parents:
12940
diff
changeset
|
886 /* 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
|
887 return 0; |
e762f0b0f0b1
(svn r17435) -Codechange: Move _cargo_payment_rates[] to CargoSpec::current_payment.
frosch <frosch@openttd.org>
parents:
12940
diff
changeset
|
888 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
889 |
6458
57cfff4ac608
(svn r9617) -Codechange: Implement callback for cargo profit calculation
peter1138 <peter1138@openttd.org>
parents:
6453
diff
changeset
|
890 /* 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
|
891 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
|
892 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
|
893 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
|
894 if (callback != CALLBACK_FAILED) { |
57cfff4ac608
(svn r9617) -Codechange: Implement callback for cargo profit calculation
peter1138 <peter1138@openttd.org>
parents:
6453
diff
changeset
|
895 int result = GB(callback, 0, 14); |
57cfff4ac608
(svn r9617) -Codechange: Implement callback for cargo profit calculation
peter1138 <peter1138@openttd.org>
parents:
6453
diff
changeset
|
896 |
57cfff4ac608
(svn r9617) -Codechange: Implement callback for cargo profit calculation
peter1138 <peter1138@openttd.org>
parents:
6453
diff
changeset
|
897 /* 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
|
898 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
|
899 |
57cfff4ac608
(svn r9617) -Codechange: Implement callback for cargo profit calculation
peter1138 <peter1138@openttd.org>
parents:
6453
diff
changeset
|
900 /* "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
|
901 * 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
|
902 * divided by 8192." */ |
12942
e762f0b0f0b1
(svn r17435) -Codechange: Move _cargo_payment_rates[] to CargoSpec::current_payment.
frosch <frosch@openttd.org>
parents:
12940
diff
changeset
|
903 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
|
904 } |
57cfff4ac608
(svn r9617) -Codechange: Implement callback for cargo profit calculation
peter1138 <peter1138@openttd.org>
parents:
6453
diff
changeset
|
905 } |
57cfff4ac608
(svn r9617) -Codechange: Implement callback for cargo profit calculation
peter1138 <peter1138@openttd.org>
parents:
6453
diff
changeset
|
906 |
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
|
907 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
|
908 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
|
909 |
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
|
910 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
|
911 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
|
912 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
|
913 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
|
914 |
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
|
915 /* |
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
|
916 * 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
|
917 * (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
|
918 * 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
|
919 * |
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
|
920 * - 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
|
921 * - 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
|
922 * - 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
|
923 * |
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
|
924 */ |
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
|
925 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
|
926 |
12942
e762f0b0f0b1
(svn r17435) -Codechange: Move _cargo_payment_rates[] to CargoSpec::current_payment.
frosch <frosch@openttd.org>
parents:
12940
diff
changeset
|
927 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
|
928 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
929 |
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
|
930 /** 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
|
931 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
|
932 |
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
|
933 /** |
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
|
934 * 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
|
935 * 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
|
936 * @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
|
937 * @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
|
938 * @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
|
939 * @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
|
940 * @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
|
941 */ |
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
|
942 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
|
943 { |
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
|
944 /* 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
|
945 * 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
|
946 * 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
|
947 * 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
|
948 * 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
|
949 */ |
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
|
950 |
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
|
951 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
|
952 |
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
|
953 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
|
954 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
|
955 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
|
956 |
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
|
957 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
|
958 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
|
959 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
|
960 } |
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
|
961 /* 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
|
962 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
|
963 |
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
|
964 /* 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
|
965 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
|
966 |
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
|
967 /* 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
|
968 _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
|
969 |
12956
3a0bbffd1a58
(svn r17449) -Fix (r17436): MSVC compile warning about comparing signed and unsigned values
rubidium <rubidium@openttd.org>
parents:
12946
diff
changeset
|
970 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
|
971 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
|
972 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
|
973 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
|
974 } |
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
|
975 |
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
|
976 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
|
977 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
978 |
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
|
979 /** |
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
|
980 * 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
|
981 * @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
|
982 * @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
|
983 * @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
|
984 * @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
|
985 * @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
|
986 * @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
|
987 * @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
|
988 * @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
|
989 * @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
|
990 * @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
|
991 */ |
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
|
992 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
|
993 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
994 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
|
995 |
17758
0e811605b53c
(svn r22542) -Add: Store cargo acceptance stats for stations.
terkhen <terkhen@openttd.org>
parents:
17756
diff
changeset
|
996 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
|
997 |
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
|
998 /* 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
|
999 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
|
1000 |
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
|
1001 /* 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
|
1002 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
|
1003 |
17758
0e811605b53c
(svn r22542) -Add: Store cargo acceptance stats for stations.
terkhen <terkhen@openttd.org>
parents:
17756
diff
changeset
|
1004 /* Update station statistics */ |
0e811605b53c
(svn r22542) -Add: Store cargo acceptance stats for stations.
terkhen <terkhen@openttd.org>
parents:
17756
diff
changeset
|
1005 if (accepted > 0) { |
0e811605b53c
(svn r22542) -Add: Store cargo acceptance stats for stations.
terkhen <terkhen@openttd.org>
parents:
17756
diff
changeset
|
1006 SetBit(st->goods[cargo_type].acceptance_pickup, GoodsEntry::GES_EVER_ACCEPTED); |
0e811605b53c
(svn r22542) -Add: Store cargo acceptance stats for stations.
terkhen <terkhen@openttd.org>
parents:
17756
diff
changeset
|
1007 SetBit(st->goods[cargo_type].acceptance_pickup, GoodsEntry::GES_CURRENT_MONTH); |
0e811605b53c
(svn r22542) -Add: Store cargo acceptance stats for stations.
terkhen <terkhen@openttd.org>
parents:
17756
diff
changeset
|
1008 SetBit(st->goods[cargo_type].acceptance_pickup, GoodsEntry::GES_ACCEPTED_BIGTICK); |
0e811605b53c
(svn r22542) -Add: Store cargo acceptance stats for stations.
terkhen <terkhen@openttd.org>
parents:
17756
diff
changeset
|
1009 } |
0e811605b53c
(svn r22542) -Add: Store cargo acceptance stats for stations.
terkhen <terkhen@openttd.org>
parents:
17756
diff
changeset
|
1010 |
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
|
1011 /* 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
|
1012 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
|
1013 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
|
1014 |
18454
b9e554b1d8a1
(svn r23298) -Add: track statistics of all incoming and outgoing goods. Incoming based on TownEffect, outgoing based on CargoType (based on patch by Terkhen)
truebrain <truebrain@openttd.org>
parents:
18397
diff
changeset
|
1015 /* Increase town's counter for town effects */ |
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
|
1016 const CargoSpec *cs = CargoSpec::Get(cargo_type); |
18454
b9e554b1d8a1
(svn r23298) -Add: track statistics of all incoming and outgoing goods. Incoming based on TownEffect, outgoing based on CargoType (based on patch by Terkhen)
truebrain <truebrain@openttd.org>
parents:
18397
diff
changeset
|
1017 st->town->received[cs->town_effect].new_act += accepted; |
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
|
1018 |
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
|
1019 /* 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
|
1020 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
|
1021 |
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
|
1022 /* 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
|
1023 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
|
1024 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
|
1025 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
|
1026 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
|
1027 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
|
1028 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
|
1029 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1030 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1031 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1032 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
|
1033 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1034 |
6559
b680e3433ca2
(svn r9761) -Codechange: refactor cargo payment out of LoadUnloadVehicle.
rubidium <rubidium@openttd.org>
parents:
6500
diff
changeset
|
1035 /** |
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
|
1036 * 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
|
1037 * 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
|
1038 * @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
|
1039 */ |
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
|
1040 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
|
1041 { |
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
|
1042 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
|
1043 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
|
1044 |
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
|
1045 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
|
1046 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
|
1047 |
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
|
1048 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
|
1049 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
|
1050 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
|
1051 } 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
|
1052 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
|
1053 } |
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
|
1054 } 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
|
1055 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
|
1056 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
|
1057 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
|
1058 |
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
|
1059 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
|
1060 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
|
1061 |
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
|
1062 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
|
1063 } |
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
|
1064 } |
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
|
1065 |
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
|
1066 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
|
1067 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
|
1068 } |
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
|
1069 |
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
|
1070 /** |
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
|
1071 * 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
|
1072 * @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
|
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 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
|
1075 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
|
1076 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
|
1077 { |
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
|
1078 } |
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 |
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
|
1080 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
|
1081 { |
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
|
1082 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
|
1083 |
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
|
1084 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
|
1085 |
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
|
1086 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
|
1087 |
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
|
1088 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
|
1089 |
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
|
1090 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
|
1091 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
|
1092 |
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 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
|
1094 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
|
1095 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
|
1096 } |
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
|
1097 |
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
|
1098 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
|
1099 } 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
|
1100 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
|
1101 } |
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
|
1102 |
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
|
1103 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
|
1104 } |
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
|
1105 |
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
|
1106 /** |
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
|
1107 * 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
|
1108 * @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
|
1109 * @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
|
1110 */ |
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
|
1111 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
|
1112 { |
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
|
1113 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
|
1114 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
|
1115 } |
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
|
1116 |
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
|
1117 /* 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
|
1118 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
|
1119 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
|
1120 |
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
|
1121 /* 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
|
1122 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
|
1123 } |
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
|
1124 |
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
|
1125 /** |
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
|
1126 * 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
|
1127 * @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
|
1128 * @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
|
1129 * @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
|
1130 */ |
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
|
1131 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
|
1132 { |
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
|
1133 Money profit = GetTransportedGoodsIncome( |
15654
22d1a4dbf678
(svn r20319) -Codechange: Align comments, add indent to a function call.
alberth <alberth@openttd.org>
parents:
15653
diff
changeset
|
1134 count, |
22d1a4dbf678
(svn r20319) -Codechange: Align comments, add indent to a function call.
alberth <alberth@openttd.org>
parents:
15653
diff
changeset
|
1135 /* 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
|
1136 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
|
1137 cp->DaysInTransit(), |
22d1a4dbf678
(svn r20319) -Codechange: Align comments, add indent to a function call.
alberth <alberth@openttd.org>
parents:
15653
diff
changeset
|
1138 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
|
1139 |
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
|
1140 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
|
1141 |
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
|
1142 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
|
1143 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
|
1144 } |
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
|
1145 |
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
|
1146 /** |
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
|
1147 * 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
|
1148 * @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
|
1149 */ |
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
|
1150 void PrepareUnload(Vehicle *front_v) |
6559
b680e3433ca2
(svn r9761) -Codechange: refactor cargo payment out of LoadUnloadVehicle.
rubidium <rubidium@openttd.org>
parents:
6500
diff
changeset
|
1151 { |
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
|
1152 /* 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
|
1153 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
|
1154 |
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
|
1155 /* 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
|
1156 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
|
1157 |
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
|
1158 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
|
1159 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
|
1160 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
|
1161 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
|
1162 } |
b680e3433ca2
(svn r9761) -Codechange: refactor cargo payment out of LoadUnloadVehicle.
rubidium <rubidium@openttd.org>
parents:
6500
diff
changeset
|
1163 } |
b680e3433ca2
(svn r9761) -Codechange: refactor cargo payment out of LoadUnloadVehicle.
rubidium <rubidium@openttd.org>
parents:
6500
diff
changeset
|
1164 } |
b680e3433ca2
(svn r9761) -Codechange: refactor cargo payment out of LoadUnloadVehicle.
rubidium <rubidium@openttd.org>
parents:
6500
diff
changeset
|
1165 |
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
|
1166 assert(front_v->cargo_payment == NULL); |
17283
daad5df59d38
(svn r22023) -Fix: verify we can allocate a CargoPacket and CargoPayment before we actually try to do so
smatz <smatz@openttd.org>
parents:
17275
diff
changeset
|
1167 /* One CargoPayment per vehicle and the vehicle limit equals the |
daad5df59d38
(svn r22023) -Fix: verify we can allocate a CargoPacket and CargoPayment before we actually try to do so
smatz <smatz@openttd.org>
parents:
17275
diff
changeset
|
1168 * limit in number of CargoPayments. Can't go wrong. */ |
daad5df59d38
(svn r22023) -Fix: verify we can allocate a CargoPacket and CargoPayment before we actually try to do so
smatz <smatz@openttd.org>
parents:
17275
diff
changeset
|
1169 assert_compile(CargoPaymentPool::MAX_SIZE == VehiclePool::MAX_SIZE); |
daad5df59d38
(svn r22023) -Fix: verify we can allocate a CargoPacket and CargoPayment before we actually try to do so
smatz <smatz@openttd.org>
parents:
17275
diff
changeset
|
1170 assert(CargoPayment::CanAllocateItem()); |
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
|
1171 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
|
1172 } |
b680e3433ca2
(svn r9761) -Codechange: refactor cargo payment out of LoadUnloadVehicle.
rubidium <rubidium@openttd.org>
parents:
6500
diff
changeset
|
1173 |
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
|
1174 /** |
18638
ac23ced64c4b
(svn r23485) -Fix: Autorefit failed if the first part of an articulated vehicle did not carry any cargo.
frosch <frosch@openttd.org>
parents:
18570
diff
changeset
|
1175 * Checks whether an articulated vehicle is empty. |
ac23ced64c4b
(svn r23485) -Fix: Autorefit failed if the first part of an articulated vehicle did not carry any cargo.
frosch <frosch@openttd.org>
parents:
18570
diff
changeset
|
1176 * @param v Vehicle |
ac23ced64c4b
(svn r23485) -Fix: Autorefit failed if the first part of an articulated vehicle did not carry any cargo.
frosch <frosch@openttd.org>
parents:
18570
diff
changeset
|
1177 * @return true if all parts are empty. |
ac23ced64c4b
(svn r23485) -Fix: Autorefit failed if the first part of an articulated vehicle did not carry any cargo.
frosch <frosch@openttd.org>
parents:
18570
diff
changeset
|
1178 */ |
ac23ced64c4b
(svn r23485) -Fix: Autorefit failed if the first part of an articulated vehicle did not carry any cargo.
frosch <frosch@openttd.org>
parents:
18570
diff
changeset
|
1179 static bool IsArticulatedVehicleEmpty(Vehicle *v) |
ac23ced64c4b
(svn r23485) -Fix: Autorefit failed if the first part of an articulated vehicle did not carry any cargo.
frosch <frosch@openttd.org>
parents:
18570
diff
changeset
|
1180 { |
ac23ced64c4b
(svn r23485) -Fix: Autorefit failed if the first part of an articulated vehicle did not carry any cargo.
frosch <frosch@openttd.org>
parents:
18570
diff
changeset
|
1181 v = v->GetFirstEnginePart(); |
ac23ced64c4b
(svn r23485) -Fix: Autorefit failed if the first part of an articulated vehicle did not carry any cargo.
frosch <frosch@openttd.org>
parents:
18570
diff
changeset
|
1182 |
ac23ced64c4b
(svn r23485) -Fix: Autorefit failed if the first part of an articulated vehicle did not carry any cargo.
frosch <frosch@openttd.org>
parents:
18570
diff
changeset
|
1183 for (; v != NULL; v = v->HasArticulatedPart() ? v->GetNextArticulatedPart() : NULL) { |
ac23ced64c4b
(svn r23485) -Fix: Autorefit failed if the first part of an articulated vehicle did not carry any cargo.
frosch <frosch@openttd.org>
parents:
18570
diff
changeset
|
1184 if (v->cargo.Count() != 0) return false; |
ac23ced64c4b
(svn r23485) -Fix: Autorefit failed if the first part of an articulated vehicle did not carry any cargo.
frosch <frosch@openttd.org>
parents:
18570
diff
changeset
|
1185 } |
ac23ced64c4b
(svn r23485) -Fix: Autorefit failed if the first part of an articulated vehicle did not carry any cargo.
frosch <frosch@openttd.org>
parents:
18570
diff
changeset
|
1186 |
ac23ced64c4b
(svn r23485) -Fix: Autorefit failed if the first part of an articulated vehicle did not carry any cargo.
frosch <frosch@openttd.org>
parents:
18570
diff
changeset
|
1187 return true; |
ac23ced64c4b
(svn r23485) -Fix: Autorefit failed if the first part of an articulated vehicle did not carry any cargo.
frosch <frosch@openttd.org>
parents:
18570
diff
changeset
|
1188 } |
ac23ced64c4b
(svn r23485) -Fix: Autorefit failed if the first part of an articulated vehicle did not carry any cargo.
frosch <frosch@openttd.org>
parents:
18570
diff
changeset
|
1189 |
ac23ced64c4b
(svn r23485) -Fix: Autorefit failed if the first part of an articulated vehicle did not carry any cargo.
frosch <frosch@openttd.org>
parents:
18570
diff
changeset
|
1190 /** |
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
|
1191 * Loads/unload the vehicle if possible. |
17939
5da57f628072
(svn r22744) -Codechange: Clarify the scope of variables in LoadUnloadVehicle().
frosch <frosch@openttd.org>
parents:
17903
diff
changeset
|
1192 * @param front 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
|
1193 * @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
|
1194 * 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
|
1195 * 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
|
1196 * 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
|
1197 */ |
17939
5da57f628072
(svn r22744) -Codechange: Clarify the scope of variables in LoadUnloadVehicle().
frosch <frosch@openttd.org>
parents:
17903
diff
changeset
|
1198 static void LoadUnloadVehicle(Vehicle *front, 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
|
1199 { |
17939
5da57f628072
(svn r22744) -Codechange: Clarify the scope of variables in LoadUnloadVehicle().
frosch <frosch@openttd.org>
parents:
17903
diff
changeset
|
1200 assert(front->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
|
1201 |
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
|
1202 /* We have not waited enough time till the next round of loading/unloading */ |
17939
5da57f628072
(svn r22744) -Codechange: Clarify the scope of variables in LoadUnloadVehicle().
frosch <frosch@openttd.org>
parents:
17903
diff
changeset
|
1203 if (front->load_unload_ticks != 0) { |
5da57f628072
(svn r22744) -Codechange: Clarify the scope of variables in LoadUnloadVehicle().
frosch <frosch@openttd.org>
parents:
17903
diff
changeset
|
1204 if (_settings_game.order.improved_load && (front->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
|
1205 /* 'Reserve' this cargo for this vehicle, because we were first. */ |
17939
5da57f628072
(svn r22744) -Codechange: Clarify the scope of variables in LoadUnloadVehicle().
frosch <frosch@openttd.org>
parents:
17903
diff
changeset
|
1206 for (Vehicle *v = front; 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
|
1207 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
|
1208 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
|
1209 } |
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
|
1210 } |
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
|
1211 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
|
1212 } |
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
|
1213 |
17939
5da57f628072
(svn r22744) -Codechange: Clarify the scope of variables in LoadUnloadVehicle().
frosch <frosch@openttd.org>
parents:
17903
diff
changeset
|
1214 StationID last_visited = front->last_station_visited; |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11730
diff
changeset
|
1215 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
|
1216 |
17939
5da57f628072
(svn r22744) -Codechange: Clarify the scope of variables in LoadUnloadVehicle().
frosch <frosch@openttd.org>
parents:
17903
diff
changeset
|
1217 if (front->type == VEH_TRAIN && (!IsTileType(front->tile, MP_STATION) || GetStationIndex(front->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
|
1218 /* 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
|
1219 * out and let the train just leave as it always did. */ |
17939
5da57f628072
(svn r22744) -Codechange: Clarify the scope of variables in LoadUnloadVehicle().
frosch <frosch@openttd.org>
parents:
17903
diff
changeset
|
1220 SetBit(front->vehicle_flags, VF_LOADING_FINISHED); |
5da57f628072
(svn r22744) -Codechange: Clarify the scope of variables in LoadUnloadVehicle().
frosch <frosch@openttd.org>
parents:
17903
diff
changeset
|
1221 front->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
|
1222 return; |
70d60b0104c1
(svn r10084) -Fix [FS#855]: reversing a train when loading at a station crashed.
rubidium <rubidium@openttd.org>
parents:
6823
diff
changeset
|
1223 } |
70d60b0104c1
(svn r10084) -Fix [FS#855]: reversing a train when loading at a station crashed.
rubidium <rubidium@openttd.org>
parents:
6823
diff
changeset
|
1224 |
6611
461107df1c8f
(svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents:
6609
diff
changeset
|
1225 int unloading_time = 0; |
13998
3d6fd0265851
(svn r18540) -Codechange: resulting in better name for 'result'.
frosch <frosch@openttd.org>
parents:
13995
diff
changeset
|
1226 bool dirty_vehicle = false; |
3d6fd0265851
(svn r18540) -Codechange: resulting in better name for 'result'.
frosch <frosch@openttd.org>
parents:
13995
diff
changeset
|
1227 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
|
1228 |
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
|
1229 bool completely_emptied = true; |
6611
461107df1c8f
(svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents:
6609
diff
changeset
|
1230 bool anything_unloaded = false; |
461107df1c8f
(svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents:
6609
diff
changeset
|
1231 bool anything_loaded = false; |
16147
2c2d2a90fd54
(svn r20843) -Fix [FS#2534] (r20506): Make sure (gradual) loading is properly terminated for consists with multiple cargo types. Don't stop loading if the timetabled wait is not over yet. (Steve-N)
michi_cc <michi_cc@openttd.org>
parents:
15944
diff
changeset
|
1232 uint32 full_load_amount = 0; |
6611
461107df1c8f
(svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents:
6609
diff
changeset
|
1233 uint32 cargo_not_full = 0; |
461107df1c8f
(svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents:
6609
diff
changeset
|
1234 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
|
1235 |
17939
5da57f628072
(svn r22744) -Codechange: Clarify the scope of variables in LoadUnloadVehicle().
frosch <frosch@openttd.org>
parents:
17903
diff
changeset
|
1236 front->cur_speed = 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
|
1237 |
17939
5da57f628072
(svn r22744) -Codechange: Clarify the scope of variables in LoadUnloadVehicle().
frosch <frosch@openttd.org>
parents:
17903
diff
changeset
|
1238 CargoPayment *payment = front->cargo_payment; |
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
|
1239 |
18638
ac23ced64c4b
(svn r23485) -Fix: Autorefit failed if the first part of an articulated vehicle did not carry any cargo.
frosch <frosch@openttd.org>
parents:
18570
diff
changeset
|
1240 uint artic_part = 0; // Articulated part we are currently trying to load. (not counting parts without capacity) |
17939
5da57f628072
(svn r22744) -Codechange: Clarify the scope of variables in LoadUnloadVehicle().
frosch <frosch@openttd.org>
parents:
17903
diff
changeset
|
1241 for (Vehicle *v = front; v != NULL; v = v->Next()) { |
18638
ac23ced64c4b
(svn r23485) -Fix: Autorefit failed if the first part of an articulated vehicle did not carry any cargo.
frosch <frosch@openttd.org>
parents:
18570
diff
changeset
|
1242 if (v == front || !v->Previous()->HasArticulatedPart()) artic_part = 0; |
6609
e78f5516e040
(svn r9829) -Codechange: more refactoring of the unloading algorithm.
rubidium <rubidium@openttd.org>
parents:
6601
diff
changeset
|
1243 if (v->cargo_cap == 0) continue; |
18638
ac23ced64c4b
(svn r23485) -Fix: Autorefit failed if the first part of an articulated vehicle did not carry any cargo.
frosch <frosch@openttd.org>
parents:
18570
diff
changeset
|
1244 artic_part++; |
6609
e78f5516e040
(svn r9829) -Codechange: more refactoring of the unloading algorithm.
rubidium <rubidium@openttd.org>
parents:
6601
diff
changeset
|
1245 |
18238
3141f1ed78eb
(svn r23074) -Codechange: Add Vehicle::GetEngine() to simplify code.
frosch <frosch@openttd.org>
parents:
18231
diff
changeset
|
1246 const Engine *e = v->GetEngine(); |
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
|
1247 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
|
1248 |
e723ec01b3a6
(svn r14672) -Fix [FS#2444]: Property 7 and callback 12 were broken for aircraft.
frosch <frosch@openttd.org>
parents:
10417
diff
changeset
|
1249 /* 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
|
1250 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
|
1251 |
18315
f8f4556edf99
(svn r23151) -Change: [NewGRF v8] Deprecate callback 12, and use callback 36 instead.
frosch <frosch@openttd.org>
parents:
18312
diff
changeset
|
1252 if (_settings_game.order.gradual_loading) { |
f8f4556edf99
(svn r23151) -Change: [NewGRF v8] Deprecate callback 12, and use callback 36 instead.
frosch <frosch@openttd.org>
parents:
18312
diff
changeset
|
1253 uint16 cb_load_amount = CALLBACK_FAILED; |
f8f4556edf99
(svn r23151) -Change: [NewGRF v8] Deprecate callback 12, and use callback 36 instead.
frosch <frosch@openttd.org>
parents:
18312
diff
changeset
|
1254 if (e->GetGRF() != NULL && e->GetGRF()->grf_version >= 8) { |
f8f4556edf99
(svn r23151) -Change: [NewGRF v8] Deprecate callback 12, and use callback 36 instead.
frosch <frosch@openttd.org>
parents:
18312
diff
changeset
|
1255 /* Use callback 36 */ |
f8f4556edf99
(svn r23151) -Change: [NewGRF v8] Deprecate callback 12, and use callback 36 instead.
frosch <frosch@openttd.org>
parents:
18312
diff
changeset
|
1256 cb_load_amount = GetVehicleProperty(v, PROP_VEHICLE_LOAD_AMOUNT, CALLBACK_FAILED); |
f8f4556edf99
(svn r23151) -Change: [NewGRF v8] Deprecate callback 12, and use callback 36 instead.
frosch <frosch@openttd.org>
parents:
18312
diff
changeset
|
1257 } else if (HasBit(e->info.callback_mask, CBM_VEHICLE_LOAD_AMOUNT)) { |
f8f4556edf99
(svn r23151) -Change: [NewGRF v8] Deprecate callback 12, and use callback 36 instead.
frosch <frosch@openttd.org>
parents:
18312
diff
changeset
|
1258 /* Use callback 12 */ |
f8f4556edf99
(svn r23151) -Change: [NewGRF v8] Deprecate callback 12, and use callback 36 instead.
frosch <frosch@openttd.org>
parents:
18312
diff
changeset
|
1259 cb_load_amount = GetVehicleCallback(CBID_VEHICLE_LOAD_AMOUNT, 0, 0, v->engine_type, v); |
f8f4556edf99
(svn r23151) -Change: [NewGRF v8] Deprecate callback 12, and use callback 36 instead.
frosch <frosch@openttd.org>
parents:
18312
diff
changeset
|
1260 } |
18312
1945b084b0dc
(svn r23148) -Change: [NewGRF] Check the results of various callbacks for validness.
frosch <frosch@openttd.org>
parents:
18275
diff
changeset
|
1261 if (cb_load_amount != CALLBACK_FAILED) { |
1945b084b0dc
(svn r23148) -Change: [NewGRF] Check the results of various callbacks for validness.
frosch <frosch@openttd.org>
parents:
18275
diff
changeset
|
1262 if (e->GetGRF()->grf_version < 8) cb_load_amount = GB(cb_load_amount, 0, 8); |
1945b084b0dc
(svn r23148) -Change: [NewGRF] Check the results of various callbacks for validness.
frosch <frosch@openttd.org>
parents:
18275
diff
changeset
|
1263 if (cb_load_amount >= 0x100) { |
1945b084b0dc
(svn r23148) -Change: [NewGRF] Check the results of various callbacks for validness.
frosch <frosch@openttd.org>
parents:
18275
diff
changeset
|
1264 ErrorUnknownCallbackResult(e->GetGRFID(), CBID_VEHICLE_LOAD_AMOUNT, cb_load_amount); |
1945b084b0dc
(svn r23148) -Change: [NewGRF] Check the results of various callbacks for validness.
frosch <frosch@openttd.org>
parents:
18275
diff
changeset
|
1265 } else if (cb_load_amount != 0) { |
1945b084b0dc
(svn r23148) -Change: [NewGRF] Check the results of various callbacks for validness.
frosch <frosch@openttd.org>
parents:
18275
diff
changeset
|
1266 load_amount = cb_load_amount; |
1945b084b0dc
(svn r23148) -Change: [NewGRF] Check the results of various callbacks for validness.
frosch <frosch@openttd.org>
parents:
18275
diff
changeset
|
1267 } |
1945b084b0dc
(svn r23148) -Change: [NewGRF] Check the results of various callbacks for validness.
frosch <frosch@openttd.org>
parents:
18275
diff
changeset
|
1268 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1269 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1270 |
6609
e78f5516e040
(svn r9829) -Codechange: more refactoring of the unloading algorithm.
rubidium <rubidium@openttd.org>
parents:
6601
diff
changeset
|
1271 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
|
1272 |
17939
5da57f628072
(svn r22744) -Codechange: Clarify the scope of variables in LoadUnloadVehicle().
frosch <frosch@openttd.org>
parents:
17903
diff
changeset
|
1273 if (HasBit(v->vehicle_flags, VF_CARGO_UNLOADING) && (front->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
|
1274 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
|
1275 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
|
1276 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
|
1277 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
|
1278 |
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
|
1279 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
|
1280 |
17939
5da57f628072
(svn r22744) -Codechange: Clarify the scope of variables in LoadUnloadVehicle().
frosch <frosch@openttd.org>
parents:
17903
diff
changeset
|
1281 if (HasBit(ge->acceptance_pickup, GoodsEntry::GES_ACCEPTANCE) && !(front->current_order.GetUnloadType() & OUFB_TRANSFER)) { |
15002
baf0e12ad2b4
(svn r19614) -Codechange: "it's" => "its" where appropriate
smatz <smatz@openttd.org>
parents:
14695
diff
changeset
|
1282 /* 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
|
1283 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
|
1284 |
13998
3d6fd0265851
(svn r18540) -Codechange: resulting in better name for 'result'.
frosch <frosch@openttd.org>
parents:
13995
diff
changeset
|
1285 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
|
1286 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
|
1287 } |
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
|
1288 |
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
|
1289 /* 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
|
1290 * 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
|
1291 * 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
|
1292 * 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
|
1293 * accept cargo that was loaded at the same station. */ |
17939
5da57f628072
(svn r22744) -Codechange: Clarify the scope of variables in LoadUnloadVehicle().
frosch <frosch@openttd.org>
parents:
17903
diff
changeset
|
1294 if ((front->current_order.GetUnloadType() & (OUFB_UNLOAD | OUFB_TRANSFER)) && (!accepted || v->cargo.Count() == cargo_count)) { |
5da57f628072
(svn r22744) -Codechange: Clarify the scope of variables in LoadUnloadVehicle().
frosch <frosch@openttd.org>
parents:
17903
diff
changeset
|
1295 remaining = v->cargo.MoveTo(&ge->cargo, amount_unloaded, front->current_order.GetUnloadType() & OUFB_TRANSFER ? VehicleCargoList::MTA_TRANSFER : VehicleCargoList::MTA_UNLOAD, payment); |
17756
6e539d6e9fe0
(svn r22540) -Codechange: Rename AcceptancePickup to GoodsEntryStatus.
terkhen <terkhen@openttd.org>
parents:
17699
diff
changeset
|
1296 if (!HasBit(ge->acceptance_pickup, GoodsEntry::GES_PICKUP)) { |
16429
7d45364dd30d
(svn r21145) -Fix: station list wasn't updated when a new cargo got a rating
rubidium <rubidium@openttd.org>
parents:
16383
diff
changeset
|
1297 InvalidateWindowData(WC_STATION_LIST, last_visited); |
17756
6e539d6e9fe0
(svn r22540) -Codechange: Rename AcceptancePickup to GoodsEntryStatus.
terkhen <terkhen@openttd.org>
parents:
17699
diff
changeset
|
1298 SetBit(ge->acceptance_pickup, GoodsEntry::GES_PICKUP); |
16429
7d45364dd30d
(svn r21145) -Fix: station list wasn't updated when a new cargo got a rating
rubidium <rubidium@openttd.org>
parents:
16383
diff
changeset
|
1299 } |
6198
a2cdd211d091
(svn r8978) -Feature: Rewrite of transfer system.
richk <richk@openttd.org>
parents:
6190
diff
changeset
|
1300 |
13998
3d6fd0265851
(svn r18540) -Codechange: resulting in better name for 'result'.
frosch <frosch@openttd.org>
parents:
13995
diff
changeset
|
1301 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
|
1302 } else if (!accepted) { |
6609
e78f5516e040
(svn r9829) -Codechange: more refactoring of the unloading algorithm.
rubidium <rubidium@openttd.org>
parents:
6601
diff
changeset
|
1303 /* 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
|
1304 * 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
|
1305 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
|
1306 |
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
|
1307 /* 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
|
1308 * 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
|
1309 * 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
|
1310 * 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
|
1311 anything_unloaded = true; |
6609
e78f5516e040
(svn r9829) -Codechange: more refactoring of the unloading algorithm.
rubidium <rubidium@openttd.org>
parents:
6601
diff
changeset
|
1312 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
|
1313 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1314 |
6609
e78f5516e040
(svn r9829) -Codechange: more refactoring of the unloading algorithm.
rubidium <rubidium@openttd.org>
parents:
6601
diff
changeset
|
1315 /* Deliver goods to the station */ |
e78f5516e040
(svn r9829) -Codechange: more refactoring of the unloading algorithm.
rubidium <rubidium@openttd.org>
parents:
6601
diff
changeset
|
1316 st->time_since_unload = 0; |
e78f5516e040
(svn r9829) -Codechange: more refactoring of the unloading algorithm.
rubidium <rubidium@openttd.org>
parents:
6601
diff
changeset
|
1317 |
e78f5516e040
(svn r9829) -Codechange: more refactoring of the unloading algorithm.
rubidium <rubidium@openttd.org>
parents:
6601
diff
changeset
|
1318 unloading_time += amount_unloaded; |
e78f5516e040
(svn r9829) -Codechange: more refactoring of the unloading algorithm.
rubidium <rubidium@openttd.org>
parents:
6601
diff
changeset
|
1319 |
6611
461107df1c8f
(svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents:
6609
diff
changeset
|
1320 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
|
1321 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
|
1322 completely_emptied = false; |
6609
e78f5516e040
(svn r9829) -Codechange: more refactoring of the unloading algorithm.
rubidium <rubidium@openttd.org>
parents:
6601
diff
changeset
|
1323 } else { |
e78f5516e040
(svn r9829) -Codechange: more refactoring of the unloading algorithm.
rubidium <rubidium@openttd.org>
parents:
6601
diff
changeset
|
1324 /* 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
|
1325 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
|
1326 } |
e78f5516e040
(svn r9829) -Codechange: more refactoring of the unloading algorithm.
rubidium <rubidium@openttd.org>
parents:
6601
diff
changeset
|
1327 |
e78f5516e040
(svn r9829) -Codechange: more refactoring of the unloading algorithm.
rubidium <rubidium@openttd.org>
parents:
6601
diff
changeset
|
1328 continue; |
e78f5516e040
(svn r9829) -Codechange: more refactoring of the unloading algorithm.
rubidium <rubidium@openttd.org>
parents:
6601
diff
changeset
|
1329 } |
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
|
1330 |
15827
56dcb448bdfb
(svn r20506) -Change: Vehicles will now stop loading after a load cycle that loaded less than possible, unless it's a full load order. This should improve behaviour with gradual loading and cargo continuously trickling in.
michi_cc <michi_cc@openttd.org>
parents:
15744
diff
changeset
|
1331 /* Do not pick up goods when we have no-load set or loading is stopped. */ |
17939
5da57f628072
(svn r22744) -Codechange: Clarify the scope of variables in LoadUnloadVehicle().
frosch <frosch@openttd.org>
parents:
17903
diff
changeset
|
1332 if (front->current_order.GetLoadType() & OLFB_NO_LOAD || HasBit(front->vehicle_flags, VF_STOP_LOADING)) 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
|
1333 |
18638
ac23ced64c4b
(svn r23485) -Fix: Autorefit failed if the first part of an articulated vehicle did not carry any cargo.
frosch <frosch@openttd.org>
parents:
18570
diff
changeset
|
1334 /* This order has a refit, if this is the first vehicle part carrying cargo and the whole vehicle is empty, try refitting. */ |
ac23ced64c4b
(svn r23485) -Fix: Autorefit failed if the first part of an articulated vehicle did not carry any cargo.
frosch <frosch@openttd.org>
parents:
18570
diff
changeset
|
1335 if (front->current_order.IsRefit() && artic_part == 1 && IsArticulatedVehicleEmpty(v) && |
18251
137b272acca5
(svn r23087) -Feature: Auto-refitting of vehicles during loading at a station when the vehicle allows it.
michi_cc <michi_cc@openttd.org>
parents:
18238
diff
changeset
|
1336 (v->type != VEH_AIRCRAFT || (Aircraft::From(v)->IsNormalAircraft() && v->Next()->cargo.Count() == 0))) { |
18638
ac23ced64c4b
(svn r23485) -Fix: Autorefit failed if the first part of an articulated vehicle did not carry any cargo.
frosch <frosch@openttd.org>
parents:
18570
diff
changeset
|
1337 Vehicle *v_start = v->GetFirstEnginePart(); |
18251
137b272acca5
(svn r23087) -Feature: Auto-refitting of vehicles during loading at a station when the vehicle allows it.
michi_cc <michi_cc@openttd.org>
parents:
18238
diff
changeset
|
1338 CargoID new_cid = front->current_order.GetRefitCargo(); |
137b272acca5
(svn r23087) -Feature: Auto-refitting of vehicles during loading at a station when the vehicle allows it.
michi_cc <michi_cc@openttd.org>
parents:
18238
diff
changeset
|
1339 byte new_subtype = front->current_order.GetRefitSubtype(); |
137b272acca5
(svn r23087) -Feature: Auto-refitting of vehicles during loading at a station when the vehicle allows it.
michi_cc <michi_cc@openttd.org>
parents:
18238
diff
changeset
|
1340 |
137b272acca5
(svn r23087) -Feature: Auto-refitting of vehicles during loading at a station when the vehicle allows it.
michi_cc <michi_cc@openttd.org>
parents:
18238
diff
changeset
|
1341 Backup<CompanyByte> cur_company(_current_company, front->owner, FILE_LINE); |
137b272acca5
(svn r23087) -Feature: Auto-refitting of vehicles during loading at a station when the vehicle allows it.
michi_cc <michi_cc@openttd.org>
parents:
18238
diff
changeset
|
1342 |
137b272acca5
(svn r23087) -Feature: Auto-refitting of vehicles during loading at a station when the vehicle allows it.
michi_cc <michi_cc@openttd.org>
parents:
18238
diff
changeset
|
1343 /* Check if all articulated parts are empty and collect refit mask. */ |
137b272acca5
(svn r23087) -Feature: Auto-refitting of vehicles during loading at a station when the vehicle allows it.
michi_cc <michi_cc@openttd.org>
parents:
18238
diff
changeset
|
1344 uint32 refit_mask = e->info.refit_mask; |
18638
ac23ced64c4b
(svn r23485) -Fix: Autorefit failed if the first part of an articulated vehicle did not carry any cargo.
frosch <frosch@openttd.org>
parents:
18570
diff
changeset
|
1345 Vehicle *w = v_start; |
18251
137b272acca5
(svn r23087) -Feature: Auto-refitting of vehicles during loading at a station when the vehicle allows it.
michi_cc <michi_cc@openttd.org>
parents:
18238
diff
changeset
|
1346 while (w->HasArticulatedPart()) { |
137b272acca5
(svn r23087) -Feature: Auto-refitting of vehicles during loading at a station when the vehicle allows it.
michi_cc <michi_cc@openttd.org>
parents:
18238
diff
changeset
|
1347 w = w->GetNextArticulatedPart(); |
137b272acca5
(svn r23087) -Feature: Auto-refitting of vehicles during loading at a station when the vehicle allows it.
michi_cc <michi_cc@openttd.org>
parents:
18238
diff
changeset
|
1348 if (w->cargo.Count() > 0) new_cid = CT_NO_REFIT; |
137b272acca5
(svn r23087) -Feature: Auto-refitting of vehicles during loading at a station when the vehicle allows it.
michi_cc <michi_cc@openttd.org>
parents:
18238
diff
changeset
|
1349 refit_mask |= EngInfo(w->engine_type)->refit_mask; |
137b272acca5
(svn r23087) -Feature: Auto-refitting of vehicles during loading at a station when the vehicle allows it.
michi_cc <michi_cc@openttd.org>
parents:
18238
diff
changeset
|
1350 } |
137b272acca5
(svn r23087) -Feature: Auto-refitting of vehicles during loading at a station when the vehicle allows it.
michi_cc <michi_cc@openttd.org>
parents:
18238
diff
changeset
|
1351 |
137b272acca5
(svn r23087) -Feature: Auto-refitting of vehicles during loading at a station when the vehicle allows it.
michi_cc <michi_cc@openttd.org>
parents:
18238
diff
changeset
|
1352 if (new_cid == CT_AUTO_REFIT) { |
137b272acca5
(svn r23087) -Feature: Auto-refitting of vehicles during loading at a station when the vehicle allows it.
michi_cc <michi_cc@openttd.org>
parents:
18238
diff
changeset
|
1353 /* Get refittable cargo type with the most waiting cargo. */ |
137b272acca5
(svn r23087) -Feature: Auto-refitting of vehicles during loading at a station when the vehicle allows it.
michi_cc <michi_cc@openttd.org>
parents:
18238
diff
changeset
|
1354 int amount = 0; |
137b272acca5
(svn r23087) -Feature: Auto-refitting of vehicles during loading at a station when the vehicle allows it.
michi_cc <michi_cc@openttd.org>
parents:
18238
diff
changeset
|
1355 CargoID cid; |
137b272acca5
(svn r23087) -Feature: Auto-refitting of vehicles during loading at a station when the vehicle allows it.
michi_cc <michi_cc@openttd.org>
parents:
18238
diff
changeset
|
1356 FOR_EACH_SET_CARGO_ID(cid, refit_mask) { |
137b272acca5
(svn r23087) -Feature: Auto-refitting of vehicles during loading at a station when the vehicle allows it.
michi_cc <michi_cc@openttd.org>
parents:
18238
diff
changeset
|
1357 if (cargo_left[cid] > amount) { |
137b272acca5
(svn r23087) -Feature: Auto-refitting of vehicles during loading at a station when the vehicle allows it.
michi_cc <michi_cc@openttd.org>
parents:
18238
diff
changeset
|
1358 /* Try to find out if auto-refitting would succeed. In case the refit is allowed, |
137b272acca5
(svn r23087) -Feature: Auto-refitting of vehicles during loading at a station when the vehicle allows it.
michi_cc <michi_cc@openttd.org>
parents:
18238
diff
changeset
|
1359 * the returned refit capacity will be greater than zero. */ |
18275
893113d8052f
(svn r23111) -Fix: Keep subtype when automatically choosing the cargo for auto-refitting.
michi_cc <michi_cc@openttd.org>
parents:
18273
diff
changeset
|
1360 new_subtype = GetBestFittingSubType(v, v, cid); |
18638
ac23ced64c4b
(svn r23485) -Fix: Autorefit failed if the first part of an articulated vehicle did not carry any cargo.
frosch <frosch@openttd.org>
parents:
18570
diff
changeset
|
1361 DoCommand(v_start->tile, v_start->index, cid | 1U << 6 | new_subtype << 8 | 1U << 16, DC_QUERY_COST, GetCmdRefitVeh(v_start)); // Auto-refit and only this vehicle including artic parts. |
18251
137b272acca5
(svn r23087) -Feature: Auto-refitting of vehicles during loading at a station when the vehicle allows it.
michi_cc <michi_cc@openttd.org>
parents:
18238
diff
changeset
|
1362 if (_returned_refit_capacity > 0) { |
137b272acca5
(svn r23087) -Feature: Auto-refitting of vehicles during loading at a station when the vehicle allows it.
michi_cc <michi_cc@openttd.org>
parents:
18238
diff
changeset
|
1363 amount = cargo_left[cid]; |
137b272acca5
(svn r23087) -Feature: Auto-refitting of vehicles during loading at a station when the vehicle allows it.
michi_cc <michi_cc@openttd.org>
parents:
18238
diff
changeset
|
1364 new_cid = cid; |
137b272acca5
(svn r23087) -Feature: Auto-refitting of vehicles during loading at a station when the vehicle allows it.
michi_cc <michi_cc@openttd.org>
parents:
18238
diff
changeset
|
1365 } |
137b272acca5
(svn r23087) -Feature: Auto-refitting of vehicles during loading at a station when the vehicle allows it.
michi_cc <michi_cc@openttd.org>
parents:
18238
diff
changeset
|
1366 } |
137b272acca5
(svn r23087) -Feature: Auto-refitting of vehicles during loading at a station when the vehicle allows it.
michi_cc <michi_cc@openttd.org>
parents:
18238
diff
changeset
|
1367 } |
137b272acca5
(svn r23087) -Feature: Auto-refitting of vehicles during loading at a station when the vehicle allows it.
michi_cc <michi_cc@openttd.org>
parents:
18238
diff
changeset
|
1368 } |
137b272acca5
(svn r23087) -Feature: Auto-refitting of vehicles during loading at a station when the vehicle allows it.
michi_cc <michi_cc@openttd.org>
parents:
18238
diff
changeset
|
1369 |
137b272acca5
(svn r23087) -Feature: Auto-refitting of vehicles during loading at a station when the vehicle allows it.
michi_cc <michi_cc@openttd.org>
parents:
18238
diff
changeset
|
1370 /* Refit if given a valid cargo. */ |
137b272acca5
(svn r23087) -Feature: Auto-refitting of vehicles during loading at a station when the vehicle allows it.
michi_cc <michi_cc@openttd.org>
parents:
18238
diff
changeset
|
1371 if (new_cid < NUM_CARGO) { |
18638
ac23ced64c4b
(svn r23485) -Fix: Autorefit failed if the first part of an articulated vehicle did not carry any cargo.
frosch <frosch@openttd.org>
parents:
18570
diff
changeset
|
1372 CommandCost cost = DoCommand(v_start->tile, v_start->index, new_cid | 1U << 6 | new_subtype << 8 | 1U << 16, DC_EXEC, GetCmdRefitVeh(v_start)); // Auto-refit and only this vehicle including artic parts. |
18273
c7bd632d9cc2
(svn r23109) -Fix: Subtract auto-refit costs from the vehicle profit.
michi_cc <michi_cc@openttd.org>
parents:
18251
diff
changeset
|
1373 if (cost.Succeeded()) front->profit_this_year -= cost.GetCost() << 8; |
18251
137b272acca5
(svn r23087) -Feature: Auto-refitting of vehicles during loading at a station when the vehicle allows it.
michi_cc <michi_cc@openttd.org>
parents:
18238
diff
changeset
|
1374 ge = &st->goods[v->cargo_type]; |
137b272acca5
(svn r23087) -Feature: Auto-refitting of vehicles during loading at a station when the vehicle allows it.
michi_cc <michi_cc@openttd.org>
parents:
18238
diff
changeset
|
1375 } |
137b272acca5
(svn r23087) -Feature: Auto-refitting of vehicles during loading at a station when the vehicle allows it.
michi_cc <michi_cc@openttd.org>
parents:
18238
diff
changeset
|
1376 |
137b272acca5
(svn r23087) -Feature: Auto-refitting of vehicles during loading at a station when the vehicle allows it.
michi_cc <michi_cc@openttd.org>
parents:
18238
diff
changeset
|
1377 cur_company.Restore(); |
137b272acca5
(svn r23087) -Feature: Auto-refitting of vehicles during loading at a station when the vehicle allows it.
michi_cc <michi_cc@openttd.org>
parents:
18238
diff
changeset
|
1378 } |
137b272acca5
(svn r23087) -Feature: Auto-refitting of vehicles during loading at a station when the vehicle allows it.
michi_cc <michi_cc@openttd.org>
parents:
18238
diff
changeset
|
1379 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1380 /* update stats */ |
6609
e78f5516e040
(svn r9829) -Codechange: more refactoring of the unloading algorithm.
rubidium <rubidium@openttd.org>
parents:
6601
diff
changeset
|
1381 int t; |
17939
5da57f628072
(svn r22744) -Codechange: Clarify the scope of variables in LoadUnloadVehicle().
frosch <frosch@openttd.org>
parents:
17903
diff
changeset
|
1382 switch (front->type) { |
16382
198b969abcda
(svn r21098) -Codechange: Ships now store their max speed in the cache instead of recalculating it every time.
terkhen <terkhen@openttd.org>
parents:
16381
diff
changeset
|
1383 case VEH_TRAIN: /* FALL THROUGH */ |
198b969abcda
(svn r21098) -Codechange: Ships now store their max speed in the cache instead of recalculating it every time.
terkhen <terkhen@openttd.org>
parents:
16381
diff
changeset
|
1384 case VEH_SHIP: |
17939
5da57f628072
(svn r22744) -Codechange: Clarify the scope of variables in LoadUnloadVehicle().
frosch <frosch@openttd.org>
parents:
17903
diff
changeset
|
1385 t = front->vcache.cached_max_speed; |
16382
198b969abcda
(svn r21098) -Codechange: Ships now store their max speed in the cache instead of recalculating it every time.
terkhen <terkhen@openttd.org>
parents:
16381
diff
changeset
|
1386 break; |
16383
6dd97e032309
(svn r21099) -Codechange: Store road vehicle max speed in the vehicle cache.
terkhen <terkhen@openttd.org>
parents:
16382
diff
changeset
|
1387 |
6dd97e032309
(svn r21099) -Codechange: Store road vehicle max speed in the vehicle cache.
terkhen <terkhen@openttd.org>
parents:
16382
diff
changeset
|
1388 case VEH_ROAD: |
17939
5da57f628072
(svn r22744) -Codechange: Clarify the scope of variables in LoadUnloadVehicle().
frosch <frosch@openttd.org>
parents:
17903
diff
changeset
|
1389 t = front->vcache.cached_max_speed / 2; |
16383
6dd97e032309
(svn r21099) -Codechange: Store road vehicle max speed in the vehicle cache.
terkhen <terkhen@openttd.org>
parents:
16382
diff
changeset
|
1390 break; |
6dd97e032309
(svn r21099) -Codechange: Store road vehicle max speed in the vehicle cache.
terkhen <terkhen@openttd.org>
parents:
16382
diff
changeset
|
1391 |
6dd97e032309
(svn r21099) -Codechange: Store road vehicle max speed in the vehicle cache.
terkhen <terkhen@openttd.org>
parents:
16382
diff
changeset
|
1392 case VEH_AIRCRAFT: |
17939
5da57f628072
(svn r22744) -Codechange: Clarify the scope of variables in LoadUnloadVehicle().
frosch <frosch@openttd.org>
parents:
17903
diff
changeset
|
1393 t = Aircraft::From(front)->GetSpeedOldUnits(); // Convert to old units. |
16383
6dd97e032309
(svn r21099) -Codechange: Store road vehicle max speed in the vehicle cache.
terkhen <terkhen@openttd.org>
parents:
16382
diff
changeset
|
1394 break; |
6dd97e032309
(svn r21099) -Codechange: Store road vehicle max speed in the vehicle cache.
terkhen <terkhen@openttd.org>
parents:
16382
diff
changeset
|
1395 |
13052
6dba8bf1c036
(svn r17550) -Fix (r8973): Aircraft are good enough, don't make them even better.
frosch <frosch@openttd.org>
parents:
13048
diff
changeset
|
1396 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
|
1397 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1398 |
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
|
1399 /* 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
|
1400 ge->last_speed = min(t, 255); |
17939
5da57f628072
(svn r22744) -Codechange: Clarify the scope of variables in LoadUnloadVehicle().
frosch <frosch@openttd.org>
parents:
17903
diff
changeset
|
1401 ge->last_age = _cur_year - front->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
|
1402 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
|
1403 |
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
|
1404 /* 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
|
1405 * 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
|
1406 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
|
1407 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
|
1408 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
|
1409 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
|
1410 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1411 /* 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
|
1412 * 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
|
1413 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
|
1414 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
|
1415 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
|
1416 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1417 |
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
|
1418 if (cap > count) cap = count; |
15827
56dcb448bdfb
(svn r20506) -Change: Vehicles will now stop loading after a load cycle that loaded less than possible, unless it's a full load order. This should improve behaviour with gradual loading and cargo continuously trickling in.
michi_cc <michi_cc@openttd.org>
parents:
15744
diff
changeset
|
1419 if (_settings_game.order.gradual_loading) { |
56dcb448bdfb
(svn r20506) -Change: Vehicles will now stop loading after a load cycle that loaded less than possible, unless it's a full load order. This should improve behaviour with gradual loading and cargo continuously trickling in.
michi_cc <michi_cc@openttd.org>
parents:
15744
diff
changeset
|
1420 cap = min(cap, load_amount); |
56dcb448bdfb
(svn r20506) -Change: Vehicles will now stop loading after a load cycle that loaded less than possible, unless it's a full load order. This should improve behaviour with gradual loading and cargo continuously trickling in.
michi_cc <michi_cc@openttd.org>
parents:
15744
diff
changeset
|
1421 cap_left = min(cap_left, load_amount); |
56dcb448bdfb
(svn r20506) -Change: Vehicles will now stop loading after a load cycle that loaded less than possible, unless it's a full load order. This should improve behaviour with gradual loading and cargo continuously trickling in.
michi_cc <michi_cc@openttd.org>
parents:
15744
diff
changeset
|
1422 } |
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
|
1423 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
|
1424 /* 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
|
1425 cap = min((uint)cargo_left[v->cargo_type], cap); |
15827
56dcb448bdfb
(svn r20506) -Change: Vehicles will now stop loading after a load cycle that loaded less than possible, unless it's a full load order. This should improve behaviour with gradual loading and cargo continuously trickling in.
michi_cc <michi_cc@openttd.org>
parents:
15744
diff
changeset
|
1426 count = cargo_left[v->cargo_type]; |
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
|
1427 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
|
1428 } |
16147
2c2d2a90fd54
(svn r20843) -Fix [FS#2534] (r20506): Make sure (gradual) loading is properly terminated for consists with multiple cargo types. Don't stop loading if the timetabled wait is not over yet. (Steve-N)
michi_cc <michi_cc@openttd.org>
parents:
15944
diff
changeset
|
1429 |
2c2d2a90fd54
(svn r20843) -Fix [FS#2534] (r20506): Make sure (gradual) loading is properly terminated for consists with multiple cargo types. Don't stop loading if the timetabled wait is not over yet. (Steve-N)
michi_cc <michi_cc@openttd.org>
parents:
15944
diff
changeset
|
1430 /* Store whether the maximum possible load amount was loaded or not.*/ |
2c2d2a90fd54
(svn r20843) -Fix [FS#2534] (r20506): Make sure (gradual) loading is properly terminated for consists with multiple cargo types. Don't stop loading if the timetabled wait is not over yet. (Steve-N)
michi_cc <michi_cc@openttd.org>
parents:
15944
diff
changeset
|
1431 if (count >= (uint)cap_left) { |
2c2d2a90fd54
(svn r20843) -Fix [FS#2534] (r20506): Make sure (gradual) loading is properly terminated for consists with multiple cargo types. Don't stop loading if the timetabled wait is not over yet. (Steve-N)
michi_cc <michi_cc@openttd.org>
parents:
15944
diff
changeset
|
1432 SetBit(full_load_amount, v->cargo_type); |
2c2d2a90fd54
(svn r20843) -Fix [FS#2534] (r20506): Make sure (gradual) loading is properly terminated for consists with multiple cargo types. Don't stop loading if the timetabled wait is not over yet. (Steve-N)
michi_cc <michi_cc@openttd.org>
parents:
15944
diff
changeset
|
1433 } else { |
2c2d2a90fd54
(svn r20843) -Fix [FS#2534] (r20506): Make sure (gradual) loading is properly terminated for consists with multiple cargo types. Don't stop loading if the timetabled wait is not over yet. (Steve-N)
michi_cc <michi_cc@openttd.org>
parents:
15944
diff
changeset
|
1434 ClrBit(full_load_amount, v->cargo_type); |
2c2d2a90fd54
(svn r20843) -Fix [FS#2534] (r20506): Make sure (gradual) loading is properly terminated for consists with multiple cargo types. Don't stop loading if the timetabled wait is not over yet. (Steve-N)
michi_cc <michi_cc@openttd.org>
parents:
15944
diff
changeset
|
1435 } |
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
|
1436 |
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
|
1437 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
|
1438 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1439 /* 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
|
1440 * 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
|
1441 * 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
|
1442 * 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
|
1443 * 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
|
1444 * 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
|
1445 * 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
|
1446 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
|
1447 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
|
1448 |
13291
07fc7c78b30b
(svn r17800) -Codechange: first steps into making CargoList a template
rubidium <rubidium@openttd.org>
parents:
13218
diff
changeset
|
1449 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
|
1450 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1451 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
|
1452 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
|
1453 |
17940
47b3cffe2782
(svn r22745) -Fix: [NewGRF] SAT_CARGO_TAKEN and AAT_STATION_CARGO_TAKEN shall only be triggered when all cargo was taken.
frosch <frosch@openttd.org>
parents:
17939
diff
changeset
|
1454 if (ge->cargo.Empty()) { |
47b3cffe2782
(svn r22745) -Fix: [NewGRF] SAT_CARGO_TAKEN and AAT_STATION_CARGO_TAKEN shall only be triggered when all cargo was taken.
frosch <frosch@openttd.org>
parents:
17939
diff
changeset
|
1455 TriggerStationAnimation(st, st->xy, SAT_CARGO_TAKEN, v->cargo_type); |
47b3cffe2782
(svn r22745) -Fix: [NewGRF] SAT_CARGO_TAKEN and AAT_STATION_CARGO_TAKEN shall only be triggered when all cargo was taken.
frosch <frosch@openttd.org>
parents:
17939
diff
changeset
|
1456 AirportAnimationTrigger(st, AAT_STATION_CARGO_TAKEN, v->cargo_type); |
47b3cffe2782
(svn r22745) -Fix: [NewGRF] SAT_CARGO_TAKEN and AAT_STATION_CARGO_TAKEN shall only be triggered when all cargo was taken.
frosch <frosch@openttd.org>
parents:
17939
diff
changeset
|
1457 } |
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
|
1458 |
7474
7b35fd1cc99d
(svn r10981) -Fix [FS#1156] (r10970): stations gave ratings for accepted cargo too.
rubidium <rubidium@openttd.org>
parents:
7458
diff
changeset
|
1459 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
|
1460 |
13998
3d6fd0265851
(svn r18540) -Codechange: resulting in better name for 'result'.
frosch <frosch@openttd.org>
parents:
13995
diff
changeset
|
1461 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
|
1462 } |
6611
461107df1c8f
(svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents:
6609
diff
changeset
|
1463 |
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
|
1464 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
|
1465 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
|
1466 } 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
|
1467 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
|
1468 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1469 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1470 |
17941
1cac4486290e
(svn r22746) -Feature: [NewGRF] Implement feature 04 property 18 bit 5.
frosch <frosch@openttd.org>
parents:
17940
diff
changeset
|
1471 if (anything_loaded || anything_unloaded) { |
1cac4486290e
(svn r22746) -Feature: [NewGRF] Implement feature 04 property 18 bit 5.
frosch <frosch@openttd.org>
parents:
17940
diff
changeset
|
1472 if (front->type == VEH_TRAIN) TriggerStationAnimation(st, st->xy, SAT_TRAIN_LOADS); |
1cac4486290e
(svn r22746) -Feature: [NewGRF] Implement feature 04 property 18 bit 5.
frosch <frosch@openttd.org>
parents:
17940
diff
changeset
|
1473 } |
1cac4486290e
(svn r22746) -Feature: [NewGRF] Implement feature 04 property 18 bit 5.
frosch <frosch@openttd.org>
parents:
17940
diff
changeset
|
1474 |
15604
ca959eb5d431
(svn r20266) -Doc: Mostly typo fixes, a few doxygen-related improvements.
alberth <alberth@openttd.org>
parents:
15601
diff
changeset
|
1475 /* 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
|
1476 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
|
1477 |
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
|
1478 /* 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
|
1479 * 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
|
1480 * 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
|
1481 * enough to fill the previous wagons) */ |
17939
5da57f628072
(svn r22744) -Codechange: Clarify the scope of variables in LoadUnloadVehicle().
frosch <frosch@openttd.org>
parents:
17903
diff
changeset
|
1482 if (_settings_game.order.improved_load && (front->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
|
1483 /* Update left cargo */ |
17939
5da57f628072
(svn r22744) -Codechange: Clarify the scope of variables in LoadUnloadVehicle().
frosch <frosch@openttd.org>
parents:
17903
diff
changeset
|
1484 for (Vehicle *v = front; 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
|
1485 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
|
1486 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
|
1487 } |
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
|
1488 } |
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
|
1489 |
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
|
1490 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
|
1491 |
17939
5da57f628072
(svn r22744) -Codechange: Clarify the scope of variables in LoadUnloadVehicle().
frosch <frosch@openttd.org>
parents:
17903
diff
changeset
|
1492 ClrBit(front->vehicle_flags, VF_STOP_LOADING); |
6611
461107df1c8f
(svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents:
6609
diff
changeset
|
1493 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
|
1494 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
|
1495 /* 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
|
1496 * 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
|
1497 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
|
1498 |
17939
5da57f628072
(svn r22744) -Codechange: Clarify the scope of variables in LoadUnloadVehicle().
frosch <frosch@openttd.org>
parents:
17903
diff
changeset
|
1499 unloading_time = gradual_loading_wait_time[front->type]; |
6611
461107df1c8f
(svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents:
6609
diff
changeset
|
1500 } |
16147
2c2d2a90fd54
(svn r20843) -Fix [FS#2534] (r20506): Make sure (gradual) loading is properly terminated for consists with multiple cargo types. Don't stop loading if the timetabled wait is not over yet. (Steve-N)
michi_cc <michi_cc@openttd.org>
parents:
15944
diff
changeset
|
1501 /* We loaded less cargo than possible for all cargo types and it's not full |
2c2d2a90fd54
(svn r20843) -Fix [FS#2534] (r20506): Make sure (gradual) loading is properly terminated for consists with multiple cargo types. Don't stop loading if the timetabled wait is not over yet. (Steve-N)
michi_cc <michi_cc@openttd.org>
parents:
15944
diff
changeset
|
1502 * load and we're not supposed to wait any longer: stop loading. */ |
17939
5da57f628072
(svn r22744) -Codechange: Clarify the scope of variables in LoadUnloadVehicle().
frosch <frosch@openttd.org>
parents:
17903
diff
changeset
|
1503 if (!anything_unloaded && full_load_amount == 0 && !(front->current_order.GetLoadType() & OLFB_FULL_LOAD) && |
5da57f628072
(svn r22744) -Codechange: Clarify the scope of variables in LoadUnloadVehicle().
frosch <frosch@openttd.org>
parents:
17903
diff
changeset
|
1504 front->current_order_time >= (uint)max(front->current_order.wait_time - front->lateness_counter, 0)) { |
5da57f628072
(svn r22744) -Codechange: Clarify the scope of variables in LoadUnloadVehicle().
frosch <frosch@openttd.org>
parents:
17903
diff
changeset
|
1505 SetBit(front->vehicle_flags, VF_STOP_LOADING); |
16147
2c2d2a90fd54
(svn r20843) -Fix [FS#2534] (r20506): Make sure (gradual) loading is properly terminated for consists with multiple cargo types. Don't stop loading if the timetabled wait is not over yet. (Steve-N)
michi_cc <michi_cc@openttd.org>
parents:
15944
diff
changeset
|
1506 } |
6611
461107df1c8f
(svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents:
6609
diff
changeset
|
1507 } else { |
461107df1c8f
(svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents:
6609
diff
changeset
|
1508 bool finished_loading = true; |
17939
5da57f628072
(svn r22744) -Codechange: Clarify the scope of variables in LoadUnloadVehicle().
frosch <frosch@openttd.org>
parents:
17903
diff
changeset
|
1509 if (front->current_order.GetLoadType() & OLFB_FULL_LOAD) { |
5da57f628072
(svn r22744) -Codechange: Clarify the scope of variables in LoadUnloadVehicle().
frosch <frosch@openttd.org>
parents:
17903
diff
changeset
|
1510 if (front->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
|
1511 /* 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
|
1512 * continue loading, no matter how much mail is in */ |
17939
5da57f628072
(svn r22744) -Codechange: Clarify the scope of variables in LoadUnloadVehicle().
frosch <frosch@openttd.org>
parents:
17903
diff
changeset
|
1513 if ((front->type == VEH_AIRCRAFT && IsCargoInClass(front->cargo_type, CC_PASSENGERS) && front->cargo_cap > front->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
|
1514 (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
|
1515 finished_loading = false; |
461107df1c8f
(svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents:
6609
diff
changeset
|
1516 } |
461107df1c8f
(svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents:
6609
diff
changeset
|
1517 } else if (cargo_not_full != 0) { |
461107df1c8f
(svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents:
6609
diff
changeset
|
1518 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
|
1519 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1520 } |
6611
461107df1c8f
(svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents:
6609
diff
changeset
|
1521 unloading_time = 20; |
461107df1c8f
(svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents:
6609
diff
changeset
|
1522 |
17939
5da57f628072
(svn r22744) -Codechange: Clarify the scope of variables in LoadUnloadVehicle().
frosch <frosch@openttd.org>
parents:
17903
diff
changeset
|
1523 SB(front->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
|
1524 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1525 |
17939
5da57f628072
(svn r22744) -Codechange: Clarify the scope of variables in LoadUnloadVehicle().
frosch <frosch@openttd.org>
parents:
17903
diff
changeset
|
1526 if (front->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
|
1527 /* Each platform tile is worth 2 rail vehicles. */ |
17939
5da57f628072
(svn r22744) -Codechange: Clarify the scope of variables in LoadUnloadVehicle().
frosch <frosch@openttd.org>
parents:
17903
diff
changeset
|
1528 int overhang = front->GetGroundVehicleCache()->cached_total_length - st->GetPlatformLength(front->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
|
1529 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
|
1530 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
|
1531 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
|
1532 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1533 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1534 |
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
|
1535 /* 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
|
1536 * 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
|
1537 * 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
|
1538 * 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
|
1539 * 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
|
1540 */ |
17939
5da57f628072
(svn r22744) -Codechange: Clarify the scope of variables in LoadUnloadVehicle().
frosch <frosch@openttd.org>
parents:
17903
diff
changeset
|
1541 if (_game_mode != GM_MENU && (_settings_client.gui.loading_indicators > (uint)(front->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
|
1542 StringID percent_up_down = STR_NULL; |
17939
5da57f628072
(svn r22744) -Codechange: Clarify the scope of variables in LoadUnloadVehicle().
frosch <frosch@openttd.org>
parents:
17903
diff
changeset
|
1543 int percent = CalcPercentVehicleFilled(front, &percent_up_down); |
5da57f628072
(svn r22744) -Codechange: Clarify the scope of variables in LoadUnloadVehicle().
frosch <frosch@openttd.org>
parents:
17903
diff
changeset
|
1544 if (front->fill_percent_te_id == INVALID_TE_ID) { |
5da57f628072
(svn r22744) -Codechange: Clarify the scope of variables in LoadUnloadVehicle().
frosch <frosch@openttd.org>
parents:
17903
diff
changeset
|
1545 front->fill_percent_te_id = ShowFillingPercent(front->x_pos, front->y_pos, front->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
|
1546 } else { |
17939
5da57f628072
(svn r22744) -Codechange: Clarify the scope of variables in LoadUnloadVehicle().
frosch <frosch@openttd.org>
parents:
17903
diff
changeset
|
1547 UpdateFillingPercent(front->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
|
1548 } |
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
|
1549 } |
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
|
1550 |
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
|
1551 /* Always wait at least 1, otherwise we'll wait 'infinitively' long. */ |
17939
5da57f628072
(svn r22744) -Codechange: Clarify the scope of variables in LoadUnloadVehicle().
frosch <frosch@openttd.org>
parents:
17903
diff
changeset
|
1552 front->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
|
1553 |
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
|
1554 if (completely_emptied) { |
17939
5da57f628072
(svn r22744) -Codechange: Clarify the scope of variables in LoadUnloadVehicle().
frosch <frosch@openttd.org>
parents:
17903
diff
changeset
|
1555 TriggerVehicle(front, VEHICLE_TRIGGER_EMPTY); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1556 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1557 |
13998
3d6fd0265851
(svn r18540) -Codechange: resulting in better name for 'result'.
frosch <frosch@openttd.org>
parents:
13995
diff
changeset
|
1558 if (dirty_vehicle) { |
17939
5da57f628072
(svn r22744) -Codechange: Clarify the scope of variables in LoadUnloadVehicle().
frosch <frosch@openttd.org>
parents:
17903
diff
changeset
|
1559 SetWindowDirty(GetWindowClassForVehicleType(front->type), front->owner); |
5da57f628072
(svn r22744) -Codechange: Clarify the scope of variables in LoadUnloadVehicle().
frosch <frosch@openttd.org>
parents:
17903
diff
changeset
|
1560 SetWindowDirty(WC_VEHICLE_DETAILS, front->index); |
5da57f628072
(svn r22744) -Codechange: Clarify the scope of variables in LoadUnloadVehicle().
frosch <frosch@openttd.org>
parents:
17903
diff
changeset
|
1561 front->MarkDirty(); |
13998
3d6fd0265851
(svn r18540) -Codechange: resulting in better name for 'result'.
frosch <frosch@openttd.org>
parents:
13995
diff
changeset
|
1562 } |
3d6fd0265851
(svn r18540) -Codechange: resulting in better name for 'result'.
frosch <frosch@openttd.org>
parents:
13995
diff
changeset
|
1563 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
|
1564 st->MarkTilesDirty(true); |
13998
3d6fd0265851
(svn r18540) -Codechange: resulting in better name for 'result'.
frosch <frosch@openttd.org>
parents:
13995
diff
changeset
|
1565 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
|
1566 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1567 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1568 |
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
|
1569 /** |
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
|
1570 * 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
|
1571 * 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
|
1572 * @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
|
1573 */ |
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
|
1574 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
|
1575 { |
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
|
1576 /* 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
|
1577 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
|
1578 |
16729
235fa32934bf
(svn r21462) -Codechange [FS#3689]: don't do unnecessary cargo reservations in while loading/unloading vehicles. It is only needed when at least one vehicle is loading; all other times it is a waste of effort. Roughly halves the time it takes to perform loading/unloading of vehicles (fonsinchen)
rubidium <rubidium@openttd.org>
parents:
16440
diff
changeset
|
1579 Vehicle *last_loading = NULL; |
235fa32934bf
(svn r21462) -Codechange [FS#3689]: don't do unnecessary cargo reservations in while loading/unloading vehicles. It is only needed when at least one vehicle is loading; all other times it is a waste of effort. Roughly halves the time it takes to perform loading/unloading of vehicles (fonsinchen)
rubidium <rubidium@openttd.org>
parents:
16440
diff
changeset
|
1580 std::list<Vehicle *>::iterator iter; |
235fa32934bf
(svn r21462) -Codechange [FS#3689]: don't do unnecessary cargo reservations in while loading/unloading vehicles. It is only needed when at least one vehicle is loading; all other times it is a waste of effort. Roughly halves the time it takes to perform loading/unloading of vehicles (fonsinchen)
rubidium <rubidium@openttd.org>
parents:
16440
diff
changeset
|
1581 |
235fa32934bf
(svn r21462) -Codechange [FS#3689]: don't do unnecessary cargo reservations in while loading/unloading vehicles. It is only needed when at least one vehicle is loading; all other times it is a waste of effort. Roughly halves the time it takes to perform loading/unloading of vehicles (fonsinchen)
rubidium <rubidium@openttd.org>
parents:
16440
diff
changeset
|
1582 /* Check if anything will be loaded at all. Otherwise we don't need to reserve either. */ |
235fa32934bf
(svn r21462) -Codechange [FS#3689]: don't do unnecessary cargo reservations in while loading/unloading vehicles. It is only needed when at least one vehicle is loading; all other times it is a waste of effort. Roughly halves the time it takes to perform loading/unloading of vehicles (fonsinchen)
rubidium <rubidium@openttd.org>
parents:
16440
diff
changeset
|
1583 for (iter = st->loading_vehicles.begin(); iter != st->loading_vehicles.end(); ++iter) { |
235fa32934bf
(svn r21462) -Codechange [FS#3689]: don't do unnecessary cargo reservations in while loading/unloading vehicles. It is only needed when at least one vehicle is loading; all other times it is a waste of effort. Roughly halves the time it takes to perform loading/unloading of vehicles (fonsinchen)
rubidium <rubidium@openttd.org>
parents:
16440
diff
changeset
|
1584 Vehicle *v = *iter; |
235fa32934bf
(svn r21462) -Codechange [FS#3689]: don't do unnecessary cargo reservations in while loading/unloading vehicles. It is only needed when at least one vehicle is loading; all other times it is a waste of effort. Roughly halves the time it takes to perform loading/unloading of vehicles (fonsinchen)
rubidium <rubidium@openttd.org>
parents:
16440
diff
changeset
|
1585 |
235fa32934bf
(svn r21462) -Codechange [FS#3689]: don't do unnecessary cargo reservations in while loading/unloading vehicles. It is only needed when at least one vehicle is loading; all other times it is a waste of effort. Roughly halves the time it takes to perform loading/unloading of vehicles (fonsinchen)
rubidium <rubidium@openttd.org>
parents:
16440
diff
changeset
|
1586 if ((v->vehstatus & (VS_STOPPED | VS_CRASHED))) continue; |
235fa32934bf
(svn r21462) -Codechange [FS#3689]: don't do unnecessary cargo reservations in while loading/unloading vehicles. It is only needed when at least one vehicle is loading; all other times it is a waste of effort. Roughly halves the time it takes to perform loading/unloading of vehicles (fonsinchen)
rubidium <rubidium@openttd.org>
parents:
16440
diff
changeset
|
1587 |
235fa32934bf
(svn r21462) -Codechange [FS#3689]: don't do unnecessary cargo reservations in while loading/unloading vehicles. It is only needed when at least one vehicle is loading; all other times it is a waste of effort. Roughly halves the time it takes to perform loading/unloading of vehicles (fonsinchen)
rubidium <rubidium@openttd.org>
parents:
16440
diff
changeset
|
1588 assert(v->load_unload_ticks != 0); |
235fa32934bf
(svn r21462) -Codechange [FS#3689]: don't do unnecessary cargo reservations in while loading/unloading vehicles. It is only needed when at least one vehicle is loading; all other times it is a waste of effort. Roughly halves the time it takes to perform loading/unloading of vehicles (fonsinchen)
rubidium <rubidium@openttd.org>
parents:
16440
diff
changeset
|
1589 if (--v->load_unload_ticks == 0) last_loading = v; |
235fa32934bf
(svn r21462) -Codechange [FS#3689]: don't do unnecessary cargo reservations in while loading/unloading vehicles. It is only needed when at least one vehicle is loading; all other times it is a waste of effort. Roughly halves the time it takes to perform loading/unloading of vehicles (fonsinchen)
rubidium <rubidium@openttd.org>
parents:
16440
diff
changeset
|
1590 } |
235fa32934bf
(svn r21462) -Codechange [FS#3689]: don't do unnecessary cargo reservations in while loading/unloading vehicles. It is only needed when at least one vehicle is loading; all other times it is a waste of effort. Roughly halves the time it takes to perform loading/unloading of vehicles (fonsinchen)
rubidium <rubidium@openttd.org>
parents:
16440
diff
changeset
|
1591 |
235fa32934bf
(svn r21462) -Codechange [FS#3689]: don't do unnecessary cargo reservations in while loading/unloading vehicles. It is only needed when at least one vehicle is loading; all other times it is a waste of effort. Roughly halves the time it takes to perform loading/unloading of vehicles (fonsinchen)
rubidium <rubidium@openttd.org>
parents:
16440
diff
changeset
|
1592 /* We only need to reserve and load/unload up to the last loading vehicle. |
235fa32934bf
(svn r21462) -Codechange [FS#3689]: don't do unnecessary cargo reservations in while loading/unloading vehicles. It is only needed when at least one vehicle is loading; all other times it is a waste of effort. Roughly halves the time it takes to perform loading/unloading of vehicles (fonsinchen)
rubidium <rubidium@openttd.org>
parents:
16440
diff
changeset
|
1593 * Anything else will be forgotten anyway after returning from this function. |
235fa32934bf
(svn r21462) -Codechange [FS#3689]: don't do unnecessary cargo reservations in while loading/unloading vehicles. It is only needed when at least one vehicle is loading; all other times it is a waste of effort. Roughly halves the time it takes to perform loading/unloading of vehicles (fonsinchen)
rubidium <rubidium@openttd.org>
parents:
16440
diff
changeset
|
1594 * |
235fa32934bf
(svn r21462) -Codechange [FS#3689]: don't do unnecessary cargo reservations in while loading/unloading vehicles. It is only needed when at least one vehicle is loading; all other times it is a waste of effort. Roughly halves the time it takes to perform loading/unloading of vehicles (fonsinchen)
rubidium <rubidium@openttd.org>
parents:
16440
diff
changeset
|
1595 * Especially this means we do _not_ need to reserve cargo for a single |
235fa32934bf
(svn r21462) -Codechange [FS#3689]: don't do unnecessary cargo reservations in while loading/unloading vehicles. It is only needed when at least one vehicle is loading; all other times it is a waste of effort. Roughly halves the time it takes to perform loading/unloading of vehicles (fonsinchen)
rubidium <rubidium@openttd.org>
parents:
16440
diff
changeset
|
1596 * consist in a station which is not allowed to load yet because its |
235fa32934bf
(svn r21462) -Codechange [FS#3689]: don't do unnecessary cargo reservations in while loading/unloading vehicles. It is only needed when at least one vehicle is loading; all other times it is a waste of effort. Roughly halves the time it takes to perform loading/unloading of vehicles (fonsinchen)
rubidium <rubidium@openttd.org>
parents:
16440
diff
changeset
|
1597 * load_unload_ticks is still not 0. |
235fa32934bf
(svn r21462) -Codechange [FS#3689]: don't do unnecessary cargo reservations in while loading/unloading vehicles. It is only needed when at least one vehicle is loading; all other times it is a waste of effort. Roughly halves the time it takes to perform loading/unloading of vehicles (fonsinchen)
rubidium <rubidium@openttd.org>
parents:
16440
diff
changeset
|
1598 */ |
235fa32934bf
(svn r21462) -Codechange [FS#3689]: don't do unnecessary cargo reservations in while loading/unloading vehicles. It is only needed when at least one vehicle is loading; all other times it is a waste of effort. Roughly halves the time it takes to perform loading/unloading of vehicles (fonsinchen)
rubidium <rubidium@openttd.org>
parents:
16440
diff
changeset
|
1599 if (last_loading == NULL) return; |
235fa32934bf
(svn r21462) -Codechange [FS#3689]: don't do unnecessary cargo reservations in while loading/unloading vehicles. It is only needed when at least one vehicle is loading; all other times it is a waste of effort. Roughly halves the time it takes to perform loading/unloading of vehicles (fonsinchen)
rubidium <rubidium@openttd.org>
parents:
16440
diff
changeset
|
1600 |
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
|
1601 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
|
1602 |
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
|
1603 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
|
1604 |
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
|
1605 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
|
1606 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
|
1607 if (!(v->vehstatus & (VS_STOPPED | VS_CRASHED))) LoadUnloadVehicle(v, cargo_left); |
16729
235fa32934bf
(svn r21462) -Codechange [FS#3689]: don't do unnecessary cargo reservations in while loading/unloading vehicles. It is only needed when at least one vehicle is loading; all other times it is a waste of effort. Roughly halves the time it takes to perform loading/unloading of vehicles (fonsinchen)
rubidium <rubidium@openttd.org>
parents:
16440
diff
changeset
|
1608 if (v == last_loading) break; |
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
|
1609 } |
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
|
1610 |
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
|
1611 /* 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
|
1612 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
|
1613 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
|
1614 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
|
1615 } |
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
|
1616 _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
|
1617 } |
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
|
1618 |
15616
d76890d16808
(svn r20279) -Doc: Doxygen additions/improvements.
alberth <alberth@openttd.org>
parents:
15604
diff
changeset
|
1619 /** |
d76890d16808
(svn r20279) -Doc: Doxygen additions/improvements.
alberth <alberth@openttd.org>
parents:
15604
diff
changeset
|
1620 * 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
|
1621 */ |
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
|
1622 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
|
1623 { |
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
|
1624 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
|
1625 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
|
1626 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
|
1627 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
|
1628 } |
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
|
1629 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
|
1630 HandleEconomyFluctuations(); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1631 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1632 |
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
|
1633 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
|
1634 { |
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
|
1635 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
|
1636 |
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
|
1637 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
|
1638 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
|
1639 |
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
|
1640 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
|
1641 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
|
1642 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
|
1643 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
|
1644 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
|
1645 AddCompanyNewsItem(STR_MESSAGE_NEWS_FORMAT, NS_COMPANY_MERGER, cni); |
18511
f1214da4c397
(svn r23355) -Codechange: rename all AI* to Script* (Rubidium)
truebrain <truebrain@openttd.org>
parents:
18454
diff
changeset
|
1646 AI::BroadcastNewEvent(new ScriptEventCompanyMerger(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
|
1647 |
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
|
1648 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
|
1649 |
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
|
1650 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
|
1651 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
|
1652 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
|
1653 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1654 |
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
|
1655 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
|
1656 |
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
|
1657 DeleteCompanyWindows(ci); |
9297
add307f2e6ea
(svn r13165) -Codechange: replace some RebuildXXXList/ResortXXXList+InvalidateWindowXXX with InvalidateWindowXXXData.
rubidium <rubidium@openttd.org>
parents:
9281
diff
changeset
|
1658 InvalidateWindowClassesData(WC_TRAINS_LIST, 0); |
add307f2e6ea
(svn r13165) -Codechange: replace some RebuildXXXList/ResortXXXList+InvalidateWindowXXX with InvalidateWindowXXXData.
rubidium <rubidium@openttd.org>
parents:
9281
diff
changeset
|
1659 InvalidateWindowClassesData(WC_SHIPS_LIST, 0); |
add307f2e6ea
(svn r13165) -Codechange: replace some RebuildXXXList/ResortXXXList+InvalidateWindowXXX with InvalidateWindowXXXData.
rubidium <rubidium@openttd.org>
parents:
9281
diff
changeset
|
1660 InvalidateWindowClassesData(WC_ROADVEH_LIST, 0); |
add307f2e6ea
(svn r13165) -Codechange: replace some RebuildXXXList/ResortXXXList+InvalidateWindowXXX with InvalidateWindowXXXData.
rubidium <rubidium@openttd.org>
parents:
9281
diff
changeset
|
1661 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
|
1662 |
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
|
1663 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
|
1664 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1665 |
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
|
1666 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
|
1667 |
15620
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15616
diff
changeset
|
1668 /** |
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15616
diff
changeset
|
1669 * 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
|
1670 * @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
|
1671 * @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
|
1672 * @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
|
1673 * @param p2 unused |
13067
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13054
diff
changeset
|
1674 * @param text unused |
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13054
diff
changeset
|
1675 * @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
|
1676 */ |
11090
df23c4e04638
(svn r15434) -Codechange: bit of type safety for the DC_xxx flags.
rubidium <rubidium@openttd.org>
parents:
11085
diff
changeset
|
1677 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
|
1678 { |
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
|
1679 CommandCost cost(EXPENSES_OTHER); |
15038
80e8104bac11
(svn r19655) -Codechange: Reduce usage magic p1 parameter.
frosch <frosch@openttd.org>
parents:
15035
diff
changeset
|
1680 CompanyID target_company = (CompanyID)p1; |
80e8104bac11
(svn r19655) -Codechange: Reduce usage magic p1 parameter.
frosch <frosch@openttd.org>
parents:
15035
diff
changeset
|
1681 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
|
1682 |
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
|
1683 /* 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
|
1684 * Cannot buy own shares */ |
15038
80e8104bac11
(svn r19655) -Codechange: Reduce usage magic p1 parameter.
frosch <frosch@openttd.org>
parents:
15035
diff
changeset
|
1685 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
|
1686 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1687 /* 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
|
1688 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
|
1689 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1690 /* 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
|
1691 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
|
1692 |
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
|
1693 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
|
1694 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
|
1695 |
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
|
1696 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
|
1697 } |
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
|
1698 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1699 |
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
|
1700 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
|
1701 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
|
1702 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
|
1703 |
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
|
1704 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
|
1705 *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
|
1706 |
15652
354307d245e5
(svn r20317) -Codechange: Move variable declaration to their first use.
alberth <alberth@openttd.org>
parents:
15623
diff
changeset
|
1707 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
|
1708 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
|
1709 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
|
1710 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
|
1711 break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1712 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1713 } |
15038
80e8104bac11
(svn r19655) -Codechange: Reduce usage magic p1 parameter.
frosch <frosch@openttd.org>
parents:
15035
diff
changeset
|
1714 SetWindowDirty(WC_COMPANY, target_company); |
16269
f1578c16487c
(svn r20970) -Add: company change notification to remote admins (dihedral)
rubidium <rubidium@openttd.org>
parents:
16164
diff
changeset
|
1715 CompanyAdminUpdate(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
|
1716 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1717 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
|
1718 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1719 |
15620
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15616
diff
changeset
|
1720 /** |
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15616
diff
changeset
|
1721 * 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
|
1722 * @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
|
1723 * @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
|
1724 * @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
|
1725 * @param p2 unused |
13067
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13054
diff
changeset
|
1726 * @param text unused |
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13054
diff
changeset
|
1727 * @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
|
1728 */ |
11090
df23c4e04638
(svn r15434) -Codechange: bit of type safety for the DC_xxx flags.
rubidium <rubidium@openttd.org>
parents:
11085
diff
changeset
|
1729 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
|
1730 { |
15038
80e8104bac11
(svn r19655) -Codechange: Reduce usage magic p1 parameter.
frosch <frosch@openttd.org>
parents:
15035
diff
changeset
|
1731 CompanyID target_company = (CompanyID)p1; |
80e8104bac11
(svn r19655) -Codechange: Reduce usage magic p1 parameter.
frosch <frosch@openttd.org>
parents:
15035
diff
changeset
|
1732 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
|
1733 |
17831
7c8f4c06bbc1
(svn r22622) -Fix: When closing down companies their shares in other companies must be sold even if share trading is disabled at that point of time.
frosch <frosch@openttd.org>
parents:
17758
diff
changeset
|
1734 /* Cannot sell own shares */ |
7c8f4c06bbc1
(svn r22622) -Fix: When closing down companies their shares in other companies must be sold even if share trading is disabled at that point of time.
frosch <frosch@openttd.org>
parents:
17758
diff
changeset
|
1735 if (c == NULL || _current_company == target_company) return CMD_ERROR; |
7c8f4c06bbc1
(svn r22622) -Fix: When closing down companies their shares in other companies must be sold even if share trading is disabled at that point of time.
frosch <frosch@openttd.org>
parents:
17758
diff
changeset
|
1736 |
7c8f4c06bbc1
(svn r22622) -Fix: When closing down companies their shares in other companies must be sold even if share trading is disabled at that point of time.
frosch <frosch@openttd.org>
parents:
17758
diff
changeset
|
1737 /* Check if selling shares is allowed (protection against modified clients). |
7c8f4c06bbc1
(svn r22622) -Fix: When closing down companies their shares in other companies must be sold even if share trading is disabled at that point of time.
frosch <frosch@openttd.org>
parents:
17758
diff
changeset
|
1738 * However, we must sell shares of companies being closed down. */ |
7c8f4c06bbc1
(svn r22622) -Fix: When closing down companies their shares in other companies must be sold even if share trading is disabled at that point of time.
frosch <frosch@openttd.org>
parents:
17758
diff
changeset
|
1739 if (!_settings_game.economy.allow_shares && !(flags & DC_BANKRUPT)) 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
|
1740 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1741 /* 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
|
1742 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
|
1743 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1744 /* 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
|
1745 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
|
1746 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
|
1747 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1748 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
|
1749 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
|
1750 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
|
1751 *b = COMPANY_SPECTATOR; |
15038
80e8104bac11
(svn r19655) -Codechange: Reduce usage magic p1 parameter.
frosch <frosch@openttd.org>
parents:
15035
diff
changeset
|
1752 SetWindowDirty(WC_COMPANY, target_company); |
16269
f1578c16487c
(svn r20970) -Add: company change notification to remote admins (dihedral)
rubidium <rubidium@openttd.org>
parents:
16164
diff
changeset
|
1753 CompanyAdminUpdate(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
|
1754 } |
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
|
1755 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
|
1756 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1757 |
15620
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15616
diff
changeset
|
1758 /** |
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15616
diff
changeset
|
1759 * 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
|
1760 * 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
|
1761 * 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
|
1762 * @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
|
1763 * @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
|
1764 * @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
|
1765 * @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
|
1766 * @param p2 unused |
13067
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13054
diff
changeset
|
1767 * @param text unused |
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13054
diff
changeset
|
1768 * @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
|
1769 */ |
11090
df23c4e04638
(svn r15434) -Codechange: bit of type safety for the DC_xxx flags.
rubidium <rubidium@openttd.org>
parents:
11085
diff
changeset
|
1770 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
|
1771 { |
15038
80e8104bac11
(svn r19655) -Codechange: Reduce usage magic p1 parameter.
frosch <frosch@openttd.org>
parents:
15035
diff
changeset
|
1772 CompanyID target_company = (CompanyID)p1; |
80e8104bac11
(svn r19655) -Codechange: Reduce usage magic p1 parameter.
frosch <frosch@openttd.org>
parents:
15035
diff
changeset
|
1773 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
|
1774 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
|
1775 |
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
|
1776 /* 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
|
1777 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
|
1778 |
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
|
1779 /* 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
|
1780 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
|
1781 |
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
|
1782 /* 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
|
1783 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
|
1784 |
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
|
1785 /* 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
|
1786 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
|
1787 |
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
|
1788 /* 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
|
1789 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
|
1790 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1791 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
|
1792 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
|
1793 } |
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
|
1794 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
|
1795 } |