Mercurial > hg > openttd
annotate src/economy.cpp @ 9281:084086b60da8 draft
(svn r13147) -Codechange: move the code to draw bankruptcy news to news_gui.cpp.
author | rubidium <rubidium@openttd.org> |
---|---|
date | Sat, 17 May 2008 21:13:05 +0000 |
parents | 85a62fb8608f |
children | add307f2e6ea |
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 |
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
|
3 /** @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
|
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
|
5 #include "stdafx.h" |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
6 #include "openttd.h" |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
7 #include "currency.h" |
6453
666fc3ef3174
(svn r9609) -Codechange: Move some function prototypes out of functions.h and into landscape.h, and add a few where they didn't exist.
maedhros <maedhros@openttd.org>
parents:
6432
diff
changeset
|
8 #include "landscape.h" |
8254
7d580c9c41fb
(svn r11818) -Codechange: split player.h into smaller pieces.
rubidium <rubidium@openttd.org>
parents:
8241
diff
changeset
|
9 #include "player_base.h" |
7d580c9c41fb
(svn r11818) -Codechange: split player.h into smaller pieces.
rubidium <rubidium@openttd.org>
parents:
8241
diff
changeset
|
10 #include "player_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
|
11 #include "command_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
|
12 #include "saveload.h" |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
13 #include "industry.h" |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
14 #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
|
15 #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
|
16 #include "network/network.h" |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
17 #include "network/network_data.h" |
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 "variables.h" |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
19 #include "vehicle_gui.h" |
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 "ai/ai.h" |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
21 #include "train.h" |
6857
0005a9ed1903
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros <maedhros@openttd.org>
parents:
6844
diff
changeset
|
22 #include "roadveh.h" |
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
|
23 #include "aircraft.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
|
24 #include "newgrf_engine.h" |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
25 #include "newgrf_sound.h" |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
26 #include "newgrf_callbacks.h" |
7168
f0216e74951d
(svn r10442) -Codechange: implement the industry production callback.
rubidium <rubidium@openttd.org>
parents:
7167
diff
changeset
|
27 #include "newgrf_industries.h" |
7229
39b4e2291424
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium <rubidium@openttd.org>
parents:
7199
diff
changeset
|
28 #include "newgrf_industrytiles.h" |
9003
ac23e012c9d7
(svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents:
8885
diff
changeset
|
29 #include "newgrf_station.h" |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
30 #include "unmovable.h" |
6091
17ebeb5a2c37
(svn r8826) -Codechange: Replace _cargoc's separate arrays with a regular struct array (with accessor) and implement new initialization method using cargo labels.
peter1138 <peter1138@openttd.org>
parents:
5998
diff
changeset
|
31 #include "cargotype.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" |
8119
b6ec923e9fa8
(svn r11680) -Codechange: refactor more out of openttd.h and functions.h.
rubidium <rubidium@openttd.org>
parents:
8116
diff
changeset
|
34 #include "tile_cmd.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
|
35 #include "functions.h" |
e300ac8001ae
(svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium <rubidium@openttd.org>
parents:
8121
diff
changeset
|
36 #include "window_func.h" |
8140
fb8a05d579da
(svn r11702) -Codechange: move all date related stuff to date*.
rubidium <rubidium@openttd.org>
parents:
8139
diff
changeset
|
37 #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
|
38 #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
|
39 #include "sound_func.h" |
8200
f7f49622b3e0
(svn r11763) -Fix: update signal states after merging a company
smatz <smatz@openttd.org>
parents:
8186
diff
changeset
|
40 #include "track_type.h" |
f7f49622b3e0
(svn r11763) -Fix: update signal states after merging a company
smatz <smatz@openttd.org>
parents:
8186
diff
changeset
|
41 #include "track_func.h" |
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
|
42 #include "road_func.h" |
8200
f7f49622b3e0
(svn r11763) -Fix: update signal states after merging a company
smatz <smatz@openttd.org>
parents:
8186
diff
changeset
|
43 #include "rail_map.h" |
8238
e9d8b0764f38
(svn r11802) -Fix [FS#716]: do not crash trains when leaving depot to a very long track
smatz <smatz@openttd.org>
parents:
8231
diff
changeset
|
44 #include "signal_func.h" |
8224
c45446125bf0
(svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium <rubidium@openttd.org>
parents:
8200
diff
changeset
|
45 #include "gfx_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
|
46 #include "autoreplace_func.h" |
9117
453c3d26f4bc
(svn r12977) -Codechange: remove quite some redundant (duplicate) function declarations.
rubidium <rubidium@openttd.org>
parents:
9111
diff
changeset
|
47 #include "player_gui.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
|
48 |
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
|
49 #include "table/strings.h" |
2495310e220f
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium <rubidium@openttd.org>
parents:
8254
diff
changeset
|
50 #include "table/sprites.h" |
2495310e220f
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium <rubidium@openttd.org>
parents:
8254
diff
changeset
|
51 |
7926
e8ce9f6469d1
(svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents:
7922
diff
changeset
|
52 /** |
e8ce9f6469d1
(svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents:
7922
diff
changeset
|
53 * 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
|
54 * |
e8ce9f6469d1
(svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents:
7922
diff
changeset
|
55 * 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
|
56 * 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
|
57 * |
e8ce9f6469d1
(svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents:
7922
diff
changeset
|
58 * @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
|
59 * @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
|
60 * @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
|
61 * @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
|
62 */ |
e8ce9f6469d1
(svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents:
7922
diff
changeset
|
63 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
|
64 { |
e8ce9f6469d1
(svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents:
7922
diff
changeset
|
65 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
|
66 } |
e8ce9f6469d1
(svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents:
7922
diff
changeset
|
67 |
e8ce9f6469d1
(svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents:
7922
diff
changeset
|
68 /** |
e8ce9f6469d1
(svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents:
7922
diff
changeset
|
69 * Multiply two unsigned integers and shift the results to right. |
e8ce9f6469d1
(svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents:
7922
diff
changeset
|
70 * |
e8ce9f6469d1
(svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents:
7922
diff
changeset
|
71 * This function multiplies two unsigned integers. The result is |
e8ce9f6469d1
(svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents:
7922
diff
changeset
|
72 * 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
|
73 * |
e8ce9f6469d1
(svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents:
7922
diff
changeset
|
74 * @param a The first unsigned integer |
e8ce9f6469d1
(svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents:
7922
diff
changeset
|
75 * @param b The second unsigned integer |
e8ce9f6469d1
(svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents:
7922
diff
changeset
|
76 * @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
|
77 * @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
|
78 */ |
e8ce9f6469d1
(svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents:
7922
diff
changeset
|
79 static inline uint32 BigMulSU(const uint32 a, const uint32 b, const uint8 shift) |
e8ce9f6469d1
(svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents:
7922
diff
changeset
|
80 { |
e8ce9f6469d1
(svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents:
7922
diff
changeset
|
81 return (uint32)((uint64)a * (uint64)b >> shift); |
e8ce9f6469d1
(svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents:
7922
diff
changeset
|
82 } |
e8ce9f6469d1
(svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents:
7922
diff
changeset
|
83 |
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
|
84 /* Score info */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
85 const ScoreInfo _score_info[] = { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
86 { SCORE_VEHICLES, 120, 100 }, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
87 { SCORE_STATIONS, 80, 100 }, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
88 { SCORE_MIN_PROFIT, 10000, 100 }, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
89 { SCORE_MIN_INCOME, 50000, 50 }, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
90 { SCORE_MAX_INCOME, 100000, 100 }, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
91 { SCORE_DELIVERED, 40000, 400 }, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
92 { SCORE_CARGO, 8, 50 }, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
93 { SCORE_MONEY, 10000000, 50 }, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
94 { SCORE_LOAN, 250000, 50 }, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
95 { SCORE_TOTAL, 0, 0 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
96 }; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
97 |
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
|
98 int _score_part[MAX_PLAYERS][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
|
99 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
|
100 Subsidy _subsidies[MAX_PLAYERS]; |
9cc845deddfe
(svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium <rubidium@openttd.org>
parents:
8114
diff
changeset
|
101 Prices _price; |
9cc845deddfe
(svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium <rubidium@openttd.org>
parents:
8114
diff
changeset
|
102 uint16 _price_frac[NUM_PRICES]; |
8119
b6ec923e9fa8
(svn r11680) -Codechange: refactor more out of openttd.h and functions.h.
rubidium <rubidium@openttd.org>
parents:
8116
diff
changeset
|
103 Money _cargo_payment_rates[NUM_CARGO]; |
b6ec923e9fa8
(svn r11680) -Codechange: refactor more out of openttd.h and functions.h.
rubidium <rubidium@openttd.org>
parents:
8116
diff
changeset
|
104 uint16 _cargo_payment_rates_frac[NUM_CARGO]; |
b6ec923e9fa8
(svn r11680) -Codechange: refactor more out of openttd.h and functions.h.
rubidium <rubidium@openttd.org>
parents:
8116
diff
changeset
|
105 Money _additional_cash_required; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
106 |
6953
41fd36025784
(svn r10208) -Codechange: replace int32 with Money where appropriate.
rubidium <rubidium@openttd.org>
parents:
6952
diff
changeset
|
107 Money CalculateCompanyValue(const Player* 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
|
108 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
109 PlayerID owner = p->index; |
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
|
110 Money value = 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
|
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) { |
7832
1f9fb5d427f9
(svn r11382) -Codechange: renamed COUNTBITS to CountBits, as it is no longer a macro (skidd13)
truelight <truelight@openttd.org>
parents:
7824
diff
changeset
|
116 if (st->owner == owner) num += CountBits(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 |
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
|
119 value += num * _price.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 || |
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
|
127 (v->type == VEH_AIRCRAFT && IsNormalAircraft(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
|
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 */ |
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
|
134 value -= p->current_loan; |
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
|
135 value += p->player_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 |
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
|
140 /** if update is set to true, the economy is updated with this score |
46d001ebacf6
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents:
6119
diff
changeset
|
141 * (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
|
142 * @param update the economy with calculated score |
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 p player been evaluated |
46d001ebacf6
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents:
6119
diff
changeset
|
144 * @return actual score of this player |
46d001ebacf6
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents:
6119
diff
changeset
|
145 * */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
146 int UpdateCompanyRatingAndValue(Player *p, bool update) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
147 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
148 byte owner = p->index; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
149 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
|
150 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
151 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
|
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 /* Count vehicles */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
154 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
155 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
|
156 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
|
157 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
|
158 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
|
159 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
160 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
|
161 if (v->owner != owner) continue; |
6773
746c984c2dfe
(svn r10009) -Codechange: Add and use Vehicle::IsPrimaryVehicle to replace individual checks depending on the vehicle type.
maedhros <maedhros@openttd.org>
parents:
6698
diff
changeset
|
162 if (IsPlayerBuildableVehicleType(v->type) && v->IsPrimaryVehicle()) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
163 num++; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
164 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
|
165 /* 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
|
166 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
|
167 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
|
168 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
|
169 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
170 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
171 } |
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 |
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
|
174 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
|
175 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
176 _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
|
177 /* Don't allow negative min_profit to show */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
178 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
|
179 _score_part[owner][SCORE_MIN_PROFIT] = ClampToI32(min_profit); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
180 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
181 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
182 /* Count stations */ |
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 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
|
185 const 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
|
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 FOR_ALL_STATIONS(st) { |
7832
1f9fb5d427f9
(svn r11382) -Codechange: renamed COUNTBITS to CountBits, as it is no longer a macro (skidd13)
truelight <truelight@openttd.org>
parents:
7824
diff
changeset
|
188 if (st->owner == owner) num += CountBits(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
|
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 _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
|
191 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
192 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
193 /* Generate statistics depending on recent income statistics */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
194 { |
6953
41fd36025784
(svn r10208) -Codechange: replace int32 with Money where appropriate.
rubidium <rubidium@openttd.org>
parents:
6952
diff
changeset
|
195 int numec = min(p->num_valid_stat_ent, 12); |
41fd36025784
(svn r10208) -Codechange: replace int32 with Money where appropriate.
rubidium <rubidium@openttd.org>
parents:
6952
diff
changeset
|
196 if (numec != 0) { |
41fd36025784
(svn r10208) -Codechange: replace int32 with Money where appropriate.
rubidium <rubidium@openttd.org>
parents:
6952
diff
changeset
|
197 const PlayerEconomyEntry *pee = p->old_economy; |
41fd36025784
(svn r10208) -Codechange: replace int32 with Money where appropriate.
rubidium <rubidium@openttd.org>
parents:
6952
diff
changeset
|
198 Money min_income = pee->income + pee->expenses; |
41fd36025784
(svn r10208) -Codechange: replace int32 with Money where appropriate.
rubidium <rubidium@openttd.org>
parents:
6952
diff
changeset
|
199 Money max_income = pee->income + pee->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
|
200 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
201 do { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
202 min_income = min(min_income, pee->income + pee->expenses); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
203 max_income = max(max_income, pee->income + pee->expenses); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
204 } while (++pee,--numec); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
205 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
206 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
|
207 _score_part[owner][SCORE_MIN_INCOME] = ClampToI32(min_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
|
208 |
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
|
209 _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
|
210 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
211 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
212 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
213 /* Generate score depending on amount of transported cargo */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
214 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
215 const PlayerEconomyEntry* pee; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
216 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
|
217 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
|
218 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
219 numec = min(p->num_valid_stat_ent, 4); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
220 if (numec != 0) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
221 pee = p->old_economy; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
222 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
|
223 do { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
224 total_delivered += pee->delivered_cargo; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
225 } while (++pee,--numec); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
226 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
227 _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
|
228 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
229 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
230 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
231 /* Generate score for variety of cargo */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
232 { |
7832
1f9fb5d427f9
(svn r11382) -Codechange: renamed COUNTBITS to CountBits, as it is no longer a macro (skidd13)
truelight <truelight@openttd.org>
parents:
7824
diff
changeset
|
233 uint num = CountBits(p->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
|
234 _score_part[owner][SCORE_CARGO] = num; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
235 if (update) p->cargo_types = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
236 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
237 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
238 /* Generate score for player money */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
239 { |
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
|
240 if (p->player_money > 0) { |
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
|
241 _score_part[owner][SCORE_MONEY] = ClampToI32(p->player_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
|
242 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
243 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
244 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
245 /* Generate score for loan */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
246 { |
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
|
247 _score_part[owner][SCORE_LOAN] = ClampToI32(_score_info[SCORE_LOAN].needed - p->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
|
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 |
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
|
250 /* 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
|
251 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
252 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
|
253 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
|
254 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
|
255 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
|
256 /* 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
|
257 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
|
258 /* 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
|
259 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
|
260 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
|
261 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
|
262 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
263 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
264 _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
|
265 |
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
|
266 /* 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
|
267 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
|
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 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
270 if (update) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
271 p->old_economy[0].performance_history = score; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
272 UpdateCompanyHQ(p, 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 p->old_economy[0].company_value = CalculateCompanyValue(p); |
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 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
276 InvalidateWindow(WC_PERFORMANCE_DETAIL, 0); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
277 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
|
278 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
279 |
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
|
280 /* use PLAYER_SPECTATOR as new_player to delete the player. */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
281 void ChangeOwnershipOfPlayerItems(PlayerID old_player, PlayerID new_player) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
282 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
283 Town *t; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
284 PlayerID old = _current_player; |
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
|
285 |
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
|
286 assert(old_player != new_player); |
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
|
287 |
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
|
288 { |
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
|
289 Player *p; |
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
|
290 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
|
291 |
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
|
292 /* See if the old_player had shares in other companies */ |
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
|
293 _current_player = old_player; |
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
|
294 FOR_ALL_PLAYERS(p) { |
8155
2ca155c0aef1
(svn r11717) -Fix [FS#1590]: make sure invalid players have all shares owned by PLAYER_SPECTATOR
smatz <smatz@openttd.org>
parents:
8144
diff
changeset
|
295 if (!p->is_active) continue; |
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
|
296 for (i = 0; i < 4; 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
|
297 if (p->share_owners[i] == old_player) { |
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
|
298 /* Sell his shares */ |
6943
fd42cb9816c6
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium <rubidium@openttd.org>
parents:
6882
diff
changeset
|
299 CommandCost res = DoCommand(0, p->index, 0, DC_EXEC, CMD_SELL_SHARE_IN_COMPANY); |
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
|
300 /* Because we are in a DoCommand, we can't just execute an other one and |
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
|
301 * expect the money to be removed. We need to do it ourself! */ |
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
|
302 SubtractMoneyFromPlayer(res); |
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
|
303 } |
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
|
304 } |
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
|
305 } |
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
|
306 |
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
|
307 /* Sell all the shares that people have on this company */ |
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
|
308 p = GetPlayer(old_player); |
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
|
309 for (i = 0; i < 4; 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
|
310 _current_player = p->share_owners[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
|
311 if (_current_player != PLAYER_SPECTATOR) { |
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
|
312 /* Sell the shares */ |
6943
fd42cb9816c6
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium <rubidium@openttd.org>
parents:
6882
diff
changeset
|
313 CommandCost res = DoCommand(0, old_player, 0, DC_EXEC, CMD_SELL_SHARE_IN_COMPANY); |
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
|
314 /* Because we are in a DoCommand, we can't just execute an other one and |
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
|
315 * expect the money to be removed. We need to do it ourself! */ |
8c022dabd50e
(svn r9533) -Fix [FS#274]: when a company is removed (either via auto-clean, bankrupt, or take over), sell all the shares he has first, then sell the shares all people have on this company, and then remove the company.
truelight <truelight@openttd.org>
parents:
6369
diff
changeset
|
316 SubtractMoneyFromPlayer(res); |
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 } |
8c022dabd50e
(svn r9533) -Fix [FS#274]: when a company is removed (either via auto-clean, bankrupt, or take over), sell all the shares he has first, then sell the shares all people have on this company, and then remove the company.
truelight <truelight@openttd.org>
parents:
6369
diff
changeset
|
318 } |
8c022dabd50e
(svn r9533) -Fix [FS#274]: when a company is removed (either via auto-clean, bankrupt, or take over), sell all the shares he has first, then sell the shares all people have on this company, and then remove the company.
truelight <truelight@openttd.org>
parents:
6369
diff
changeset
|
319 } |
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 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
321 _current_player = old_player; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
322 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
323 /* Temporarily increase the player's money, to be sure that |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
324 * 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
|
325 * Not too drastically though, because it could overflow */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
326 if (new_player == PLAYER_SPECTATOR) { |
6952
752d9adbb23a
(svn r10207) -Codechange: remove the redundant player_money in favour of the money64, which is now renamed to player_money.
rubidium <rubidium@openttd.org>
parents:
6950
diff
changeset
|
327 GetPlayer(old_player)->player_money = MAX_UVALUE(uint64) >> 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
|
328 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
329 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
330 if (new_player == PLAYER_SPECTATOR) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
331 Subsidy *s; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
332 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
333 for (s = _subsidies; s != endof(_subsidies); s++) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
334 if (s->cargo_type != CT_INVALID && s->age >= 12) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
335 if (GetStation(s->to)->owner == old_player) s->cargo_type = CT_INVALID; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
336 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
337 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
338 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
339 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
340 /* 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
|
341 FOR_ALL_TOWNS(t) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
342 /* If a player takes over, give the ratings to that player. */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
343 if (new_player != PLAYER_SPECTATOR) { |
7928
4e8dfd103163
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7926
diff
changeset
|
344 if (HasBit(t->have_ratings, old_player)) { |
4e8dfd103163
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7926
diff
changeset
|
345 if (HasBit(t->have_ratings, new_player)) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
346 // use max of the two ratings. |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
347 t->ratings[new_player] = max(t->ratings[new_player], t->ratings[old_player]); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
348 } 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
|
349 SetBit(t->have_ratings, new_player); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
350 t->ratings[new_player] = t->ratings[old_player]; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
351 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
352 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
353 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
354 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
355 /* Reset the ratings for the old player */ |
8814
eb3b487b80a4
(svn r12560) -Cleanup: town_cmd.cpp and header files - variable scope and a bit of coding style
smatz <smatz@openttd.org>
parents:
8786
diff
changeset
|
356 t->ratings[old_player] = RATING_INITIAL; |
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
|
357 ClrBit(t->have_ratings, old_player); |
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 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
360 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
361 int num_train = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
362 int num_road = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
363 int num_ship = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
364 int num_aircraft = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
365 Vehicle *v; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
366 |
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
|
367 /* Determine Ids for the new 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
|
368 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
|
369 if (v->owner == new_player) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
370 switch (v->type) { |
6259
4a39d6291d58
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium <rubidium@openttd.org>
parents:
6248
diff
changeset
|
371 case VEH_TRAIN: if (IsFrontEngine(v)) num_train++; break; |
6857
0005a9ed1903
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros <maedhros@openttd.org>
parents:
6844
diff
changeset
|
372 case VEH_ROAD: if (IsRoadVehFront(v)) num_road++; break; |
6259
4a39d6291d58
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium <rubidium@openttd.org>
parents:
6248
diff
changeset
|
373 case VEH_SHIP: num_ship++; break; |
4a39d6291d58
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium <rubidium@openttd.org>
parents:
6248
diff
changeset
|
374 case VEH_AIRCRAFT: if (IsNormalAircraft(v)) num_aircraft++; 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
|
375 default: break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
376 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
377 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
378 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
379 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
380 FOR_ALL_VEHICLES(v) { |
7954
38bb7c45688f
(svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13 <skidd13@openttd.org>
parents:
7931
diff
changeset
|
381 if (v->owner == old_player && IsInsideMM(v->type, VEH_TRAIN, VEH_AIRCRAFT + 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
|
382 if (new_player == PLAYER_SPECTATOR) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
383 DeleteWindowById(WC_VEHICLE_VIEW, v->index); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
384 DeleteWindowById(WC_VEHICLE_DETAILS, v->index); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
385 DeleteWindowById(WC_VEHICLE_ORDERS, v->index); |
6876
d73e7573898d
(svn r10117) -Fix [FS#863]: When deleting the vehicles of bankrupt players, delete trains as
maedhros <maedhros@openttd.org>
parents:
6857
diff
changeset
|
386 |
d73e7573898d
(svn r10117) -Fix [FS#863]: When deleting the vehicles of bankrupt players, delete trains as
maedhros <maedhros@openttd.org>
parents:
6857
diff
changeset
|
387 if (v->IsPrimaryVehicle() || (v->type == VEH_TRAIN && IsFreeWagon(v))) { |
d73e7573898d
(svn r10117) -Fix [FS#863]: When deleting the vehicles of bankrupt players, delete trains as
maedhros <maedhros@openttd.org>
parents:
6857
diff
changeset
|
388 switch (v->type) { |
d73e7573898d
(svn r10117) -Fix [FS#863]: When deleting the vehicles of bankrupt players, delete trains as
maedhros <maedhros@openttd.org>
parents:
6857
diff
changeset
|
389 default: NOT_REACHED(); |
d73e7573898d
(svn r10117) -Fix [FS#863]: When deleting the vehicles of bankrupt players, delete trains as
maedhros <maedhros@openttd.org>
parents:
6857
diff
changeset
|
390 |
d73e7573898d
(svn r10117) -Fix [FS#863]: When deleting the vehicles of bankrupt players, delete trains as
maedhros <maedhros@openttd.org>
parents:
6857
diff
changeset
|
391 case VEH_TRAIN: { |
d73e7573898d
(svn r10117) -Fix [FS#863]: When deleting the vehicles of bankrupt players, delete trains as
maedhros <maedhros@openttd.org>
parents:
6857
diff
changeset
|
392 Vehicle *u = v; |
d73e7573898d
(svn r10117) -Fix [FS#863]: When deleting the vehicles of bankrupt players, delete trains as
maedhros <maedhros@openttd.org>
parents:
6857
diff
changeset
|
393 do { |
d73e7573898d
(svn r10117) -Fix [FS#863]: When deleting the vehicles of bankrupt players, delete trains as
maedhros <maedhros@openttd.org>
parents:
6857
diff
changeset
|
394 Vehicle *next = GetNextVehicle(u); |
7398
6324d82f421d
(svn r10770) -Codechange: use the pool item class as super class for the vehicle struct.
rubidium <rubidium@openttd.org>
parents:
7329
diff
changeset
|
395 delete u; |
6876
d73e7573898d
(svn r10117) -Fix [FS#863]: When deleting the vehicles of bankrupt players, delete trains as
maedhros <maedhros@openttd.org>
parents:
6857
diff
changeset
|
396 u = next; |
d73e7573898d
(svn r10117) -Fix [FS#863]: When deleting the vehicles of bankrupt players, delete trains as
maedhros <maedhros@openttd.org>
parents:
6857
diff
changeset
|
397 } while (u != NULL); |
d73e7573898d
(svn r10117) -Fix [FS#863]: When deleting the vehicles of bankrupt players, delete trains as
maedhros <maedhros@openttd.org>
parents:
6857
diff
changeset
|
398 } break; |
d73e7573898d
(svn r10117) -Fix [FS#863]: When deleting the vehicles of bankrupt players, delete trains as
maedhros <maedhros@openttd.org>
parents:
6857
diff
changeset
|
399 |
d73e7573898d
(svn r10117) -Fix [FS#863]: When deleting the vehicles of bankrupt players, delete trains as
maedhros <maedhros@openttd.org>
parents:
6857
diff
changeset
|
400 case VEH_ROAD: |
d73e7573898d
(svn r10117) -Fix [FS#863]: When deleting the vehicles of bankrupt players, delete trains as
maedhros <maedhros@openttd.org>
parents:
6857
diff
changeset
|
401 case VEH_SHIP: |
7398
6324d82f421d
(svn r10770) -Codechange: use the pool item class as super class for the vehicle struct.
rubidium <rubidium@openttd.org>
parents:
7329
diff
changeset
|
402 delete v; |
6876
d73e7573898d
(svn r10117) -Fix [FS#863]: When deleting the vehicles of bankrupt players, delete trains as
maedhros <maedhros@openttd.org>
parents:
6857
diff
changeset
|
403 break; |
d73e7573898d
(svn r10117) -Fix [FS#863]: When deleting the vehicles of bankrupt players, delete trains as
maedhros <maedhros@openttd.org>
parents:
6857
diff
changeset
|
404 |
d73e7573898d
(svn r10117) -Fix [FS#863]: When deleting the vehicles of bankrupt players, delete trains as
maedhros <maedhros@openttd.org>
parents:
6857
diff
changeset
|
405 case VEH_AIRCRAFT: |
d73e7573898d
(svn r10117) -Fix [FS#863]: When deleting the vehicles of bankrupt players, delete trains as
maedhros <maedhros@openttd.org>
parents:
6857
diff
changeset
|
406 DeleteVehicleChain(v); |
d73e7573898d
(svn r10117) -Fix [FS#863]: When deleting the vehicles of bankrupt players, delete trains as
maedhros <maedhros@openttd.org>
parents:
6857
diff
changeset
|
407 break; |
d73e7573898d
(svn r10117) -Fix [FS#863]: When deleting the vehicles of bankrupt players, delete trains as
maedhros <maedhros@openttd.org>
parents:
6857
diff
changeset
|
408 } |
d73e7573898d
(svn r10117) -Fix [FS#863]: When deleting the vehicles of bankrupt players, delete trains as
maedhros <maedhros@openttd.org>
parents:
6857
diff
changeset
|
409 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
410 } else { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
411 v->owner = new_player; |
8186
6d098ac32840
(svn r11749) -Fix (r11352): when a bankrupted company is bought, reset vehicle color mapping so the vehicles use the new owner color
glx <glx@openttd.org>
parents:
8157
diff
changeset
|
412 v->colormap = PAL_NONE; |
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
|
413 v->group_id = DEFAULT_GROUP; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
414 if (IsEngineCountable(v)) GetPlayer(new_player)->num_engines[v->engine_type]++; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
415 switch (v->type) { |
6259
4a39d6291d58
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium <rubidium@openttd.org>
parents:
6248
diff
changeset
|
416 case VEH_TRAIN: if (IsFrontEngine(v)) v->unitnumber = ++num_train; break; |
6857
0005a9ed1903
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros <maedhros@openttd.org>
parents:
6844
diff
changeset
|
417 case VEH_ROAD: if (IsRoadVehFront(v)) v->unitnumber = ++num_road; break; |
6259
4a39d6291d58
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium <rubidium@openttd.org>
parents:
6248
diff
changeset
|
418 case VEH_SHIP: v->unitnumber = ++num_ship; break; |
4a39d6291d58
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium <rubidium@openttd.org>
parents:
6248
diff
changeset
|
419 case VEH_AIRCRAFT: if (IsNormalAircraft(v)) v->unitnumber = ++num_aircraft; break; |
6621
c751437b3bac
(svn r9841) -Codechange: add a little more type strictness to the vehicle types.
rubidium <rubidium@openttd.org>
parents:
6620
diff
changeset
|
420 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
|
421 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
422 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
423 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
424 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
425 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
426 |
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
|
427 /* 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
|
428 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
429 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
|
430 do { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
431 ChangeTileOwner(tile, old_player, new_player); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
432 } while (++tile != MapSize()); |
8200
f7f49622b3e0
(svn r11763) -Fix: update signal states after merging a company
smatz <smatz@openttd.org>
parents:
8186
diff
changeset
|
433 |
f7f49622b3e0
(svn r11763) -Fix: update signal states after merging a company
smatz <smatz@openttd.org>
parents:
8186
diff
changeset
|
434 if (new_player != PLAYER_SPECTATOR) { |
f7f49622b3e0
(svn r11763) -Fix: update signal states after merging a company
smatz <smatz@openttd.org>
parents:
8186
diff
changeset
|
435 /* Update all signals because there can be new segment that was owned by two players |
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
|
436 * 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
|
437 * 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
|
438 * 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
|
439 tile = 0; |
f7f49622b3e0
(svn r11763) -Fix: update signal states after merging a company
smatz <smatz@openttd.org>
parents:
8186
diff
changeset
|
440 |
f7f49622b3e0
(svn r11763) -Fix: update signal states after merging a company
smatz <smatz@openttd.org>
parents:
8186
diff
changeset
|
441 do { |
f7f49622b3e0
(svn r11763) -Fix: update signal states after merging a company
smatz <smatz@openttd.org>
parents:
8186
diff
changeset
|
442 if (IsTileType(tile, MP_RAILWAY) && IsTileOwner(tile, new_player) && HasSignals(tile)) { |
f7f49622b3e0
(svn r11763) -Fix: update signal states after merging a company
smatz <smatz@openttd.org>
parents:
8186
diff
changeset
|
443 TrackBits tracks = GetTrackBits(tile); |
f7f49622b3e0
(svn r11763) -Fix: update signal states after merging a company
smatz <smatz@openttd.org>
parents:
8186
diff
changeset
|
444 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
|
445 Track track = RemoveFirstTrack(&tracks); |
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
|
446 if (HasSignalOnTrack(tile, track)) AddTrackToSignalBuffer(tile, track, new_player); |
8200
f7f49622b3e0
(svn r11763) -Fix: update signal states after merging a company
smatz <smatz@openttd.org>
parents:
8186
diff
changeset
|
447 } while (tracks != TRACK_BIT_NONE); |
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
|
448 } else if (IsLevelCrossingTile(tile) && IsTileOwner(tile, new_player)) { |
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
|
449 UpdateLevelCrossing(tile); |
8200
f7f49622b3e0
(svn r11763) -Fix: update signal states after merging a company
smatz <smatz@openttd.org>
parents:
8186
diff
changeset
|
450 } |
f7f49622b3e0
(svn r11763) -Fix: update signal states after merging a company
smatz <smatz@openttd.org>
parents:
8186
diff
changeset
|
451 } 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
|
452 } |
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
|
453 |
8347
a83dd50f52f9
(svn r11913) -Fix (r11871): update signals after company bankrupt and disaster too
smatz <smatz@openttd.org>
parents:
8342
diff
changeset
|
454 /* 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
|
455 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
|
456 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
457 |
9058
c73011639858
(svn r12906) -Fix: vehicle groups, engine replacement rules and player/company names were not properly reset/freed after bankrupt (before new player start)
smatz <smatz@openttd.org>
parents:
9043
diff
changeset
|
458 /* In all cases clear replace engine rules. |
c73011639858
(svn r12906) -Fix: vehicle groups, engine replacement rules and player/company names were not properly reset/freed after bankrupt (before new player start)
smatz <smatz@openttd.org>
parents:
9043
diff
changeset
|
459 * Even if it was copied, it could interfere with new owner's rules */ |
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
|
460 RemoveAllEngineReplacementForPlayer(GetPlayer(old_player)); |
c73011639858
(svn r12906) -Fix: vehicle groups, engine replacement rules and player/company names were not properly reset/freed after bankrupt (before new player start)
smatz <smatz@openttd.org>
parents:
9043
diff
changeset
|
461 |
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
|
462 if (new_player == PLAYER_SPECTATOR) { |
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
|
463 RemoveAllGroupsForPlayer(old_player); |
c73011639858
(svn r12906) -Fix: vehicle groups, engine replacement rules and player/company names were not properly reset/freed after bankrupt (before new player start)
smatz <smatz@openttd.org>
parents:
9043
diff
changeset
|
464 } else { |
c73011639858
(svn r12906) -Fix: vehicle groups, engine replacement rules and player/company names were not properly reset/freed after bankrupt (before new player start)
smatz <smatz@openttd.org>
parents:
9043
diff
changeset
|
465 Group *g; |
c73011639858
(svn r12906) -Fix: vehicle groups, engine replacement rules and player/company names were not properly reset/freed after bankrupt (before new player start)
smatz <smatz@openttd.org>
parents:
9043
diff
changeset
|
466 FOR_ALL_GROUPS(g) { |
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
|
467 if (g->owner == old_player) g->owner = new_player; |
c73011639858
(svn r12906) -Fix: vehicle groups, engine replacement rules and player/company names were not properly reset/freed after bankrupt (before new player start)
smatz <smatz@openttd.org>
parents:
9043
diff
changeset
|
468 } |
c73011639858
(svn r12906) -Fix: vehicle groups, engine replacement rules and player/company names were not properly reset/freed after bankrupt (before new player start)
smatz <smatz@openttd.org>
parents:
9043
diff
changeset
|
469 } |
c73011639858
(svn r12906) -Fix: vehicle groups, engine replacement rules and player/company names were not properly reset/freed after bankrupt (before new player start)
smatz <smatz@openttd.org>
parents:
9043
diff
changeset
|
470 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
471 /* Change color of existing windows */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
472 if (new_player != PLAYER_SPECTATOR) ChangeWindowOwner(old_player, new_player); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
473 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
474 _current_player = old; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
475 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
476 MarkWholeScreenDirty(); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
477 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
478 |
6262
a457647cd27d
(svn r9071) -Fix [FS#459]: when in networking an other player takes over an AI which is also controlled by a player, move the player with the company to the company who bought out the AI
truelight <truelight@openttd.org>
parents:
6259
diff
changeset
|
479 static void ChangeNetworkOwner(PlayerID current_player, PlayerID new_player) |
a457647cd27d
(svn r9071) -Fix [FS#459]: when in networking an other player takes over an AI which is also controlled by a player, move the player with the company to the company who bought out the AI
truelight <truelight@openttd.org>
parents:
6259
diff
changeset
|
480 { |
a457647cd27d
(svn r9071) -Fix [FS#459]: when in networking an other player takes over an AI which is also controlled by a player, move the player with the company to the company who bought out the AI
truelight <truelight@openttd.org>
parents:
6259
diff
changeset
|
481 #ifdef ENABLE_NETWORK |
a457647cd27d
(svn r9071) -Fix [FS#459]: when in networking an other player takes over an AI which is also controlled by a player, move the player with the company to the company who bought out the AI
truelight <truelight@openttd.org>
parents:
6259
diff
changeset
|
482 if (!_networking) return; |
a457647cd27d
(svn r9071) -Fix [FS#459]: when in networking an other player takes over an AI which is also controlled by a player, move the player with the company to the company who bought out the AI
truelight <truelight@openttd.org>
parents:
6259
diff
changeset
|
483 |
a457647cd27d
(svn r9071) -Fix [FS#459]: when in networking an other player takes over an AI which is also controlled by a player, move the player with the company to the company who bought out the AI
truelight <truelight@openttd.org>
parents:
6259
diff
changeset
|
484 if (current_player == _local_player) { |
a457647cd27d
(svn r9071) -Fix [FS#459]: when in networking an other player takes over an AI which is also controlled by a player, move the player with the company to the company who bought out the AI
truelight <truelight@openttd.org>
parents:
6259
diff
changeset
|
485 _network_playas = new_player; |
a457647cd27d
(svn r9071) -Fix [FS#459]: when in networking an other player takes over an AI which is also controlled by a player, move the player with the company to the company who bought out the AI
truelight <truelight@openttd.org>
parents:
6259
diff
changeset
|
486 SetLocalPlayer(new_player); |
a457647cd27d
(svn r9071) -Fix [FS#459]: when in networking an other player takes over an AI which is also controlled by a player, move the player with the company to the company who bought out the AI
truelight <truelight@openttd.org>
parents:
6259
diff
changeset
|
487 } |
a457647cd27d
(svn r9071) -Fix [FS#459]: when in networking an other player takes over an AI which is also controlled by a player, move the player with the company to the company who bought out the AI
truelight <truelight@openttd.org>
parents:
6259
diff
changeset
|
488 |
a457647cd27d
(svn r9071) -Fix [FS#459]: when in networking an other player takes over an AI which is also controlled by a player, move the player with the company to the company who bought out the AI
truelight <truelight@openttd.org>
parents:
6259
diff
changeset
|
489 if (!_network_server) return; |
a457647cd27d
(svn r9071) -Fix [FS#459]: when in networking an other player takes over an AI which is also controlled by a player, move the player with the company to the company who bought out the AI
truelight <truelight@openttd.org>
parents:
6259
diff
changeset
|
490 |
a457647cd27d
(svn r9071) -Fix [FS#459]: when in networking an other player takes over an AI which is also controlled by a player, move the player with the company to the company who bought out the AI
truelight <truelight@openttd.org>
parents:
6259
diff
changeset
|
491 /* The server has to handle all administrative issues, for example |
a457647cd27d
(svn r9071) -Fix [FS#459]: when in networking an other player takes over an AI which is also controlled by a player, move the player with the company to the company who bought out the AI
truelight <truelight@openttd.org>
parents:
6259
diff
changeset
|
492 * updating and notifying all clients of what has happened */ |
a457647cd27d
(svn r9071) -Fix [FS#459]: when in networking an other player takes over an AI which is also controlled by a player, move the player with the company to the company who bought out the AI
truelight <truelight@openttd.org>
parents:
6259
diff
changeset
|
493 NetworkTCPSocketHandler *cs; |
a457647cd27d
(svn r9071) -Fix [FS#459]: when in networking an other player takes over an AI which is also controlled by a player, move the player with the company to the company who bought out the AI
truelight <truelight@openttd.org>
parents:
6259
diff
changeset
|
494 NetworkClientInfo *ci = NetworkFindClientInfoFromIndex(NETWORK_SERVER_INDEX); |
a457647cd27d
(svn r9071) -Fix [FS#459]: when in networking an other player takes over an AI which is also controlled by a player, move the player with the company to the company who bought out the AI
truelight <truelight@openttd.org>
parents:
6259
diff
changeset
|
495 |
a457647cd27d
(svn r9071) -Fix [FS#459]: when in networking an other player takes over an AI which is also controlled by a player, move the player with the company to the company who bought out the AI
truelight <truelight@openttd.org>
parents:
6259
diff
changeset
|
496 /* The server has just changed from player */ |
a457647cd27d
(svn r9071) -Fix [FS#459]: when in networking an other player takes over an AI which is also controlled by a player, move the player with the company to the company who bought out the AI
truelight <truelight@openttd.org>
parents:
6259
diff
changeset
|
497 if (current_player == ci->client_playas) { |
a457647cd27d
(svn r9071) -Fix [FS#459]: when in networking an other player takes over an AI which is also controlled by a player, move the player with the company to the company who bought out the AI
truelight <truelight@openttd.org>
parents:
6259
diff
changeset
|
498 ci->client_playas = new_player; |
a457647cd27d
(svn r9071) -Fix [FS#459]: when in networking an other player takes over an AI which is also controlled by a player, move the player with the company to the company who bought out the AI
truelight <truelight@openttd.org>
parents:
6259
diff
changeset
|
499 NetworkUpdateClientInfo(NETWORK_SERVER_INDEX); |
a457647cd27d
(svn r9071) -Fix [FS#459]: when in networking an other player takes over an AI which is also controlled by a player, move the player with the company to the company who bought out the AI
truelight <truelight@openttd.org>
parents:
6259
diff
changeset
|
500 } |
a457647cd27d
(svn r9071) -Fix [FS#459]: when in networking an other player takes over an AI which is also controlled by a player, move the player with the company to the company who bought out the AI
truelight <truelight@openttd.org>
parents:
6259
diff
changeset
|
501 |
a457647cd27d
(svn r9071) -Fix [FS#459]: when in networking an other player takes over an AI which is also controlled by a player, move the player with the company to the company who bought out the AI
truelight <truelight@openttd.org>
parents:
6259
diff
changeset
|
502 /* Find all clients that were in control of this company, and mark them as new_player */ |
a457647cd27d
(svn r9071) -Fix [FS#459]: when in networking an other player takes over an AI which is also controlled by a player, move the player with the company to the company who bought out the AI
truelight <truelight@openttd.org>
parents:
6259
diff
changeset
|
503 FOR_ALL_CLIENTS(cs) { |
a457647cd27d
(svn r9071) -Fix [FS#459]: when in networking an other player takes over an AI which is also controlled by a player, move the player with the company to the company who bought out the AI
truelight <truelight@openttd.org>
parents:
6259
diff
changeset
|
504 ci = DEREF_CLIENT_INFO(cs); |
a457647cd27d
(svn r9071) -Fix [FS#459]: when in networking an other player takes over an AI which is also controlled by a player, move the player with the company to the company who bought out the AI
truelight <truelight@openttd.org>
parents:
6259
diff
changeset
|
505 if (current_player == ci->client_playas) { |
a457647cd27d
(svn r9071) -Fix [FS#459]: when in networking an other player takes over an AI which is also controlled by a player, move the player with the company to the company who bought out the AI
truelight <truelight@openttd.org>
parents:
6259
diff
changeset
|
506 ci->client_playas = new_player; |
a457647cd27d
(svn r9071) -Fix [FS#459]: when in networking an other player takes over an AI which is also controlled by a player, move the player with the company to the company who bought out the AI
truelight <truelight@openttd.org>
parents:
6259
diff
changeset
|
507 NetworkUpdateClientInfo(ci->client_index); |
a457647cd27d
(svn r9071) -Fix [FS#459]: when in networking an other player takes over an AI which is also controlled by a player, move the player with the company to the company who bought out the AI
truelight <truelight@openttd.org>
parents:
6259
diff
changeset
|
508 } |
a457647cd27d
(svn r9071) -Fix [FS#459]: when in networking an other player takes over an AI which is also controlled by a player, move the player with the company to the company who bought out the AI
truelight <truelight@openttd.org>
parents:
6259
diff
changeset
|
509 } |
a457647cd27d
(svn r9071) -Fix [FS#459]: when in networking an other player takes over an AI which is also controlled by a player, move the player with the company to the company who bought out the AI
truelight <truelight@openttd.org>
parents:
6259
diff
changeset
|
510 #endif /* ENABLE_NETWORK */ |
a457647cd27d
(svn r9071) -Fix [FS#459]: when in networking an other player takes over an AI which is also controlled by a player, move the player with the company to the company who bought out the AI
truelight <truelight@openttd.org>
parents:
6259
diff
changeset
|
511 } |
a457647cd27d
(svn r9071) -Fix [FS#459]: when in networking an other player takes over an AI which is also controlled by a player, move the player with the company to the company who bought out the AI
truelight <truelight@openttd.org>
parents:
6259
diff
changeset
|
512 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
513 static void PlayersCheckBankrupt(Player *p) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
514 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
515 PlayerID owner; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
516 |
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
|
517 /* If the player has money again, it does not go bankrupt */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
518 if (p->player_money >= 0) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
519 p->quarters_of_bankrupcy = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
520 return; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
521 } |
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 p->quarters_of_bankrupcy++; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
524 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
525 owner = p->index; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
526 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
527 switch (p->quarters_of_bankrupcy) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
528 case 2: |
9199
dbe675dc54c4
(svn r13065) -Codechange: remove the need for the news string callbacks. Patch by Cirdan.
rubidium <rubidium@openttd.org>
parents:
9158
diff
changeset
|
529 SetDParam(0, STR_7056_TRANSPORT_COMPANY_IN_TROUBLE); |
dbe675dc54c4
(svn r13065) -Codechange: remove the need for the news string callbacks. Patch by Cirdan.
rubidium <rubidium@openttd.org>
parents:
9158
diff
changeset
|
530 SetDParam(1, STR_7057_WILL_BE_SOLD_OFF_OR_DECLARED); |
dbe675dc54c4
(svn r13065) -Codechange: remove the need for the news string callbacks. Patch by Cirdan.
rubidium <rubidium@openttd.org>
parents:
9158
diff
changeset
|
531 SetDParam(2, owner); |
9257
2216e638534b
(svn r13123) -Codechange: passing the bankrupt type via data_b is not needed anymore. Patch by Cirdan.
rubidium <rubidium@openttd.org>
parents:
9236
diff
changeset
|
532 AddNewsItem(STR_02B6, NS_COMPANY_TROUBLE, 0, 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
|
533 break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
534 case 3: { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
535 /* XXX - In multiplayer, should we ask other players if it wants to take |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
536 over when it is a human company? -- TrueLight */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
537 if (IsHumanPlayer(owner)) { |
9199
dbe675dc54c4
(svn r13065) -Codechange: remove the need for the news string callbacks. Patch by Cirdan.
rubidium <rubidium@openttd.org>
parents:
9158
diff
changeset
|
538 SetDParam(0, STR_7056_TRANSPORT_COMPANY_IN_TROUBLE); |
dbe675dc54c4
(svn r13065) -Codechange: remove the need for the news string callbacks. Patch by Cirdan.
rubidium <rubidium@openttd.org>
parents:
9158
diff
changeset
|
539 SetDParam(1, STR_7057_WILL_BE_SOLD_OFF_OR_DECLARED); |
dbe675dc54c4
(svn r13065) -Codechange: remove the need for the news string callbacks. Patch by Cirdan.
rubidium <rubidium@openttd.org>
parents:
9158
diff
changeset
|
540 SetDParam(2, owner); |
9257
2216e638534b
(svn r13123) -Codechange: passing the bankrupt type via data_b is not needed anymore. Patch by Cirdan.
rubidium <rubidium@openttd.org>
parents:
9236
diff
changeset
|
541 AddNewsItem(STR_02B6, NS_COMPANY_TROUBLE, 0, 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
|
542 break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
543 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
544 |
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
|
545 /* 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
|
546 * right now */ |
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
|
547 Money val = CalculateCompanyValue(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
|
548 if (val > 0) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
549 p->bankrupt_value = val; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
550 p->bankrupt_asked = 1 << owner; // Don't ask the owner |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
551 p->bankrupt_timeout = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
552 break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
553 } |
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
|
554 /* Else, falltrue 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
|
555 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
556 case 4: { |
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
|
557 /* Close everything the owner has open */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
558 DeletePlayerWindows(owner); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
559 |
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
|
560 /* Show bankrupt news */ |
9199
dbe675dc54c4
(svn r13065) -Codechange: remove the need for the news string callbacks. Patch by Cirdan.
rubidium <rubidium@openttd.org>
parents:
9158
diff
changeset
|
561 SetDParam(0, STR_705C_BANKRUPT); |
dbe675dc54c4
(svn r13065) -Codechange: remove the need for the news string callbacks. Patch by Cirdan.
rubidium <rubidium@openttd.org>
parents:
9158
diff
changeset
|
562 SetDParam(1, STR_705D_HAS_BEEN_CLOSED_DOWN_BY); |
dbe675dc54c4
(svn r13065) -Codechange: remove the need for the news string callbacks. Patch by Cirdan.
rubidium <rubidium@openttd.org>
parents:
9158
diff
changeset
|
563 SetDParam(2, p->index); |
9257
2216e638534b
(svn r13123) -Codechange: passing the bankrupt type via data_b is not needed anymore. Patch by Cirdan.
rubidium <rubidium@openttd.org>
parents:
9236
diff
changeset
|
564 AddNewsItem(STR_02B6, NS_COMPANY_BANKRUPT, 0, 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
|
565 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
566 if (IsHumanPlayer(owner)) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
567 /* XXX - If we are in offline mode, leave the player playing. Eg. there |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
568 * is no THE-END, otherwise mark the player as spectator to make sure |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
569 * he/she is no long in control of this company */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
570 if (!_networking) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
571 p->bankrupt_asked = 0xFF; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
572 p->bankrupt_timeout = 0x456; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
573 break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
574 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
575 |
6262
a457647cd27d
(svn r9071) -Fix [FS#459]: when in networking an other player takes over an AI which is also controlled by a player, move the player with the company to the company who bought out the AI
truelight <truelight@openttd.org>
parents:
6259
diff
changeset
|
576 ChangeNetworkOwner(owner, PLAYER_SPECTATOR); |
5584
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 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
579 /* Remove the player */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
580 ChangeOwnershipOfPlayerItems(owner, PLAYER_SPECTATOR); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
581 /* Register the player as not-active */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
582 p->is_active = false; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
583 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
584 if (!IsHumanPlayer(owner) && (!_networking || _network_server) && _ai.enabled) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
585 AI_PlayerDied(owner); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
586 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
587 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
588 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
589 |
6247
57363e064324
(svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents:
6227
diff
changeset
|
590 static void PlayersGenStatistics() |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
591 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
592 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
|
593 Player *p; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
594 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
595 FOR_ALL_STATIONS(st) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
596 _current_player = st->owner; |
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
|
597 CommandCost cost(EXPENSES_PROPERTY, _price.station_value >> 1); |
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
|
598 SubtractMoneyFromPlayer(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
|
599 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
600 |
7928
4e8dfd103163
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7926
diff
changeset
|
601 if (!HasBit(1<<0|1<<3|1<<6|1<<9, _cur_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
|
602 return; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
603 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
604 FOR_ALL_PLAYERS(p) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
605 if (p->is_active) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
606 memmove(&p->old_economy[1], &p->old_economy[0], sizeof(p->old_economy) - sizeof(p->old_economy[0])); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
607 p->old_economy[0] = p->cur_economy; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
608 memset(&p->cur_economy, 0, sizeof(p->cur_economy)); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
609 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
610 if (p->num_valid_stat_ent != 24) p->num_valid_stat_ent++; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
611 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
612 UpdateCompanyRatingAndValue(p, true); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
613 PlayersCheckBankrupt(p); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
614 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
615 if (p->block_preview != 0) p->block_preview--; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
616 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
617 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
618 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
619 InvalidateWindow(WC_INCOME_GRAPH, 0); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
620 InvalidateWindow(WC_OPERATING_PROFIT, 0); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
621 InvalidateWindow(WC_DELIVERED_CARGO, 0); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
622 InvalidateWindow(WC_PERFORMANCE_HISTORY, 0); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
623 InvalidateWindow(WC_COMPANY_VALUE, 0); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
624 InvalidateWindow(WC_COMPANY_LEAGUE, 0); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
625 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
626 |
6953
41fd36025784
(svn r10208) -Codechange: replace int32 with Money where appropriate.
rubidium <rubidium@openttd.org>
parents:
6952
diff
changeset
|
627 static void AddSingleInflation(Money *value, uint16 *frac, int32 amt) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
628 { |
6953
41fd36025784
(svn r10208) -Codechange: replace int32 with Money where appropriate.
rubidium <rubidium@openttd.org>
parents:
6952
diff
changeset
|
629 /* Is it safe to add inflation ? */ |
6957
d2ef90986630
(svn r10212) -Fix [FS#723]: money overflow bugs in many locations.
rubidium <rubidium@openttd.org>
parents:
6955
diff
changeset
|
630 if ((INT64_MAX / amt) < (*value + 1)) { |
d2ef90986630
(svn r10212) -Fix [FS#723]: money overflow bugs in many locations.
rubidium <rubidium@openttd.org>
parents:
6955
diff
changeset
|
631 *value = INT64_MAX / amt; |
6953
41fd36025784
(svn r10208) -Codechange: replace int32 with Money where appropriate.
rubidium <rubidium@openttd.org>
parents:
6952
diff
changeset
|
632 *frac = 0; |
41fd36025784
(svn r10208) -Codechange: replace int32 with Money where appropriate.
rubidium <rubidium@openttd.org>
parents:
6952
diff
changeset
|
633 } else { |
41fd36025784
(svn r10208) -Codechange: replace int32 with Money where appropriate.
rubidium <rubidium@openttd.org>
parents:
6952
diff
changeset
|
634 int64 tmp = (int64)*value * amt + *frac; |
41fd36025784
(svn r10208) -Codechange: replace int32 with Money where appropriate.
rubidium <rubidium@openttd.org>
parents:
6952
diff
changeset
|
635 *frac = GB(tmp, 0, 16); |
41fd36025784
(svn r10208) -Codechange: replace int32 with Money where appropriate.
rubidium <rubidium@openttd.org>
parents:
6952
diff
changeset
|
636 *value += tmp >> 16; |
41fd36025784
(svn r10208) -Codechange: replace int32 with Money where appropriate.
rubidium <rubidium@openttd.org>
parents:
6952
diff
changeset
|
637 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
638 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
639 |
6247
57363e064324
(svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents:
6227
diff
changeset
|
640 static void AddInflation() |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
641 { |
7244
00f3d8da22e4
(svn r10541) -Fix [FS#1028]: cargo payment rates overflow.
rubidium <rubidium@openttd.org>
parents:
7229
diff
changeset
|
642 /* 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
|
643 * 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
|
644 * 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
|
645 * 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
|
646 * the minimum running cost. |
00f3d8da22e4
(svn r10541) -Fix [FS#1028]: cargo payment rates overflow.
rubidium <rubidium@openttd.org>
parents:
7229
diff
changeset
|
647 * |
00f3d8da22e4
(svn r10541) -Fix [FS#1028]: cargo payment rates overflow.
rubidium <rubidium@openttd.org>
parents:
7229
diff
changeset
|
648 * 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
|
649 * 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
|
650 * 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
|
651 * 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
|
652 * 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
|
653 * 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
|
654 * 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
|
655 * 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
|
656 */ |
00f3d8da22e4
(svn r10541) -Fix [FS#1028]: cargo payment rates overflow.
rubidium <rubidium@openttd.org>
parents:
7229
diff
changeset
|
657 if ((_cur_year - _patches.starting_year) >= (ORIGINAL_MAX_YEAR - ORIGINAL_BASE_YEAR)) return; |
00f3d8da22e4
(svn r10541) -Fix [FS#1028]: cargo payment rates overflow.
rubidium <rubidium@openttd.org>
parents:
7229
diff
changeset
|
658 |
6119 | 659 /* Approximation for (100 + infl_amount)% ** (1 / 12) - 100% |
660 * scaled by 65536 | |
661 * 12 -> months per year | |
662 * This is only a good approxiamtion for small values | |
663 */ | |
6953
41fd36025784
(svn r10208) -Codechange: replace int32 with Money where appropriate.
rubidium <rubidium@openttd.org>
parents:
6952
diff
changeset
|
664 Money inf = _economy.infl_amount * 54; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
665 |
6119 | 666 for (uint i = 0; i != NUM_PRICES; i++) { |
6953
41fd36025784
(svn r10208) -Codechange: replace int32 with Money where appropriate.
rubidium <rubidium@openttd.org>
parents:
6952
diff
changeset
|
667 AddSingleInflation((Money*)&_price + i, _price_frac + i, inf); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
668 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
669 |
7244
00f3d8da22e4
(svn r10541) -Fix [FS#1028]: cargo payment rates overflow.
rubidium <rubidium@openttd.org>
parents:
7229
diff
changeset
|
670 AddSingleInflation(&_economy.max_loan_unround, &_economy.max_loan_unround_fract, inf); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
671 |
7244
00f3d8da22e4
(svn r10541) -Fix [FS#1028]: cargo payment rates overflow.
rubidium <rubidium@openttd.org>
parents:
7229
diff
changeset
|
672 if (_economy.max_loan + 50000 <= _economy.max_loan_unround) _economy.max_loan += 50000; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
673 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
674 inf = _economy.infl_amount_pr * 54; |
6350
8132258640be
(svn r9388) -Codechange: variable scope and type, and standardify all CargoID loops.
peter1138 <peter1138@openttd.org>
parents:
6315
diff
changeset
|
675 for (CargoID i = 0; i < NUM_CARGO; i++) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
676 AddSingleInflation( |
6953
41fd36025784
(svn r10208) -Codechange: replace int32 with Money where appropriate.
rubidium <rubidium@openttd.org>
parents:
6952
diff
changeset
|
677 (Money*)_cargo_payment_rates + i, |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
678 _cargo_payment_rates_frac + i, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
679 inf |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
680 ); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
681 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
682 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
683 InvalidateWindowClasses(WC_BUILD_VEHICLE); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
684 InvalidateWindowClasses(WC_REPLACE_VEHICLE); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
685 InvalidateWindowClasses(WC_VEHICLE_DETAILS); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
686 InvalidateWindow(WC_PAYMENT_RATES, 0); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
687 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
688 |
6247
57363e064324
(svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents:
6227
diff
changeset
|
689 static void PlayersPayInterest() |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
690 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
691 const Player* p; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
692 int interest = _economy.interest_rate * 54; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
693 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
694 FOR_ALL_PLAYERS(p) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
695 if (!p->is_active) continue; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
696 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
697 _current_player = p->index; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
698 |
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
|
699 SubtractMoneyFromPlayer(CommandCost(EXPENSES_LOAN_INT, (Money)BigMulSU(p->current_loan, interest, 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
|
700 |
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
|
701 SubtractMoneyFromPlayer(CommandCost(EXPENSES_OTHER, _price.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
|
702 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
703 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
704 |
6247
57363e064324
(svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents:
6227
diff
changeset
|
705 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
|
706 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
707 if (_opt.diff.economy == 0) return; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
708 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
709 if (--_economy.fluct == 0) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
710 _economy.fluct = -(int)GB(Random(), 0, 2); |
9234
02827bf3dc03
(svn r13100) -Codechange: reduce the amount of parameters passed via AddNewsMessage as there is (for each news message type) a tuple of 4 parameters that is the same for all calls.
rubidium <rubidium@openttd.org>
parents:
9199
diff
changeset
|
711 AddNewsItem(STR_7073_WORLD_RECESSION_FINANCIAL, NS_ECONOMY, 0, 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
|
712 } 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
|
713 _economy.fluct = GB(Random(), 0, 8) + 312; |
9234
02827bf3dc03
(svn r13100) -Codechange: reduce the amount of parameters passed via AddNewsMessage as there is (for each news message type) a tuple of 4 parameters that is the same for all calls.
rubidium <rubidium@openttd.org>
parents:
9199
diff
changeset
|
714 AddNewsItem(STR_7074_RECESSION_OVER_UPTURN_IN, NS_ECONOMY, 0, 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
|
715 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
716 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
717 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
718 static byte _price_category[NUM_PRICES] = { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
719 0, 2, 2, 2, 2, 2, 2, 2, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
720 2, 2, 2, 2, 2, 2, 2, 2, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
721 2, 2, 2, 2, 2, 2, 2, 2, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
722 2, 2, 2, 2, 2, 2, 2, 2, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
723 2, 2, 2, 2, 2, 2, 2, 2, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
724 2, 2, 1, 1, 1, 1, 1, 1, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
725 2, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
726 }; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
727 |
6953
41fd36025784
(svn r10208) -Codechange: replace int32 with Money where appropriate.
rubidium <rubidium@openttd.org>
parents:
6952
diff
changeset
|
728 static const Money _price_base[NUM_PRICES] = { |
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
|
729 100, ///< station_value |
46d001ebacf6
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents:
6119
diff
changeset
|
730 100, ///< build_rail |
46d001ebacf6
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents:
6119
diff
changeset
|
731 95, ///< build_road |
46d001ebacf6
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents:
6119
diff
changeset
|
732 65, ///< build_signals |
46d001ebacf6
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents:
6119
diff
changeset
|
733 275, ///< build_bridge |
46d001ebacf6
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents:
6119
diff
changeset
|
734 600, ///< build_train_depot |
46d001ebacf6
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents:
6119
diff
changeset
|
735 500, ///< build_road_depot |
46d001ebacf6
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents:
6119
diff
changeset
|
736 700, ///< build_ship_depot |
46d001ebacf6
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents:
6119
diff
changeset
|
737 450, ///< build_tunnel |
46d001ebacf6
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents:
6119
diff
changeset
|
738 200, ///< train_station_track |
46d001ebacf6
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents:
6119
diff
changeset
|
739 180, ///< train_station_length |
46d001ebacf6
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents:
6119
diff
changeset
|
740 600, ///< build_airport |
46d001ebacf6
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents:
6119
diff
changeset
|
741 200, ///< build_bus_station |
46d001ebacf6
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents:
6119
diff
changeset
|
742 200, ///< build_truck_station |
46d001ebacf6
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents:
6119
diff
changeset
|
743 350, ///< build_dock |
46d001ebacf6
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents:
6119
diff
changeset
|
744 400000, ///< build_railvehicle |
46d001ebacf6
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents:
6119
diff
changeset
|
745 2000, ///< build_railwagon |
46d001ebacf6
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents:
6119
diff
changeset
|
746 700000, ///< aircraft_base |
46d001ebacf6
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents:
6119
diff
changeset
|
747 14000, ///< roadveh_base |
46d001ebacf6
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents:
6119
diff
changeset
|
748 65000, ///< ship_base |
46d001ebacf6
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents:
6119
diff
changeset
|
749 20, ///< build_trees |
46d001ebacf6
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents:
6119
diff
changeset
|
750 250, ///< terraform |
7977
6035dbaf9329
(svn r11533) -Codechange: Rename some unclear clear_x prices member names.
belugas <belugas@openttd.org>
parents:
7967
diff
changeset
|
751 20, ///< clear_grass |
6035dbaf9329
(svn r11533) -Codechange: Rename some unclear clear_x prices member names.
belugas <belugas@openttd.org>
parents:
7967
diff
changeset
|
752 40, ///< clear_roughland |
6035dbaf9329
(svn r11533) -Codechange: Rename some unclear clear_x prices member names.
belugas <belugas@openttd.org>
parents:
7967
diff
changeset
|
753 200, ///< clear_rocks |
6035dbaf9329
(svn r11533) -Codechange: Rename some unclear clear_x prices member names.
belugas <belugas@openttd.org>
parents:
7967
diff
changeset
|
754 500, ///< clear_fields |
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
|
755 20, ///< remove_trees |
46d001ebacf6
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents:
6119
diff
changeset
|
756 -70, ///< remove_rail |
46d001ebacf6
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents:
6119
diff
changeset
|
757 10, ///< remove_signals |
46d001ebacf6
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents:
6119
diff
changeset
|
758 50, ///< clear_bridge |
46d001ebacf6
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents:
6119
diff
changeset
|
759 80, ///< remove_train_depot |
46d001ebacf6
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents:
6119
diff
changeset
|
760 80, ///< remove_road_depot |
46d001ebacf6
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents:
6119
diff
changeset
|
761 90, ///< remove_ship_depot |
46d001ebacf6
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents:
6119
diff
changeset
|
762 30, ///< clear_tunnel |
46d001ebacf6
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents:
6119
diff
changeset
|
763 10000, ///< clear_water |
46d001ebacf6
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents:
6119
diff
changeset
|
764 50, ///< remove_rail_station |
46d001ebacf6
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents:
6119
diff
changeset
|
765 30, ///< remove_airport |
46d001ebacf6
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents:
6119
diff
changeset
|
766 50, ///< remove_bus_station |
46d001ebacf6
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents:
6119
diff
changeset
|
767 50, ///< remove_truck_station |
46d001ebacf6
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents:
6119
diff
changeset
|
768 55, ///< remove_dock |
46d001ebacf6
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents:
6119
diff
changeset
|
769 1600, ///< remove_house |
46d001ebacf6
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents:
6119
diff
changeset
|
770 40, ///< remove_road |
8624
707304c7c1fa
(svn r12207) -Change: rail running costs are engine class, not rail type
peter1138 <peter1138@openttd.org>
parents:
8614
diff
changeset
|
771 5600, ///< running_rail[0] steam |
707304c7c1fa
(svn r12207) -Change: rail running costs are engine class, not rail type
peter1138 <peter1138@openttd.org>
parents:
8614
diff
changeset
|
772 5200, ///< running_rail[1] diesel |
707304c7c1fa
(svn r12207) -Change: rail running costs are engine class, not rail type
peter1138 <peter1138@openttd.org>
parents:
8614
diff
changeset
|
773 4800, ///< running_rail[2] electric |
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
|
774 9600, ///< aircraft_running |
46d001ebacf6
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents:
6119
diff
changeset
|
775 1600, ///< roadveh_running |
46d001ebacf6
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents:
6119
diff
changeset
|
776 5600, ///< ship_running |
46d001ebacf6
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents:
6119
diff
changeset
|
777 1000000, ///< build_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
|
778 }; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
779 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
780 static byte price_base_multiplier[NUM_PRICES]; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
781 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
782 /** |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
783 * 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
|
784 */ |
6247
57363e064324
(svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents:
6227
diff
changeset
|
785 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
|
786 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
787 uint i; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
788 |
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
|
789 /* 8 means no 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
|
790 for (i = 0; i < NUM_PRICES; i++) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
791 price_base_multiplier[i] = 8; |
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 * Change a price base by the given factor. |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
796 * The price base is altered by factors of two, with an offset of 8. |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
797 * NewBaseCost = OldBaseCost * 2^(n-8) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
798 * @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
|
799 * @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
|
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 void SetPriceBaseMultiplier(uint price, byte factor) |
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 assert(price < NUM_PRICES); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
804 price_base_multiplier[price] = factor; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
805 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
806 |
6247
57363e064324
(svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents:
6227
diff
changeset
|
807 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
|
808 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
809 int i; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
810 |
6953
41fd36025784
(svn r10208) -Codechange: replace int32 with Money where appropriate.
rubidium <rubidium@openttd.org>
parents:
6952
diff
changeset
|
811 assert(sizeof(_price) == NUM_PRICES * sizeof(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
|
812 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
813 for (i = 0; i != NUM_PRICES; i++) { |
6953
41fd36025784
(svn r10208) -Codechange: replace int32 with Money where appropriate.
rubidium <rubidium@openttd.org>
parents:
6952
diff
changeset
|
814 Money price = _price_base[i]; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
815 if (_price_category[i] != 0) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
816 uint mod = _price_category[i] == 1 ? _opt.diff.vehicle_costs : _opt.diff.construction_cost; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
817 if (mod < 1) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
818 price = price * 3 >> 2; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
819 } else if (mod > 1) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
820 price = price * 9 >> 3; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
821 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
822 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
823 if (price_base_multiplier[i] > 8) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
824 price <<= price_base_multiplier[i] - 8; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
825 } else { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
826 price >>= 8 - price_base_multiplier[i]; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
827 } |
6953
41fd36025784
(svn r10208) -Codechange: replace int32 with Money where appropriate.
rubidium <rubidium@openttd.org>
parents:
6952
diff
changeset
|
828 ((Money*)&_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
|
829 _price_frac[i] = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
830 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
831 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
832 _economy.interest_rate = _opt.diff.initial_interest; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
833 _economy.infl_amount = _opt.diff.initial_interest; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
834 _economy.infl_amount_pr = max(0, _opt.diff.initial_interest - 1); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
835 _economy.max_loan_unround = _economy.max_loan = _opt.diff.max_loan * 1000; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
836 _economy.fluct = GB(Random(), 0, 8) + 168; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
837 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
838 |
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
|
839 |
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
|
840 Money GetPriceByIndex(uint8 index) |
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
|
841 { |
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
|
842 if (index > NUM_PRICES) return 0; |
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
|
843 |
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
|
844 return ((Money*)&_price)[index]; |
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
|
845 } |
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
|
846 |
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
|
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 Pair SetupSubsidyDecodeParam(const Subsidy* s, bool mode) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
849 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
850 TileIndex tile; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
851 TileIndex tile2; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
852 Pair tp; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
853 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
854 /* if mode is false, use the singular form */ |
6091
17ebeb5a2c37
(svn r8826) -Codechange: Replace _cargoc's separate arrays with a regular struct array (with accessor) and implement new initialization method using cargo labels.
peter1138 <peter1138@openttd.org>
parents:
5998
diff
changeset
|
855 const CargoSpec *cs = GetCargo(s->cargo_type); |
7287
93dc4159295a
(svn r10628) -Fix (r10606,FS#1055): Revert r10606 and fix the plural problem another way.
peter1138 <peter1138@openttd.org>
parents:
7266
diff
changeset
|
856 SetDParam(0, mode ? cs->name : cs->name_single); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
857 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
858 if (s->age < 12) { |
6315
6089c21d196c
(svn r9257) -Codechange: Use cargo's town effect property for determining subsidy source/target type.
peter1138 <peter1138@openttd.org>
parents:
6262
diff
changeset
|
859 if (cs->town_effect != TE_PASSENGERS && cs->town_effect != TE_MAIL) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
860 SetDParam(1, STR_INDUSTRY); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
861 SetDParam(2, s->from); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
862 tile = GetIndustry(s->from)->xy; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
863 |
6315
6089c21d196c
(svn r9257) -Codechange: Use cargo's town effect property for determining subsidy source/target type.
peter1138 <peter1138@openttd.org>
parents:
6262
diff
changeset
|
864 if (cs->town_effect != TE_GOODS && cs->town_effect != TE_FOOD) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
865 SetDParam(4, STR_INDUSTRY); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
866 SetDParam(5, s->to); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
867 tile2 = GetIndustry(s->to)->xy; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
868 } else { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
869 SetDParam(4, STR_TOWN); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
870 SetDParam(5, s->to); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
871 tile2 = GetTown(s->to)->xy; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
872 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
873 } else { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
874 SetDParam(1, STR_TOWN); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
875 SetDParam(2, s->from); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
876 tile = GetTown(s->from)->xy; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
877 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
878 SetDParam(4, STR_TOWN); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
879 SetDParam(5, s->to); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
880 tile2 = GetTown(s->to)->xy; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
881 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
882 } else { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
883 SetDParam(1, s->from); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
884 tile = GetStation(s->from)->xy; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
885 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
886 SetDParam(2, s->to); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
887 tile2 = GetStation(s->to)->xy; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
888 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
889 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
890 tp.a = tile; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
891 tp.b = tile2; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
892 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
893 return tp; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
894 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
895 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
896 void DeleteSubsidyWithTown(TownID index) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
897 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
898 Subsidy *s; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
899 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
900 for (s = _subsidies; s != endof(_subsidies); s++) { |
6315
6089c21d196c
(svn r9257) -Codechange: Use cargo's town effect property for determining subsidy source/target type.
peter1138 <peter1138@openttd.org>
parents:
6262
diff
changeset
|
901 if (s->cargo_type != CT_INVALID && s->age < 12) { |
6089c21d196c
(svn r9257) -Codechange: Use cargo's town effect property for determining subsidy source/target type.
peter1138 <peter1138@openttd.org>
parents:
6262
diff
changeset
|
902 const CargoSpec *cs = GetCargo(s->cargo_type); |
6089c21d196c
(svn r9257) -Codechange: Use cargo's town effect property for determining subsidy source/target type.
peter1138 <peter1138@openttd.org>
parents:
6262
diff
changeset
|
903 if (((cs->town_effect == TE_PASSENGERS || cs->town_effect == TE_MAIL) && (index == s->from || index == s->to)) || |
6089c21d196c
(svn r9257) -Codechange: Use cargo's town effect property for determining subsidy source/target type.
peter1138 <peter1138@openttd.org>
parents:
6262
diff
changeset
|
904 ((cs->town_effect == TE_GOODS || cs->town_effect == TE_FOOD) && index == s->to)) { |
6089c21d196c
(svn r9257) -Codechange: Use cargo's town effect property for determining subsidy source/target type.
peter1138 <peter1138@openttd.org>
parents:
6262
diff
changeset
|
905 s->cargo_type = CT_INVALID; |
6089c21d196c
(svn r9257) -Codechange: Use cargo's town effect property for determining subsidy source/target type.
peter1138 <peter1138@openttd.org>
parents:
6262
diff
changeset
|
906 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
907 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
908 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
909 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
910 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
911 void DeleteSubsidyWithIndustry(IndustryID index) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
912 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
913 Subsidy *s; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
914 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
915 for (s = _subsidies; s != endof(_subsidies); s++) { |
6315
6089c21d196c
(svn r9257) -Codechange: Use cargo's town effect property for determining subsidy source/target type.
peter1138 <peter1138@openttd.org>
parents:
6262
diff
changeset
|
916 if (s->cargo_type != CT_INVALID && s->age < 12) { |
6089c21d196c
(svn r9257) -Codechange: Use cargo's town effect property for determining subsidy source/target type.
peter1138 <peter1138@openttd.org>
parents:
6262
diff
changeset
|
917 const CargoSpec *cs = GetCargo(s->cargo_type); |
6089c21d196c
(svn r9257) -Codechange: Use cargo's town effect property for determining subsidy source/target type.
peter1138 <peter1138@openttd.org>
parents:
6262
diff
changeset
|
918 if (cs->town_effect != TE_PASSENGERS && cs->town_effect != TE_MAIL && |
6089c21d196c
(svn r9257) -Codechange: Use cargo's town effect property for determining subsidy source/target type.
peter1138 <peter1138@openttd.org>
parents:
6262
diff
changeset
|
919 (index == s->from || (cs->town_effect != TE_GOODS && cs->town_effect != TE_FOOD && index == s->to))) { |
6089c21d196c
(svn r9257) -Codechange: Use cargo's town effect property for determining subsidy source/target type.
peter1138 <peter1138@openttd.org>
parents:
6262
diff
changeset
|
920 s->cargo_type = CT_INVALID; |
6089c21d196c
(svn r9257) -Codechange: Use cargo's town effect property for determining subsidy source/target type.
peter1138 <peter1138@openttd.org>
parents:
6262
diff
changeset
|
921 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
922 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
923 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
924 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
925 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
926 void DeleteSubsidyWithStation(StationID index) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
927 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
928 Subsidy *s; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
929 bool dirty = false; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
930 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
931 for (s = _subsidies; s != endof(_subsidies); s++) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
932 if (s->cargo_type != CT_INVALID && s->age >= 12 && |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
933 (s->from == index || s->to == index)) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
934 s->cargo_type = CT_INVALID; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
935 dirty = true; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
936 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
937 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
938 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
939 if (dirty) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
940 InvalidateWindow(WC_SUBSIDIES_LIST, 0); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
941 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
942 |
6248
0789677a15a0
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium <rubidium@openttd.org>
parents:
6247
diff
changeset
|
943 struct FoundRoute { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
944 uint distance; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
945 CargoID cargo; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
946 void *from; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
947 void *to; |
6248
0789677a15a0
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium <rubidium@openttd.org>
parents:
6247
diff
changeset
|
948 }; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
949 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
950 static void FindSubsidyPassengerRoute(FoundRoute *fr) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
951 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
952 Town *from,*to; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
953 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
954 fr->distance = (uint)-1; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
955 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
956 fr->from = from = GetRandomTown(); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
957 if (from == NULL || from->population < 400) return; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
958 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
959 fr->to = to = GetRandomTown(); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
960 if (from == to || to == NULL || to->population < 400 || to->pct_pass_transported > 42) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
961 return; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
962 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
963 fr->distance = DistanceManhattan(from->xy, to->xy); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
964 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
965 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
966 static void FindSubsidyCargoRoute(FoundRoute *fr) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
967 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
968 Industry *i; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
969 int trans, total; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
970 CargoID cargo; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
971 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
972 fr->distance = (uint)-1; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
973 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
974 fr->from = i = GetRandomIndustry(); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
975 if (i == NULL) return; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
976 |
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
|
977 /* Randomize cargo type */ |
7928
4e8dfd103163
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7926
diff
changeset
|
978 if (HasBit(Random(), 0) && i->produced_cargo[1] != CT_INVALID) { |
7645
5178857fa331
(svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx <glx@openttd.org>
parents:
7642
diff
changeset
|
979 cargo = i->produced_cargo[1]; |
6819
ffc184231f4a
(svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium <rubidium@openttd.org>
parents:
6773
diff
changeset
|
980 trans = i->last_month_pct_transported[1]; |
ffc184231f4a
(svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium <rubidium@openttd.org>
parents:
6773
diff
changeset
|
981 total = i->last_month_production[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
|
982 } else { |
7645
5178857fa331
(svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx <glx@openttd.org>
parents:
7642
diff
changeset
|
983 cargo = i->produced_cargo[0]; |
6819
ffc184231f4a
(svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium <rubidium@openttd.org>
parents:
6773
diff
changeset
|
984 trans = i->last_month_pct_transported[0]; |
ffc184231f4a
(svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium <rubidium@openttd.org>
parents:
6773
diff
changeset
|
985 total = i->last_month_production[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
|
986 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
987 |
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
|
988 /* Quit if no production in this industry |
46d001ebacf6
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents:
6119
diff
changeset
|
989 * or if the cargo type is passengers |
46d001ebacf6
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents:
6119
diff
changeset
|
990 * or if the pct transported is already large enough */ |
6315
6089c21d196c
(svn r9257) -Codechange: Use cargo's town effect property for determining subsidy source/target type.
peter1138 <peter1138@openttd.org>
parents:
6262
diff
changeset
|
991 if (total == 0 || trans > 42 || cargo == CT_INVALID) return; |
6089c21d196c
(svn r9257) -Codechange: Use cargo's town effect property for determining subsidy source/target type.
peter1138 <peter1138@openttd.org>
parents:
6262
diff
changeset
|
992 |
6089c21d196c
(svn r9257) -Codechange: Use cargo's town effect property for determining subsidy source/target type.
peter1138 <peter1138@openttd.org>
parents:
6262
diff
changeset
|
993 const CargoSpec *cs = GetCargo(cargo); |
6089c21d196c
(svn r9257) -Codechange: Use cargo's town effect property for determining subsidy source/target type.
peter1138 <peter1138@openttd.org>
parents:
6262
diff
changeset
|
994 if (cs->town_effect == TE_PASSENGERS) 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
|
995 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
996 fr->cargo = cargo; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
997 |
6315
6089c21d196c
(svn r9257) -Codechange: Use cargo's town effect property for determining subsidy source/target type.
peter1138 <peter1138@openttd.org>
parents:
6262
diff
changeset
|
998 if (cs->town_effect == TE_GOODS || cs->town_effect == TE_FOOD) { |
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
|
999 /* The destination is a town */ |
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 Town *t = GetRandomTown(); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1001 |
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
|
1002 /* Only want big towns */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1003 if (t == NULL || t->population < 900) return; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1004 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1005 fr->distance = DistanceManhattan(i->xy, t->xy); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1006 fr->to = t; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1007 } else { |
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
|
1008 /* The destination is an 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
|
1009 Industry *i2 = GetRandomIndustry(); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1010 |
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
|
1011 /* The industry must accept the cargo */ |
7645
5178857fa331
(svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx <glx@openttd.org>
parents:
7642
diff
changeset
|
1012 if (i2 == NULL || i == i2 || |
5178857fa331
(svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx <glx@openttd.org>
parents:
7642
diff
changeset
|
1013 (cargo != i2->accepts_cargo[0] && |
5178857fa331
(svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx <glx@openttd.org>
parents:
7642
diff
changeset
|
1014 cargo != i2->accepts_cargo[1] && |
5178857fa331
(svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx <glx@openttd.org>
parents:
7642
diff
changeset
|
1015 cargo != i2->accepts_cargo[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
|
1016 return; |
6636
03f0effaab7b
(svn r9867) -Codechange: Remove data duplication. The exact same values can be found in the industry spec, so take it from there instead.
belugas <belugas@openttd.org>
parents:
6635
diff
changeset
|
1017 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1018 fr->distance = DistanceManhattan(i->xy, i2->xy); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1019 fr->to = i2; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1020 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1021 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1022 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1023 static bool CheckSubsidyDuplicate(Subsidy *s) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1024 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1025 const Subsidy* ss; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1026 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1027 for (ss = _subsidies; ss != endof(_subsidies); ss++) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1028 if (s != ss && |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1029 ss->from == s->from && |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1030 ss->to == s->to && |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1031 ss->cargo_type == s->cargo_type) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1032 s->cargo_type = CT_INVALID; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1033 return true; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1034 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1035 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1036 return false; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1037 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1038 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1039 |
6247
57363e064324
(svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents:
6227
diff
changeset
|
1040 static void SubsidyMonthlyHandler() |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1041 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1042 Subsidy *s; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1043 Pair pair; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1044 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
|
1045 uint n; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1046 FoundRoute fr; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1047 bool modified = false; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1048 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1049 for (s = _subsidies; s != endof(_subsidies); s++) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1050 if (s->cargo_type == CT_INVALID) continue; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1051 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1052 if (s->age == 12-1) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1053 pair = SetupSubsidyDecodeParam(s, 1); |
9234
02827bf3dc03
(svn r13100) -Codechange: reduce the amount of parameters passed via AddNewsMessage as there is (for each news message type) a tuple of 4 parameters that is the same for all calls.
rubidium <rubidium@openttd.org>
parents:
9199
diff
changeset
|
1054 AddNewsItem(STR_202E_OFFER_OF_SUBSIDY_EXPIRED, NS_SUBSIDIES, pair.a, pair.b); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1055 s->cargo_type = CT_INVALID; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1056 modified = true; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1057 } else if (s->age == 2*12-1) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1058 st = GetStation(s->to); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1059 if (st->owner == _local_player) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1060 pair = SetupSubsidyDecodeParam(s, 1); |
9234
02827bf3dc03
(svn r13100) -Codechange: reduce the amount of parameters passed via AddNewsMessage as there is (for each news message type) a tuple of 4 parameters that is the same for all calls.
rubidium <rubidium@openttd.org>
parents:
9199
diff
changeset
|
1061 AddNewsItem(STR_202F_SUBSIDY_WITHDRAWN_SERVICE, NS_SUBSIDIES, pair.a, pair.b); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1062 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1063 s->cargo_type = CT_INVALID; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1064 modified = true; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1065 } else { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1066 s->age++; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1067 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1068 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1069 |
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
|
1070 /* 25% chance to go on */ |
7967
e30c5ec2d272
(svn r11523) -Codechange: Move the CHANCE macros to core/random_func.cpp cause they depend on Random()
skidd13 <skidd13@openttd.org>
parents:
7954
diff
changeset
|
1071 if (Chance16(1,4)) { |
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
|
1072 /* Find a free slot*/ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1073 s = _subsidies; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1074 while (s->cargo_type != CT_INVALID) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1075 if (++s == endof(_subsidies)) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1076 goto no_add; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1077 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1078 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1079 n = 1000; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1080 do { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1081 FindSubsidyPassengerRoute(&fr); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1082 if (fr.distance <= 70) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1083 s->cargo_type = CT_PASSENGERS; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1084 s->from = ((Town*)fr.from)->index; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1085 s->to = ((Town*)fr.to)->index; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1086 goto add_subsidy; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1087 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1088 FindSubsidyCargoRoute(&fr); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1089 if (fr.distance <= 70) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1090 s->cargo_type = fr.cargo; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1091 s->from = ((Industry*)fr.from)->index; |
6315
6089c21d196c
(svn r9257) -Codechange: Use cargo's town effect property for determining subsidy source/target type.
peter1138 <peter1138@openttd.org>
parents:
6262
diff
changeset
|
1092 { |
6089c21d196c
(svn r9257) -Codechange: Use cargo's town effect property for determining subsidy source/target type.
peter1138 <peter1138@openttd.org>
parents:
6262
diff
changeset
|
1093 const CargoSpec *cs = GetCargo(fr.cargo); |
6089c21d196c
(svn r9257) -Codechange: Use cargo's town effect property for determining subsidy source/target type.
peter1138 <peter1138@openttd.org>
parents:
6262
diff
changeset
|
1094 s->to = (cs->town_effect == TE_GOODS || cs->town_effect == TE_FOOD) ? ((Town*)fr.to)->index : ((Industry*)fr.to)->index; |
6089c21d196c
(svn r9257) -Codechange: Use cargo's town effect property for determining subsidy source/target type.
peter1138 <peter1138@openttd.org>
parents:
6262
diff
changeset
|
1095 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1096 add_subsidy: |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1097 if (!CheckSubsidyDuplicate(s)) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1098 s->age = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1099 pair = SetupSubsidyDecodeParam(s, 0); |
9234
02827bf3dc03
(svn r13100) -Codechange: reduce the amount of parameters passed via AddNewsMessage as there is (for each news message type) a tuple of 4 parameters that is the same for all calls.
rubidium <rubidium@openttd.org>
parents:
9199
diff
changeset
|
1100 AddNewsItem(STR_2030_SERVICE_SUBSIDY_OFFERED, NS_SUBSIDIES, pair.a, pair.b); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1101 modified = true; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1102 break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1103 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1104 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1105 } while (n--); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1106 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1107 no_add:; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1108 if (modified) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1109 InvalidateWindow(WC_SUBSIDIES_LIST, 0); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1110 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1111 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1112 static const SaveLoad _subsidies_desc[] = { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1113 SLE_VAR(Subsidy, cargo_type, SLE_UINT8), |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1114 SLE_VAR(Subsidy, age, SLE_UINT8), |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1115 SLE_CONDVAR(Subsidy, from, SLE_FILE_U8 | SLE_VAR_U16, 0, 4), |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1116 SLE_CONDVAR(Subsidy, from, SLE_UINT16, 5, SL_MAX_VERSION), |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1117 SLE_CONDVAR(Subsidy, to, SLE_FILE_U8 | SLE_VAR_U16, 0, 4), |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1118 SLE_CONDVAR(Subsidy, to, SLE_UINT16, 5, SL_MAX_VERSION), |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1119 SLE_END() |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1120 }; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1121 |
6247
57363e064324
(svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents:
6227
diff
changeset
|
1122 static void Save_SUBS() |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1123 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1124 int i; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1125 Subsidy *s; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1126 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1127 for (i = 0; i != lengthof(_subsidies); i++) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1128 s = &_subsidies[i]; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1129 if (s->cargo_type != CT_INVALID) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1130 SlSetArrayIndex(i); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1131 SlObject(s, _subsidies_desc); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1132 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1133 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1134 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1135 |
6247
57363e064324
(svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents:
6227
diff
changeset
|
1136 static void Load_SUBS() |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1137 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1138 int index; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1139 while ((index = SlIterateArray()) != -1) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1140 SlObject(&_subsidies[index], _subsidies_desc); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1141 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1142 |
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
|
1143 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
|
1144 { |
6091
17ebeb5a2c37
(svn r8826) -Codechange: Replace _cargoc's separate arrays with a regular struct array (with accessor) and implement new initialization method using cargo labels.
peter1138 <peter1138@openttd.org>
parents:
5998
diff
changeset
|
1145 const CargoSpec *cs = GetCargo(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
|
1146 |
6458
57cfff4ac608
(svn r9617) -Codechange: Implement callback for cargo profit calculation
peter1138 <peter1138@openttd.org>
parents:
6453
diff
changeset
|
1147 /* 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
|
1148 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
|
1149 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
|
1150 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
|
1151 if (callback != CALLBACK_FAILED) { |
57cfff4ac608
(svn r9617) -Codechange: Implement callback for cargo profit calculation
peter1138 <peter1138@openttd.org>
parents:
6453
diff
changeset
|
1152 int result = GB(callback, 0, 14); |
57cfff4ac608
(svn r9617) -Codechange: Implement callback for cargo profit calculation
peter1138 <peter1138@openttd.org>
parents:
6453
diff
changeset
|
1153 |
57cfff4ac608
(svn r9617) -Codechange: Implement callback for cargo profit calculation
peter1138 <peter1138@openttd.org>
parents:
6453
diff
changeset
|
1154 /* Simulate a 15 bit signed value */ |
7928
4e8dfd103163
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7926
diff
changeset
|
1155 if (HasBit(callback, 14)) result = 0x4000 - result; |
6458
57cfff4ac608
(svn r9617) -Codechange: Implement callback for cargo profit calculation
peter1138 <peter1138@openttd.org>
parents:
6453
diff
changeset
|
1156 |
57cfff4ac608
(svn r9617) -Codechange: Implement callback for cargo profit calculation
peter1138 <peter1138@openttd.org>
parents:
6453
diff
changeset
|
1157 /* "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
|
1158 * 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
|
1159 * divided by 8192." */ |
57cfff4ac608
(svn r9617) -Codechange: Implement callback for cargo profit calculation
peter1138 <peter1138@openttd.org>
parents:
6453
diff
changeset
|
1160 return result * num_pieces * _cargo_payment_rates[cargo_type] / 8192; |
57cfff4ac608
(svn r9617) -Codechange: Implement callback for cargo profit calculation
peter1138 <peter1138@openttd.org>
parents:
6453
diff
changeset
|
1161 } |
57cfff4ac608
(svn r9617) -Codechange: Implement callback for cargo profit calculation
peter1138 <peter1138@openttd.org>
parents:
6453
diff
changeset
|
1162 } |
57cfff4ac608
(svn r9617) -Codechange: Implement callback for cargo profit calculation
peter1138 <peter1138@openttd.org>
parents:
6453
diff
changeset
|
1163 |
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
|
1164 /* zero the distance (thus income) if it's the bank and very short transport. */ |
7329
5846403c5d11
(svn r10692) -Fix (r10691): those good old days that LT_NORMAL was still called LT_NORMAL :)
rubidium <rubidium@openttd.org>
parents:
7328
diff
changeset
|
1165 if (_opt.landscape == LT_TEMPERATE && cs->label == 'VALU' && dist < 10) return 0; |
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
|
1166 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1167 |
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
|
1168 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
|
1169 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
|
1170 |
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
|
1171 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
|
1172 const int days2 = cs->transit_days[1]; |
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
|
1173 const int days_over_days1 = transit_days - days1; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1174 |
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
|
1175 /* |
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
|
1176 * 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
|
1177 * (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
|
1178 * 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
|
1179 * |
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
|
1180 * - 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
|
1181 * - 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
|
1182 * - 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
|
1183 * |
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
|
1184 */ |
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
|
1185 int time_factor; |
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
|
1186 if (days_over_days1 <= 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
|
1187 time_factor = MAX_TIME_FACTOR; |
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
|
1188 } else if (days_over_days1 <= days2) { |
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
|
1189 time_factor = MAX_TIME_FACTOR - days_over_days1; |
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
|
1190 } else { |
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
|
1191 time_factor = MAX_TIME_FACTOR - 2 * days_over_days1 + days2; |
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
|
1192 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1193 |
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
|
1194 if (time_factor < MIN_TIME_FACTOR) time_factor = 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
|
1195 |
7926
e8ce9f6469d1
(svn r11479) -Codechange: Move the BIGMUL functions to the file of their usage
skidd13 <skidd13@openttd.org>
parents:
7922
diff
changeset
|
1196 return BigMulS(dist * time_factor * num_pieces, _cargo_payment_rates[cargo_type], 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
|
1197 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1198 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1199 static void DeliverGoodsToIndustry(TileIndex xy, CargoID cargo_type, int num_pieces) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1200 { |
6635
5b5c06df5899
(svn r9866) -Codechange: remove the technical one-input-cargo-creates-one-output-cargo limit in the factories, sawmills, steelmills and the ones I'm forgetting to mention right now. Use of this functionality will come later.
rubidium <rubidium@openttd.org>
parents:
6621
diff
changeset
|
1201 Industry *best = NULL; |
5b5c06df5899
(svn r9866) -Codechange: remove the technical one-input-cargo-creates-one-output-cargo limit in the factories, sawmills, steelmills and the ones I'm forgetting to mention right now. Use of this functionality will come later.
rubidium <rubidium@openttd.org>
parents:
6621
diff
changeset
|
1202 Industry *ind; |
5b5c06df5899
(svn r9866) -Codechange: remove the technical one-input-cargo-creates-one-output-cargo limit in the factories, sawmills, steelmills and the ones I'm forgetting to mention right now. Use of this functionality will come later.
rubidium <rubidium@openttd.org>
parents:
6621
diff
changeset
|
1203 const IndustrySpec *indspec; |
5b5c06df5899
(svn r9866) -Codechange: remove the technical one-input-cargo-creates-one-output-cargo limit in the factories, sawmills, steelmills and the ones I'm forgetting to mention right now. Use of this functionality will come later.
rubidium <rubidium@openttd.org>
parents:
6621
diff
changeset
|
1204 uint best_dist; |
6639
0333109c382d
(svn r9870) -Codechange: Silence two compiler warnings and give proper type to the "type" member of industry struct
belugas <belugas@openttd.org>
parents:
6636
diff
changeset
|
1205 uint accepted_cargo_index = 0; ///< unlikely value, just for warning removing |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1206 |
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
|
1207 /* Check if there's an industry close to the station that accepts the cargo |
46d001ebacf6
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents:
6119
diff
changeset
|
1208 * XXX - Think of something better to |
46d001ebacf6
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents:
6119
diff
changeset
|
1209 * 1) Only deliver to industries which are withing the catchment radius |
46d001ebacf6
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents:
6119
diff
changeset
|
1210 * 2) Distribute between industries if more then one is present */ |
6635
5b5c06df5899
(svn r9866) -Codechange: remove the technical one-input-cargo-creates-one-output-cargo limit in the factories, sawmills, steelmills and the ones I'm forgetting to mention right now. Use of this functionality will come later.
rubidium <rubidium@openttd.org>
parents:
6621
diff
changeset
|
1211 best_dist = (_patches.station_spread + 8) * 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
|
1212 FOR_ALL_INDUSTRIES(ind) { |
6635
5b5c06df5899
(svn r9866) -Codechange: remove the technical one-input-cargo-creates-one-output-cargo limit in the factories, sawmills, steelmills and the ones I'm forgetting to mention right now. Use of this functionality will come later.
rubidium <rubidium@openttd.org>
parents:
6621
diff
changeset
|
1213 indspec = GetIndustrySpec(ind->type); |
6639
0333109c382d
(svn r9870) -Codechange: Silence two compiler warnings and give proper type to the "type" member of industry struct
belugas <belugas@openttd.org>
parents:
6636
diff
changeset
|
1214 uint i; |
6635
5b5c06df5899
(svn r9866) -Codechange: remove the technical one-input-cargo-creates-one-output-cargo limit in the factories, sawmills, steelmills and the ones I'm forgetting to mention right now. Use of this functionality will come later.
rubidium <rubidium@openttd.org>
parents:
6621
diff
changeset
|
1215 |
7645
5178857fa331
(svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx <glx@openttd.org>
parents:
7642
diff
changeset
|
1216 for (i = 0; i < lengthof(ind->accepts_cargo); i++) { |
5178857fa331
(svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx <glx@openttd.org>
parents:
7642
diff
changeset
|
1217 if (cargo_type == ind->accepts_cargo[i]) break; |
6635
5b5c06df5899
(svn r9866) -Codechange: remove the technical one-input-cargo-creates-one-output-cargo limit in the factories, sawmills, steelmills and the ones I'm forgetting to mention right now. Use of this functionality will come later.
rubidium <rubidium@openttd.org>
parents:
6621
diff
changeset
|
1218 } |
5b5c06df5899
(svn r9866) -Codechange: remove the technical one-input-cargo-creates-one-output-cargo limit in the factories, sawmills, steelmills and the ones I'm forgetting to mention right now. Use of this functionality will come later.
rubidium <rubidium@openttd.org>
parents:
6621
diff
changeset
|
1219 |
6639
0333109c382d
(svn r9870) -Codechange: Silence two compiler warnings and give proper type to the "type" member of industry struct
belugas <belugas@openttd.org>
parents:
6636
diff
changeset
|
1220 /* Check if matching cargo has been found */ |
7645
5178857fa331
(svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx <glx@openttd.org>
parents:
7642
diff
changeset
|
1221 if (i == lengthof(ind->accepts_cargo)) continue; |
6635
5b5c06df5899
(svn r9866) -Codechange: remove the technical one-input-cargo-creates-one-output-cargo limit in the factories, sawmills, steelmills and the ones I'm forgetting to mention right now. Use of this functionality will come later.
rubidium <rubidium@openttd.org>
parents:
6621
diff
changeset
|
1222 |
7928
4e8dfd103163
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7926
diff
changeset
|
1223 if (HasBit(indspec->callback_flags, CBM_IND_REFUSE_CARGO)) { |
7199
0814b1155c40
(svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium <rubidium@openttd.org>
parents:
7195
diff
changeset
|
1224 uint16 res = GetIndustryCallback(CBID_INDUSTRY_REFUSE_CARGO, 0, GetReverseCargoTranslation(cargo_type, indspec->grf_prop.grffile), ind, ind->type, ind->xy); |
0814b1155c40
(svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium <rubidium@openttd.org>
parents:
7195
diff
changeset
|
1225 if (res == 0) continue; |
0814b1155c40
(svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium <rubidium@openttd.org>
parents:
7195
diff
changeset
|
1226 } |
0814b1155c40
(svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium <rubidium@openttd.org>
parents:
7195
diff
changeset
|
1227 |
6635
5b5c06df5899
(svn r9866) -Codechange: remove the technical one-input-cargo-creates-one-output-cargo limit in the factories, sawmills, steelmills and the ones I'm forgetting to mention right now. Use of this functionality will come later.
rubidium <rubidium@openttd.org>
parents:
6621
diff
changeset
|
1228 uint dist = DistanceManhattan(ind->xy, xy); |
5b5c06df5899
(svn r9866) -Codechange: remove the technical one-input-cargo-creates-one-output-cargo limit in the factories, sawmills, steelmills and the ones I'm forgetting to mention right now. Use of this functionality will come later.
rubidium <rubidium@openttd.org>
parents:
6621
diff
changeset
|
1229 |
5b5c06df5899
(svn r9866) -Codechange: remove the technical one-input-cargo-creates-one-output-cargo limit in the factories, sawmills, steelmills and the ones I'm forgetting to mention right now. Use of this functionality will come later.
rubidium <rubidium@openttd.org>
parents:
6621
diff
changeset
|
1230 if (dist < best_dist) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1231 best = ind; |
6635
5b5c06df5899
(svn r9866) -Codechange: remove the technical one-input-cargo-creates-one-output-cargo limit in the factories, sawmills, steelmills and the ones I'm forgetting to mention right now. Use of this functionality will come later.
rubidium <rubidium@openttd.org>
parents:
6621
diff
changeset
|
1232 best_dist = dist; |
5b5c06df5899
(svn r9866) -Codechange: remove the technical one-input-cargo-creates-one-output-cargo limit in the factories, sawmills, steelmills and the ones I'm forgetting to mention right now. Use of this functionality will come later.
rubidium <rubidium@openttd.org>
parents:
6621
diff
changeset
|
1233 accepted_cargo_index = i; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1234 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1235 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1236 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1237 /* Found one? */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1238 if (best != NULL) { |
6635
5b5c06df5899
(svn r9866) -Codechange: remove the technical one-input-cargo-creates-one-output-cargo limit in the factories, sawmills, steelmills and the ones I'm forgetting to mention right now. Use of this functionality will come later.
rubidium <rubidium@openttd.org>
parents:
6621
diff
changeset
|
1239 indspec = GetIndustrySpec(best->type); |
7165
c3b231638b80
(svn r10439) -Codechange: initial steps for customized industry productions.
rubidium <rubidium@openttd.org>
parents:
7124
diff
changeset
|
1240 uint16 callback = indspec->callback_flags; |
7186
0a85b5cc61f4
(svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium <rubidium@openttd.org>
parents:
7168
diff
changeset
|
1241 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1242 best->was_cargo_delivered = true; |
7186
0a85b5cc61f4
(svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium <rubidium@openttd.org>
parents:
7168
diff
changeset
|
1243 best->last_cargo_accepted_at = _date; |
7165
c3b231638b80
(svn r10439) -Codechange: initial steps for customized industry productions.
rubidium <rubidium@openttd.org>
parents:
7124
diff
changeset
|
1244 |
7928
4e8dfd103163
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7926
diff
changeset
|
1245 if (HasBit(callback, CBM_IND_PRODUCTION_CARGO_ARRIVAL) || HasBit(callback, CBM_IND_PRODUCTION_256_TICKS)) { |
7165
c3b231638b80
(svn r10439) -Codechange: initial steps for customized industry productions.
rubidium <rubidium@openttd.org>
parents:
7124
diff
changeset
|
1246 best->incoming_cargo_waiting[accepted_cargo_index] = min(num_pieces + best->incoming_cargo_waiting[accepted_cargo_index], 0xFFFF); |
7928
4e8dfd103163
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7926
diff
changeset
|
1247 if (HasBit(callback, CBM_IND_PRODUCTION_CARGO_ARRIVAL)) { |
7195
c8da88633a44
(svn r10473) -Codechange: make the industry "window", the one that shows when you click on an industry, more flexible to allow easier integration with newindustries.
rubidium <rubidium@openttd.org>
parents:
7186
diff
changeset
|
1248 IndustryProductionCallback(best, 0); |
c8da88633a44
(svn r10473) -Codechange: make the industry "window", the one that shows when you click on an industry, more flexible to allow easier integration with newindustries.
rubidium <rubidium@openttd.org>
parents:
7186
diff
changeset
|
1249 } else { |
c8da88633a44
(svn r10473) -Codechange: make the industry "window", the one that shows when you click on an industry, more flexible to allow easier integration with newindustries.
rubidium <rubidium@openttd.org>
parents:
7186
diff
changeset
|
1250 InvalidateWindow(WC_INDUSTRY_VIEW, best->index); |
c8da88633a44
(svn r10473) -Codechange: make the industry "window", the one that shows when you click on an industry, more flexible to allow easier integration with newindustries.
rubidium <rubidium@openttd.org>
parents:
7186
diff
changeset
|
1251 } |
7165
c3b231638b80
(svn r10439) -Codechange: initial steps for customized industry productions.
rubidium <rubidium@openttd.org>
parents:
7124
diff
changeset
|
1252 } else { |
c3b231638b80
(svn r10439) -Codechange: initial steps for customized industry productions.
rubidium <rubidium@openttd.org>
parents:
7124
diff
changeset
|
1253 best->produced_cargo_waiting[0] = min(best->produced_cargo_waiting[0] + (num_pieces * indspec->input_cargo_multiplier[accepted_cargo_index][0] / 256), 0xFFFF); |
c3b231638b80
(svn r10439) -Codechange: initial steps for customized industry productions.
rubidium <rubidium@openttd.org>
parents:
7124
diff
changeset
|
1254 best->produced_cargo_waiting[1] = min(best->produced_cargo_waiting[1] + (num_pieces * indspec->input_cargo_multiplier[accepted_cargo_index][1] / 256), 0xFFFF); |
c3b231638b80
(svn r10439) -Codechange: initial steps for customized industry productions.
rubidium <rubidium@openttd.org>
parents:
7124
diff
changeset
|
1255 } |
7229
39b4e2291424
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium <rubidium@openttd.org>
parents:
7199
diff
changeset
|
1256 |
7860
9676dc785085
(svn r11410) -Codechange: implement random triggers for industries.
rubidium <rubidium@openttd.org>
parents:
7832
diff
changeset
|
1257 TriggerIndustry(best, INDUSTRY_TRIGGER_RECEIVED_CARGO); |
7229
39b4e2291424
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium <rubidium@openttd.org>
parents:
7199
diff
changeset
|
1258 StartStopIndustryTileAnimation(best, IAT_INDUSTRY_RECEIVED_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
|
1259 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1260 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1261 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1262 static bool CheckSubsidised(Station *from, Station *to, CargoID cargo_type) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1263 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1264 Subsidy *s; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1265 TileIndex xy; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1266 Pair pair; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1267 |
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
|
1268 /* check if there is an already existing subsidy that applies to us */ |
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 for (s = _subsidies; s != endof(_subsidies); s++) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1270 if (s->cargo_type == cargo_type && |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1271 s->age >= 12 && |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1272 s->from == from->index && |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1273 s->to == to->index) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1274 return true; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1275 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1276 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1277 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1278 /* check if there's a new subsidy that applies.. */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1279 for (s = _subsidies; s != endof(_subsidies); s++) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1280 if (s->cargo_type == cargo_type && s->age < 12) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1281 /* Check distance from source */ |
6315
6089c21d196c
(svn r9257) -Codechange: Use cargo's town effect property for determining subsidy source/target type.
peter1138 <peter1138@openttd.org>
parents:
6262
diff
changeset
|
1282 const CargoSpec *cs = GetCargo(cargo_type); |
6089c21d196c
(svn r9257) -Codechange: Use cargo's town effect property for determining subsidy source/target type.
peter1138 <peter1138@openttd.org>
parents:
6262
diff
changeset
|
1283 if (cs->town_effect == TE_PASSENGERS || cs->town_effect == TE_MAIL) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1284 xy = GetTown(s->from)->xy; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1285 } else { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1286 xy = (GetIndustry(s->from))->xy; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1287 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1288 if (DistanceMax(xy, from->xy) > 9) continue; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1289 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1290 /* Check distance from dest */ |
6315
6089c21d196c
(svn r9257) -Codechange: Use cargo's town effect property for determining subsidy source/target type.
peter1138 <peter1138@openttd.org>
parents:
6262
diff
changeset
|
1291 switch (cs->town_effect) { |
6089c21d196c
(svn r9257) -Codechange: Use cargo's town effect property for determining subsidy source/target type.
peter1138 <peter1138@openttd.org>
parents:
6262
diff
changeset
|
1292 case TE_PASSENGERS: |
6089c21d196c
(svn r9257) -Codechange: Use cargo's town effect property for determining subsidy source/target type.
peter1138 <peter1138@openttd.org>
parents:
6262
diff
changeset
|
1293 case TE_MAIL: |
6089c21d196c
(svn r9257) -Codechange: Use cargo's town effect property for determining subsidy source/target type.
peter1138 <peter1138@openttd.org>
parents:
6262
diff
changeset
|
1294 case TE_GOODS: |
6089c21d196c
(svn r9257) -Codechange: Use cargo's town effect property for determining subsidy source/target type.
peter1138 <peter1138@openttd.org>
parents:
6262
diff
changeset
|
1295 case TE_FOOD: |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1296 xy = GetTown(s->to)->xy; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1297 break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1298 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1299 default: |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1300 xy = GetIndustry(s->to)->xy; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1301 break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1302 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1303 if (DistanceMax(xy, to->xy) > 9) continue; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1304 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1305 /* Found a subsidy, change the values to indicate that it's in use */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1306 s->age = 12; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1307 s->from = from->index; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1308 s->to = to->index; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1309 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1310 /* Add a news item */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1311 pair = SetupSubsidyDecodeParam(s, 0); |
7124
198ce784f799
(svn r10397) -Fix [FS#969]: subsidy awarded messages broken due to {COMPANY} now taking 1 (not 2) parameters. also remove an unnecessary dereference.
peter1138 <peter1138@openttd.org>
parents:
7067
diff
changeset
|
1312 InjectDParam(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
|
1313 |
7124
198ce784f799
(svn r10397) -Fix [FS#969]: subsidy awarded messages broken due to {COMPANY} now taking 1 (not 2) parameters. also remove an unnecessary dereference.
peter1138 <peter1138@openttd.org>
parents:
7067
diff
changeset
|
1314 SetDParam(0, _current_player); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1315 AddNewsItem( |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1316 STR_2031_SERVICE_SUBSIDY_AWARDED + _opt.diff.subsidy_multiplier, |
9234
02827bf3dc03
(svn r13100) -Codechange: reduce the amount of parameters passed via AddNewsMessage as there is (for each news message type) a tuple of 4 parameters that is the same for all calls.
rubidium <rubidium@openttd.org>
parents:
9199
diff
changeset
|
1317 NS_SUBSIDIES, |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1318 pair.a, pair.b |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1319 ); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1320 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1321 InvalidateWindow(WC_SUBSIDIES_LIST, 0); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1322 return true; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1323 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1324 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1325 return false; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1326 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1327 |
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
|
1328 static Money DeliverGoods(int num_pieces, CargoID cargo_type, StationID source, StationID dest, TileIndex source_tile, byte days_in_transit) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1329 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1330 bool subsidised; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1331 Station *s_from, *s_to; |
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
|
1332 Money profit; |
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 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1334 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
|
1335 |
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
|
1336 /* Update player 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
|
1337 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1338 Player *p = GetPlayer(_current_player); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1339 p->cur_economy.delivered_cargo += num_pieces; |
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
|
1340 SetBit(p->cargo_types, 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
|
1341 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1342 |
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
|
1343 /* Get station pointers. */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1344 s_from = GetStation(source); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1345 s_to = GetStation(dest); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1346 |
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
|
1347 /* Check if a subsidy applies. */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1348 subsidised = CheckSubsidised(s_from, s_to, cargo_type); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1349 |
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
|
1350 /* Increase town's counter for some special goods types */ |
6315
6089c21d196c
(svn r9257) -Codechange: Use cargo's town effect property for determining subsidy source/target type.
peter1138 <peter1138@openttd.org>
parents:
6262
diff
changeset
|
1351 const CargoSpec *cs = GetCargo(cargo_type); |
6089c21d196c
(svn r9257) -Codechange: Use cargo's town effect property for determining subsidy source/target type.
peter1138 <peter1138@openttd.org>
parents:
6262
diff
changeset
|
1352 if (cs->town_effect == TE_FOOD) s_to->town->new_act_food += num_pieces; |
6089c21d196c
(svn r9257) -Codechange: Use cargo's town effect property for determining subsidy source/target type.
peter1138 <peter1138@openttd.org>
parents:
6262
diff
changeset
|
1353 if (cs->town_effect == TE_WATER) s_to->town->new_act_water += num_pieces; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1354 |
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
|
1355 /* Give the goods to the 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
|
1356 DeliverGoodsToIndustry(s_to->xy, cargo_type, num_pieces); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1357 |
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
|
1358 /* Determine profit */ |
5683
809a5610092f
(svn r8144) -Fix: [FS#163] When a station is removed, vehicles do not get excessive payment any longer, as the origin TILE is now stored as long as the origin STATION for the transported cargos. Basically this is only a temporary fix until cargopackets are implemented, but it fixes one of the oldest known bugs (Special Thanks to Darkvater for lots of testing)
celestar <celestar@openttd.org>
parents:
5668
diff
changeset
|
1359 profit = GetTransportedGoodsIncome(num_pieces, DistanceManhattan(source_tile, s_to->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
|
1360 |
6125
46d001ebacf6
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents:
6119
diff
changeset
|
1361 /* Modify profit if a subsidy is in effect */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1362 if (subsidised) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1363 switch (_opt.diff.subsidy_multiplier) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1364 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
|
1365 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
|
1366 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
|
1367 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
|
1368 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1369 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1370 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1371 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
|
1372 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1373 |
6559
b680e3433ca2
(svn r9761) -Codechange: refactor cargo payment out of LoadUnloadVehicle.
rubidium <rubidium@openttd.org>
parents:
6500
diff
changeset
|
1374 /** |
b680e3433ca2
(svn r9761) -Codechange: refactor cargo payment out of LoadUnloadVehicle.
rubidium <rubidium@openttd.org>
parents:
6500
diff
changeset
|
1375 * Performs the vehicle payment _and_ marks the vehicle to be unloaded. |
b680e3433ca2
(svn r9761) -Codechange: refactor cargo payment out of LoadUnloadVehicle.
rubidium <rubidium@openttd.org>
parents:
6500
diff
changeset
|
1376 * @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
|
1377 */ |
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
|
1378 void VehiclePayment(Vehicle *front_v) |
6559
b680e3433ca2
(svn r9761) -Codechange: refactor cargo payment out of LoadUnloadVehicle.
rubidium <rubidium@openttd.org>
parents:
6500
diff
changeset
|
1379 { |
b680e3433ca2
(svn r9761) -Codechange: refactor cargo payment out of LoadUnloadVehicle.
rubidium <rubidium@openttd.org>
parents:
6500
diff
changeset
|
1380 int result = 0; |
b680e3433ca2
(svn r9761) -Codechange: refactor cargo payment out of LoadUnloadVehicle.
rubidium <rubidium@openttd.org>
parents:
6500
diff
changeset
|
1381 |
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
|
1382 Money vehicle_profit = 0; // Money paid to the train |
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
|
1383 Money route_profit = 0; // The grand total amount for the route. A-D of transfer chain A-B-C-D |
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
|
1384 Money virtual_profit = 0; // The virtual profit for entire vehicle chain |
6559
b680e3433ca2
(svn r9761) -Codechange: refactor cargo payment out of LoadUnloadVehicle.
rubidium <rubidium@openttd.org>
parents:
6500
diff
changeset
|
1385 |
b680e3433ca2
(svn r9761) -Codechange: refactor cargo payment out of LoadUnloadVehicle.
rubidium <rubidium@openttd.org>
parents:
6500
diff
changeset
|
1386 StationID last_visited = front_v->last_station_visited; |
b680e3433ca2
(svn r9761) -Codechange: refactor cargo payment out of LoadUnloadVehicle.
rubidium <rubidium@openttd.org>
parents:
6500
diff
changeset
|
1387 Station *st = GetStation(last_visited); |
b680e3433ca2
(svn r9761) -Codechange: refactor cargo payment out of LoadUnloadVehicle.
rubidium <rubidium@openttd.org>
parents:
6500
diff
changeset
|
1388 |
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
|
1389 /* The owner of the train wants to be paid */ |
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
|
1390 PlayerID old_player = _current_player; |
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
|
1391 _current_player = front_v->owner; |
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
|
1392 |
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
|
1393 /* 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
|
1394 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
|
1395 |
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
|
1396 /* Start unloading in at the first possible moment */ |
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
|
1397 front_v->load_unload_time_rem = 1; |
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
|
1398 |
7492
09743324277c
(svn r11003) -Codechange: replace Vehicle->next to Vehicle->Next() and Vehicle->SetNext() so we can trap instances that change a next pointer and (in the future) update the first/previous pointers based on that.
rubidium <rubidium@openttd.org>
parents:
7474
diff
changeset
|
1399 for (Vehicle *v = front_v; v != NULL; v = v->Next()) { |
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
|
1400 /* No cargo to unload */ |
8883
23eea6824c4b
(svn r12650) -Feature: ability to force a vehicle to not load at a station.
rubidium <rubidium@openttd.org>
parents:
8873
diff
changeset
|
1401 if (v->cargo_cap == 0 || v->cargo.Empty() || front_v->current_order.GetUnloadType() & OUFB_NO_UNLOAD) continue; |
6559
b680e3433ca2
(svn r9761) -Codechange: refactor cargo payment out of LoadUnloadVehicle.
rubidium <rubidium@openttd.org>
parents:
6500
diff
changeset
|
1402 |
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
|
1403 /* All cargo has already been paid for, no need to pay again */ |
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
|
1404 if (!v->cargo.UnpaidCargo()) { |
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
|
1405 SetBit(v->vehicle_flags, VF_CARGO_UNLOADING); |
6882
7a26a3a8edfe
(svn r10125) -Fix [FS#865]: under some circumstances the wagons of a train didn't get loaded properly.
rubidium <rubidium@openttd.org>
parents:
6879
diff
changeset
|
1406 continue; |
7a26a3a8edfe
(svn r10125) -Fix [FS#865]: under some circumstances the wagons of a train didn't get loaded properly.
rubidium <rubidium@openttd.org>
parents:
6879
diff
changeset
|
1407 } |
6559
b680e3433ca2
(svn r9761) -Codechange: refactor cargo payment out of LoadUnloadVehicle.
rubidium <rubidium@openttd.org>
parents:
6500
diff
changeset
|
1408 |
b680e3433ca2
(svn r9761) -Codechange: refactor cargo payment out of LoadUnloadVehicle.
rubidium <rubidium@openttd.org>
parents:
6500
diff
changeset
|
1409 GoodsEntry *ge = &st->goods[v->cargo_type]; |
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
|
1410 const CargoList::List *cargos = v->cargo.Packets(); |
6559
b680e3433ca2
(svn r9761) -Codechange: refactor cargo payment out of LoadUnloadVehicle.
rubidium <rubidium@openttd.org>
parents:
6500
diff
changeset
|
1411 |
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
|
1412 for (CargoList::List::const_iterator it = cargos->begin(); it != cargos->end(); it++) { |
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
|
1413 CargoPacket *cp = *it; |
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
|
1414 if (!cp->paid_for && |
f0f87c5a431e
(svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium <rubidium@openttd.org>
parents:
7002
diff
changeset
|
1415 cp->source != last_visited && |
7928
4e8dfd103163
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7926
diff
changeset
|
1416 HasBit(ge->acceptance_pickup, GoodsEntry::ACCEPTANCE) && |
8855
2acce887e7ec
(svn r12617) -Codechange: add type safety to the Order's load and unload types.
rubidium <rubidium@openttd.org>
parents:
8843
diff
changeset
|
1417 (front_v->current_order.GetUnloadType() & OUFB_TRANSFER) == 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
|
1418 /* Deliver goods to the station */ |
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
|
1419 st->time_since_unload = 0; |
6559
b680e3433ca2
(svn r9761) -Codechange: refactor cargo payment out of LoadUnloadVehicle.
rubidium <rubidium@openttd.org>
parents:
6500
diff
changeset
|
1420 |
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
|
1421 /* handle end of route payment */ |
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
|
1422 Money profit = DeliverGoods(cp->count, v->cargo_type, cp->source, last_visited, cp->source_xy, cp->days_in_transit); |
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
|
1423 cp->paid_for = true; |
7436
4714d6c676d1
(svn r10857) -Fix: feeder-income was broken; substract the feeder-costs from the vehicle-income, not from the route-income (tnx to RichK for all the info)
truelight <truelight@openttd.org>
parents:
7398
diff
changeset
|
1424 route_profit += profit; // display amount paid for final route delivery, A-D of a chain A-B-C-D |
4714d6c676d1
(svn r10857) -Fix: feeder-income was broken; substract the feeder-costs from the vehicle-income, not from the route-income (tnx to RichK for all the info)
truelight <truelight@openttd.org>
parents:
7398
diff
changeset
|
1425 vehicle_profit += profit - cp->feeder_share; // whole vehicle is not payed for transfers picked up earlier |
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
|
1426 |
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
|
1427 result |= 1; |
6882
7a26a3a8edfe
(svn r10125) -Fix [FS#865]: under some circumstances the wagons of a train didn't get loaded properly.
rubidium <rubidium@openttd.org>
parents:
6879
diff
changeset
|
1428 |
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
|
1429 SetBit(v->vehicle_flags, VF_CARGO_UNLOADING); |
8855
2acce887e7ec
(svn r12617) -Codechange: add type safety to the Order's load and unload types.
rubidium <rubidium@openttd.org>
parents:
8843
diff
changeset
|
1430 } else if (front_v->current_order.GetUnloadType() & (OUFB_UNLOAD | OUFB_TRANSFER)) { |
2acce887e7ec
(svn r12617) -Codechange: add type safety to the Order's load and unload types.
rubidium <rubidium@openttd.org>
parents:
8843
diff
changeset
|
1431 if (!cp->paid_for && (front_v->current_order.GetUnloadType() & OUFB_TRANSFER) != 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
|
1432 Money profit = GetTransportedGoodsIncome( |
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
|
1433 cp->count, |
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
|
1434 /* pay transfer vehicle for only the part of transfer it has done: ie. cargo_loaded_at_xy to here */ |
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
|
1435 DistanceManhattan(cp->loaded_at_xy, GetStation(last_visited)->xy), |
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
|
1436 cp->days_in_transit, |
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 v->cargo_type); |
6559
b680e3433ca2
(svn r9761) -Codechange: refactor cargo payment out of LoadUnloadVehicle.
rubidium <rubidium@openttd.org>
parents:
6500
diff
changeset
|
1438 |
8556
8aae08d562cc
(svn r12134) -Change: count the number of ticks a vehicle was running this day to calculate running cost
smatz <smatz@openttd.org>
parents:
8424
diff
changeset
|
1439 front_v->profit_this_year += profit << 8; |
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
|
1440 virtual_profit += profit; // accumulate transfer profits for whole vehicle |
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
|
1441 cp->feeder_share += profit; // account for the (virtual) profit already made for the cargo packet |
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
|
1442 cp->paid_for = true; // record that the cargo has been paid for to eliminate double counting |
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
|
1443 } |
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
|
1444 result |= 2; |
6559
b680e3433ca2
(svn r9761) -Codechange: refactor cargo payment out of LoadUnloadVehicle.
rubidium <rubidium@openttd.org>
parents:
6500
diff
changeset
|
1445 |
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
|
1446 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
|
1447 } |
b680e3433ca2
(svn r9761) -Codechange: refactor cargo payment out of LoadUnloadVehicle.
rubidium <rubidium@openttd.org>
parents:
6500
diff
changeset
|
1448 } |
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
|
1449 v->cargo.InvalidateCache(); |
6559
b680e3433ca2
(svn r9761) -Codechange: refactor cargo payment out of LoadUnloadVehicle.
rubidium <rubidium@openttd.org>
parents:
6500
diff
changeset
|
1450 } |
b680e3433ca2
(svn r9761) -Codechange: refactor cargo payment out of LoadUnloadVehicle.
rubidium <rubidium@openttd.org>
parents:
6500
diff
changeset
|
1451 |
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 if (virtual_profit > 0) { |
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
|
1453 ShowFeederIncomeAnimation(front_v->x_pos, front_v->y_pos, front_v->z_pos, virtual_profit); |
6559
b680e3433ca2
(svn r9761) -Codechange: refactor cargo payment out of LoadUnloadVehicle.
rubidium <rubidium@openttd.org>
parents:
6500
diff
changeset
|
1454 } |
b680e3433ca2
(svn r9761) -Codechange: refactor cargo payment out of LoadUnloadVehicle.
rubidium <rubidium@openttd.org>
parents:
6500
diff
changeset
|
1455 |
b680e3433ca2
(svn r9761) -Codechange: refactor cargo payment out of LoadUnloadVehicle.
rubidium <rubidium@openttd.org>
parents:
6500
diff
changeset
|
1456 if (route_profit != 0) { |
8556
8aae08d562cc
(svn r12134) -Change: count the number of ticks a vehicle was running this day to calculate running cost
smatz <smatz@openttd.org>
parents:
8424
diff
changeset
|
1457 front_v->profit_this_year += vehicle_profit << 8; |
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
|
1458 SubtractMoneyFromPlayer(CommandCost(front_v->GetExpenseType(true), -route_profit)); |
6559
b680e3433ca2
(svn r9761) -Codechange: refactor cargo payment out of LoadUnloadVehicle.
rubidium <rubidium@openttd.org>
parents:
6500
diff
changeset
|
1459 |
b680e3433ca2
(svn r9761) -Codechange: refactor cargo payment out of LoadUnloadVehicle.
rubidium <rubidium@openttd.org>
parents:
6500
diff
changeset
|
1460 if (IsLocalPlayer() && !PlayVehicleSound(front_v, VSE_LOAD_UNLOAD)) { |
b680e3433ca2
(svn r9761) -Codechange: refactor cargo payment out of LoadUnloadVehicle.
rubidium <rubidium@openttd.org>
parents:
6500
diff
changeset
|
1461 SndPlayVehicleFx(SND_14_CASHTILL, front_v); |
b680e3433ca2
(svn r9761) -Codechange: refactor cargo payment out of LoadUnloadVehicle.
rubidium <rubidium@openttd.org>
parents:
6500
diff
changeset
|
1462 } |
b680e3433ca2
(svn r9761) -Codechange: refactor cargo payment out of LoadUnloadVehicle.
rubidium <rubidium@openttd.org>
parents:
6500
diff
changeset
|
1463 |
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
|
1464 ShowCostOrIncomeAnimation(front_v->x_pos, front_v->y_pos, front_v->z_pos, -vehicle_profit); |
6559
b680e3433ca2
(svn r9761) -Codechange: refactor cargo payment out of LoadUnloadVehicle.
rubidium <rubidium@openttd.org>
parents:
6500
diff
changeset
|
1465 } |
b680e3433ca2
(svn r9761) -Codechange: refactor cargo payment out of LoadUnloadVehicle.
rubidium <rubidium@openttd.org>
parents:
6500
diff
changeset
|
1466 |
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
|
1467 _current_player = old_player; |
6559
b680e3433ca2
(svn r9761) -Codechange: refactor cargo payment out of LoadUnloadVehicle.
rubidium <rubidium@openttd.org>
parents:
6500
diff
changeset
|
1468 } |
b680e3433ca2
(svn r9761) -Codechange: refactor cargo payment out of LoadUnloadVehicle.
rubidium <rubidium@openttd.org>
parents:
6500
diff
changeset
|
1469 |
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
|
1470 /** |
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
|
1471 * Loads/unload the vehicle if possible. |
e1cdf0b1265b
(svn r9794) -Codechange: refactor the question whether a vehicle can be loaded into LoadUnloadVehicle instead of duplicating it for each vehicle.
rubidium <rubidium@openttd.org>
parents:
6565
diff
changeset
|
1472 * @param v the vehicle to be (un)loaded |
6618
a0ebb1506656
(svn r9838) -Fix: make "improved loading" a proper improved loading instead of loading one (semi-)random vehicle at a time:
rubidium <rubidium@openttd.org>
parents:
6616
diff
changeset
|
1473 * @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
|
1474 * 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
|
1475 * 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
|
1476 * 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
|
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 static void LoadUnloadVehicle(Vehicle *v, int *cargo_left) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1479 { |
8837
bdaf8866039c
(svn r12585) -Fix (r12584): assumption that assertions were enabled during compilation/testing was flawed.
rubidium <rubidium@openttd.org>
parents:
8814
diff
changeset
|
1480 assert(v->current_order.IsType(OT_LOADING)); |
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
|
1481 |
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
|
1482 /* We have not waited enough time till the next round of loading/unloading */ |
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 if (--v->load_unload_time_rem != 0) { |
8855
2acce887e7ec
(svn r12617) -Codechange: add type safety to the Order's load and unload types.
rubidium <rubidium@openttd.org>
parents:
8843
diff
changeset
|
1484 if (_patches.improved_load && (v->current_order.GetLoadType() & OLFB_FULL_LOAD)) { |
6618
a0ebb1506656
(svn r9838) -Fix: make "improved loading" a proper improved loading instead of loading one (semi-)random vehicle at a time:
rubidium <rubidium@openttd.org>
parents:
6616
diff
changeset
|
1485 /* 'Reserve' this cargo for this vehicle, because we were first. */ |
7492
09743324277c
(svn r11003) -Codechange: replace Vehicle->next to Vehicle->Next() and Vehicle->SetNext() so we can trap instances that change a next pointer and (in the future) update the first/previous pointers based on that.
rubidium <rubidium@openttd.org>
parents:
7474
diff
changeset
|
1486 for (; v != NULL; v = v->Next()) { |
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
|
1487 if (v->cargo_cap != 0) cargo_left[v->cargo_type] -= v->cargo_cap - v->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
|
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 } |
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
|
1490 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
|
1491 } |
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
|
1492 |
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
|
1493 StationID last_visited = v->last_station_visited; |
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
|
1494 Station *st = GetStation(last_visited); |
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
|
1495 |
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
|
1496 if (v->type == VEH_TRAIN && (!IsTileType(v->tile, MP_STATION) || GetStationIndex(v->tile) != st->index)) { |
6844
70d60b0104c1
(svn r10084) -Fix [FS#855]: reversing a train when loading at a station crashed.
rubidium <rubidium@openttd.org>
parents:
6823
diff
changeset
|
1497 /* 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
|
1498 * out and let the train just leave as it always did. */ |
7931
44ff7a6d801f
(svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7929
diff
changeset
|
1499 SetBit(v->vehicle_flags, VF_LOADING_FINISHED); |
6844
70d60b0104c1
(svn r10084) -Fix [FS#855]: reversing a train when loading at a station crashed.
rubidium <rubidium@openttd.org>
parents:
6823
diff
changeset
|
1500 return; |
70d60b0104c1
(svn r10084) -Fix [FS#855]: reversing a train when loading at a station crashed.
rubidium <rubidium@openttd.org>
parents:
6823
diff
changeset
|
1501 } |
70d60b0104c1
(svn r10084) -Fix [FS#855]: reversing a train when loading at a station crashed.
rubidium <rubidium@openttd.org>
parents:
6823
diff
changeset
|
1502 |
6611
461107df1c8f
(svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents:
6609
diff
changeset
|
1503 int unloading_time = 0; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1504 Vehicle *u = v; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1505 int result = 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
|
1506 uint cap; |
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
|
1507 |
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
|
1508 bool completely_emptied = true; |
6611
461107df1c8f
(svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents:
6609
diff
changeset
|
1509 bool anything_unloaded = false; |
461107df1c8f
(svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents:
6609
diff
changeset
|
1510 bool anything_loaded = false; |
461107df1c8f
(svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents:
6609
diff
changeset
|
1511 uint32 cargo_not_full = 0; |
461107df1c8f
(svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents:
6609
diff
changeset
|
1512 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
|
1513 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1514 v->cur_speed = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1515 |
7492
09743324277c
(svn r11003) -Codechange: replace Vehicle->next to Vehicle->Next() and Vehicle->SetNext() so we can trap instances that change a next pointer and (in the future) update the first/previous pointers based on that.
rubidium <rubidium@openttd.org>
parents:
7474
diff
changeset
|
1516 for (; v != NULL; v = v->Next()) { |
6609
e78f5516e040
(svn r9829) -Codechange: more refactoring of the unloading algorithm.
rubidium <rubidium@openttd.org>
parents:
6601
diff
changeset
|
1517 if (v->cargo_cap == 0) continue; |
e78f5516e040
(svn r9829) -Codechange: more refactoring of the unloading algorithm.
rubidium <rubidium@openttd.org>
parents:
6601
diff
changeset
|
1518 |
e78f5516e040
(svn r9829) -Codechange: more refactoring of the unloading algorithm.
rubidium <rubidium@openttd.org>
parents:
6601
diff
changeset
|
1519 byte load_amount = EngInfo(v->engine_type)->load_amount; |
7928
4e8dfd103163
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7926
diff
changeset
|
1520 if (_patches.gradual_loading && HasBit(EngInfo(v->engine_type)->callbackmask, CBM_VEHICLE_LOAD_AMOUNT)) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1521 uint16 cb_load_amount = GetVehicleCallback(CBID_VEHICLE_LOAD_AMOUNT, 0, 0, v->engine_type, v); |
9020
94bb527c979f
(svn r12819) -Codechange: handle more NewGRFs in the same way as TTDP does it, i.e. testing the low bits for 0xFF or 0 instead of all bits.
rubidium <rubidium@openttd.org>
parents:
9003
diff
changeset
|
1522 if (cb_load_amount != CALLBACK_FAILED && GB(cb_load_amount, 0, 8) != 0) load_amount = GB(cb_load_amount, 0, 8); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1523 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1524 |
6609
e78f5516e040
(svn r9829) -Codechange: more refactoring of the unloading algorithm.
rubidium <rubidium@openttd.org>
parents:
6601
diff
changeset
|
1525 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
|
1526 |
8883
23eea6824c4b
(svn r12650) -Feature: ability to force a vehicle to not load at a station.
rubidium <rubidium@openttd.org>
parents:
8873
diff
changeset
|
1527 if (HasBit(v->vehicle_flags, VF_CARGO_UNLOADING) && (u->current_order.GetUnloadType() & OUFB_NO_UNLOAD) == 0) { |
7010
f0f87c5a431e
(svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium <rubidium@openttd.org>
parents:
7002
diff
changeset
|
1528 uint cargo_count = v->cargo.Count(); |
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
|
1529 uint amount_unloaded = _patches.gradual_loading ? min(cargo_count, load_amount) : cargo_count; |
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
|
1530 bool remaining; // Are there cargo entities in this vehicle that can still be unloaded here? |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1531 |
8855
2acce887e7ec
(svn r12617) -Codechange: add type safety to the Order's load and unload types.
rubidium <rubidium@openttd.org>
parents:
8843
diff
changeset
|
1532 if (HasBit(ge->acceptance_pickup, GoodsEntry::ACCEPTANCE) && !(u->current_order.GetUnloadType() & OUFB_TRANSFER)) { |
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
|
1533 /* The cargo has reached it's final destination, the packets may now be destroyed */ |
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
|
1534 remaining = v->cargo.MoveTo(NULL, amount_unloaded, CargoList::MTA_FINAL_DELIVERY, last_visited); |
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
|
1535 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1536 result |= 1; |
8855
2acce887e7ec
(svn r12617) -Codechange: add type safety to the Order's load and unload types.
rubidium <rubidium@openttd.org>
parents:
8843
diff
changeset
|
1537 } else if (u->current_order.GetUnloadType() & (OUFB_UNLOAD | OUFB_TRANSFER)) { |
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
|
1538 remaining = v->cargo.MoveTo(&ge->cargo, amount_unloaded); |
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
|
1539 SetBit(ge->acceptance_pickup, GoodsEntry::PICKUP); |
6198
a2cdd211d091
(svn r8978) -Feature: Rewrite of transfer system.
richk <richk@openttd.org>
parents:
6190
diff
changeset
|
1540 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1541 result |= 2; |
6609
e78f5516e040
(svn r9829) -Codechange: more refactoring of the unloading algorithm.
rubidium <rubidium@openttd.org>
parents:
6601
diff
changeset
|
1542 } else { |
e78f5516e040
(svn r9829) -Codechange: more refactoring of the unloading algorithm.
rubidium <rubidium@openttd.org>
parents:
6601
diff
changeset
|
1543 /* The order changed while unloading (unset unload/transfer) or the |
e78f5516e040
(svn r9829) -Codechange: more refactoring of the unloading algorithm.
rubidium <rubidium@openttd.org>
parents:
6601
diff
changeset
|
1544 * station does not accept goods anymore. */ |
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
|
1545 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
|
1546 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
|
1547 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1548 |
6609
e78f5516e040
(svn r9829) -Codechange: more refactoring of the unloading algorithm.
rubidium <rubidium@openttd.org>
parents:
6601
diff
changeset
|
1549 /* Deliver goods to the station */ |
e78f5516e040
(svn r9829) -Codechange: more refactoring of the unloading algorithm.
rubidium <rubidium@openttd.org>
parents:
6601
diff
changeset
|
1550 st->time_since_unload = 0; |
e78f5516e040
(svn r9829) -Codechange: more refactoring of the unloading algorithm.
rubidium <rubidium@openttd.org>
parents:
6601
diff
changeset
|
1551 |
e78f5516e040
(svn r9829) -Codechange: more refactoring of the unloading algorithm.
rubidium <rubidium@openttd.org>
parents:
6601
diff
changeset
|
1552 unloading_time += amount_unloaded; |
e78f5516e040
(svn r9829) -Codechange: more refactoring of the unloading algorithm.
rubidium <rubidium@openttd.org>
parents:
6601
diff
changeset
|
1553 |
6611
461107df1c8f
(svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents:
6609
diff
changeset
|
1554 anything_unloaded = true; |
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
|
1555 if (_patches.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
|
1556 completely_emptied = false; |
6609
e78f5516e040
(svn r9829) -Codechange: more refactoring of the unloading algorithm.
rubidium <rubidium@openttd.org>
parents:
6601
diff
changeset
|
1557 } else { |
e78f5516e040
(svn r9829) -Codechange: more refactoring of the unloading algorithm.
rubidium <rubidium@openttd.org>
parents:
6601
diff
changeset
|
1558 /* 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
|
1559 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
|
1560 } |
e78f5516e040
(svn r9829) -Codechange: more refactoring of the unloading algorithm.
rubidium <rubidium@openttd.org>
parents:
6601
diff
changeset
|
1561 |
e78f5516e040
(svn r9829) -Codechange: more refactoring of the unloading algorithm.
rubidium <rubidium@openttd.org>
parents:
6601
diff
changeset
|
1562 continue; |
e78f5516e040
(svn r9829) -Codechange: more refactoring of the unloading algorithm.
rubidium <rubidium@openttd.org>
parents:
6601
diff
changeset
|
1563 } |
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
|
1564 |
8885
2d7e1a978a1a
(svn r12652) -Codechange: rework the order GUI a little more to make it a little more clear that 'transfer' is just an unload type.
rubidium <rubidium@openttd.org>
parents:
8883
diff
changeset
|
1565 /* Do not pick up goods when we have no-load set. */ |
2d7e1a978a1a
(svn r12652) -Codechange: rework the order GUI a little more to make it a little more clear that 'transfer' is just an unload type.
rubidium <rubidium@openttd.org>
parents:
8883
diff
changeset
|
1566 if (u->current_order.GetLoadType() & OLFB_NO_LOAD) continue; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
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 /* update stats */ |
6609
e78f5516e040
(svn r9829) -Codechange: more refactoring of the unloading algorithm.
rubidium <rubidium@openttd.org>
parents:
6601
diff
changeset
|
1569 int t; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1570 switch (u->type) { |
6259
4a39d6291d58
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium <rubidium@openttd.org>
parents:
6248
diff
changeset
|
1571 case VEH_TRAIN: t = u->u.rail.cached_max_speed; break; |
4a39d6291d58
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium <rubidium@openttd.org>
parents:
6248
diff
changeset
|
1572 case VEH_ROAD: t = u->max_speed / 2; 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
|
1573 default: t = u->max_speed; break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1574 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1575 |
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
|
1576 /* 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
|
1577 ge->last_speed = min(t, 255); |
6990
a19700261804
(svn r10246) -Fix (r10297): some forgotten money conversions and truncation issues. Thanks to benc for providing the patch.
rubidium <rubidium@openttd.org>
parents:
6957
diff
changeset
|
1578 ge->last_age = _cur_year - u->build_year; |
7458
7e4d907043ef
(svn r10953) -Fix [FS#1139, FS#1143]: stations would not get a rating when there were already two stations with a "more than default" rating as no cargo would be moved to the station to be picked up.
rubidium <rubidium@openttd.org>
parents:
7447
diff
changeset
|
1579 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
|
1580 |
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
|
1581 /* 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
|
1582 * has capacity for it, load it on the vehicle. */ |
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
|
1583 if (!ge->cargo.Empty() && |
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
|
1584 (cap = v->cargo_cap - v->cargo.Count()) != 0) { |
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
|
1585 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
|
1586 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1587 /* 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
|
1588 * the same cargo type at this station */ |
6698
956093bebe56
(svn r9930) -Fix (r9838): obiwan could cause vehicles to way a long time (2.5 years) at stations.
rubidium <rubidium@openttd.org>
parents:
6643
diff
changeset
|
1589 if (_patches.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
|
1590 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
|
1591 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
|
1592 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1593 |
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
|
1594 if (cap > count) cap = count; |
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
|
1595 if (_patches.gradual_loading) cap = min(cap, load_amount); |
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
|
1596 if (_patches.improved_load) { |
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
|
1597 /* 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
|
1598 cap = min((uint)cargo_left[v->cargo_type], cap); |
6618
a0ebb1506656
(svn r9838) -Fix: make "improved loading" a proper improved loading instead of loading one (semi-)random vehicle at a time:
rubidium <rubidium@openttd.org>
parents:
6616
diff
changeset
|
1599 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
|
1600 } |
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 |
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
|
1602 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
|
1603 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1604 /* 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
|
1605 * 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
|
1606 * 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
|
1607 * 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
|
1608 * 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
|
1609 * 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
|
1610 * 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
|
1611 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
|
1612 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
|
1613 |
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
|
1614 ge->cargo.MoveTo(&v->cargo, cap, CargoList::MTA_CARGO_LOAD, st->xy); |
6198
a2cdd211d091
(svn r8978) -Feature: Rewrite of transfer system.
richk <richk@openttd.org>
parents:
6190
diff
changeset
|
1615 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1616 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
|
1617 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
|
1618 |
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
|
1619 StationAnimationTrigger(st, st->xy, STAT_ANIM_CARGO_TAKEN, v->cargo_type); |
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
|
1620 |
7474
7b35fd1cc99d
(svn r10981) -Fix [FS#1156] (r10970): stations gave ratings for accepted cargo too.
rubidium <rubidium@openttd.org>
parents:
7458
diff
changeset
|
1621 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
|
1622 |
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 result |= 2; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1624 } |
6611
461107df1c8f
(svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents:
6609
diff
changeset
|
1625 |
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
|
1626 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
|
1627 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
|
1628 } 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
|
1629 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
|
1630 } |
5584
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 |
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
|
1633 /* Only set completly_emptied, if we just unloaded all remaining cargo */ |
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
|
1634 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
|
1635 |
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
|
1636 /* 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
|
1637 * 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
|
1638 * 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
|
1639 * enough to fill the previous wagons) */ |
8855
2acce887e7ec
(svn r12617) -Codechange: add type safety to the Order's load and unload types.
rubidium <rubidium@openttd.org>
parents:
8843
diff
changeset
|
1640 if (_patches.improved_load && (u->current_order.GetLoadType() & OLFB_FULL_LOAD)) { |
6618
a0ebb1506656
(svn r9838) -Fix: make "improved loading" a proper improved loading instead of loading one (semi-)random vehicle at a time:
rubidium <rubidium@openttd.org>
parents:
6616
diff
changeset
|
1641 /* Update left cargo */ |
7492
09743324277c
(svn r11003) -Codechange: replace Vehicle->next to Vehicle->Next() and Vehicle->SetNext() so we can trap instances that change a next pointer and (in the future) update the first/previous pointers based on that.
rubidium <rubidium@openttd.org>
parents:
7474
diff
changeset
|
1642 for (v = u; v != NULL; v = v->Next()) { |
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
|
1643 if (v->cargo_cap != 0) cargo_left[v->cargo_type] -= v->cargo_cap - v->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
|
1644 } |
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
|
1645 } |
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
|
1646 |
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 v = u; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1648 |
6611
461107df1c8f
(svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents:
6609
diff
changeset
|
1649 if (anything_loaded || anything_unloaded) { |
461107df1c8f
(svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents:
6609
diff
changeset
|
1650 if (_patches.gradual_loading) { |
461107df1c8f
(svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents:
6609
diff
changeset
|
1651 /* The time it takes to load one 'slice' of cargo or passengers depends |
461107df1c8f
(svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents:
6609
diff
changeset
|
1652 * on the vehicle type - the values here are those found in TTDPatch */ |
461107df1c8f
(svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents:
6609
diff
changeset
|
1653 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
|
1654 |
6611
461107df1c8f
(svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents:
6609
diff
changeset
|
1655 unloading_time = gradual_loading_wait_time[v->type]; |
461107df1c8f
(svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents:
6609
diff
changeset
|
1656 } |
461107df1c8f
(svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents:
6609
diff
changeset
|
1657 } else { |
461107df1c8f
(svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents:
6609
diff
changeset
|
1658 bool finished_loading = true; |
8855
2acce887e7ec
(svn r12617) -Codechange: add type safety to the Order's load and unload types.
rubidium <rubidium@openttd.org>
parents:
8843
diff
changeset
|
1659 if (v->current_order.GetLoadType() & OLFB_FULL_LOAD) { |
8873
9780f2a6cd20
(svn r12640) -Codechange: let GetLoadType make a difference between full load and full load any based on the patch setting instead of using the patch setting directly.
rubidium <rubidium@openttd.org>
parents:
8855
diff
changeset
|
1660 if (v->current_order.GetLoadType() == OLF_FULL_LOAD_ANY) { |
6611
461107df1c8f
(svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents:
6609
diff
changeset
|
1661 /* 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
|
1662 * continue loading, no matter how much mail is in */ |
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
|
1663 if ((v->type == VEH_AIRCRAFT && IsCargoInClass(v->cargo_type, CC_PASSENGERS) && v->cargo_cap != v->cargo.Count()) || |
6611
461107df1c8f
(svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents:
6609
diff
changeset
|
1664 (cargo_not_full && (cargo_full & ~cargo_not_full) == 0)) { // There are stull non-full cargos |
461107df1c8f
(svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents:
6609
diff
changeset
|
1665 finished_loading = false; |
461107df1c8f
(svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents:
6609
diff
changeset
|
1666 } |
461107df1c8f
(svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents:
6609
diff
changeset
|
1667 } else if (cargo_not_full != 0) { |
461107df1c8f
(svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents:
6609
diff
changeset
|
1668 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
|
1669 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1670 } |
6611
461107df1c8f
(svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents:
6609
diff
changeset
|
1671 unloading_time = 20; |
461107df1c8f
(svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents:
6609
diff
changeset
|
1672 |
461107df1c8f
(svn r9831) -Codechange: more refactoring of the loading/unloading.
rubidium <rubidium@openttd.org>
parents:
6609
diff
changeset
|
1673 SB(v->vehicle_flags, VF_LOADING_FINISHED, 1, finished_loading); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1674 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1675 |
6259
4a39d6291d58
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium <rubidium@openttd.org>
parents:
6248
diff
changeset
|
1676 if (v->type == VEH_TRAIN) { |
6125
46d001ebacf6
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents:
6119
diff
changeset
|
1677 /* Each platform tile is worth 2 rail vehicles. */ |
5998
bec0f8d9440b
(svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar <celestar@openttd.org>
parents:
5955
diff
changeset
|
1678 int overhang = v->u.rail.cached_total_length - st->GetPlatformLength(v->tile) * TILE_SIZE; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1679 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
|
1680 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
|
1681 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
|
1682 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1683 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1684 |
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
|
1685 /* 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
|
1686 * In the Game Menu do not display indicators |
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
|
1687 * If _patches.loading_indicators == 2, show indicators (bool can be promoted to int as 0 or 1 - results in 2 > 0,1 ) |
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
|
1688 * if _patches.loading_indicators == 1, _local_player must be the owner or must be a spectator to show ind., so 1 > 0 |
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
|
1689 * if _patches.loading_indicators == 0, do not display indicators ... 0 is never greater than anything |
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
|
1690 */ |
7563
417e3ca82c7d
(svn r11088) -Fix (r11063, r11067): MSVC warning C4804: '>' : unsafe use of type 'bool' in operation
glx <glx@openttd.org>
parents:
7543
diff
changeset
|
1691 if (_game_mode != GM_MENU && (_patches.loading_indicators > (uint)(v->owner != _local_player && _local_player != PLAYER_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
|
1692 StringID percent_up_down = STR_NULL; |
d03670858cef
(svn r10270) -Add: prefixed the loading indicator with an arrow, up meaning vehicle is loading, down meaning vehicle is unloading
truelight <truelight@openttd.org>
parents:
7010
diff
changeset
|
1693 int percent = CalcPercentVehicleFilled(v, &percent_up_down); |
6998
13ea0d5f8acf
(svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight <truelight@openttd.org>
parents:
6991
diff
changeset
|
1694 if (v->fill_percent_te_id == INVALID_TE_ID) { |
7014
d03670858cef
(svn r10270) -Add: prefixed the loading indicator with an arrow, up meaning vehicle is loading, down meaning vehicle is unloading
truelight <truelight@openttd.org>
parents:
7010
diff
changeset
|
1695 v->fill_percent_te_id = ShowFillingPercent(v->x_pos, v->y_pos, v->z_pos + 20, percent, percent_up_down); |
6998
13ea0d5f8acf
(svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight <truelight@openttd.org>
parents:
6991
diff
changeset
|
1696 } else { |
7014
d03670858cef
(svn r10270) -Add: prefixed the loading indicator with an arrow, up meaning vehicle is loading, down meaning vehicle is unloading
truelight <truelight@openttd.org>
parents:
7010
diff
changeset
|
1697 UpdateFillingPercent(v->fill_percent_te_id, percent, percent_up_down); |
6998
13ea0d5f8acf
(svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight <truelight@openttd.org>
parents:
6991
diff
changeset
|
1698 } |
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
|
1699 } |
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
|
1700 |
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 v->load_unload_time_rem = unloading_time; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1702 |
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
|
1703 if (completely_emptied) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1704 TriggerVehicle(v, VEHICLE_TRIGGER_EMPTY); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1705 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1706 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1707 if (result != 0) { |
9043
9d514f6b9e04
(svn r12862) -Codechange: reduce code duplication for VehicleType -> WindowClass lookup
smatz <smatz@openttd.org>
parents:
9020
diff
changeset
|
1708 InvalidateWindow(GetWindowClassForVehicleType(v->type), v->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
|
1709 InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
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
|
1710 |
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
|
1711 st->MarkTilesDirty(true); |
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
|
1712 v->MarkDirty(); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1713 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1714 if (result & 2) InvalidateWindow(WC_STATION_VIEW, last_visited); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1715 } |
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 |
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
|
1718 /** |
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
|
1719 * 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
|
1720 * 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
|
1721 * @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
|
1722 */ |
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
|
1723 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
|
1724 { |
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
|
1725 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
|
1726 |
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
|
1727 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
|
1728 |
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
|
1729 std::list<Vehicle *>::iterator iter; |
ce5601a32593
(svn r9836) -Codechange: make non-improved loading happen FIFO-ish; generally loading/unloading will happen fifo, but there are no guarantees on the FIFO-ness. For (better) FIFO guarantees you still need to use improved loading.
rubidium <rubidium@openttd.org>
parents:
6611
diff
changeset
|
1730 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
|
1731 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
|
1732 if (!(v->vehstatus & (VS_STOPPED | VS_CRASHED))) LoadUnloadVehicle(v, cargo_left); |
6616
ce5601a32593
(svn r9836) -Codechange: make non-improved loading happen FIFO-ish; generally loading/unloading will happen fifo, but there are no guarantees on the FIFO-ness. For (better) FIFO guarantees you still need to use improved loading.
rubidium <rubidium@openttd.org>
parents:
6611
diff
changeset
|
1733 } |
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
|
1734 } |
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
|
1735 |
6247
57363e064324
(svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents:
6227
diff
changeset
|
1736 void PlayersMonthlyLoop() |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1737 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1738 PlayersGenStatistics(); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1739 if (_patches.inflation && _cur_year < MAX_YEAR) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1740 AddInflation(); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1741 PlayersPayInterest(); |
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
|
1742 /* Reset the _current_player flag */ |
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 _current_player = OWNER_NONE; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1744 HandleEconomyFluctuations(); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1745 SubsidyMonthlyHandler(); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1746 } |
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 static void DoAcquireCompany(Player *p) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1749 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1750 Player *owner; |
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
|
1751 int i; |
6953
41fd36025784
(svn r10208) -Codechange: replace int32 with Money where appropriate.
rubidium <rubidium@openttd.org>
parents:
6952
diff
changeset
|
1752 Money value; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1753 |
9199
dbe675dc54c4
(svn r13065) -Codechange: remove the need for the news string callbacks. Patch by Cirdan.
rubidium <rubidium@openttd.org>
parents:
9158
diff
changeset
|
1754 SetDParam(0, STR_7059_TRANSPORT_COMPANY_MERGER); |
dbe675dc54c4
(svn r13065) -Codechange: remove the need for the news string callbacks. Patch by Cirdan.
rubidium <rubidium@openttd.org>
parents:
9158
diff
changeset
|
1755 SetDParam(1, p->bankrupt_value == 0 ? STR_707F_HAS_BEEN_TAKEN_OVER_BY : STR_705A_HAS_BEEN_SOLD_TO_FOR); |
dbe675dc54c4
(svn r13065) -Codechange: remove the need for the news string callbacks. Patch by Cirdan.
rubidium <rubidium@openttd.org>
parents:
9158
diff
changeset
|
1756 SetDParam(2, p->index); |
dbe675dc54c4
(svn r13065) -Codechange: remove the need for the news string callbacks. Patch by Cirdan.
rubidium <rubidium@openttd.org>
parents:
9158
diff
changeset
|
1757 SetDParam(3, _current_player); |
dbe675dc54c4
(svn r13065) -Codechange: remove the need for the news string callbacks. Patch by Cirdan.
rubidium <rubidium@openttd.org>
parents:
9158
diff
changeset
|
1758 SetDParam(4, p->bankrupt_value); |
9257
2216e638534b
(svn r13123) -Codechange: passing the bankrupt type via data_b is not needed anymore. Patch by Cirdan.
rubidium <rubidium@openttd.org>
parents:
9236
diff
changeset
|
1759 AddNewsItem(STR_02B6, NS_COMPANY_MERGER, 0, _current_player); |
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 |
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
|
1761 /* original code does this a little bit differently */ |
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
|
1762 PlayerID pi = p->index; |
6262
a457647cd27d
(svn r9071) -Fix [FS#459]: when in networking an other player takes over an AI which is also controlled by a player, move the player with the company to the company who bought out the AI
truelight <truelight@openttd.org>
parents:
6259
diff
changeset
|
1763 ChangeNetworkOwner(pi, _current_player); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1764 ChangeOwnershipOfPlayerItems(pi, _current_player); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1765 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1766 if (p->bankrupt_value == 0) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1767 owner = GetPlayer(_current_player); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1768 owner->current_loan += p->current_loan; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1769 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1770 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1771 value = CalculateCompanyValue(p) >> 2; |
6953
41fd36025784
(svn r10208) -Codechange: replace int32 with Money where appropriate.
rubidium <rubidium@openttd.org>
parents:
6952
diff
changeset
|
1772 PlayerID old_player = _current_player; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1773 for (i = 0; i != 4; i++) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1774 if (p->share_owners[i] != PLAYER_SPECTATOR) { |
6953
41fd36025784
(svn r10208) -Codechange: replace int32 with Money where appropriate.
rubidium <rubidium@openttd.org>
parents:
6952
diff
changeset
|
1775 _current_player = p->share_owners[i]; |
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
|
1776 SubtractMoneyFromPlayer(CommandCost(EXPENSES_OTHER, -value)); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1777 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1778 } |
6953
41fd36025784
(svn r10208) -Codechange: replace int32 with Money where appropriate.
rubidium <rubidium@openttd.org>
parents:
6952
diff
changeset
|
1779 _current_player = old_player; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1780 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1781 p->is_active = false; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1782 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1783 DeletePlayerWindows(pi); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1784 RebuildVehicleLists(); //Updates the open windows to add the newly acquired vehicles to the lists |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1785 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1786 |
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
|
1787 extern int GetAmountOwnedBy(const Player *p, PlayerID 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
|
1788 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1789 /** Acquire shares in an opposing company. |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1790 * @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
|
1791 * @param flags type of operation |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1792 * @param p1 player to buy the shares from |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1793 * @param p2 unused |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1794 */ |
6943
fd42cb9816c6
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium <rubidium@openttd.org>
parents:
6882
diff
changeset
|
1795 CommandCost CmdBuyShareInCompany(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1796 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1797 Player *p; |
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
|
1798 CommandCost cost(EXPENSES_OTHER); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1799 |
7503
876e29bc9d5d
(svn r11018) -Fix [FS#1169]: Disallow buying/selling shares in your own company or a bankrupted/non-existant company.
rubidium <rubidium@openttd.org>
parents:
7492
diff
changeset
|
1800 /* Check if buying shares is allowed (protection against modified clients) */ |
876e29bc9d5d
(svn r11018) -Fix [FS#1169]: Disallow buying/selling shares in your own company or a bankrupted/non-existant company.
rubidium <rubidium@openttd.org>
parents:
7492
diff
changeset
|
1801 /* Cannot buy own shares */ |
876e29bc9d5d
(svn r11018) -Fix [FS#1169]: Disallow buying/selling shares in your own company or a bankrupted/non-existant company.
rubidium <rubidium@openttd.org>
parents:
7492
diff
changeset
|
1802 if (!IsValidPlayer((PlayerID)p1) || !_patches.allow_shares || _current_player == (PlayerID)p1) return CMD_ERROR; |
876e29bc9d5d
(svn r11018) -Fix [FS#1169]: Disallow buying/selling shares in your own company or a bankrupted/non-existant company.
rubidium <rubidium@openttd.org>
parents:
7492
diff
changeset
|
1803 |
876e29bc9d5d
(svn r11018) -Fix [FS#1169]: Disallow buying/selling shares in your own company or a bankrupted/non-existant company.
rubidium <rubidium@openttd.org>
parents:
7492
diff
changeset
|
1804 p = GetPlayer((PlayerID)p1); |
876e29bc9d5d
(svn r11018) -Fix [FS#1169]: Disallow buying/selling shares in your own company or a bankrupted/non-existant company.
rubidium <rubidium@openttd.org>
parents:
7492
diff
changeset
|
1805 |
876e29bc9d5d
(svn r11018) -Fix [FS#1169]: Disallow buying/selling shares in your own company or a bankrupted/non-existant company.
rubidium <rubidium@openttd.org>
parents:
7492
diff
changeset
|
1806 /* Cannot buy shares of non-existent nor bankrupted company */ |
876e29bc9d5d
(svn r11018) -Fix [FS#1169]: Disallow buying/selling shares in your own company or a bankrupted/non-existant company.
rubidium <rubidium@openttd.org>
parents:
7492
diff
changeset
|
1807 if (!p->is_active) 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
|
1808 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1809 /* Protect new companies from hostile takeovers */ |
8424
17e30bf8f359
(svn r11994) -Codechange: Remove numbers from string names where the strings aren't present in TTD, since they don't correspond to either TTD's TextIDs or OpenTTD's StringIDs.
maedhros <maedhros@openttd.org>
parents:
8347
diff
changeset
|
1810 if (_cur_year - p->inaugurated_year < 6) return_cmd_error(STR_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
|
1811 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1812 /* Those lines are here for network-protection (clients can be slow) */ |
6950
d2846442a133
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium <rubidium@openttd.org>
parents:
6943
diff
changeset
|
1813 if (GetAmountOwnedBy(p, PLAYER_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
|
1814 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1815 /* We can not buy out a real player (temporarily). TODO: well, enable it obviously */ |
6950
d2846442a133
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium <rubidium@openttd.org>
parents:
6943
diff
changeset
|
1816 if (GetAmountOwnedBy(p, PLAYER_SPECTATOR) == 1 && !p->is_ai) 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
|
1817 |
6950
d2846442a133
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium <rubidium@openttd.org>
parents:
6943
diff
changeset
|
1818 cost.AddCost(CalculateCompanyValue(p) >> 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
|
1819 if (flags & DC_EXEC) { |
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
|
1820 PlayerByte* b = p->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
|
1821 int i; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1822 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1823 while (*b != PLAYER_SPECTATOR) b++; /* share owners is guaranteed to contain at least one PLAYER_SPECTATOR */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1824 *b = _current_player; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1825 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1826 for (i = 0; p->share_owners[i] == _current_player;) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1827 if (++i == 4) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1828 p->bankrupt_value = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1829 DoAcquireCompany(p); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1830 break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1831 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1832 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1833 InvalidateWindow(WC_COMPANY, p1); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1834 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1835 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
|
1836 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1837 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1838 /** Sell shares in an opposing company. |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1839 * @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
|
1840 * @param flags type of operation |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1841 * @param p1 player to sell the shares from |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1842 * @param p2 unused |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1843 */ |
6943
fd42cb9816c6
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium <rubidium@openttd.org>
parents:
6882
diff
changeset
|
1844 CommandCost CmdSellShareInCompany(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1845 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1846 Player *p; |
6953
41fd36025784
(svn r10208) -Codechange: replace int32 with Money where appropriate.
rubidium <rubidium@openttd.org>
parents:
6952
diff
changeset
|
1847 Money 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
|
1848 |
7503
876e29bc9d5d
(svn r11018) -Fix [FS#1169]: Disallow buying/selling shares in your own company or a bankrupted/non-existant company.
rubidium <rubidium@openttd.org>
parents:
7492
diff
changeset
|
1849 /* Check if selling shares is allowed (protection against modified clients) */ |
876e29bc9d5d
(svn r11018) -Fix [FS#1169]: Disallow buying/selling shares in your own company or a bankrupted/non-existant company.
rubidium <rubidium@openttd.org>
parents:
7492
diff
changeset
|
1850 /* Cannot sell own shares */ |
876e29bc9d5d
(svn r11018) -Fix [FS#1169]: Disallow buying/selling shares in your own company or a bankrupted/non-existant company.
rubidium <rubidium@openttd.org>
parents:
7492
diff
changeset
|
1851 if (!IsValidPlayer((PlayerID)p1) || !_patches.allow_shares || _current_player == (PlayerID)p1) return CMD_ERROR; |
876e29bc9d5d
(svn r11018) -Fix [FS#1169]: Disallow buying/selling shares in your own company or a bankrupted/non-existant company.
rubidium <rubidium@openttd.org>
parents:
7492
diff
changeset
|
1852 |
876e29bc9d5d
(svn r11018) -Fix [FS#1169]: Disallow buying/selling shares in your own company or a bankrupted/non-existant company.
rubidium <rubidium@openttd.org>
parents:
7492
diff
changeset
|
1853 p = GetPlayer((PlayerID)p1); |
876e29bc9d5d
(svn r11018) -Fix [FS#1169]: Disallow buying/selling shares in your own company or a bankrupted/non-existant company.
rubidium <rubidium@openttd.org>
parents:
7492
diff
changeset
|
1854 |
876e29bc9d5d
(svn r11018) -Fix [FS#1169]: Disallow buying/selling shares in your own company or a bankrupted/non-existant company.
rubidium <rubidium@openttd.org>
parents:
7492
diff
changeset
|
1855 /* Cannot sell shares of non-existent nor bankrupted company */ |
876e29bc9d5d
(svn r11018) -Fix [FS#1169]: Disallow buying/selling shares in your own company or a bankrupted/non-existant company.
rubidium <rubidium@openttd.org>
parents:
7492
diff
changeset
|
1856 if (!p->is_active) 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
|
1857 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1858 /* Those lines are here for network-protection (clients can be slow) */ |
6950
d2846442a133
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium <rubidium@openttd.org>
parents:
6943
diff
changeset
|
1859 if (GetAmountOwnedBy(p, _current_player) == 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
|
1860 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1861 /* adjust it a little to make it less profitable to sell and buy */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1862 cost = CalculateCompanyValue(p) >> 2; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1863 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
|
1864 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1865 if (flags & DC_EXEC) { |
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
|
1866 PlayerByte* b = p->share_owners; |
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
|
1867 while (*b != _current_player) b++; // share owners is guaranteed to contain player |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1868 *b = PLAYER_SPECTATOR; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1869 InvalidateWindow(WC_COMPANY, p1); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1870 } |
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
|
1871 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
|
1872 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1873 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1874 /** Buy up another company. |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1875 * 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
|
1876 * that company. |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1877 * @todo currently this only works for AI players |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1878 * @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
|
1879 * @param flags type of operation |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1880 * @param p1 player/company to buy up |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1881 * @param p2 unused |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1882 */ |
6943
fd42cb9816c6
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium <rubidium@openttd.org>
parents:
6882
diff
changeset
|
1883 CommandCost CmdBuyCompany(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1884 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1885 Player *p; |
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
|
1886 PlayerID pid = (PlayerID)p1; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1887 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1888 /* Disable takeovers in multiplayer games */ |
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
|
1889 if (!IsValidPlayer(pid) || _networking) return CMD_ERROR; |
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
|
1890 |
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
|
1891 /* Do not allow players to take over themselves */ |
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
|
1892 if (pid == _current_player) 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
|
1893 |
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
|
1894 p = GetPlayer(pid); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1895 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1896 if (!p->is_ai) return CMD_ERROR; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1897 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1898 if (flags & DC_EXEC) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1899 DoAcquireCompany(p); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1900 } |
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
|
1901 return CommandCost(EXPENSES_OTHER, p->bankrupt_value); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1902 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1903 |
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
|
1904 /** Prices */ |
6247
57363e064324
(svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents:
6227
diff
changeset
|
1905 static void SaveLoad_PRIC() |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1906 { |
6955
8eca8406026b
(svn r10210) -Codechange: make all money related variables 64 bits, so overflowing them should become a little harder.
rubidium <rubidium@openttd.org>
parents:
6954
diff
changeset
|
1907 int vt = CheckSavegameVersion(65) ? (SLE_FILE_I32 | SLE_VAR_I64) : SLE_INT64; |
8eca8406026b
(svn r10210) -Codechange: make all money related variables 64 bits, so overflowing them should become a little harder.
rubidium <rubidium@openttd.org>
parents:
6954
diff
changeset
|
1908 SlArray(&_price, NUM_PRICES, vt); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1909 SlArray(&_price_frac, NUM_PRICES, SLE_UINT16); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1910 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1911 |
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
|
1912 /** Cargo payment rates */ |
6247
57363e064324
(svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents:
6227
diff
changeset
|
1913 static void SaveLoad_CAPR() |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1914 { |
6463
0315af802158
(svn r9638) -Feature: Increase cargo types from 12 to 32 and enable newcargo flag in NewGRF loader.
peter1138 <peter1138@openttd.org>
parents:
6458
diff
changeset
|
1915 uint num_cargo = CheckSavegameVersion(55) ? 12 : NUM_CARGO; |
6955
8eca8406026b
(svn r10210) -Codechange: make all money related variables 64 bits, so overflowing them should become a little harder.
rubidium <rubidium@openttd.org>
parents:
6954
diff
changeset
|
1916 int vt = CheckSavegameVersion(65) ? (SLE_FILE_I32 | SLE_VAR_I64) : SLE_INT64; |
8eca8406026b
(svn r10210) -Codechange: make all money related variables 64 bits, so overflowing them should become a little harder.
rubidium <rubidium@openttd.org>
parents:
6954
diff
changeset
|
1917 SlArray(&_cargo_payment_rates, num_cargo, vt); |
6463
0315af802158
(svn r9638) -Feature: Increase cargo types from 12 to 32 and enable newcargo flag in NewGRF loader.
peter1138 <peter1138@openttd.org>
parents:
6458
diff
changeset
|
1918 SlArray(&_cargo_payment_rates_frac, num_cargo, SLE_UINT16); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1919 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1920 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1921 static const SaveLoad _economy_desc[] = { |
6955
8eca8406026b
(svn r10210) -Codechange: make all money related variables 64 bits, so overflowing them should become a little harder.
rubidium <rubidium@openttd.org>
parents:
6954
diff
changeset
|
1922 SLE_CONDVAR(Economy, max_loan, SLE_FILE_I32 | SLE_VAR_I64, 0, 64), |
8eca8406026b
(svn r10210) -Codechange: make all money related variables 64 bits, so overflowing them should become a little harder.
rubidium <rubidium@openttd.org>
parents:
6954
diff
changeset
|
1923 SLE_CONDVAR(Economy, max_loan, SLE_INT64, 65, SL_MAX_VERSION), |
8eca8406026b
(svn r10210) -Codechange: make all money related variables 64 bits, so overflowing them should become a little harder.
rubidium <rubidium@openttd.org>
parents:
6954
diff
changeset
|
1924 SLE_CONDVAR(Economy, max_loan_unround, SLE_FILE_I32 | SLE_VAR_I64, 0, 64), |
8eca8406026b
(svn r10210) -Codechange: make all money related variables 64 bits, so overflowing them should become a little harder.
rubidium <rubidium@openttd.org>
parents:
6954
diff
changeset
|
1925 SLE_CONDVAR(Economy, max_loan_unround, SLE_INT64, 65, SL_MAX_VERSION), |
7244
00f3d8da22e4
(svn r10541) -Fix [FS#1028]: cargo payment rates overflow.
rubidium <rubidium@openttd.org>
parents:
7229
diff
changeset
|
1926 SLE_CONDVAR(Economy, max_loan_unround_fract, SLE_UINT16, 70, SL_MAX_VERSION), |
6955
8eca8406026b
(svn r10210) -Codechange: make all money related variables 64 bits, so overflowing them should become a little harder.
rubidium <rubidium@openttd.org>
parents:
6954
diff
changeset
|
1927 SLE_VAR(Economy, fluct, SLE_FILE_I16 | SLE_VAR_I32), |
8eca8406026b
(svn r10210) -Codechange: make all money related variables 64 bits, so overflowing them should become a little harder.
rubidium <rubidium@openttd.org>
parents:
6954
diff
changeset
|
1928 SLE_VAR(Economy, interest_rate, SLE_UINT8), |
8eca8406026b
(svn r10210) -Codechange: make all money related variables 64 bits, so overflowing them should become a little harder.
rubidium <rubidium@openttd.org>
parents:
6954
diff
changeset
|
1929 SLE_VAR(Economy, infl_amount, SLE_UINT8), |
8eca8406026b
(svn r10210) -Codechange: make all money related variables 64 bits, so overflowing them should become a little harder.
rubidium <rubidium@openttd.org>
parents:
6954
diff
changeset
|
1930 SLE_VAR(Economy, infl_amount_pr, SLE_UINT8), |
8eca8406026b
(svn r10210) -Codechange: make all money related variables 64 bits, so overflowing them should become a little harder.
rubidium <rubidium@openttd.org>
parents:
6954
diff
changeset
|
1931 SLE_END() |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1932 }; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1933 |
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
|
1934 /** Economy variables */ |
6247
57363e064324
(svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents:
6227
diff
changeset
|
1935 static void SaveLoad_ECMY() |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1936 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1937 SlObject(&_economy, _economy_desc); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1938 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1939 |
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
|
1940 extern const ChunkHandler _economy_chunk_handlers[] = { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1941 { 'PRIC', SaveLoad_PRIC, SaveLoad_PRIC, CH_RIFF | CH_AUTO_LENGTH}, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1942 { 'CAPR', SaveLoad_CAPR, SaveLoad_CAPR, CH_RIFF | CH_AUTO_LENGTH}, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1943 { 'SUBS', Save_SUBS, Load_SUBS, CH_ARRAY}, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1944 { 'ECMY', SaveLoad_ECMY, SaveLoad_ECMY, CH_RIFF | CH_LAST}, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1945 }; |