author | peter1138 |
Thu, 14 Dec 2006 15:14:29 +0000 | |
changeset 5333 | 8e7d68b06399 |
parent 5284 | 3c42e8e18392 |
child 5369 | 4363e2fc3e4a |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
0 | 3 |
#include "stdafx.h" |
1891
92a3b0aa0946
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1884
diff
changeset
|
4 |
#include "openttd.h" |
2291
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2272
diff
changeset
|
5 |
#include "currency.h" |
2163
637ec3c361f5
(svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents:
2159
diff
changeset
|
6 |
#include "functions.h" |
1309
dab90d4cbf2d
(svn r1813) Declare functions implemented in strings.c in their own shiny new header (though i think some of these function don't belong into strings.c)
tron
parents:
1308
diff
changeset
|
7 |
#include "strings.h" // XXX InjectDParam() |
507
8aa8100b0b22
(svn r815) Include strings.h only in the files which need it.
tron
parents:
499
diff
changeset
|
8 |
#include "table/strings.h" |
2218
abd47ef7d902
(svn r2736) -Codechange: De-mystified GfxDrawFillRect a bit, and used enums from table/sprites.h. You can now change the number of bits used for sprites and switches in the SpriteSetup enum and the rest should work automagically. Can be used to increase the number of active sprites to 2^19 in case there are no colortables (recolor sprites) in any newgrf. We should possibly move the the colortables to an own list, but how to detect them in a newgrf.
celestar
parents:
2186
diff
changeset
|
9 |
#include "table/sprites.h" |
679
e959706a3e4d
(svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
653
diff
changeset
|
10 |
#include "map.h" |
0 | 11 |
#include "news.h" |
12 |
#include "player.h" |
|
13 |
#include "station.h" |
|
14 |
#include "vehicle.h" |
|
15 |
#include "window.h" |
|
16 |
#include "gfx.h" |
|
17 |
#include "command.h" |
|
18 |
#include "saveload.h" |
|
19 |
#include "economy.h" |
|
20 |
#include "industry.h" |
|
21 |
#include "town.h" |
|
239 | 22 |
#include "network.h" |
337
66647f97e7c0
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
260
diff
changeset
|
23 |
#include "sound.h" |
445
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
337
diff
changeset
|
24 |
#include "engine.h" |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
25 |
#include "network_data.h" |
2159
3b634157c3b2
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2150
diff
changeset
|
26 |
#include "variables.h" |
3b634157c3b2
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2150
diff
changeset
|
27 |
#include "vehicle_gui.h" |
2395
19b4da30806b
(svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents:
2306
diff
changeset
|
28 |
#include "ai/ai.h" |
2676
2ba71e034d97
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2642
diff
changeset
|
29 |
#include "train.h" |
2962
dbd168a4703a
(svn r3524) - Split newgrf features from engine.[ch] into newgrf_engine.[ch], and add the new files to project files.
peter1138
parents:
2952
diff
changeset
|
30 |
#include "newgrf_engine.h" |
4701 | 31 |
#include "newgrf_sound.h" |
5211
651c9272ad22
(svn r7326) -Feature: Add support for gradual (un)loading of vehicles (Maedhros)
peter1138
parents:
5077
diff
changeset
|
32 |
#include "newgrf_callbacks.h" |
3386
edda700ed8e5
(svn r4194) -Codechange: Renamed UpdatePlayerHouse to UpdateCompanyHQ because the rest of the code calls it Comapany HQ. Moved it to unmovable_cmd.c because CompanyHQ is an unmovable and has nothing to do with economy.
celestar
parents:
3347
diff
changeset
|
33 |
#include "unmovable.h" |
4261
2ec8f5a9747b
(svn r5887) -Cleanup: move date related functions, defines and variables to date.[ch]
rubidium
parents:
4260
diff
changeset
|
34 |
#include "date.h" |
0 | 35 |
|
2261
3f78323707bb
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2218
diff
changeset
|
36 |
// Score info |
3f78323707bb
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2218
diff
changeset
|
37 |
const ScoreInfo _score_info[] = { |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3655
diff
changeset
|
38 |
{ SCORE_VEHICLES, 120, 100 }, |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3655
diff
changeset
|
39 |
{ SCORE_STATIONS, 80, 100 }, |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3655
diff
changeset
|
40 |
{ SCORE_MIN_PROFIT, 10000, 100 }, |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3655
diff
changeset
|
41 |
{ SCORE_MIN_INCOME, 50000, 50 }, |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3655
diff
changeset
|
42 |
{ SCORE_MAX_INCOME, 100000, 100 }, |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3655
diff
changeset
|
43 |
{ SCORE_DELIVERED, 40000, 400 }, |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3655
diff
changeset
|
44 |
{ SCORE_CARGO, 8, 50 }, |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3655
diff
changeset
|
45 |
{ SCORE_MONEY, 10000000, 50 }, |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3655
diff
changeset
|
46 |
{ SCORE_LOAN, 250000, 50 }, |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3655
diff
changeset
|
47 |
{ SCORE_TOTAL, 0, 0 } |
2261
3f78323707bb
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2218
diff
changeset
|
48 |
}; |
3f78323707bb
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2218
diff
changeset
|
49 |
|
3f78323707bb
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2218
diff
changeset
|
50 |
int _score_part[MAX_PLAYERS][NUM_SCORE]; |
3f78323707bb
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2218
diff
changeset
|
51 |
|
2639 | 52 |
int64 CalculateCompanyValue(const Player* p) |
2475 | 53 |
{ |
54 |
PlayerID owner = p->index; |
|
200
03b8104d1479
(svn r201) -Fix: [1025836] Company values bigger dan int32 were put to negative
truelight
parents:
193
diff
changeset
|
55 |
int64 value; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
56 |
|
0 | 57 |
{ |
58 |
Station *st; |
|
59 |
uint num = 0; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
60 |
|
0 | 61 |
FOR_ALL_STATIONS(st) { |
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
62 |
if (st->owner == owner) { |
0 | 63 |
uint facil = st->facilities; |
64 |
do num += (facil&1); while (facil >>= 1); |
|
65 |
} |
|
66 |
} |
|
67 |
||
68 |
value = num * _price.station_value * 25; |
|
69 |
} |
|
70 |
||
71 |
{ |
|
72 |
Vehicle *v; |
|
73 |
||
74 |
FOR_ALL_VEHICLES(v) { |
|
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
75 |
if (v->owner != owner) continue; |
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
76 |
|
0 | 77 |
if (v->type == VEH_Train || |
78 |
v->type == VEH_Road || |
|
79 |
(v->type == VEH_Aircraft && v->subtype<=2) || |
|
80 |
v->type == VEH_Ship) { |
|
81 |
value += v->value * 3 >> 1; |
|
82 |
} |
|
83 |
} |
|
84 |
} |
|
85 |
||
997
71cf4e50d259
(svn r1495) -Fix: Loan does not count against the company value
celestar
parents:
970
diff
changeset
|
86 |
value += p->money64 - p->current_loan; // add real money value |
1019
6363b8a4273e
(svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents:
997
diff
changeset
|
87 |
|
1651
cb5dc4dc3c40
(svn r2155) - Fix: Company value was $2 when value more than an int32 could handle (use max64 instead of max)
Darkvater
parents:
1634
diff
changeset
|
88 |
return max64(value, 1); |
0 | 89 |
} |
90 |
||
116
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
91 |
// if update is set to true, the economy is updated with this score |
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
92 |
// (also the house is updated, should only be true in the on-tick event) |
147
d0c8100d18cf
(svn r148) -Feature: Company HQ can now be moved somewhere else (cost 1% of company value). Water floods HQ.
darkvater
parents:
116
diff
changeset
|
93 |
int UpdateCompanyRatingAndValue(Player *p, bool update) |
0 | 94 |
{ |
95 |
byte owner = p->index; |
|
116
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
96 |
int score = 0; |
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
97 |
|
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
98 |
memset(_score_part[owner], 0, sizeof(_score_part[owner])); |
0 | 99 |
|
100 |
/* Count vehicles */ |
|
101 |
{ |
|
102 |
Vehicle *v; |
|
2829
e2dde3fe0bd9
(svn r3377) -Fix: [ FS#24 ] Min. profit in detail performance rating gave you full points if you had no vehicles, and was limited to 20k. Solved both. (Partly based on Graphite his patch)
truelight
parents:
2815
diff
changeset
|
103 |
int32 min_profit = 0; |
e2dde3fe0bd9
(svn r3377) -Fix: [ FS#24 ] Min. profit in detail performance rating gave you full points if you had no vehicles, and was limited to 20k. Solved both. (Partly based on Graphite his patch)
truelight
parents:
2815
diff
changeset
|
104 |
bool min_profit_first = true; |
0 | 105 |
uint num = 0; |
106 |
||
107 |
FOR_ALL_VEHICLES(v) { |
|
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3655
diff
changeset
|
108 |
if (v->owner != owner) continue; |
2676
2ba71e034d97
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2642
diff
changeset
|
109 |
if ((v->type == VEH_Train && IsFrontEngine(v)) || |
2829
e2dde3fe0bd9
(svn r3377) -Fix: [ FS#24 ] Min. profit in detail performance rating gave you full points if you had no vehicles, and was limited to 20k. Solved both. (Partly based on Graphite his patch)
truelight
parents:
2815
diff
changeset
|
110 |
v->type == VEH_Road || |
e2dde3fe0bd9
(svn r3377) -Fix: [ FS#24 ] Min. profit in detail performance rating gave you full points if you had no vehicles, and was limited to 20k. Solved both. (Partly based on Graphite his patch)
truelight
parents:
2815
diff
changeset
|
111 |
(v->type == VEH_Aircraft && v->subtype <= 2) || |
e2dde3fe0bd9
(svn r3377) -Fix: [ FS#24 ] Min. profit in detail performance rating gave you full points if you had no vehicles, and was limited to 20k. Solved both. (Partly based on Graphite his patch)
truelight
parents:
2815
diff
changeset
|
112 |
v->type == VEH_Ship) { |
0 | 113 |
num++; |
114 |
if (v->age > 730) { |
|
2829
e2dde3fe0bd9
(svn r3377) -Fix: [ FS#24 ] Min. profit in detail performance rating gave you full points if you had no vehicles, and was limited to 20k. Solved both. (Partly based on Graphite his patch)
truelight
parents:
2815
diff
changeset
|
115 |
/* Find the vehicle with the lowest amount of profit */ |
e2dde3fe0bd9
(svn r3377) -Fix: [ FS#24 ] Min. profit in detail performance rating gave you full points if you had no vehicles, and was limited to 20k. Solved both. (Partly based on Graphite his patch)
truelight
parents:
2815
diff
changeset
|
116 |
if (min_profit_first == true) { |
e2dde3fe0bd9
(svn r3377) -Fix: [ FS#24 ] Min. profit in detail performance rating gave you full points if you had no vehicles, and was limited to 20k. Solved both. (Partly based on Graphite his patch)
truelight
parents:
2815
diff
changeset
|
117 |
min_profit = v->profit_last_year; |
e2dde3fe0bd9
(svn r3377) -Fix: [ FS#24 ] Min. profit in detail performance rating gave you full points if you had no vehicles, and was limited to 20k. Solved both. (Partly based on Graphite his patch)
truelight
parents:
2815
diff
changeset
|
118 |
min_profit_first = false; |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3655
diff
changeset
|
119 |
} else if (min_profit > v->profit_last_year) { |
0 | 120 |
min_profit = v->profit_last_year; |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3655
diff
changeset
|
121 |
} |
0 | 122 |
} |
123 |
} |
|
124 |
} |
|
125 |
||
116
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
126 |
_score_part[owner][SCORE_VEHICLES] = num; |
2829
e2dde3fe0bd9
(svn r3377) -Fix: [ FS#24 ] Min. profit in detail performance rating gave you full points if you had no vehicles, and was limited to 20k. Solved both. (Partly based on Graphite his patch)
truelight
parents:
2815
diff
changeset
|
127 |
/* Don't allow negative min_profit to show */ |
1407
bbcdd50795e3
(svn r1911) Put back an "if" i accidently removed in r1898
tron
parents:
1394
diff
changeset
|
128 |
if (min_profit > 0) |
bbcdd50795e3
(svn r1911) Put back an "if" i accidently removed in r1898
tron
parents:
1394
diff
changeset
|
129 |
_score_part[owner][SCORE_MIN_PROFIT] = min_profit; |
0 | 130 |
} |
131 |
||
132 |
/* Count stations */ |
|
133 |
{ |
|
134 |
uint num = 0; |
|
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3017
diff
changeset
|
135 |
const Station* st; |
0 | 136 |
|
137 |
FOR_ALL_STATIONS(st) { |
|
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
138 |
if (st->owner == owner) { |
0 | 139 |
int facil = st->facilities; |
140 |
do num += facil&1; while (facil>>=1); |
|
141 |
} |
|
142 |
} |
|
116
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
143 |
_score_part[owner][SCORE_STATIONS] = num; |
0 | 144 |
} |
145 |
||
146 |
/* Generate statistics depending on recent income statistics */ |
|
147 |
{ |
|
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3017
diff
changeset
|
148 |
const PlayerEconomyEntry* pee; |
0 | 149 |
int numec; |
150 |
int32 min_income; |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
151 |
int32 max_income; |
0 | 152 |
|
153 |
numec = min(p->num_valid_stat_ent, 12); |
|
154 |
if (numec != 0) { |
|
155 |
min_income = 0x7FFFFFFF; |
|
156 |
max_income = 0; |
|
157 |
pee = p->old_economy; |
|
158 |
do { |
|
159 |
min_income = min(min_income, pee->income + pee->expenses); |
|
160 |
max_income = max(max_income, pee->income + pee->expenses); |
|
161 |
} while (++pee,--numec); |
|
162 |
||
163 |
if (min_income > 0) |
|
116
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
164 |
_score_part[owner][SCORE_MIN_INCOME] = min_income; |
0 | 165 |
|
116
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
166 |
_score_part[owner][SCORE_MAX_INCOME] = max_income; |
0 | 167 |
} |
168 |
} |
|
169 |
||
170 |
/* Generate score depending on amount of transported cargo */ |
|
171 |
{ |
|
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3017
diff
changeset
|
172 |
const PlayerEconomyEntry* pee; |
0 | 173 |
int numec; |
174 |
uint32 total_delivered; |
|
175 |
||
176 |
numec = min(p->num_valid_stat_ent, 4); |
|
177 |
if (numec != 0) { |
|
178 |
pee = p->old_economy; |
|
179 |
total_delivered = 0; |
|
180 |
do { |
|
181 |
total_delivered += pee->delivered_cargo; |
|
182 |
} while (++pee,--numec); |
|
183 |
||
116
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
184 |
_score_part[owner][SCORE_DELIVERED] = total_delivered; |
0 | 185 |
} |
186 |
} |
|
116
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
187 |
|
0 | 188 |
/* Generate score for variety of cargo */ |
189 |
{ |
|
190 |
uint cargo = p->cargo_types; |
|
191 |
uint num = 0; |
|
192 |
do num += cargo&1; while (cargo>>=1); |
|
116
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
193 |
_score_part[owner][SCORE_CARGO] = num; |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3017
diff
changeset
|
194 |
if (update) p->cargo_types = 0; |
0 | 195 |
} |
196 |
||
197 |
/* Generate score for player money */ |
|
198 |
{ |
|
199 |
int32 money = p->player_money; |
|
200 |
if (money > 0) { |
|
116
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
201 |
_score_part[owner][SCORE_MONEY] = money; |
0 | 202 |
} |
203 |
} |
|
204 |
||
205 |
/* Generate score for loan */ |
|
206 |
{ |
|
2261
3f78323707bb
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2218
diff
changeset
|
207 |
_score_part[owner][SCORE_LOAN] = _score_info[SCORE_LOAN].needed - p->current_loan; |
116
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
208 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
209 |
|
116
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
210 |
// Now we calculate the score for each item.. |
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
211 |
{ |
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
212 |
int i; |
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
213 |
int total_score = 0; |
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
214 |
int s; |
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
215 |
score = 0; |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3017
diff
changeset
|
216 |
for (i = 0; i < NUM_SCORE; i++) { |
116
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
217 |
// Skip the total |
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
218 |
if (i == SCORE_TOTAL) continue; |
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
219 |
// Check the score |
2261
3f78323707bb
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2218
diff
changeset
|
220 |
s = (_score_part[owner][i] >= _score_info[i].needed) ? |
3f78323707bb
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2218
diff
changeset
|
221 |
_score_info[i].score : |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3017
diff
changeset
|
222 |
_score_part[owner][i] * _score_info[i].score / _score_info[i].needed; |
116
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
223 |
if (s < 0) s = 0; |
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
224 |
score += s; |
2261
3f78323707bb
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2218
diff
changeset
|
225 |
total_score += _score_info[i].score; |
116
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
226 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
227 |
|
116
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
228 |
_score_part[owner][SCORE_TOTAL] = score; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
229 |
|
116
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
230 |
// We always want the score scaled to SCORE_MAX (1000) |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3017
diff
changeset
|
231 |
if (total_score != SCORE_MAX) score = score * SCORE_MAX / total_score; |
0 | 232 |
} |
233 |
||
116
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
234 |
if (update) { |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3655
diff
changeset
|
235 |
p->old_economy[0].performance_history = score; |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3655
diff
changeset
|
236 |
UpdateCompanyHQ(p, score); |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3655
diff
changeset
|
237 |
p->old_economy[0].company_value = CalculateCompanyValue(p); |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3655
diff
changeset
|
238 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
239 |
|
116
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
240 |
InvalidateWindow(WC_PERFORMANCE_DETAIL, 0); |
147
d0c8100d18cf
(svn r148) -Feature: Company HQ can now be moved somewhere else (cost 1% of company value). Water floods HQ.
darkvater
parents:
116
diff
changeset
|
241 |
return score; |
0 | 242 |
} |
243 |
||
4848
56549aa3e234
(svn r6774) -Codechange: Rename the badly named OWNER_SPECTATOR to PLAYER_SPECTATOR and
Darkvater
parents:
4845
diff
changeset
|
244 |
// use PLAYER_SPECTATOR as new_player to delete the player. |
1797
a19c4181f1b7
(svn r2301) - CodeChange: prettyify ChangeOwnerShipOfPlayerItems() a bit
Darkvater
parents:
1793
diff
changeset
|
245 |
void ChangeOwnershipOfPlayerItems(PlayerID old_player, PlayerID new_player) |
0 | 246 |
{ |
5284
3c42e8e18392
(svn r7433) -Fix (r2301): Town ratings were not reset when a company went bankrupt.
peter1138
parents:
5251
diff
changeset
|
247 |
Town *t; |
1797
a19c4181f1b7
(svn r2301) - CodeChange: prettyify ChangeOwnerShipOfPlayerItems() a bit
Darkvater
parents:
1793
diff
changeset
|
248 |
PlayerID old = _current_player; |
0 | 249 |
_current_player = old_player; |
250 |
||
4260
8a9824f6e501
(svn r5886) -Fix [FS#273]: Incomplete removal of player owned property due to lack of money.
Darkvater
parents:
4077
diff
changeset
|
251 |
/* Temporarily increase the player's money, to be sure that |
4549
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4540
diff
changeset
|
252 |
* removing his/her property doesn't fail because of lack of money. |
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4540
diff
changeset
|
253 |
* Not too drastically though, because it could overflow */ |
4848
56549aa3e234
(svn r6774) -Codechange: Rename the badly named OWNER_SPECTATOR to PLAYER_SPECTATOR and
Darkvater
parents:
4845
diff
changeset
|
254 |
if (new_player == PLAYER_SPECTATOR) { |
4540
2f70d57828e1
(svn r6369) -Fix (r5886): On loading of game in scenario editor the player was given
Darkvater
parents:
4434
diff
changeset
|
255 |
GetPlayer(old_player)->money64 = MAX_UVALUE(uint64) >>2; // jackpot ;p |
4423
cc00f674d978
(svn r6178) -Fix r5886: only setting ->money64 isn't enough, as some routines still use ->player_money.
truelight
parents:
4356
diff
changeset
|
256 |
UpdatePlayerMoney32(GetPlayer(old_player)); |
4260
8a9824f6e501
(svn r5886) -Fix [FS#273]: Incomplete removal of player owned property due to lack of money.
Darkvater
parents:
4077
diff
changeset
|
257 |
} |
8a9824f6e501
(svn r5886) -Fix [FS#273]: Incomplete removal of player owned property due to lack of money.
Darkvater
parents:
4077
diff
changeset
|
258 |
|
4848
56549aa3e234
(svn r6774) -Codechange: Rename the badly named OWNER_SPECTATOR to PLAYER_SPECTATOR and
Darkvater
parents:
4845
diff
changeset
|
259 |
if (new_player == PLAYER_SPECTATOR) { |
0 | 260 |
Subsidy *s; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
261 |
|
1797
a19c4181f1b7
(svn r2301) - CodeChange: prettyify ChangeOwnerShipOfPlayerItems() a bit
Darkvater
parents:
1793
diff
changeset
|
262 |
for (s = _subsidies; s != endof(_subsidies); s++) { |
2469
1bfbb0dc0b75
(svn r2995) Replace 0xFF/0xFFFF with CT_INVALID/OWNER_SPECTATOR/INVALID_STATION where appropriate
tron
parents:
2436
diff
changeset
|
263 |
if (s->cargo_type != CT_INVALID && s->age >= 12) { |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3655
diff
changeset
|
264 |
if (GetStation(s->to)->owner == old_player) s->cargo_type = CT_INVALID; |
0 | 265 |
} |
266 |
} |
|
267 |
} |
|
268 |
||
1797
a19c4181f1b7
(svn r2301) - CodeChange: prettyify ChangeOwnerShipOfPlayerItems() a bit
Darkvater
parents:
1793
diff
changeset
|
269 |
/* Take care of rating in towns */ |
5284
3c42e8e18392
(svn r7433) -Fix (r2301): Town ratings were not reset when a company went bankrupt.
peter1138
parents:
5251
diff
changeset
|
270 |
FOR_ALL_TOWNS(t) { |
3c42e8e18392
(svn r7433) -Fix (r2301): Town ratings were not reset when a company went bankrupt.
peter1138
parents:
5251
diff
changeset
|
271 |
/* If a player takes over, give the ratings to that player. */ |
3c42e8e18392
(svn r7433) -Fix (r2301): Town ratings were not reset when a company went bankrupt.
peter1138
parents:
5251
diff
changeset
|
272 |
if (new_player != PLAYER_SPECTATOR) { |
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
273 |
if (HASBIT(t->have_ratings, old_player)) { |
4260
8a9824f6e501
(svn r5886) -Fix [FS#273]: Incomplete removal of player owned property due to lack of money.
Darkvater
parents:
4077
diff
changeset
|
274 |
if (HASBIT(t->have_ratings, new_player)) { |
8a9824f6e501
(svn r5886) -Fix [FS#273]: Incomplete removal of player owned property due to lack of money.
Darkvater
parents:
4077
diff
changeset
|
275 |
// use max of the two ratings. |
8a9824f6e501
(svn r5886) -Fix [FS#273]: Incomplete removal of player owned property due to lack of money.
Darkvater
parents:
4077
diff
changeset
|
276 |
t->ratings[new_player] = max(t->ratings[new_player], t->ratings[old_player]); |
8a9824f6e501
(svn r5886) -Fix [FS#273]: Incomplete removal of player owned property due to lack of money.
Darkvater
parents:
4077
diff
changeset
|
277 |
} else { |
8a9824f6e501
(svn r5886) -Fix [FS#273]: Incomplete removal of player owned property due to lack of money.
Darkvater
parents:
4077
diff
changeset
|
278 |
SETBIT(t->have_ratings, new_player); |
8a9824f6e501
(svn r5886) -Fix [FS#273]: Incomplete removal of player owned property due to lack of money.
Darkvater
parents:
4077
diff
changeset
|
279 |
t->ratings[new_player] = t->ratings[old_player]; |
1797
a19c4181f1b7
(svn r2301) - CodeChange: prettyify ChangeOwnerShipOfPlayerItems() a bit
Darkvater
parents:
1793
diff
changeset
|
280 |
} |
4260
8a9824f6e501
(svn r5886) -Fix [FS#273]: Incomplete removal of player owned property due to lack of money.
Darkvater
parents:
4077
diff
changeset
|
281 |
} |
5284
3c42e8e18392
(svn r7433) -Fix (r2301): Town ratings were not reset when a company went bankrupt.
peter1138
parents:
5251
diff
changeset
|
282 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
283 |
|
5284
3c42e8e18392
(svn r7433) -Fix (r2301): Town ratings were not reset when a company went bankrupt.
peter1138
parents:
5251
diff
changeset
|
284 |
/* Reset the ratings for the old player */ |
3c42e8e18392
(svn r7433) -Fix (r2301): Town ratings were not reset when a company went bankrupt.
peter1138
parents:
5251
diff
changeset
|
285 |
t->ratings[old_player] = 500; |
3c42e8e18392
(svn r7433) -Fix (r2301): Town ratings were not reset when a company went bankrupt.
peter1138
parents:
5251
diff
changeset
|
286 |
CLRBIT(t->have_ratings, old_player); |
0 | 287 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
288 |
|
0 | 289 |
{ |
290 |
int num_train = 0; |
|
291 |
int num_road = 0; |
|
292 |
int num_ship = 0; |
|
293 |
int num_aircraft = 0; |
|
294 |
Vehicle *v; |
|
295 |
||
296 |
// Determine Ids for the new vehicles |
|
297 |
FOR_ALL_VEHICLES(v) { |
|
298 |
if (v->owner == new_player) { |
|
1797
a19c4181f1b7
(svn r2301) - CodeChange: prettyify ChangeOwnerShipOfPlayerItems() a bit
Darkvater
parents:
1793
diff
changeset
|
299 |
switch (v->type) { |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3655
diff
changeset
|
300 |
case VEH_Train: if (IsFrontEngine(v)) num_train++; break; |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3655
diff
changeset
|
301 |
case VEH_Road: num_road++; break; |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3655
diff
changeset
|
302 |
case VEH_Ship: num_ship++; break; |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3655
diff
changeset
|
303 |
case VEH_Aircraft: if (v->subtype <= 2) num_aircraft++; break; |
1797
a19c4181f1b7
(svn r2301) - CodeChange: prettyify ChangeOwnerShipOfPlayerItems() a bit
Darkvater
parents:
1793
diff
changeset
|
304 |
default: break; |
a19c4181f1b7
(svn r2301) - CodeChange: prettyify ChangeOwnerShipOfPlayerItems() a bit
Darkvater
parents:
1793
diff
changeset
|
305 |
} |
0 | 306 |
} |
307 |
} |
|
308 |
||
309 |
FOR_ALL_VEHICLES(v) { |
|
2951 | 310 |
if (v->owner == old_player && IS_BYTE_INSIDE(v->type, VEH_Train, VEH_Aircraft + 1)) { |
4848
56549aa3e234
(svn r6774) -Codechange: Rename the badly named OWNER_SPECTATOR to PLAYER_SPECTATOR and
Darkvater
parents:
4845
diff
changeset
|
311 |
if (new_player == PLAYER_SPECTATOR) { |
0 | 312 |
DeleteWindowById(WC_VEHICLE_VIEW, v->index); |
313 |
DeleteWindowById(WC_VEHICLE_DETAILS, v->index); |
|
314 |
DeleteWindowById(WC_VEHICLE_ORDERS, v->index); |
|
315 |
DeleteVehicle(v); |
|
316 |
} else { |
|
317 |
v->owner = new_player; |
|
4621
79238ae21c0d
(svn r6479) -Fix r6424: FS#348 Plane autoreplace glitch
bjarni
parents:
4549
diff
changeset
|
318 |
if (IsEngineCountable(v)) GetPlayer(new_player)->num_engines[v->engine_type]++; |
2989 | 319 |
switch (v->type) { |
320 |
case VEH_Train: if (IsFrontEngine(v)) v->unitnumber = ++num_train; break; |
|
321 |
case VEH_Road: v->unitnumber = ++num_road; break; |
|
322 |
case VEH_Ship: v->unitnumber = ++num_ship; break; |
|
323 |
case VEH_Aircraft: if (v->subtype <= 2) v->unitnumber = ++num_aircraft; break; |
|
324 |
} |
|
0 | 325 |
} |
326 |
} |
|
327 |
} |
|
328 |
} |
|
329 |
||
330 |
// Change ownership of tiles |
|
331 |
{ |
|
1797
a19c4181f1b7
(svn r2301) - CodeChange: prettyify ChangeOwnerShipOfPlayerItems() a bit
Darkvater
parents:
1793
diff
changeset
|
332 |
TileIndex tile = 0; |
0 | 333 |
do { |
334 |
ChangeTileOwner(tile, old_player, new_player); |
|
863
8d09f9331a80
(svn r1344) Use MapSize[XY]() (or MapSize()/MapMax[XY]() where appropriate) instead of TILES_[XY]
tron
parents:
830
diff
changeset
|
335 |
} while (++tile != MapSize()); |
0 | 336 |
} |
337 |
||
5077
587701a06b6a
(svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents:
5067
diff
changeset
|
338 |
/* Change color of existing windows */ |
587701a06b6a
(svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents:
5067
diff
changeset
|
339 |
if (new_player != PLAYER_SPECTATOR) ChangeWindowOwner(old_player, new_player); |
0 | 340 |
|
780
f7d6976a1fc8
(svn r1247) -Fix: [ 1090313 ] Shares are now also sold when a company goes bankrupt
truelight
parents:
768
diff
changeset
|
341 |
{ |
f7d6976a1fc8
(svn r1247) -Fix: [ 1090313 ] Shares are now also sold when a company goes bankrupt
truelight
parents:
768
diff
changeset
|
342 |
Player *p; |
f7d6976a1fc8
(svn r1247) -Fix: [ 1090313 ] Shares are now also sold when a company goes bankrupt
truelight
parents:
768
diff
changeset
|
343 |
uint i; |
f7d6976a1fc8
(svn r1247) -Fix: [ 1090313 ] Shares are now also sold when a company goes bankrupt
truelight
parents:
768
diff
changeset
|
344 |
|
f7d6976a1fc8
(svn r1247) -Fix: [ 1090313 ] Shares are now also sold when a company goes bankrupt
truelight
parents:
768
diff
changeset
|
345 |
/* Check for shares */ |
f7d6976a1fc8
(svn r1247) -Fix: [ 1090313 ] Shares are now also sold when a company goes bankrupt
truelight
parents:
768
diff
changeset
|
346 |
FOR_ALL_PLAYERS(p) { |
1797
a19c4181f1b7
(svn r2301) - CodeChange: prettyify ChangeOwnerShipOfPlayerItems() a bit
Darkvater
parents:
1793
diff
changeset
|
347 |
for (i = 0; i < 4; i++) { |
780
f7d6976a1fc8
(svn r1247) -Fix: [ 1090313 ] Shares are now also sold when a company goes bankrupt
truelight
parents:
768
diff
changeset
|
348 |
/* 'Sell' the share if this player has any */ |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3655
diff
changeset
|
349 |
if (p->share_owners[i] == _current_player) { |
4848
56549aa3e234
(svn r6774) -Codechange: Rename the badly named OWNER_SPECTATOR to PLAYER_SPECTATOR and
Darkvater
parents:
4845
diff
changeset
|
350 |
p->share_owners[i] = PLAYER_SPECTATOR; |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3655
diff
changeset
|
351 |
} |
780
f7d6976a1fc8
(svn r1247) -Fix: [ 1090313 ] Shares are now also sold when a company goes bankrupt
truelight
parents:
768
diff
changeset
|
352 |
} |
f7d6976a1fc8
(svn r1247) -Fix: [ 1090313 ] Shares are now also sold when a company goes bankrupt
truelight
parents:
768
diff
changeset
|
353 |
} |
1962
51ee4f459268
(svn r2468) -Codechange: Got rid of DEREF_PLAYER and replaced it by GetPlayer
celestar
parents:
1935
diff
changeset
|
354 |
p = GetPlayer(_current_player); |
780
f7d6976a1fc8
(svn r1247) -Fix: [ 1090313 ] Shares are now also sold when a company goes bankrupt
truelight
parents:
768
diff
changeset
|
355 |
/* Sell all the shares that people have on this company */ |
1797
a19c4181f1b7
(svn r2301) - CodeChange: prettyify ChangeOwnerShipOfPlayerItems() a bit
Darkvater
parents:
1793
diff
changeset
|
356 |
for (i = 0; i < 4; i++) |
4848
56549aa3e234
(svn r6774) -Codechange: Rename the badly named OWNER_SPECTATOR to PLAYER_SPECTATOR and
Darkvater
parents:
4845
diff
changeset
|
357 |
p->share_owners[i] = PLAYER_SPECTATOR; |
780
f7d6976a1fc8
(svn r1247) -Fix: [ 1090313 ] Shares are now also sold when a company goes bankrupt
truelight
parents:
768
diff
changeset
|
358 |
} |
f7d6976a1fc8
(svn r1247) -Fix: [ 1090313 ] Shares are now also sold when a company goes bankrupt
truelight
parents:
768
diff
changeset
|
359 |
|
0 | 360 |
_current_player = old; |
361 |
||
362 |
MarkWholeScreenDirty(); |
|
363 |
} |
|
364 |
||
365 |
static void PlayersCheckBankrupt(Player *p) |
|
366 |
{ |
|
2475 | 367 |
PlayerID owner; |
200
03b8104d1479
(svn r201) -Fix: [1025836] Company values bigger dan int32 were put to negative
truelight
parents:
193
diff
changeset
|
368 |
int64 val; |
0 | 369 |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
370 |
// If the player has money again, it does not go bankrupt |
0 | 371 |
if (p->player_money >= 0) { |
372 |
p->quarters_of_bankrupcy = 0; |
|
373 |
return; |
|
374 |
} |
|
375 |
||
376 |
p->quarters_of_bankrupcy++; |
|
377 |
||
378 |
owner = p->index; |
|
379 |
||
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
380 |
switch (p->quarters_of_bankrupcy) { |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
381 |
case 2: |
4873
7cb19235cf60
(svn r6803) -Codechange: Substitute magic numbers by an enum for the news windows
Darkvater
parents:
4854
diff
changeset
|
382 |
AddNewsItem( (StringID)(owner | NB_BTROUBLE), |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
383 |
NEWS_FLAGS(NM_CALLBACK, 0, NT_COMPANY_INFO, DNC_BANKRUPCY),0,0); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
384 |
break; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
385 |
case 3: { |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
386 |
/* XXX - In multiplayer, should we ask other players if it wants to take |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
387 |
over when it is a human company? -- TrueLight */ |
4845
49105d3b5a9a
(svn r6771) -Codechange: Replace two macros with functions. IS_HUMAN_PLAYER and
Darkvater
parents:
4814
diff
changeset
|
388 |
if (IsHumanPlayer(owner)) { |
4873
7cb19235cf60
(svn r6803) -Codechange: Substitute magic numbers by an enum for the news windows
Darkvater
parents:
4854
diff
changeset
|
389 |
AddNewsItem( (StringID)(owner | NB_BTROUBLE), |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
390 |
NEWS_FLAGS(NM_CALLBACK, 0, NT_COMPANY_INFO, DNC_BANKRUPCY),0,0); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
391 |
break; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
392 |
} |
0 | 393 |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
394 |
// Check if the company has any value.. if not, declare it bankrupt |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
395 |
// right now |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
396 |
val = CalculateCompanyValue(p); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
397 |
if (val > 0) { |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
398 |
p->bankrupt_value = val; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
399 |
p->bankrupt_asked = 1 << owner; // Don't ask the owner |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
400 |
p->bankrupt_timeout = 0; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
401 |
break; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
402 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
403 |
// Else, falltrue to case 4... |
0 | 404 |
} |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
405 |
case 4: { |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
406 |
// Close everything the owner has open |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
407 |
DeletePlayerWindows(owner); |
0 | 408 |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
409 |
// Show bankrupt news |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
410 |
SetDParam(0, p->name_1); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
411 |
SetDParam(1, p->name_2); |
4873
7cb19235cf60
(svn r6803) -Codechange: Substitute magic numbers by an enum for the news windows
Darkvater
parents:
4854
diff
changeset
|
412 |
AddNewsItem( (StringID)(owner | NB_BBANKRUPT), NEWS_FLAGS(NM_CALLBACK, 0, NT_COMPANY_INFO, DNC_BANKRUPCY),0,0); |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
413 |
|
5067
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4880
diff
changeset
|
414 |
if (IsHumanPlayer(owner)) { |
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4880
diff
changeset
|
415 |
/* XXX - If we are in offline mode, leave the player playing. Eg. there |
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4880
diff
changeset
|
416 |
* is no THE-END, otherwise mark the player as spectator to make sure |
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4880
diff
changeset
|
417 |
* he/she is no long in control of this company */ |
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4880
diff
changeset
|
418 |
if (!_networking) { |
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4880
diff
changeset
|
419 |
p->bankrupt_asked = 0xFF; |
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4880
diff
changeset
|
420 |
p->bankrupt_timeout = 0x456; |
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4880
diff
changeset
|
421 |
break; |
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4880
diff
changeset
|
422 |
} else if (owner == _local_player) { |
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4880
diff
changeset
|
423 |
_local_player = _network_playas = PLAYER_SPECTATOR; |
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4880
diff
changeset
|
424 |
} |
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4880
diff
changeset
|
425 |
|
630
fd3c36132342
(svn r1061) -Fix: [Network] Compiling without ENABLE_NETWORK now works again correctly
truelight
parents:
599
diff
changeset
|
426 |
#ifdef ENABLE_NETWORK |
5067
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4880
diff
changeset
|
427 |
/* The server has to handle all administrative issues, for example |
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4880
diff
changeset
|
428 |
* updating and notifying all clients of what has happened */ |
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4880
diff
changeset
|
429 |
if (_network_server) { |
4880
0708f34e3586
(svn r6816) -Codechange: Some coding style, variable localization, const correctness.
Darkvater
parents:
4878
diff
changeset
|
430 |
const NetworkClientState *cs; |
5067
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4880
diff
changeset
|
431 |
NetworkClientInfo *ci = NetworkFindClientInfoFromIndex(NETWORK_SERVER_INDEX); |
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4880
diff
changeset
|
432 |
|
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4880
diff
changeset
|
433 |
/* The server has just gone belly-up, mark it as spectator */ |
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4880
diff
changeset
|
434 |
if (owner == ci->client_playas) { |
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4880
diff
changeset
|
435 |
ci->client_playas = PLAYER_SPECTATOR; |
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4880
diff
changeset
|
436 |
NetworkUpdateClientInfo(NETWORK_SERVER_INDEX); |
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4880
diff
changeset
|
437 |
} |
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4880
diff
changeset
|
438 |
|
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4880
diff
changeset
|
439 |
/* Find all clients that were in control of this company, |
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4880
diff
changeset
|
440 |
* and mark them as spectator; broadcast this message to everyone */ |
687
e8d646a00eb1
(svn r1128) -Fix: [Network] Going bankrupt of human-players was corrupted in networkgames
truelight
parents:
679
diff
changeset
|
441 |
FOR_ALL_CLIENTS(cs) { |
5067
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4880
diff
changeset
|
442 |
ci = DEREF_CLIENT_INFO(cs); |
4878
744717de172e
(svn r6814) -Codechange: For network games ci->client_playas was always p->index + 1. To
Darkvater
parents:
4873
diff
changeset
|
443 |
if (ci->client_playas == owner) { |
4848
56549aa3e234
(svn r6774) -Codechange: Rename the badly named OWNER_SPECTATOR to PLAYER_SPECTATOR and
Darkvater
parents:
4845
diff
changeset
|
444 |
ci->client_playas = PLAYER_SPECTATOR; |
5067
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4880
diff
changeset
|
445 |
NetworkUpdateClientInfo(ci->client_index); |
687
e8d646a00eb1
(svn r1128) -Fix: [Network] Going bankrupt of human-players was corrupted in networkgames
truelight
parents:
679
diff
changeset
|
446 |
} |
e8d646a00eb1
(svn r1128) -Fix: [Network] Going bankrupt of human-players was corrupted in networkgames
truelight
parents:
679
diff
changeset
|
447 |
} |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
448 |
} |
687
e8d646a00eb1
(svn r1128) -Fix: [Network] Going bankrupt of human-players was corrupted in networkgames
truelight
parents:
679
diff
changeset
|
449 |
#endif /* ENABLE_NETWORK */ |
5067
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4880
diff
changeset
|
450 |
} |
687
e8d646a00eb1
(svn r1128) -Fix: [Network] Going bankrupt of human-players was corrupted in networkgames
truelight
parents:
679
diff
changeset
|
451 |
|
5067
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4880
diff
changeset
|
452 |
/* Remove the player */ |
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4880
diff
changeset
|
453 |
ChangeOwnershipOfPlayerItems(owner, PLAYER_SPECTATOR); |
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4880
diff
changeset
|
454 |
/* Register the player as not-active */ |
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4880
diff
changeset
|
455 |
p->is_active = false; |
2395
19b4da30806b
(svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents:
2306
diff
changeset
|
456 |
|
5067
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4880
diff
changeset
|
457 |
if (!IsHumanPlayer(owner) && (!_networking || _network_server) && _ai.enabled) |
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4880
diff
changeset
|
458 |
AI_PlayerDied(owner); |
0 | 459 |
} |
460 |
} |
|
461 |
} |
|
462 |
||
463 |
void DrawNewsBankrupcy(Window *w) |
|
464 |
{ |
|
465 |
Player *p; |
|
466 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
467 |
DrawNewsBorder(w); |
0 | 468 |
|
4873
7cb19235cf60
(svn r6803) -Codechange: Substitute magic numbers by an enum for the news windows
Darkvater
parents:
4854
diff
changeset
|
469 |
p = GetPlayer(GB(WP(w,news_d).ni->string_id, 0, 4)); |
0 | 470 |
DrawPlayerFace(p->face, p->player_color, 2, 23); |
2218
abd47ef7d902
(svn r2736) -Codechange: De-mystified GfxDrawFillRect a bit, and used enums from table/sprites.h. You can now change the number of bits used for sprites and switches in the SpriteSetup enum and the rest should work automagically. Can be used to increase the number of active sprites to 2^19 in case there are no colortables (recolor sprites) in any newgrf. We should possibly move the the colortables to an own list, but how to detect them in a newgrf.
celestar
parents:
2186
diff
changeset
|
471 |
GfxFillRect(3, 23, 3+91, 23+118, 0x323 | USE_COLORTABLE); |
0 | 472 |
|
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
473 |
SetDParam(0, p->president_name_1); |
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
474 |
SetDParam(1, p->president_name_2); |
0 | 475 |
|
476 |
DrawStringMultiCenter(49, 148, STR_7058_PRESIDENT, 94); |
|
477 |
||
4873
7cb19235cf60
(svn r6803) -Codechange: Substitute magic numbers by an enum for the news windows
Darkvater
parents:
4854
diff
changeset
|
478 |
switch (WP(w,news_d).ni->string_id & 0xF0) { |
7cb19235cf60
(svn r6803) -Codechange: Substitute magic numbers by an enum for the news windows
Darkvater
parents:
4854
diff
changeset
|
479 |
case NB_BTROUBLE: |
0 | 480 |
DrawStringCentered(w->width>>1, 1, STR_7056_TRANSPORT_COMPANY_IN_TROUBLE, 0); |
481 |
||
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
482 |
SetDParam(0, p->name_1); |
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
483 |
SetDParam(1, p->name_2); |
0 | 484 |
|
485 |
DrawStringMultiCenter( |
|
486 |
((w->width - 101) >> 1) + 98, |
|
487 |
90, |
|
488 |
STR_7057_WILL_BE_SOLD_OFF_OR_DECLARED, |
|
489 |
w->width - 101); |
|
490 |
break; |
|
491 |
||
4873
7cb19235cf60
(svn r6803) -Codechange: Substitute magic numbers by an enum for the news windows
Darkvater
parents:
4854
diff
changeset
|
492 |
case NB_BMERGER: { |
0 | 493 |
int32 price; |
494 |
||
495 |
DrawStringCentered(w->width>>1, 1, STR_7059_TRANSPORT_COMPANY_MERGER, 0); |
|
496 |
COPY_IN_DPARAM(0,WP(w,news_d).ni->params, 2); |
|
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
497 |
SetDParam(2, p->name_1); |
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
498 |
SetDParam(3, p->name_2); |
0 | 499 |
price = WP(w,news_d).ni->params[2]; |
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
500 |
SetDParam(4, price); |
0 | 501 |
DrawStringMultiCenter( |
502 |
((w->width - 101) >> 1) + 98, |
|
503 |
90, |
|
504 |
price==0 ? STR_707F_HAS_BEEN_TAKEN_OVER_BY : STR_705A_HAS_BEEN_SOLD_TO_FOR, |
|
505 |
w->width - 101); |
|
506 |
break; |
|
507 |
} |
|
508 |
||
4873
7cb19235cf60
(svn r6803) -Codechange: Substitute magic numbers by an enum for the news windows
Darkvater
parents:
4854
diff
changeset
|
509 |
case NB_BBANKRUPT: |
0 | 510 |
DrawStringCentered(w->width>>1, 1, STR_705C_BANKRUPT, 0); |
511 |
COPY_IN_DPARAM(0,WP(w,news_d).ni->params, 2); |
|
512 |
DrawStringMultiCenter( |
|
513 |
((w->width - 101) >> 1) + 98, |
|
514 |
90, |
|
515 |
STR_705D_HAS_BEEN_CLOSED_DOWN_BY, |
|
516 |
w->width - 101); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
517 |
break; |
0 | 518 |
|
4873
7cb19235cf60
(svn r6803) -Codechange: Substitute magic numbers by an enum for the news windows
Darkvater
parents:
4854
diff
changeset
|
519 |
case NB_BNEWCOMPANY: |
0 | 520 |
DrawStringCentered(w->width>>1, 1, STR_705E_NEW_TRANSPORT_COMPANY_LAUNCHED, 0); |
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
521 |
SetDParam(0, p->name_1); |
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
522 |
SetDParam(1, p->name_2); |
0 | 523 |
COPY_IN_DPARAM(2,WP(w,news_d).ni->params, 2); |
524 |
DrawStringMultiCenter( |
|
525 |
((w->width - 101) >> 1) + 98, |
|
526 |
90, |
|
527 |
STR_705F_STARTS_CONSTRUCTION_NEAR, |
|
528 |
w->width - 101); |
|
529 |
break; |
|
530 |
||
531 |
default: |
|
532 |
NOT_REACHED(); |
|
533 |
} |
|
534 |
} |
|
535 |
||
2436
177cb6a8339f
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2425
diff
changeset
|
536 |
StringID GetNewsStringBankrupcy(const NewsItem *ni) |
0 | 537 |
{ |
4873
7cb19235cf60
(svn r6803) -Codechange: Substitute magic numbers by an enum for the news windows
Darkvater
parents:
4854
diff
changeset
|
538 |
const Player *p = GetPlayer(GB(ni->string_id, 0, 4)); |
0 | 539 |
|
4873
7cb19235cf60
(svn r6803) -Codechange: Substitute magic numbers by an enum for the news windows
Darkvater
parents:
4854
diff
changeset
|
540 |
switch (ni->string_id & 0xF0) { |
7cb19235cf60
(svn r6803) -Codechange: Substitute magic numbers by an enum for the news windows
Darkvater
parents:
4854
diff
changeset
|
541 |
case NB_BTROUBLE: |
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
542 |
SetDParam(0, STR_7056_TRANSPORT_COMPANY_IN_TROUBLE); |
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
543 |
SetDParam(1, STR_7057_WILL_BE_SOLD_OFF_OR_DECLARED); |
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
544 |
SetDParam(2, p->name_1); |
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
545 |
SetDParam(3, p->name_2); |
0 | 546 |
return STR_02B6; |
4873
7cb19235cf60
(svn r6803) -Codechange: Substitute magic numbers by an enum for the news windows
Darkvater
parents:
4854
diff
changeset
|
547 |
case NB_BMERGER: |
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
548 |
SetDParam(0, STR_7059_TRANSPORT_COMPANY_MERGER); |
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
549 |
SetDParam(1, STR_705A_HAS_BEEN_SOLD_TO_FOR); |
0 | 550 |
COPY_IN_DPARAM(2,ni->params, 2); |
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
551 |
SetDParam(4, p->name_1); |
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
552 |
SetDParam(5, p->name_2); |
0 | 553 |
COPY_IN_DPARAM(6,ni->params + 2, 1); |
554 |
return STR_02B6; |
|
4873
7cb19235cf60
(svn r6803) -Codechange: Substitute magic numbers by an enum for the news windows
Darkvater
parents:
4854
diff
changeset
|
555 |
case NB_BBANKRUPT: |
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
556 |
SetDParam(0, STR_705C_BANKRUPT); |
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
557 |
SetDParam(1, STR_705D_HAS_BEEN_CLOSED_DOWN_BY); |
0 | 558 |
COPY_IN_DPARAM(2,ni->params, 2); |
559 |
return STR_02B6; |
|
4873
7cb19235cf60
(svn r6803) -Codechange: Substitute magic numbers by an enum for the news windows
Darkvater
parents:
4854
diff
changeset
|
560 |
case NB_BNEWCOMPANY: |
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
561 |
SetDParam(0, STR_705E_NEW_TRANSPORT_COMPANY_LAUNCHED); |
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
562 |
SetDParam(1, STR_705F_STARTS_CONSTRUCTION_NEAR); |
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
563 |
SetDParam(2, p->name_1); |
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
564 |
SetDParam(3, p->name_2); |
0 | 565 |
COPY_IN_DPARAM(4,ni->params, 2); |
566 |
return STR_02B6; |
|
567 |
default: |
|
568 |
NOT_REACHED(); |
|
569 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
570 |
|
0 | 571 |
/* useless, but avoids compiler warning this way */ |
572 |
return 0; |
|
573 |
} |
|
574 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1067
diff
changeset
|
575 |
static void PlayersGenStatistics(void) |
0 | 576 |
{ |
577 |
Station *st; |
|
578 |
Player *p; |
|
579 |
||
580 |
FOR_ALL_STATIONS(st) { |
|
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
581 |
_current_player = st->owner; |
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
582 |
SET_EXPENSES_TYPE(EXPENSES_PROPERTY); |
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
583 |
SubtractMoneyFromPlayer(_price.station_value >> 1); |
0 | 584 |
} |
585 |
||
586 |
if (!HASBIT(1<<0|1<<3|1<<6|1<<9, _cur_month)) |
|
587 |
return; |
|
588 |
||
589 |
FOR_ALL_PLAYERS(p) { |
|
590 |
if (p->is_active) { |
|
591 |
memmove(&p->old_economy, &p->cur_economy, sizeof(p->old_economy)); |
|
592 |
memset(&p->cur_economy, 0, sizeof(p->cur_economy)); |
|
593 |
||
594 |
if (p->num_valid_stat_ent != 24) |
|
595 |
p->num_valid_stat_ent++; |
|
596 |
||
116
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
597 |
UpdateCompanyRatingAndValue(p, true); |
0 | 598 |
PlayersCheckBankrupt(p); |
599 |
||
600 |
if (p->block_preview != 0) |
|
601 |
p->block_preview--; |
|
602 |
} |
|
603 |
} |
|
604 |
||
605 |
InvalidateWindow(WC_INCOME_GRAPH, 0); |
|
606 |
InvalidateWindow(WC_OPERATING_PROFIT, 0); |
|
607 |
InvalidateWindow(WC_DELIVERED_CARGO, 0); |
|
608 |
InvalidateWindow(WC_PERFORMANCE_HISTORY, 0); |
|
609 |
InvalidateWindow(WC_COMPANY_VALUE, 0); |
|
610 |
InvalidateWindow(WC_COMPANY_LEAGUE, 0); |
|
611 |
} |
|
612 |
||
613 |
static void AddSingleInflation(int32 *value, uint16 *frac, int32 amt) |
|
614 |
{ |
|
615 |
int64 tmp; |
|
616 |
int32 low; |
|
617 |
tmp = BIGMULS(*value, amt); |
|
618 |
*frac = (uint16)(low = (uint16)tmp + *frac); |
|
619 |
*value += (int32)(tmp >> 16) + (low >> 16); |
|
620 |
} |
|
621 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1067
diff
changeset
|
622 |
static void AddInflation(void) |
0 | 623 |
{ |
624 |
int i; |
|
625 |
int32 inf = _economy.infl_amount * 54; |
|
626 |
||
2639 | 627 |
for (i = 0; i != NUM_PRICES; i++) { |
628 |
AddSingleInflation((int32*)&_price + i, _price_frac + i, inf); |
|
0 | 629 |
} |
630 |
||
631 |
_economy.max_loan_unround += BIGMULUS(_economy.max_loan_unround, inf, 16); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
632 |
|
0 | 633 |
if (_economy.max_loan + 50000 <= _economy.max_loan_unround) |
634 |
_economy.max_loan += 50000; |
|
635 |
||
636 |
inf = _economy.infl_amount_pr * 54; |
|
2639 | 637 |
for (i = 0; i != NUM_CARGO; i++) { |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
638 |
AddSingleInflation( |
1884
ae1d6213c6dd
(svn r2390) - Codechange: Fix some warnings on GCC 4.0.0
hackykid
parents:
1881
diff
changeset
|
639 |
(int32*)_cargo_payment_rates + i, |
0 | 640 |
_cargo_payment_rates_frac + i, |
641 |
inf |
|
642 |
); |
|
643 |
} |
|
644 |
||
645 |
InvalidateWindowClasses(WC_BUILD_VEHICLE); |
|
1098
481fbdea1569
(svn r1599) fix: autoreplace window now updates when inflation alters prices
bjarni
parents:
1093
diff
changeset
|
646 |
InvalidateWindowClasses(WC_REPLACE_VEHICLE); |
0 | 647 |
InvalidateWindowClasses(WC_VEHICLE_DETAILS); |
648 |
InvalidateWindow(WC_PAYMENT_RATES, 0); |
|
649 |
} |
|
650 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1067
diff
changeset
|
651 |
static void PlayersPayInterest(void) |
0 | 652 |
{ |
2548
97ada3bd2702
(svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents:
2544
diff
changeset
|
653 |
const Player* p; |
0 | 654 |
int interest = _economy.interest_rate * 54; |
655 |
||
656 |
FOR_ALL_PLAYERS(p) { |
|
2639 | 657 |
if (!p->is_active) continue; |
0 | 658 |
|
659 |
_current_player = p->index; |
|
660 |
SET_EXPENSES_TYPE(EXPENSES_LOAN_INT); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
661 |
|
0 | 662 |
SubtractMoneyFromPlayer(BIGMULUS(p->current_loan, interest, 16)); |
663 |
||
664 |
SET_EXPENSES_TYPE(EXPENSES_OTHER); |
|
665 |
SubtractMoneyFromPlayer(_price.station_value >> 2); |
|
666 |
} |
|
667 |
} |
|
668 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1067
diff
changeset
|
669 |
static void HandleEconomyFluctuations(void) |
0 | 670 |
{ |
2639 | 671 |
if (_opt.diff.economy == 0) return; |
0 | 672 |
|
673 |
if (--_economy.fluct == 0) { |
|
2642 | 674 |
_economy.fluct = -(int)GB(Random(), 0, 2); |
0 | 675 |
AddNewsItem(STR_7073_WORLD_RECESSION_FINANCIAL, NEWS_FLAGS(NM_NORMAL,0,NT_ECONOMY,0), 0, 0); |
676 |
} else if (_economy.fluct == -12) { |
|
2642 | 677 |
_economy.fluct = GB(Random(), 0, 8) + 312; |
0 | 678 |
AddNewsItem(STR_7074_RECESSION_OVER_UPTURN_IN, NEWS_FLAGS(NM_NORMAL,0,NT_ECONOMY,0), 0, 0); |
679 |
} |
|
680 |
} |
|
681 |
||
682 |
static byte _price_category[NUM_PRICES] = { |
|
683 |
0, 2, 2, 2, 2, 2, 2, 2, |
|
684 |
2, 2, 2, 2, 2, 2, 2, 2, |
|
685 |
2, 2, 2, 2, 2, 2, 2, 2, |
|
686 |
2, 2, 2, 2, 2, 2, 2, 2, |
|
687 |
2, 2, 2, 2, 2, 2, 2, 2, |
|
688 |
2, 2, 1, 1, 1, 1, 1, 1, |
|
689 |
2, |
|
690 |
}; |
|
691 |
||
692 |
static const int32 _price_base[NUM_PRICES] = { |
|
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
693 |
100, // station_value |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
694 |
100, // build_rail |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
695 |
95, // build_road |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
696 |
65, // build_signals |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
697 |
275, // build_bridge |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
698 |
600, // build_train_depot |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
699 |
500, // build_road_depot |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
700 |
700, // build_ship_depot |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
701 |
450, // build_tunnel |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
702 |
200, // train_station_track |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
703 |
180, // train_station_length |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
704 |
600, // build_airport |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
705 |
200, // build_bus_station |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
706 |
200, // build_truck_station |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
707 |
350, // build_dock |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
708 |
400000, // build_railvehicle |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
709 |
2000, // build_railwagon |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
710 |
700000, // aircraft_base |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
711 |
14000, // roadveh_base |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
712 |
65000, // ship_base |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
713 |
20, // build_trees |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
714 |
250, // terraform |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
715 |
20, // clear_1 |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
716 |
40, // purchase_land |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
717 |
200, // clear_2 |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
718 |
500, // clear_3 |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
719 |
20, // remove_trees |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
720 |
-70, // remove_rail |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
721 |
10, // remove_signals |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
722 |
50, // clear_bridge |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
723 |
80, // remove_train_depot |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
724 |
80, // remove_road_depot |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
725 |
90, // remove_ship_depot |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
726 |
30, // clear_tunnel |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
727 |
10000, // clear_water |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
728 |
50, // remove_rail_station |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
729 |
30, // remove_airport |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
730 |
50, // remove_bus_station |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
731 |
50, // remove_truck_station |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
732 |
55, // remove_dock |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
733 |
1600, // remove_house |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
734 |
40, // remove_road |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
735 |
5600, // running_rail[0] railroad |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
736 |
5200, // running_rail[1] monorail |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
737 |
4800, // running_rail[2] maglev |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
738 |
9600, // aircraft_running |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
739 |
1600, // roadveh_running |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
740 |
5600, // ship_running |
9 | 741 |
1000000, // build_industry |
0 | 742 |
}; |
743 |
||
2506
777ac2d9a98a
(svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents:
2504
diff
changeset
|
744 |
static byte price_base_multiplier[NUM_PRICES]; |
777ac2d9a98a
(svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents:
2504
diff
changeset
|
745 |
|
777ac2d9a98a
(svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents:
2504
diff
changeset
|
746 |
/** |
777ac2d9a98a
(svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents:
2504
diff
changeset
|
747 |
* Reset changes to the price base multipliers. |
777ac2d9a98a
(svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents:
2504
diff
changeset
|
748 |
*/ |
777ac2d9a98a
(svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents:
2504
diff
changeset
|
749 |
void ResetPriceBaseMultipliers(void) |
777ac2d9a98a
(svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents:
2504
diff
changeset
|
750 |
{ |
2508
c1a1af1920ce
(svn r3034) -NewGRF: Improve error checking of setting price bases.
peter1138
parents:
2506
diff
changeset
|
751 |
uint i; |
2506
777ac2d9a98a
(svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents:
2504
diff
changeset
|
752 |
|
777ac2d9a98a
(svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents:
2504
diff
changeset
|
753 |
// 8 means no multiplier. |
777ac2d9a98a
(svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents:
2504
diff
changeset
|
754 |
for (i = 0; i < NUM_PRICES; i++) |
777ac2d9a98a
(svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents:
2504
diff
changeset
|
755 |
price_base_multiplier[i] = 8; |
777ac2d9a98a
(svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents:
2504
diff
changeset
|
756 |
} |
777ac2d9a98a
(svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents:
2504
diff
changeset
|
757 |
|
777ac2d9a98a
(svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents:
2504
diff
changeset
|
758 |
/** |
777ac2d9a98a
(svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents:
2504
diff
changeset
|
759 |
* Change a price base by the given factor. |
777ac2d9a98a
(svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents:
2504
diff
changeset
|
760 |
* The price base is altered by factors of two, with an offset of 8. |
777ac2d9a98a
(svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents:
2504
diff
changeset
|
761 |
* NewBaseCost = OldBaseCost * 2^(n-8) |
777ac2d9a98a
(svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents:
2504
diff
changeset
|
762 |
* @param price Index of price base to change. |
777ac2d9a98a
(svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents:
2504
diff
changeset
|
763 |
* @param factor Amount to change by. |
777ac2d9a98a
(svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents:
2504
diff
changeset
|
764 |
*/ |
2508
c1a1af1920ce
(svn r3034) -NewGRF: Improve error checking of setting price bases.
peter1138
parents:
2506
diff
changeset
|
765 |
void SetPriceBaseMultiplier(uint price, byte factor) |
2506
777ac2d9a98a
(svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents:
2504
diff
changeset
|
766 |
{ |
2508
c1a1af1920ce
(svn r3034) -NewGRF: Improve error checking of setting price bases.
peter1138
parents:
2506
diff
changeset
|
767 |
assert(price < NUM_PRICES); |
c1a1af1920ce
(svn r3034) -NewGRF: Improve error checking of setting price bases.
peter1138
parents:
2506
diff
changeset
|
768 |
price_base_multiplier[price] = factor; |
2506
777ac2d9a98a
(svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents:
2504
diff
changeset
|
769 |
} |
777ac2d9a98a
(svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents:
2504
diff
changeset
|
770 |
|
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1067
diff
changeset
|
771 |
void StartupEconomy(void) |
0 | 772 |
{ |
773 |
int i; |
|
774 |
||
775 |
assert(sizeof(_price) == NUM_PRICES * sizeof(int32)); |
|
776 |
||
2952 | 777 |
for (i = 0; i != NUM_PRICES; i++) { |
0 | 778 |
int32 price = _price_base[i]; |
779 |
if (_price_category[i] != 0) { |
|
780 |
uint mod = _price_category[i] == 1 ? _opt.diff.vehicle_costs : _opt.diff.construction_cost; |
|
781 |
if (mod < 1) { |
|
782 |
price = price * 3 >> 2; |
|
783 |
} else if (mod > 1) { |
|
784 |
price = price * 9 >> 3; |
|
785 |
} |
|
786 |
} |
|
2506
777ac2d9a98a
(svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents:
2504
diff
changeset
|
787 |
if (price_base_multiplier[i] > 8) { |
777ac2d9a98a
(svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents:
2504
diff
changeset
|
788 |
price <<= price_base_multiplier[i] - 8; |
777ac2d9a98a
(svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents:
2504
diff
changeset
|
789 |
} else { |
777ac2d9a98a
(svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents:
2504
diff
changeset
|
790 |
price >>= 8 - price_base_multiplier[i]; |
777ac2d9a98a
(svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents:
2504
diff
changeset
|
791 |
} |
0 | 792 |
((int32*)&_price)[i] = price; |
793 |
_price_frac[i] = 0; |
|
794 |
} |
|
795 |
||
796 |
_economy.interest_rate = _opt.diff.initial_interest; |
|
797 |
_economy.infl_amount = _opt.diff.initial_interest; |
|
798 |
_economy.infl_amount_pr = max(0, _opt.diff.initial_interest - 1); |
|
799 |
_economy.max_loan_unround = _economy.max_loan = _opt.diff.max_loan * 1000; |
|
2150
010d923a81a9
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2070
diff
changeset
|
800 |
_economy.fluct = GB(Random(), 0, 8) + 168; |
0 | 801 |
} |
802 |
||
2630 | 803 |
Pair SetupSubsidyDecodeParam(const Subsidy* s, bool mode) |
0 | 804 |
{ |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
805 |
TileIndex tile; |
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
806 |
TileIndex tile2; |
0 | 807 |
Pair tp; |
808 |
||
2272
fc701f21b2be
(svn r2794) Fix a comment and get rid of some parentheses using DeMorgan's law
tron
parents:
2261
diff
changeset
|
809 |
/* if mode is false, use the singular form */ |
fc701f21b2be
(svn r2794) Fix a comment and get rid of some parentheses using DeMorgan's law
tron
parents:
2261
diff
changeset
|
810 |
SetDParam(0, _cargoc.names_s[s->cargo_type] + (mode ? 0 : 32)); |
0 | 811 |
|
812 |
if (s->age < 12) { |
|
2272
fc701f21b2be
(svn r2794) Fix a comment and get rid of some parentheses using DeMorgan's law
tron
parents:
2261
diff
changeset
|
813 |
if (s->cargo_type != CT_PASSENGERS && s->cargo_type != CT_MAIL) { |
2070
26c657906f25
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2063
diff
changeset
|
814 |
SetDParam(1, STR_INDUSTRY); |
26c657906f25
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2063
diff
changeset
|
815 |
SetDParam(2, s->from); |
26c657906f25
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2063
diff
changeset
|
816 |
tile = GetIndustry(s->from)->xy; |
0 | 817 |
|
818 |
if (s->cargo_type != CT_GOODS && s->cargo_type != CT_FOOD) { |
|
2070
26c657906f25
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2063
diff
changeset
|
819 |
SetDParam(4, STR_INDUSTRY); |
26c657906f25
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2063
diff
changeset
|
820 |
SetDParam(5, s->to); |
26c657906f25
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2063
diff
changeset
|
821 |
tile2 = GetIndustry(s->to)->xy; |
0 | 822 |
} else { |
2070
26c657906f25
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2063
diff
changeset
|
823 |
SetDParam(4, STR_TOWN); |
26c657906f25
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2063
diff
changeset
|
824 |
SetDParam(5, s->to); |
26c657906f25
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2063
diff
changeset
|
825 |
tile2 = GetTown(s->to)->xy; |
0 | 826 |
} |
827 |
} else { |
|
2070
26c657906f25
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2063
diff
changeset
|
828 |
SetDParam(1, STR_TOWN); |
26c657906f25
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2063
diff
changeset
|
829 |
SetDParam(2, s->from); |
26c657906f25
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2063
diff
changeset
|
830 |
tile = GetTown(s->from)->xy; |
0 | 831 |
|
2070
26c657906f25
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2063
diff
changeset
|
832 |
SetDParam(4, STR_TOWN); |
26c657906f25
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2063
diff
changeset
|
833 |
SetDParam(5, s->to); |
26c657906f25
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2063
diff
changeset
|
834 |
tile2 = GetTown(s->to)->xy; |
0 | 835 |
} |
836 |
} else { |
|
2070
26c657906f25
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2063
diff
changeset
|
837 |
SetDParam(1, s->from); |
26c657906f25
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2063
diff
changeset
|
838 |
tile = GetStation(s->from)->xy; |
0 | 839 |
|
2070
26c657906f25
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2063
diff
changeset
|
840 |
SetDParam(2, s->to); |
26c657906f25
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2063
diff
changeset
|
841 |
tile2 = GetStation(s->to)->xy; |
0 | 842 |
} |
843 |
||
844 |
tp.a = tile; |
|
845 |
tp.b = tile2; |
|
846 |
||
847 |
return tp; |
|
848 |
} |
|
849 |
||
4330
7306bda145ab
(svn r6005) -Cleanup: introduce IndustryID and use it
rubidium
parents:
4329
diff
changeset
|
850 |
void DeleteSubsidyWithIndustry(IndustryID index) |
0 | 851 |
{ |
852 |
Subsidy *s; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
853 |
|
2952 | 854 |
for (s = _subsidies; s != endof(_subsidies); s++) { |
2469
1bfbb0dc0b75
(svn r2995) Replace 0xFF/0xFFFF with CT_INVALID/OWNER_SPECTATOR/INVALID_STATION where appropriate
tron
parents:
2436
diff
changeset
|
855 |
if (s->cargo_type != CT_INVALID && s->age < 12 && |
0 | 856 |
s->cargo_type != CT_PASSENGERS && s->cargo_type != CT_MAIL && |
857 |
(index == s->from || (s->cargo_type!=CT_GOODS && s->cargo_type!=CT_FOOD && index==s->to))) { |
|
2469
1bfbb0dc0b75
(svn r2995) Replace 0xFF/0xFFFF with CT_INVALID/OWNER_SPECTATOR/INVALID_STATION where appropriate
tron
parents:
2436
diff
changeset
|
858 |
s->cargo_type = CT_INVALID; |
0 | 859 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
860 |
} |
0 | 861 |
} |
862 |
||
4330
7306bda145ab
(svn r6005) -Cleanup: introduce IndustryID and use it
rubidium
parents:
4329
diff
changeset
|
863 |
void DeleteSubsidyWithStation(StationID index) |
0 | 864 |
{ |
865 |
Subsidy *s; |
|
866 |
bool dirty = false; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
867 |
|
2952 | 868 |
for (s = _subsidies; s != endof(_subsidies); s++) { |
2469
1bfbb0dc0b75
(svn r2995) Replace 0xFF/0xFFFF with CT_INVALID/OWNER_SPECTATOR/INVALID_STATION where appropriate
tron
parents:
2436
diff
changeset
|
869 |
if (s->cargo_type != CT_INVALID && s->age >= 12 && |
0 | 870 |
(s->from == index || s->to == index)) { |
2469
1bfbb0dc0b75
(svn r2995) Replace 0xFF/0xFFFF with CT_INVALID/OWNER_SPECTATOR/INVALID_STATION where appropriate
tron
parents:
2436
diff
changeset
|
871 |
s->cargo_type = CT_INVALID; |
0 | 872 |
dirty = true; |
873 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
874 |
} |
0 | 875 |
|
876 |
if (dirty) |
|
877 |
InvalidateWindow(WC_SUBSIDIES_LIST, 0); |
|
878 |
} |
|
879 |
||
880 |
typedef struct FoundRoute { |
|
881 |
uint distance; |
|
3344
d86c852715fa
(svn r4128) - CodeChange: Add proper semantics for CargoID for such variables instead of using the general byte-type.
Darkvater
parents:
3047
diff
changeset
|
882 |
CargoID cargo; |
0 | 883 |
void *from; |
884 |
void *to; |
|
885 |
} FoundRoute; |
|
886 |
||
887 |
static void FindSubsidyPassengerRoute(FoundRoute *fr) |
|
888 |
{ |
|
889 |
Town *from,*to; |
|
890 |
||
891 |
fr->distance = (uint)-1; |
|
892 |
||
4356
bc52a48e2590
(svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents:
4354
diff
changeset
|
893 |
fr->from = from = GetRandomTown(); |
bc52a48e2590
(svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents:
4354
diff
changeset
|
894 |
if (from == NULL || from->population < 400) return; |
0 | 895 |
|
4356
bc52a48e2590
(svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents:
4354
diff
changeset
|
896 |
fr->to = to = GetRandomTown(); |
bc52a48e2590
(svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents:
4354
diff
changeset
|
897 |
if (from == to || to == NULL || to->population < 400 || to->pct_pass_transported > 42) |
0 | 898 |
return; |
899 |
||
1245
768d9bc95aaa
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1098
diff
changeset
|
900 |
fr->distance = DistanceManhattan(from->xy, to->xy); |
0 | 901 |
} |
902 |
||
903 |
static void FindSubsidyCargoRoute(FoundRoute *fr) |
|
904 |
{ |
|
905 |
Industry *i; |
|
906 |
int trans, total; |
|
3344
d86c852715fa
(svn r4128) - CodeChange: Add proper semantics for CargoID for such variables instead of using the general byte-type.
Darkvater
parents:
3047
diff
changeset
|
907 |
CargoID cargo; |
0 | 908 |
|
909 |
fr->distance = (uint)-1; |
|
910 |
||
4356
bc52a48e2590
(svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents:
4354
diff
changeset
|
911 |
fr->from = i = GetRandomIndustry(); |
bc52a48e2590
(svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents:
4354
diff
changeset
|
912 |
if (i == NULL) return; |
0 | 913 |
|
914 |
// Randomize cargo type |
|
2469
1bfbb0dc0b75
(svn r2995) Replace 0xFF/0xFFFF with CT_INVALID/OWNER_SPECTATOR/INVALID_STATION where appropriate
tron
parents:
2436
diff
changeset
|
915 |
if (Random()&1 && i->produced_cargo[1] != CT_INVALID) { |
0 | 916 |
cargo = i->produced_cargo[1]; |
917 |
trans = i->pct_transported[1]; |
|
918 |
total = i->total_production[1]; |
|
919 |
} else { |
|
920 |
cargo = i->produced_cargo[0]; |
|
921 |
trans = i->pct_transported[0]; |
|
922 |
total = i->total_production[0]; |
|
923 |
} |
|
924 |
||
925 |
// Quit if no production in this industry |
|
926 |
// or if the cargo type is passengers |
|
927 |
// or if the pct transported is already large enough |
|
2469
1bfbb0dc0b75
(svn r2995) Replace 0xFF/0xFFFF with CT_INVALID/OWNER_SPECTATOR/INVALID_STATION where appropriate
tron
parents:
2436
diff
changeset
|
928 |
if (total == 0 || trans > 42 || cargo == CT_INVALID || cargo == CT_PASSENGERS) |
0 | 929 |
return; |
930 |
||
931 |
fr->cargo = cargo; |
|
932 |
||
933 |
if (cargo == CT_GOODS || cargo == CT_FOOD) { |
|
934 |
// The destination is a town |
|
4356
bc52a48e2590
(svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents:
4354
diff
changeset
|
935 |
Town *t = GetRandomTown(); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
936 |
|
0 | 937 |
// Only want big towns |
4356
bc52a48e2590
(svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents:
4354
diff
changeset
|
938 |
if (t == NULL || t->population < 900) return; |
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
939 |
|
1245
768d9bc95aaa
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1098
diff
changeset
|
940 |
fr->distance = DistanceManhattan(i->xy, t->xy); |
0 | 941 |
fr->to = t; |
942 |
} else { |
|
943 |
// The destination is an industry |
|
4356
bc52a48e2590
(svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents:
4354
diff
changeset
|
944 |
Industry *i2 = GetRandomIndustry(); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
945 |
|
0 | 946 |
// The industry must accept the cargo |
4356
bc52a48e2590
(svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents:
4354
diff
changeset
|
947 |
if (i == i2 || i == NULL || |
0 | 948 |
(cargo != i2->accepts_cargo[0] && |
949 |
cargo != i2->accepts_cargo[1] && |
|
950 |
cargo != i2->accepts_cargo[2])) |
|
951 |
return; |
|
1245
768d9bc95aaa
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1098
diff
changeset
|
952 |
fr->distance = DistanceManhattan(i->xy, i2->xy); |
0 | 953 |
fr->to = i2; |
954 |
} |
|
955 |
} |
|
956 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
957 |
static bool CheckSubsidyDuplicate(Subsidy *s) |
0 | 958 |
{ |
2630 | 959 |
const Subsidy* ss; |
0 | 960 |
|
2639 | 961 |
for (ss = _subsidies; ss != endof(_subsidies); ss++) { |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
962 |
if (s != ss && |
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
963 |
ss->from == s->from && |
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
964 |
ss->to == s->to && |
0 | 965 |
ss->cargo_type == s->cargo_type) { |
2469
1bfbb0dc0b75
(svn r2995) Replace 0xFF/0xFFFF with CT_INVALID/OWNER_SPECTATOR/INVALID_STATION where appropriate
tron
parents:
2436
diff
changeset
|
966 |
s->cargo_type = CT_INVALID; |
0 | 967 |
return true; |
968 |
} |
|
969 |
} |
|
970 |
return false; |
|
971 |
} |
|
972 |
||
239 | 973 |
|
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1067
diff
changeset
|
974 |
static void SubsidyMonthlyHandler(void) |
0 | 975 |
{ |
976 |
Subsidy *s; |
|
977 |
Pair pair; |
|
978 |
Station *st; |
|
979 |
uint n; |
|
980 |
FoundRoute fr; |
|
981 |
bool modified = false; |
|
982 |
||
2952 | 983 |
for (s = _subsidies; s != endof(_subsidies); s++) { |
984 |
if (s->cargo_type == CT_INVALID) continue; |
|
0 | 985 |
|
986 |
if (s->age == 12-1) { |
|
987 |
pair = SetupSubsidyDecodeParam(s, 1); |
|
988 |
AddNewsItem(STR_202E_OFFER_OF_SUBSIDY_EXPIRED, NEWS_FLAGS(NM_NORMAL, NF_TILE, NT_SUBSIDIES, 0), pair.a, pair.b); |
|
2469
1bfbb0dc0b75
(svn r2995) Replace 0xFF/0xFFFF with CT_INVALID/OWNER_SPECTATOR/INVALID_STATION where appropriate
tron
parents:
2436
diff
changeset
|
989 |
s->cargo_type = CT_INVALID; |
0 | 990 |
modified = true; |
991 |
} else if (s->age == 2*12-1) { |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
863
diff
changeset
|
992 |
st = GetStation(s->to); |
0 | 993 |
if (st->owner == _local_player) { |
994 |
pair = SetupSubsidyDecodeParam(s, 1); |
|
995 |
AddNewsItem(STR_202F_SUBSIDY_WITHDRAWN_SERVICE, NEWS_FLAGS(NM_NORMAL, NF_TILE, NT_SUBSIDIES, 0), pair.a, pair.b); |
|
996 |
} |
|
2469
1bfbb0dc0b75
(svn r2995) Replace 0xFF/0xFFFF with CT_INVALID/OWNER_SPECTATOR/INVALID_STATION where appropriate
tron
parents:
2436
diff
changeset
|
997 |
s->cargo_type = CT_INVALID; |
0 | 998 |
modified = true; |
999 |
} else { |
|
1000 |
s->age++; |
|
1001 |
} |
|
1002 |
} |
|
1003 |
||
1004 |
// 25% chance to go on |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
1005 |
if (CHANCE16(1,4)) { |
0 | 1006 |
// Find a free slot |
1007 |
s = _subsidies; |
|
2469
1bfbb0dc0b75
(svn r2995) Replace 0xFF/0xFFFF with CT_INVALID/OWNER_SPECTATOR/INVALID_STATION where appropriate
tron
parents:
2436
diff
changeset
|
1008 |
while (s->cargo_type != CT_INVALID) { |
0 | 1009 |
if (++s == endof(_subsidies)) |
1010 |
goto no_add; |
|
1011 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
1012 |
|
0 | 1013 |
n = 1000; |
1014 |
do { |
|
1015 |
FindSubsidyPassengerRoute(&fr); |
|
1016 |
if (fr.distance <= 70) { |
|
1017 |
s->cargo_type = CT_PASSENGERS; |
|
1018 |
s->from = ((Town*)fr.from)->index; |
|
1019 |
s->to = ((Town*)fr.to)->index; |
|
1020 |
goto add_subsidy; |
|
1021 |
} |
|
1022 |
FindSubsidyCargoRoute(&fr); |
|
1023 |
if (fr.distance <= 70) { |
|
1024 |
s->cargo_type = fr.cargo; |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
863
diff
changeset
|
1025 |
s->from = ((Industry*)fr.from)->index; |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
863
diff
changeset
|
1026 |
s->to = (fr.cargo == CT_GOODS || fr.cargo == CT_FOOD) ? ((Town*)fr.to)->index : ((Industry*)fr.to)->index; |
0 | 1027 |
add_subsidy: |
1028 |
if (!CheckSubsidyDuplicate(s)) { |
|
1029 |
s->age = 0; |
|
1030 |
pair = SetupSubsidyDecodeParam(s, 0); |
|
1031 |
AddNewsItem(STR_2030_SERVICE_SUBSIDY_OFFERED, NEWS_FLAGS(NM_NORMAL, NF_TILE, NT_SUBSIDIES, 0), pair.a, pair.b); |
|
1032 |
modified = true; |
|
1033 |
break; |
|
1034 |
} |
|
1035 |
} |
|
239 | 1036 |
} while (n--); |
0 | 1037 |
} |
1038 |
no_add:; |
|
1039 |
if (modified) |
|
1040 |
InvalidateWindow(WC_SUBSIDIES_LIST, 0); |
|
1041 |
} |
|
1042 |
||
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1797
diff
changeset
|
1043 |
static const SaveLoad _subsidies_desc[] = { |
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1044 |
SLE_VAR(Subsidy, cargo_type, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1045 |
SLE_VAR(Subsidy, age, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1046 |
SLE_CONDVAR(Subsidy, from, SLE_FILE_U8 | SLE_VAR_U16, 0, 4), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1047 |
SLE_CONDVAR(Subsidy, from, SLE_UINT16, 5, SL_MAX_VERSION), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1048 |
SLE_CONDVAR(Subsidy, to, SLE_FILE_U8 | SLE_VAR_U16, 0, 4), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1049 |
SLE_CONDVAR(Subsidy, to, SLE_UINT16, 5, SL_MAX_VERSION), |
0 | 1050 |
SLE_END() |
1051 |
}; |
|
1052 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1067
diff
changeset
|
1053 |
static void Save_SUBS(void) |
0 | 1054 |
{ |
1055 |
int i; |
|
1056 |
Subsidy *s; |
|
1057 |
||
2952 | 1058 |
for (i = 0; i != lengthof(_subsidies); i++) { |
0 | 1059 |
s = &_subsidies[i]; |
2469
1bfbb0dc0b75
(svn r2995) Replace 0xFF/0xFFFF with CT_INVALID/OWNER_SPECTATOR/INVALID_STATION where appropriate
tron
parents:
2436
diff
changeset
|
1060 |
if (s->cargo_type != CT_INVALID) { |
0 | 1061 |
SlSetArrayIndex(i); |
1062 |
SlObject(s, _subsidies_desc); |
|
1063 |
} |
|
1064 |
} |
|
1065 |
} |
|
1066 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1067
diff
changeset
|
1067 |
static void Load_SUBS(void) |
0 | 1068 |
{ |
1069 |
int index; |
|
1070 |
while ((index = SlIterateArray()) != -1) |
|
1071 |
SlObject(&_subsidies[index], _subsidies_desc); |
|
1072 |
} |
|
1073 |
||
3344
d86c852715fa
(svn r4128) - CodeChange: Add proper semantics for CargoID for such variables instead of using the general byte-type.
Darkvater
parents:
3047
diff
changeset
|
1074 |
int32 GetTransportedGoodsIncome(uint num_pieces, uint dist, byte transit_days, CargoID cargo_type) |
0 | 1075 |
{ |
3344
d86c852715fa
(svn r4128) - CodeChange: Add proper semantics for CargoID for such variables instead of using the general byte-type.
Darkvater
parents:
3047
diff
changeset
|
1076 |
CargoID cargo = cargo_type; |
0 | 1077 |
byte f; |
1078 |
||
1079 |
/* zero the distance if it's the bank and very short transport. */ |
|
1080 |
if (_opt.landscape == LT_NORMAL && cargo == CT_VALUABLES && dist < 10) |
|
1081 |
dist = 0; |
|
1082 |
||
1083 |
f = 255; |
|
1084 |
if (transit_days > _cargoc.transit_days_1[cargo]) { |
|
1085 |
transit_days -= _cargoc.transit_days_1[cargo]; |
|
1086 |
f -= transit_days; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
1087 |
|
0 | 1088 |
if (transit_days > _cargoc.transit_days_2[cargo]) { |
1089 |
transit_days -= _cargoc.transit_days_2[cargo]; |
|
1090 |
||
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
1091 |
if (f < transit_days) { |
0 | 1092 |
f = 0; |
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
1093 |
} else { |
0 | 1094 |
f -= transit_days; |
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
1095 |
} |
0 | 1096 |
} |
1097 |
} |
|
1098 |
if (f < 31) f = 31; |
|
1099 |
||
1100 |
return BIGMULSS(dist * f * num_pieces, _cargo_payment_rates[cargo], 21); |
|
1101 |
} |
|
1102 |
||
3344
d86c852715fa
(svn r4128) - CodeChange: Add proper semantics for CargoID for such variables instead of using the general byte-type.
Darkvater
parents:
3047
diff
changeset
|
1103 |
static void DeliverGoodsToIndustry(TileIndex xy, CargoID cargo_type, int num_pieces) |
0 | 1104 |
{ |
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
1105 |
Industry* best = NULL; |
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
1106 |
Industry* ind; |
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
1107 |
uint u; |
0 | 1108 |
|
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
1109 |
// Check if there's an industry close to the station that accepts the cargo |
3613
6e13c86ae147
(svn r4508) -Fix: (FS#125) Fixed a problem that caused DeliverGoodsToIndustry to not work as intended. Note: write something better for this entire function
celestar
parents:
3580
diff
changeset
|
1110 |
// XXX - Think of something better to |
6e13c86ae147
(svn r4508) -Fix: (FS#125) Fixed a problem that caused DeliverGoodsToIndustry to not work as intended. Note: write something better for this entire function
celestar
parents:
3580
diff
changeset
|
1111 |
// 1) Only deliver to industries which are withing the catchment radius |
6e13c86ae147
(svn r4508) -Fix: (FS#125) Fixed a problem that caused DeliverGoodsToIndustry to not work as intended. Note: write something better for this entire function
celestar
parents:
3580
diff
changeset
|
1112 |
// 2) Distribute between industries if more then one is present |
6e13c86ae147
(svn r4508) -Fix: (FS#125) Fixed a problem that caused DeliverGoodsToIndustry to not work as intended. Note: write something better for this entire function
celestar
parents:
3580
diff
changeset
|
1113 |
u = (_patches.station_spread + 8) * 2; |
830
8114845804c9
(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents:
820
diff
changeset
|
1114 |
FOR_ALL_INDUSTRIES(ind) { |
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
1115 |
uint t; |
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
1116 |
|
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
1117 |
if (( cargo_type == ind->accepts_cargo[0] || |
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
1118 |
cargo_type == ind->accepts_cargo[1] || |
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
1119 |
cargo_type == ind->accepts_cargo[2] |
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
1120 |
) && |
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
1121 |
ind->produced_cargo[0] != CT_INVALID && |
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
1122 |
ind->produced_cargo[0] != cargo_type && |
3613
6e13c86ae147
(svn r4508) -Fix: (FS#125) Fixed a problem that caused DeliverGoodsToIndustry to not work as intended. Note: write something better for this entire function
celestar
parents:
3580
diff
changeset
|
1123 |
(t = DistanceManhattan(ind->xy, xy)) < u) { |
0 | 1124 |
u = t; |
1125 |
best = ind; |
|
1126 |
} |
|
1127 |
} |
|
1128 |
||
1129 |
/* Found one? */ |
|
1130 |
if (best != NULL) { |
|
1131 |
best->was_cargo_delivered = true; |
|
1132 |
best->cargo_waiting[0] = min(best->cargo_waiting[0] + num_pieces, 0xFFFF); |
|
1133 |
} |
|
1134 |
} |
|
1135 |
||
3344
d86c852715fa
(svn r4128) - CodeChange: Add proper semantics for CargoID for such variables instead of using the general byte-type.
Darkvater
parents:
3047
diff
changeset
|
1136 |
static bool CheckSubsidised(Station *from, Station *to, CargoID cargo_type) |
0 | 1137 |
{ |
1138 |
Subsidy *s; |
|
1139 |
TileIndex xy; |
|
1140 |
Pair pair; |
|
1141 |
Player *p; |
|
1142 |
||
1143 |
// check if there is an already existing subsidy that applies to us |
|
2951 | 1144 |
for (s = _subsidies; s != endof(_subsidies); s++) { |
0 | 1145 |
if (s->cargo_type == cargo_type && |
1146 |
s->age >= 12 && |
|
1147 |
s->from == from->index && |
|
2951 | 1148 |
s->to == to->index) { |
0 | 1149 |
return true; |
2951 | 1150 |
} |
0 | 1151 |
} |
1152 |
||
1153 |
/* check if there's a new subsidy that applies.. */ |
|
2951 | 1154 |
for (s = _subsidies; s != endof(_subsidies); s++) { |
0 | 1155 |
if (s->cargo_type == cargo_type && s->age < 12) { |
1156 |
/* Check distance from source */ |
|
1157 |
if (cargo_type == CT_PASSENGERS || cargo_type == CT_MAIL) { |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
863
diff
changeset
|
1158 |
xy = GetTown(s->from)->xy; |
0 | 1159 |
} else { |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
863
diff
changeset
|
1160 |
xy = (GetIndustry(s->from))->xy; |
0 | 1161 |
} |
2951 | 1162 |
if (DistanceMax(xy, from->xy) > 9) continue; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
1163 |
|
0 | 1164 |
/* Check distance from dest */ |
2989 | 1165 |
switch (cargo_type) { |
1166 |
case CT_PASSENGERS: |
|
1167 |
case CT_MAIL: |
|
1168 |
case CT_GOODS: |
|
1169 |
case CT_FOOD: |
|
1170 |
xy = GetTown(s->to)->xy; |
|
1171 |
break; |
|
1172 |
||
1173 |
default: |
|
1174 |
xy = GetIndustry(s->to)->xy; |
|
1175 |
break; |
|
0 | 1176 |
} |
2951 | 1177 |
if (DistanceMax(xy, to->xy) > 9) continue; |
0 | 1178 |
|
1179 |
/* Found a subsidy, change the values to indicate that it's in use */ |
|
1180 |
s->age = 12; |
|
1181 |
s->from = from->index; |
|
1182 |
s->to = to->index; |
|
1183 |
||
1184 |
/* Add a news item */ |
|
1185 |
pair = SetupSubsidyDecodeParam(s, 0); |
|
1309
dab90d4cbf2d
(svn r1813) Declare functions implemented in strings.c in their own shiny new header (though i think some of these function don't belong into strings.c)
tron
parents:
1308
diff
changeset
|
1186 |
InjectDParam(2); |
0 | 1187 |
|
1962
51ee4f459268
(svn r2468) -Codechange: Got rid of DEREF_PLAYER and replaced it by GetPlayer
celestar
parents:
1935
diff
changeset
|
1188 |
p = GetPlayer(_current_player); |
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
1189 |
SetDParam(0, p->name_1); |
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
1190 |
SetDParam(1, p->name_2); |
0 | 1191 |
AddNewsItem( |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
1192 |
STR_2031_SERVICE_SUBSIDY_AWARDED + _opt.diff.subsidy_multiplier, |
0 | 1193 |
NEWS_FLAGS(NM_NORMAL, NF_TILE, NT_SUBSIDIES, 0), |
2951 | 1194 |
pair.a, pair.b |
1195 |
); |
|
0 | 1196 |
|
1197 |
InvalidateWindow(WC_SUBSIDIES_LIST, 0); |
|
1198 |
return true; |
|
1199 |
} |
|
1200 |
} |
|
1201 |
return false; |
|
1202 |
} |
|
1203 |
||
3347
d5d8ace1bb13
(svn r4131) - CodeChange: Add proper semantics for StationID for such variables instead of using the general uint16-type. StationID was added for depots, waypoints and stations where necessary. We probably need to change GetDepot(), IsDepotIndex(), IsStationIndex(), GetWaypoint() and IsWaypointIndex() as well to use StationID.
Darkvater
parents:
3344
diff
changeset
|
1204 |
static int32 DeliverGoods(int num_pieces, CargoID cargo_type, StationID source, StationID dest, byte days_in_transit) |
0 | 1205 |
{ |
1206 |
bool subsidised; |
|
1207 |
Station *s_from, *s_to; |
|
1208 |
int32 profit; |
|
1209 |
||
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3655
diff
changeset
|
1210 |
assert(num_pieces > 0); |
0 | 1211 |
|
1212 |
// Update player statistics |
|
1213 |
{ |
|
1962
51ee4f459268
(svn r2468) -Codechange: Got rid of DEREF_PLAYER and replaced it by GetPlayer
celestar
parents:
1935
diff
changeset
|
1214 |
Player *p = GetPlayer(_current_player); |
0 | 1215 |
p->cur_economy.delivered_cargo += num_pieces; |
1216 |
SETBIT(p->cargo_types, cargo_type); |
|
1217 |
} |
|
1218 |
||
1219 |
// Get station pointers. |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
863
diff
changeset
|
1220 |
s_from = GetStation(source); |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
863
diff
changeset
|
1221 |
s_to = GetStation(dest); |
0 | 1222 |
|
1223 |
// Check if a subsidy applies. |
|
1224 |
subsidised = CheckSubsidised(s_from, s_to, cargo_type); |
|
1225 |
||
1226 |
// Increase town's counter for some special goods types |
|
1935
f43f062c9498
(svn r2441) -Feature: You can now give transfer order to set up feeder systems
celestar
parents:
1905
diff
changeset
|
1227 |
if (cargo_type == CT_FOOD) s_to->town->new_act_food += num_pieces; |
f43f062c9498
(svn r2441) -Feature: You can now give transfer order to set up feeder systems
celestar
parents:
1905
diff
changeset
|
1228 |
if (cargo_type == CT_WATER) s_to->town->new_act_water += num_pieces; |
0 | 1229 |
|
1230 |
// Give the goods to the industry. |
|
1231 |
DeliverGoodsToIndustry(s_to->xy, cargo_type, num_pieces); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
1232 |
|
0 | 1233 |
// Determine profit |
1935
f43f062c9498
(svn r2441) -Feature: You can now give transfer order to set up feeder systems
celestar
parents:
1905
diff
changeset
|
1234 |
profit = GetTransportedGoodsIncome(num_pieces, DistanceManhattan(s_from->xy, s_to->xy), days_in_transit, cargo_type); |
0 | 1235 |
|
1236 |
// Modify profit if a subsidy is in effect |
|
1237 |
if (subsidised) { |
|
2989 | 1238 |
switch (_opt.diff.subsidy_multiplier) { |
3655
ed8ce86fb219
(svn r4570) - Fix: subsidy calculation was too high, broken in r3564
peter1138
parents:
3613
diff
changeset
|
1239 |
case 0: profit += profit >> 1; break; |
ed8ce86fb219
(svn r4570) - Fix: subsidy calculation was too high, broken in r3564
peter1138
parents:
3613
diff
changeset
|
1240 |
case 1: profit *= 2; break; |
ed8ce86fb219
(svn r4570) - Fix: subsidy calculation was too high, broken in r3564
peter1138
parents:
3613
diff
changeset
|
1241 |
case 2: profit *= 3; break; |
ed8ce86fb219
(svn r4570) - Fix: subsidy calculation was too high, broken in r3564
peter1138
parents:
3613
diff
changeset
|
1242 |
default: profit *= 4; break; |
0 | 1243 |
} |
1244 |
} |
|
1245 |
||
1246 |
return profit; |
|
1247 |
} |
|
1248 |
||
523
1184a22723ad
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1249 |
/* |
1184a22723ad
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1250 |
* Returns true if Vehicle v should wait loading because other vehicle is |
1184a22723ad
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1251 |
* already loading the same cargo type |
1184a22723ad
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1252 |
* v = vehicle to load, u = GetFirstInChain(v) |
1184a22723ad
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1253 |
*/ |
2951 | 1254 |
static bool LoadWait(const Vehicle* v, const Vehicle* u) |
1255 |
{ |
|
523
1184a22723ad
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1256 |
const Vehicle *w; |
1184a22723ad
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1257 |
const Vehicle *x; |
1184a22723ad
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1258 |
bool has_any_cargo = false; |
1184a22723ad
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1259 |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
1260 |
if (!(u->current_order.flags & OF_FULL_LOAD)) return false; |
523
1184a22723ad
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1261 |
|
1184a22723ad
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1262 |
for (w = u; w != NULL; w = w->next) { |
1184a22723ad
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1263 |
if (w->cargo_count != 0) { |
1184a22723ad
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1264 |
if (v->cargo_type == w->cargo_type && |
2951 | 1265 |
u->last_station_visited == w->cargo_source) { |
523
1184a22723ad
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1266 |
return false; |
2951 | 1267 |
} |
523
1184a22723ad
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1268 |
has_any_cargo = true; |
1184a22723ad
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1269 |
} |
1184a22723ad
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1270 |
} |
1184a22723ad
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1271 |
|
1184a22723ad
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1272 |
FOR_ALL_VEHICLES(x) { |
2676
2ba71e034d97
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2642
diff
changeset
|
1273 |
if ((x->type != VEH_Train || IsFrontEngine(x)) && // for all locs |
523
1184a22723ad
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1274 |
u->last_station_visited == x->last_station_visited && // at the same station |
1184a22723ad
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1275 |
!(x->vehstatus & VS_STOPPED) && // not stopped |
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
1276 |
x->current_order.type == OT_LOADING && // loading |
523
1184a22723ad
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1277 |
u != x) { // not itself |
1184a22723ad
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1278 |
bool other_has_any_cargo = false; |
1184a22723ad
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1279 |
bool has_space_for_same_type = false; |
1184a22723ad
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1280 |
bool other_has_same_type = false; |
1184a22723ad
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1281 |
|
1184a22723ad
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1282 |
for (w = x; w != NULL; w = w->next) { |
2951 | 1283 |
if (w->cargo_count < w->cargo_cap && v->cargo_type == w->cargo_type) { |
523
1184a22723ad
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1284 |
has_space_for_same_type = true; |
2951 | 1285 |
} |
523
1184a22723ad
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1286 |
|
1184a22723ad
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1287 |
if (w->cargo_count != 0) { |
1184a22723ad
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1288 |
if (v->cargo_type == w->cargo_type && |
2951 | 1289 |
u->last_station_visited == w->cargo_source) { |
523
1184a22723ad
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1290 |
other_has_same_type = true; |
2951 | 1291 |
} |
523
1184a22723ad
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1292 |
other_has_any_cargo = true; |
1184a22723ad
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1293 |
} |
1184a22723ad
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1294 |
} |
1184a22723ad
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1295 |
|
1184a22723ad
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1296 |
if (has_space_for_same_type) { |
1184a22723ad
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1297 |
if (other_has_same_type) return true; |
1184a22723ad
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1298 |
if (other_has_any_cargo && !has_any_cargo) return true; |
1184a22723ad
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1299 |
} |
1184a22723ad
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1300 |
} |
1184a22723ad
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1301 |
} |
1184a22723ad
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1302 |
|
1184a22723ad
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1303 |
return false; |
1184a22723ad
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1304 |
} |
1184a22723ad
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1305 |
|
5211
651c9272ad22
(svn r7326) -Feature: Add support for gradual (un)loading of vehicles (Maedhros)
peter1138
parents:
5077
diff
changeset
|
1306 |
int LoadUnloadVehicle(Vehicle *v, bool just_arrived) |
0 | 1307 |
{ |
1308 |
int profit = 0; |
|
4814
5b71fe860fc3
(svn r6738) - Fix (r2441): Only apply the virtual transfer profit if the order is a transfer order, rather than to any unload order. This fixes an issue where the AI doesn't know that a route is unprofitable.
peter1138
parents:
4701
diff
changeset
|
1309 |
int v_profit = 0; //virtual profit for feeder systems |
1935
f43f062c9498
(svn r2441) -Feature: You can now give transfer order to set up feeder systems
celestar
parents:
1905
diff
changeset
|
1310 |
int v_profit_total = 0; |
0 | 1311 |
int unloading_time = 20; |
1312 |
Vehicle *u = v; |
|
1313 |
int result = 0; |
|
3347
d5d8ace1bb13
(svn r4131) - CodeChange: Add proper semantics for StationID for such variables instead of using the general uint16-type. StationID was added for depots, waypoints and stations where necessary. We probably need to change GetDepot(), IsDepotIndex(), IsStationIndex(), GetWaypoint() and IsWaypointIndex() as well to use StationID.
Darkvater
parents:
3344
diff
changeset
|
1314 |
StationID last_visited; |
0 | 1315 |
Station *st; |
1316 |
int t; |
|
1317 |
uint count, cap; |
|
2498
befad2fe53d2
(svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents:
2475
diff
changeset
|
1318 |
PlayerID old_player; |
445
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
337
diff
changeset
|
1319 |
bool completely_empty = true; |
5211
651c9272ad22
(svn r7326) -Feature: Add support for gradual (un)loading of vehicles (Maedhros)
peter1138
parents:
5077
diff
changeset
|
1320 |
byte load_amount; |
5251
3be755f9ab99
(svn r7377) -Fix (r7326): With gradual loading, make sure cargo is only paid for once, and always notify the station the vehicle was present. (Maedhros)
peter1138
parents:
5220
diff
changeset
|
1321 |
bool anything_loaded = false; |
0 | 1322 |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
1323 |
assert(v->current_order.type == OT_LOADING); |
0 | 1324 |
|
1325 |
v->cur_speed = 0; |
|
5251
3be755f9ab99
(svn r7377) -Fix (r7326): With gradual loading, make sure cargo is only paid for once, and always notify the station the vehicle was present. (Maedhros)
peter1138
parents:
5220
diff
changeset
|
1326 |
|
3be755f9ab99
(svn r7377) -Fix (r7326): With gradual loading, make sure cargo is only paid for once, and always notify the station the vehicle was present. (Maedhros)
peter1138
parents:
5220
diff
changeset
|
1327 |
/* Loading can only have finished when all the cargo has been unloaded, and |
3be755f9ab99
(svn r7377) -Fix (r7326): With gradual loading, make sure cargo is only paid for once, and always notify the station the vehicle was present. (Maedhros)
peter1138
parents:
5220
diff
changeset
|
1328 |
* there is nothing left to load. It's easier to clear this if the |
3be755f9ab99
(svn r7377) -Fix (r7326): With gradual loading, make sure cargo is only paid for once, and always notify the station the vehicle was present. (Maedhros)
peter1138
parents:
5220
diff
changeset
|
1329 |
* conditions haven't been met than attempting to check them all before |
3be755f9ab99
(svn r7377) -Fix (r7326): With gradual loading, make sure cargo is only paid for once, and always notify the station the vehicle was present. (Maedhros)
peter1138
parents:
5220
diff
changeset
|
1330 |
* enabling though. */ |
5211
651c9272ad22
(svn r7326) -Feature: Add support for gradual (un)loading of vehicles (Maedhros)
peter1138
parents:
5077
diff
changeset
|
1331 |
SETBIT(v->load_status, LS_LOADING_FINISHED); |
1539
3d5b40209884
(svn r2043) -Fix: committed too many files in the last commit
truelight
parents:
1538
diff
changeset
|
1332 |
|
1561
b52c96c6edcf
(svn r2065) -Fix: reverted revision 2044, because it had more negative effects than positive
truelight
parents:
1540
diff
changeset
|
1333 |
old_player = _current_player; |
b52c96c6edcf
(svn r2065) -Fix: reverted revision 2044, because it had more negative effects than positive
truelight
parents:
1540
diff
changeset
|
1334 |
_current_player = v->owner; |
b52c96c6edcf
(svn r2065) -Fix: reverted revision 2044, because it had more negative effects than positive
truelight
parents:
1540
diff
changeset
|
1335 |
|
2989 | 1336 |
last_visited = v->last_station_visited; |
1337 |
st = GetStation(last_visited); |
|
0 | 1338 |
|
499 | 1339 |
for (; v != NULL; v = v->next) { |
2639 | 1340 |
GoodsEntry* ge; |
5211
651c9272ad22
(svn r7326) -Feature: Add support for gradual (un)loading of vehicles (Maedhros)
peter1138
parents:
5077
diff
changeset
|
1341 |
load_amount = EngInfo(v->engine_type)->load_amount; |
651c9272ad22
(svn r7326) -Feature: Add support for gradual (un)loading of vehicles (Maedhros)
peter1138
parents:
5077
diff
changeset
|
1342 |
if (_patches.gradual_loading) { |
651c9272ad22
(svn r7326) -Feature: Add support for gradual (un)loading of vehicles (Maedhros)
peter1138
parents:
5077
diff
changeset
|
1343 |
uint16 cb_load_amount = GetVehicleCallback(CBID_VEHICLE_LOAD_AMOUNT, 0, 0, v->engine_type, v); |
651c9272ad22
(svn r7326) -Feature: Add support for gradual (un)loading of vehicles (Maedhros)
peter1138
parents:
5077
diff
changeset
|
1344 |
if (cb_load_amount != CALLBACK_FAILED) load_amount = cb_load_amount & 0xFF; |
651c9272ad22
(svn r7326) -Feature: Add support for gradual (un)loading of vehicles (Maedhros)
peter1138
parents:
5077
diff
changeset
|
1345 |
} |
2639 | 1346 |
|
499 | 1347 |
if (v->cargo_cap == 0) continue; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
1348 |
|
5251
3be755f9ab99
(svn r7377) -Fix (r7326): With gradual loading, make sure cargo is only paid for once, and always notify the station the vehicle was present. (Maedhros)
peter1138
parents:
5220
diff
changeset
|
1349 |
/* If the vehicle has just arrived, set it to unload. */ |
5211
651c9272ad22
(svn r7326) -Feature: Add support for gradual (un)loading of vehicles (Maedhros)
peter1138
parents:
5077
diff
changeset
|
1350 |
if (just_arrived) SETBIT(v->load_status, LS_CARGO_UNLOADING); |
651c9272ad22
(svn r7326) -Feature: Add support for gradual (un)loading of vehicles (Maedhros)
peter1138
parents:
5077
diff
changeset
|
1351 |
|
0 | 1352 |
ge = &st->goods[v->cargo_type]; |
5211
651c9272ad22
(svn r7326) -Feature: Add support for gradual (un)loading of vehicles (Maedhros)
peter1138
parents:
5077
diff
changeset
|
1353 |
count = GB(ge->waiting_acceptance, 0, 12); |
0 | 1354 |
|
1355 |
/* unload? */ |
|
5211
651c9272ad22
(svn r7326) -Feature: Add support for gradual (un)loading of vehicles (Maedhros)
peter1138
parents:
5077
diff
changeset
|
1356 |
if (v->cargo_count != 0 && HASBIT(v->load_status, LS_CARGO_UNLOADING)) { |
5251
3be755f9ab99
(svn r7377) -Fix (r7326): With gradual loading, make sure cargo is only paid for once, and always notify the station the vehicle was present. (Maedhros)
peter1138
parents:
5220
diff
changeset
|
1357 |
uint16 amount_unloaded = _patches.gradual_loading ? min(v->cargo_count, load_amount) : v->cargo_count; |
3be755f9ab99
(svn r7377) -Fix (r7326): With gradual loading, make sure cargo is only paid for once, and always notify the station the vehicle was present. (Maedhros)
peter1138
parents:
5220
diff
changeset
|
1358 |
|
3be755f9ab99
(svn r7377) -Fix (r7326): With gradual loading, make sure cargo is only paid for once, and always notify the station the vehicle was present. (Maedhros)
peter1138
parents:
5220
diff
changeset
|
1359 |
CLRBIT(u->load_status, LS_LOADING_FINISHED); |
3be755f9ab99
(svn r7377) -Fix (r7326): With gradual loading, make sure cargo is only paid for once, and always notify the station the vehicle was present. (Maedhros)
peter1138
parents:
5220
diff
changeset
|
1360 |
|
2639 | 1361 |
if (v->cargo_source != last_visited && ge->waiting_acceptance & 0x8000 && !(u->current_order.flags & OF_TRANSFER)) { |
0 | 1362 |
// deliver goods to the station |
1416
f3ac4388c069
(svn r1920) -Fix: no longer a station where you only unload is bad for your town-rating
truelight
parents:
1415
diff
changeset
|
1363 |
st->time_since_unload = 0; |
f3ac4388c069
(svn r1920) -Fix: no longer a station where you only unload is bad for your town-rating
truelight
parents:
1415
diff
changeset
|
1364 |
|
0 | 1365 |
unloading_time += v->cargo_count; /* TTDBUG: bug in original TTD */ |
5251
3be755f9ab99
(svn r7377) -Fix (r7326): With gradual loading, make sure cargo is only paid for once, and always notify the station the vehicle was present. (Maedhros)
peter1138
parents:
5220
diff
changeset
|
1366 |
if (just_arrived && !HASBIT(v->load_status, LS_CARGO_PAID_FOR)) { |
3be755f9ab99
(svn r7377) -Fix (r7326): With gradual loading, make sure cargo is only paid for once, and always notify the station the vehicle was present. (Maedhros)
peter1138
parents:
5220
diff
changeset
|
1367 |
profit += DeliverGoods(v->cargo_count, v->cargo_type, v->cargo_source, last_visited, v->cargo_days); |
3be755f9ab99
(svn r7377) -Fix (r7326): With gradual loading, make sure cargo is only paid for once, and always notify the station the vehicle was present. (Maedhros)
peter1138
parents:
5220
diff
changeset
|
1368 |
SETBIT(v->load_status, LS_CARGO_PAID_FOR); |
3be755f9ab99
(svn r7377) -Fix (r7326): With gradual loading, make sure cargo is only paid for once, and always notify the station the vehicle was present. (Maedhros)
peter1138
parents:
5220
diff
changeset
|
1369 |
} |
0 | 1370 |
result |= 1; |
5251
3be755f9ab99
(svn r7377) -Fix (r7326): With gradual loading, make sure cargo is only paid for once, and always notify the station the vehicle was present. (Maedhros)
peter1138
parents:
5220
diff
changeset
|
1371 |
v->cargo_count -= amount_unloaded; |
3be755f9ab99
(svn r7377) -Fix (r7326): With gradual loading, make sure cargo is only paid for once, and always notify the station the vehicle was present. (Maedhros)
peter1138
parents:
5220
diff
changeset
|
1372 |
if (_patches.gradual_loading) continue; |
2639 | 1373 |
} else if (u->current_order.flags & (OF_UNLOAD | OF_TRANSFER)) { |
0 | 1374 |
/* unload goods and let it wait at the station */ |
1375 |
st->time_since_unload = 0; |
|
5251
3be755f9ab99
(svn r7377) -Fix (r7326): With gradual loading, make sure cargo is only paid for once, and always notify the station the vehicle was present. (Maedhros)
peter1138
parents:
5220
diff
changeset
|
1376 |
if (just_arrived && (u->current_order.flags & OF_TRANSFER) && !HASBIT(v->load_status, LS_CARGO_PAID_FOR)) { |
4814
5b71fe860fc3
(svn r6738) - Fix (r2441): Only apply the virtual transfer profit if the order is a transfer order, rather than to any unload order. This fixes an issue where the AI doesn't know that a route is unprofitable.
peter1138
parents:
4701
diff
changeset
|
1377 |
v_profit = GetTransportedGoodsIncome( |
5b71fe860fc3
(svn r6738) - Fix (r2441): Only apply the virtual transfer profit if the order is a transfer order, rather than to any unload order. This fixes an issue where the AI doesn't know that a route is unprofitable.
peter1138
parents:
4701
diff
changeset
|
1378 |
v->cargo_count, |
5b71fe860fc3
(svn r6738) - Fix (r2441): Only apply the virtual transfer profit if the order is a transfer order, rather than to any unload order. This fixes an issue where the AI doesn't know that a route is unprofitable.
peter1138
parents:
4701
diff
changeset
|
1379 |
DistanceManhattan(GetStation(v->cargo_source)->xy, GetStation(last_visited)->xy), |
5b71fe860fc3
(svn r6738) - Fix (r2441): Only apply the virtual transfer profit if the order is a transfer order, rather than to any unload order. This fixes an issue where the AI doesn't know that a route is unprofitable.
peter1138
parents:
4701
diff
changeset
|
1380 |
v->cargo_days, |
5b71fe860fc3
(svn r6738) - Fix (r2441): Only apply the virtual transfer profit if the order is a transfer order, rather than to any unload order. This fixes an issue where the AI doesn't know that a route is unprofitable.
peter1138
parents:
4701
diff
changeset
|
1381 |
v->cargo_type) * 3 / 2; |
1935
f43f062c9498
(svn r2441) -Feature: You can now give transfer order to set up feeder systems
celestar
parents:
1905
diff
changeset
|
1382 |
|
4814
5b71fe860fc3
(svn r6738) - Fix (r2441): Only apply the virtual transfer profit if the order is a transfer order, rather than to any unload order. This fixes an issue where the AI doesn't know that a route is unprofitable.
peter1138
parents:
4701
diff
changeset
|
1383 |
v_profit_total += v_profit; |
5251
3be755f9ab99
(svn r7377) -Fix (r7326): With gradual loading, make sure cargo is only paid for once, and always notify the station the vehicle was present. (Maedhros)
peter1138
parents:
5220
diff
changeset
|
1384 |
SETBIT(v->load_status, LS_CARGO_PAID_FOR); |
4814
5b71fe860fc3
(svn r6738) - Fix (r2441): Only apply the virtual transfer profit if the order is a transfer order, rather than to any unload order. This fixes an issue where the AI doesn't know that a route is unprofitable.
peter1138
parents:
4701
diff
changeset
|
1385 |
} |
1935
f43f062c9498
(svn r2441) -Feature: You can now give transfer order to set up feeder systems
celestar
parents:
1905
diff
changeset
|
1386 |
|
f43f062c9498
(svn r2441) -Feature: You can now give transfer order to set up feeder systems
celestar
parents:
1905
diff
changeset
|
1387 |
unloading_time += v->cargo_count; |
2504
7c27fc230cda
(svn r3030) More work for GB/SB, this time concerning the waiting_acceptance attribute of stations
tron
parents:
2498
diff
changeset
|
1388 |
t = GB(ge->waiting_acceptance, 0, 12); |
7c27fc230cda
(svn r3030) More work for GB/SB, this time concerning the waiting_acceptance attribute of stations
tron
parents:
2498
diff
changeset
|
1389 |
if (t == 0) { |
0 | 1390 |
// No goods waiting at station |
1391 |
ge->enroute_time = v->cargo_days; |
|
1392 |
ge->enroute_from = v->cargo_source; |
|
1393 |
} else { |
|
1394 |
// Goods already waiting at station. Set counters to the worst value. |
|
1395 |
if (v->cargo_days >= ge->enroute_time) |
|
1396 |
ge->enroute_time = v->cargo_days; |
|
1266
9dc5638fe8cc
(svn r1770) -Fix: Hopefully last pieces of code that are containing a station-id
truelight
parents:
1245
diff
changeset
|
1397 |
if (last_visited != ge->enroute_from) |
0 | 1398 |
ge->enroute_from = v->cargo_source; |
1399 |
} |
|
1400 |
// Update amount of waiting cargo |
|
5211
651c9272ad22
(svn r7326) -Feature: Add support for gradual (un)loading of vehicles (Maedhros)
peter1138
parents:
5077
diff
changeset
|
1401 |
SB(ge->waiting_acceptance, 0, 12, min(amount_unloaded + t, 0xFFF)); |
4814
5b71fe860fc3
(svn r6738) - Fix (r2441): Only apply the virtual transfer profit if the order is a transfer order, rather than to any unload order. This fixes an issue where the AI doesn't know that a route is unprofitable.
peter1138
parents:
4701
diff
changeset
|
1402 |
|
5b71fe860fc3
(svn r6738) - Fix (r2441): Only apply the virtual transfer profit if the order is a transfer order, rather than to any unload order. This fixes an issue where the AI doesn't know that a route is unprofitable.
peter1138
parents:
4701
diff
changeset
|
1403 |
if (u->current_order.flags & OF_TRANSFER) { |
5b71fe860fc3
(svn r6738) - Fix (r2441): Only apply the virtual transfer profit if the order is a transfer order, rather than to any unload order. This fixes an issue where the AI doesn't know that a route is unprofitable.
peter1138
parents:
4701
diff
changeset
|
1404 |
ge->feeder_profit += v_profit; |
5b71fe860fc3
(svn r6738) - Fix (r2441): Only apply the virtual transfer profit if the order is a transfer order, rather than to any unload order. This fixes an issue where the AI doesn't know that a route is unprofitable.
peter1138
parents:
4701
diff
changeset
|
1405 |
u->profit_this_year += v_profit; |
5b71fe860fc3
(svn r6738) - Fix (r2441): Only apply the virtual transfer profit if the order is a transfer order, rather than to any unload order. This fixes an issue where the AI doesn't know that a route is unprofitable.
peter1138
parents:
4701
diff
changeset
|
1406 |
} |
0 | 1407 |
result |= 2; |
5211
651c9272ad22
(svn r7326) -Feature: Add support for gradual (un)loading of vehicles (Maedhros)
peter1138
parents:
5077
diff
changeset
|
1408 |
v->cargo_count -= amount_unloaded; |
5251
3be755f9ab99
(svn r7377) -Fix (r7326): With gradual loading, make sure cargo is only paid for once, and always notify the station the vehicle was present. (Maedhros)
peter1138
parents:
5220
diff
changeset
|
1409 |
if (_patches.gradual_loading) continue; |
0 | 1410 |
} |
445
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
337
diff
changeset
|
1411 |
|
2951 | 1412 |
if (v->cargo_count != 0) completely_empty = false; |
0 | 1413 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
1414 |
|
5251
3be755f9ab99
(svn r7377) -Fix (r7326): With gradual loading, make sure cargo is only paid for once, and always notify the station the vehicle was present. (Maedhros)
peter1138
parents:
5220
diff
changeset
|
1415 |
/* The vehicle must have been unloaded because it is either empty, or |
3be755f9ab99
(svn r7377) -Fix (r7326): With gradual loading, make sure cargo is only paid for once, and always notify the station the vehicle was present. (Maedhros)
peter1138
parents:
5220
diff
changeset
|
1416 |
* the UNLOADING bit is already clear in v->load_status. */ |
3be755f9ab99
(svn r7377) -Fix (r7326): With gradual loading, make sure cargo is only paid for once, and always notify the station the vehicle was present. (Maedhros)
peter1138
parents:
5220
diff
changeset
|
1417 |
CLRBIT(v->load_status, LS_CARGO_UNLOADING); |
3be755f9ab99
(svn r7377) -Fix (r7326): With gradual loading, make sure cargo is only paid for once, and always notify the station the vehicle was present. (Maedhros)
peter1138
parents:
5220
diff
changeset
|
1418 |
CLRBIT(v->load_status, LS_CARGO_PAID_FOR); |
3be755f9ab99
(svn r7377) -Fix (r7326): With gradual loading, make sure cargo is only paid for once, and always notify the station the vehicle was present. (Maedhros)
peter1138
parents:
5220
diff
changeset
|
1419 |
|
0 | 1420 |
/* don't pick up goods that we unloaded */ |
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
1421 |
if (u->current_order.flags & OF_UNLOAD) continue; |
0 | 1422 |
|
1423 |
/* update stats */ |
|
1424 |
ge->days_since_pickup = 0; |
|
2989 | 1425 |
switch (u->type) { |
1426 |
case VEH_Train: t = u->u.rail.cached_max_speed; break; |
|
1427 |
case VEH_Road: t = u->max_speed / 2; break; |
|
1428 |
default: t = u->max_speed; break; |
|
1429 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
1430 |
|
0 | 1431 |
// if last speed is 0, we treat that as if no vehicle has ever visited the station. |
2989 | 1432 |
ge->last_speed = min(t, 255); |
4329
9759d5c52010
(svn r6002) -Cleanup: remove the now redundant BASE_YEAR constant.
rubidium
parents:
4293
diff
changeset
|
1433 |
ge->last_age = _cur_year - v->build_year; |
0 | 1434 |
|
1435 |
// If there's goods waiting at the station, and the vehicle |
|
1436 |
// has capacity for it, load it on the vehicle. |
|
2504
7c27fc230cda
(svn r3030) More work for GB/SB, this time concerning the waiting_acceptance attribute of stations
tron
parents:
2498
diff
changeset
|
1437 |
if (count != 0 && |
0 | 1438 |
(cap = v->cargo_cap - v->cargo_count) != 0) { |
1935
f43f062c9498
(svn r2441) -Feature: You can now give transfer order to set up feeder systems
celestar
parents:
1905
diff
changeset
|
1439 |
int cargoshare; |
f43f062c9498
(svn r2441) -Feature: You can now give transfer order to set up feeder systems
celestar
parents:
1905
diff
changeset
|
1440 |
int feeder_profit_share; |
f43f062c9498
(svn r2441) -Feature: You can now give transfer order to set up feeder systems
celestar
parents:
1905
diff
changeset
|
1441 |
|
445
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
337
diff
changeset
|
1442 |
if (v->cargo_count == 0) |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
337
diff
changeset
|
1443 |
TriggerVehicle(v, VEHICLE_TRIGGER_NEW_CARGO); |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
337
diff
changeset
|
1444 |
|
523
1184a22723ad
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1445 |
/* Skip loading this vehicle if another train/vehicle is already handling |
1184a22723ad
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1446 |
* the same cargo type at this station */ |
5211
651c9272ad22
(svn r7326) -Feature: Add support for gradual (un)loading of vehicles (Maedhros)
peter1138
parents:
5077
diff
changeset
|
1447 |
if (_patches.improved_load && (u->current_order.flags & OF_FULL_LOAD) && LoadWait(v,u)) continue; |
523
1184a22723ad
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1448 |
|
445
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
337
diff
changeset
|
1449 |
/* TODO: Regarding this, when we do gradual loading, we |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
337
diff
changeset
|
1450 |
* should first unload all vehicles and then start |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
337
diff
changeset
|
1451 |
* loading them. Since this will cause |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
337
diff
changeset
|
1452 |
* VEHICLE_TRIGGER_EMPTY to be called at the time when |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
337
diff
changeset
|
1453 |
* the whole vehicle chain is really totally empty, the |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
337
diff
changeset
|
1454 |
* @completely_empty assignment can then be safely |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
337
diff
changeset
|
1455 |
* removed; that's how TTDPatch behaves too. --pasky */ |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
337
diff
changeset
|
1456 |
completely_empty = false; |
5251
3be755f9ab99
(svn r7377) -Fix (r7326): With gradual loading, make sure cargo is only paid for once, and always notify the station the vehicle was present. (Maedhros)
peter1138
parents:
5220
diff
changeset
|
1457 |
anything_loaded = true; |
445
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
337
diff
changeset
|
1458 |
|
0 | 1459 |
if (cap > count) cap = count; |
5211
651c9272ad22
(svn r7326) -Feature: Add support for gradual (un)loading of vehicles (Maedhros)
peter1138
parents:
5077
diff
changeset
|
1460 |
if (_patches.gradual_loading) cap = min(cap, load_amount); |
651c9272ad22
(svn r7326) -Feature: Add support for gradual (un)loading of vehicles (Maedhros)
peter1138
parents:
5077
diff
changeset
|
1461 |
if (cap < count) CLRBIT(u->load_status, LS_LOADING_FINISHED); |
1935
f43f062c9498
(svn r2441) -Feature: You can now give transfer order to set up feeder systems
celestar
parents:
1905
diff
changeset
|
1462 |
cargoshare = cap * 10000 / ge->waiting_acceptance; |
f43f062c9498
(svn r2441) -Feature: You can now give transfer order to set up feeder systems
celestar
parents:
1905
diff
changeset
|
1463 |
feeder_profit_share = ge->feeder_profit * cargoshare / 10000; |
0 | 1464 |
v->cargo_count += cap; |
1465 |
ge->waiting_acceptance -= cap; |
|
1935
f43f062c9498
(svn r2441) -Feature: You can now give transfer order to set up feeder systems
celestar
parents:
1905
diff
changeset
|
1466 |
v->profit_this_year -= feeder_profit_share; |
f43f062c9498
(svn r2441) -Feature: You can now give transfer order to set up feeder systems
celestar
parents:
1905
diff
changeset
|
1467 |
ge->feeder_profit -= feeder_profit_share; |
0 | 1468 |
unloading_time += cap; |
1469 |
st->time_since_load = 0; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
1470 |
|
0 | 1471 |
// And record the source of the cargo, and the days in travel. |
2815
2afe3aed98f3
(svn r3363) -Fix: 'fixed' the transfer problem. This doesn't really fix it, but gives a bit more fair amount of money. Can only be fixed correctly with CargoPackets as suggested in branch.
truelight
parents:
2684
diff
changeset
|
1472 |
v->cargo_source = ge->enroute_from; |
0 | 1473 |
v->cargo_days = ge->enroute_time; |
1474 |
result |= 2; |
|
3580
607e4245d024
(svn r4466) -Fix: (FS#71) Game no longer crashes when the last vehicle serving a station has been deleted.
celestar
parents:
3491
diff
changeset
|
1475 |
st->last_vehicle_type = v->type; |
0 | 1476 |
} |
1477 |
} |
|
1478 |
||
5211
651c9272ad22
(svn r7326) -Feature: Add support for gradual (un)loading of vehicles (Maedhros)
peter1138
parents:
5077
diff
changeset
|
1479 |
v = u; |
1935
f43f062c9498
(svn r2441) -Feature: You can now give transfer order to set up feeder systems
celestar
parents:
1905
diff
changeset
|
1480 |
|
5211
651c9272ad22
(svn r7326) -Feature: Add support for gradual (un)loading of vehicles (Maedhros)
peter1138
parents:
5077
diff
changeset
|
1481 |
if (_patches.gradual_loading) { |
651c9272ad22
(svn r7326) -Feature: Add support for gradual (un)loading of vehicles (Maedhros)
peter1138
parents:
5077
diff
changeset
|
1482 |
/* The time it takes to load one 'slice' of cargo or passengers depends |
651c9272ad22
(svn r7326) -Feature: Add support for gradual (un)loading of vehicles (Maedhros)
peter1138
parents:
5077
diff
changeset
|
1483 |
* on the vehicle type - the values here are those found in TTDPatch */ |
651c9272ad22
(svn r7326) -Feature: Add support for gradual (un)loading of vehicles (Maedhros)
peter1138
parents:
5077
diff
changeset
|
1484 |
uint gradual_loading_wait_time[] = { 40, 20, 10, 20 }; |
651c9272ad22
(svn r7326) -Feature: Add support for gradual (un)loading of vehicles (Maedhros)
peter1138
parents:
5077
diff
changeset
|
1485 |
|
651c9272ad22
(svn r7326) -Feature: Add support for gradual (un)loading of vehicles (Maedhros)
peter1138
parents:
5077
diff
changeset
|
1486 |
unloading_time = gradual_loading_wait_time[v->type - VEH_Train]; |
5251
3be755f9ab99
(svn r7377) -Fix (r7326): With gradual loading, make sure cargo is only paid for once, and always notify the station the vehicle was present. (Maedhros)
peter1138
parents:
5220
diff
changeset
|
1487 |
if (HASBIT(v->load_status, LS_LOADING_FINISHED)) { |
3be755f9ab99
(svn r7377) -Fix (r7326): With gradual loading, make sure cargo is only paid for once, and always notify the station the vehicle was present. (Maedhros)
peter1138
parents:
5220
diff
changeset
|
1488 |
if (anything_loaded) { |
3be755f9ab99
(svn r7377) -Fix (r7326): With gradual loading, make sure cargo is only paid for once, and always notify the station the vehicle was present. (Maedhros)
peter1138
parents:
5220
diff
changeset
|
1489 |
unloading_time += 20; |
3be755f9ab99
(svn r7377) -Fix (r7326): With gradual loading, make sure cargo is only paid for once, and always notify the station the vehicle was present. (Maedhros)
peter1138
parents:
5220
diff
changeset
|
1490 |
} else { |
3be755f9ab99
(svn r7377) -Fix (r7326): With gradual loading, make sure cargo is only paid for once, and always notify the station the vehicle was present. (Maedhros)
peter1138
parents:
5220
diff
changeset
|
1491 |
unloading_time = 20; |
3be755f9ab99
(svn r7377) -Fix (r7326): With gradual loading, make sure cargo is only paid for once, and always notify the station the vehicle was present. (Maedhros)
peter1138
parents:
5220
diff
changeset
|
1492 |
} |
3be755f9ab99
(svn r7377) -Fix (r7326): With gradual loading, make sure cargo is only paid for once, and always notify the station the vehicle was present. (Maedhros)
peter1138
parents:
5220
diff
changeset
|
1493 |
} |
5211
651c9272ad22
(svn r7326) -Feature: Add support for gradual (un)loading of vehicles (Maedhros)
peter1138
parents:
5077
diff
changeset
|
1494 |
} |
0 | 1495 |
|
2951 | 1496 |
if (v_profit_total > 0) { |
1935
f43f062c9498
(svn r2441) -Feature: You can now give transfer order to set up feeder systems
celestar
parents:
1905
diff
changeset
|
1497 |
ShowFeederIncomeAnimation(v->x_pos, v->y_pos, v->z_pos, v_profit_total); |
2951 | 1498 |
} |
1935
f43f062c9498
(svn r2441) -Feature: You can now give transfer order to set up feeder systems
celestar
parents:
1905
diff
changeset
|
1499 |
|
0 | 1500 |
if (v->type == VEH_Train) { |
2587
d554e2a03afa
(svn r3124) Alter train loading/unloading time to use the actual length of the train instead of the number of wagons. The actual length is cached in the first vehicle of the train.
peter1138
parents:
2548
diff
changeset
|
1501 |
// Each platform tile is worth 2 rail vehicles. |
3421
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3386
diff
changeset
|
1502 |
int overhang = v->u.rail.cached_total_length - GetStationPlatforms(st, v->tile) * TILE_SIZE; |
2587
d554e2a03afa
(svn r3124) Alter train loading/unloading time to use the actual length of the train instead of the number of wagons. The actual length is cached in the first vehicle of the train.
peter1138
parents:
2548
diff
changeset
|
1503 |
if (overhang > 0) { |
d554e2a03afa
(svn r3124) Alter train loading/unloading time to use the actual length of the train instead of the number of wagons. The actual length is cached in the first vehicle of the train.
peter1138
parents:
2548
diff
changeset
|
1504 |
unloading_time <<= 1; |
d554e2a03afa
(svn r3124) Alter train loading/unloading time to use the actual length of the train instead of the number of wagons. The actual length is cached in the first vehicle of the train.
peter1138
parents:
2548
diff
changeset
|
1505 |
unloading_time += (overhang * unloading_time) / 8; |
0 | 1506 |
} |
1507 |
} |
|
1508 |
||
1509 |
v->load_unload_time_rem = unloading_time; |
|
1510 |
||
445
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
337
diff
changeset
|
1511 |
if (completely_empty) { |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
337
diff
changeset
|
1512 |
TriggerVehicle(v, VEHICLE_TRIGGER_EMPTY); |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
337
diff
changeset
|
1513 |
} |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
337
diff
changeset
|
1514 |
|
0 | 1515 |
if (result != 0) { |
1516 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
|
5220
f96f67f4250e
(svn r7335) -Codechange: redraw station tiles when cargo is moved, for newstations
peter1138
parents:
5211
diff
changeset
|
1517 |
MarkStationTilesDirty(st); |
0 | 1518 |
|
2951 | 1519 |
if (result & 2) InvalidateWindow(WC_STATION_VIEW, last_visited); |
0 | 1520 |
|
1521 |
if (profit != 0) { |
|
1522 |
v->profit_this_year += profit; |
|
1523 |
SubtractMoneyFromPlayer(-profit); |
|
1524 |
||
4701 | 1525 |
if (IsLocalPlayer() && !PlayVehicleSound(v, VSE_LOAD_UNLOAD)) { |
1526 |
SndPlayVehicleFx(SND_14_CASHTILL, v); |
|
1527 |
} |
|
0 | 1528 |
|
1529 |
ShowCostOrIncomeAnimation(v->x_pos, v->y_pos, v->z_pos, -profit); |
|
1530 |
} |
|
1531 |
} |
|
1532 |
||
260
32fcaaf9f4ef
(svn r266) -Fix: hopefully fixed the desync problem nicely (and reverted the
truelight
parents:
240
diff
changeset
|
1533 |
_current_player = old_player; |
0 | 1534 |
return result; |
1535 |
} |
|
1536 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1067
diff
changeset
|
1537 |
void PlayersMonthlyLoop(void) |
0 | 1538 |
{ |
1539 |
PlayersGenStatistics(); |
|
4293
2c24234a7aec
(svn r5926) -Codechange: make _cur_year contain the full year, instead of the offset since 1920
rubidium
parents:
4286
diff
changeset
|
1540 |
if (_patches.inflation && _cur_year < MAX_YEAR) |
0 | 1541 |
AddInflation(); |
1542 |
PlayersPayInterest(); |
|
206 | 1543 |
// Reset the _current_player flag |
1544 |
_current_player = OWNER_NONE; |
|
0 | 1545 |
HandleEconomyFluctuations(); |
1546 |
SubsidyMonthlyHandler(); |
|
1547 |
} |
|
1548 |
||
1549 |
static void DoAcquireCompany(Player *p) |
|
1550 |
{ |
|
1551 |
Player *owner; |
|
1552 |
int i,pi; |
|
200
03b8104d1479
(svn r201) -Fix: [1025836] Company values bigger dan int32 were put to negative
truelight
parents:
193
diff
changeset
|
1553 |
int64 value; |
0 | 1554 |
|
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
1555 |
SetDParam(0, p->name_1); |
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
1556 |
SetDParam(1, p->name_2); |
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
1557 |
SetDParam(2, p->bankrupt_value); |
4873
7cb19235cf60
(svn r6803) -Codechange: Substitute magic numbers by an enum for the news windows
Darkvater
parents:
4854
diff
changeset
|
1558 |
AddNewsItem( (StringID)(_current_player | NB_BMERGER), NEWS_FLAGS(NM_CALLBACK, 0, NT_COMPANY_INFO, DNC_BANKRUPCY),0,0); |
0 | 1559 |
|
1560 |
// original code does this a little bit differently |
|
1561 |
pi = p->index; |
|
1562 |
ChangeOwnershipOfPlayerItems(pi, _current_player); |
|
1563 |
||
1564 |
if (p->bankrupt_value == 0) { |
|
1962
51ee4f459268
(svn r2468) -Codechange: Got rid of DEREF_PLAYER and replaced it by GetPlayer
celestar
parents:
1935
diff
changeset
|
1565 |
owner = GetPlayer(_current_player); |
0 | 1566 |
owner->current_loan += p->current_loan; |
1567 |
} |
|
1568 |
||
1569 |
value = CalculateCompanyValue(p) >> 2; |
|
2952 | 1570 |
for (i = 0; i != 4; i++) { |
4848
56549aa3e234
(svn r6774) -Codechange: Rename the badly named OWNER_SPECTATOR to PLAYER_SPECTATOR and
Darkvater
parents:
4845
diff
changeset
|
1571 |
if (p->share_owners[i] != PLAYER_SPECTATOR) { |
1962
51ee4f459268
(svn r2468) -Codechange: Got rid of DEREF_PLAYER and replaced it by GetPlayer
celestar
parents:
1935
diff
changeset
|
1572 |
owner = GetPlayer(p->share_owners[i]); |
0 | 1573 |
owner->money64 += value; |
1574 |
owner->yearly_expenses[0][EXPENSES_OTHER] += value; |
|
1575 |
UpdatePlayerMoney32(owner); |
|
1576 |
} |
|
1577 |
} |
|
1578 |
||
1579 |
p->is_active = false; |
|
1580 |
||
1581 |
DeletePlayerWindows(pi); |
|
4434
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4423
diff
changeset
|
1582 |
RebuildVehicleLists(); //Updates the open windows to add the newly acquired vehicles to the lists |
0 | 1583 |
} |
1584 |
||
599
80e49e323483
(svn r1023) -Fix: [Network] [ 1083692 ] You can no longer buy out a company in MP
truelight
parents:
555
diff
changeset
|
1585 |
extern int GetAmountOwnedBy(Player *p, byte owner); |
80e49e323483
(svn r1023) -Fix: [Network] [ 1083692 ] You can no longer buy out a company in MP
truelight
parents:
555
diff
changeset
|
1586 |
|
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1707
diff
changeset
|
1587 |
/** Acquire shares in an opposing company. |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3421
diff
changeset
|
1588 |
* @param tile unused |
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1707
diff
changeset
|
1589 |
* @param p1 player to buy the shares from |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1707
diff
changeset
|
1590 |
* @param p2 unused |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1707
diff
changeset
|
1591 |
*/ |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3421
diff
changeset
|
1592 |
int32 CmdBuyShareInCompany(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 1593 |
{ |
1594 |
Player *p; |
|
200
03b8104d1479
(svn r201) -Fix: [1025836] Company values bigger dan int32 were put to negative
truelight
parents:
193
diff
changeset
|
1595 |
int64 cost; |
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1707
diff
changeset
|
1596 |
|
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1707
diff
changeset
|
1597 |
/* Check if buying shares is allowed (protection against modified clients */ |
4850
b4e9be22945f
(svn r6776) -Codechange: Use IsValidPlayer() function to determine of a PlayerID is an
Darkvater
parents:
4848
diff
changeset
|
1598 |
if (!IsValidPlayer((PlayerID)p1) || !_patches.allow_shares) return CMD_ERROR; |
0 | 1599 |
|
1600 |
SET_EXPENSES_TYPE(EXPENSES_OTHER); |
|
1962
51ee4f459268
(svn r2468) -Codechange: Got rid of DEREF_PLAYER and replaced it by GetPlayer
celestar
parents:
1935
diff
changeset
|
1601 |
p = GetPlayer(p1); |
1019
6363b8a4273e
(svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents:
997
diff
changeset
|
1602 |
|
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1707
diff
changeset
|
1603 |
/* Protect new companies from hostile takeovers */ |
4329
9759d5c52010
(svn r6002) -Cleanup: remove the now redundant BASE_YEAR constant.
rubidium
parents:
4293
diff
changeset
|
1604 |
if (_cur_year - p->inaugurated_year < 6) return_cmd_error(STR_7080_PROTECTED); |
930
524b02923ede
(svn r1418) -Feature: [1098254] (dis)Allow Shares. Add patch options to allow buying/selling of shares (Hackykid)
darkvater
parents:
919
diff
changeset
|
1605 |
|
599
80e49e323483
(svn r1023) -Fix: [Network] [ 1083692 ] You can no longer buy out a company in MP
truelight
parents:
555
diff
changeset
|
1606 |
/* Those lines are here for network-protection (clients can be slow) */ |
4848
56549aa3e234
(svn r6774) -Codechange: Rename the badly named OWNER_SPECTATOR to PLAYER_SPECTATOR and
Darkvater
parents:
4845
diff
changeset
|
1607 |
if (GetAmountOwnedBy(p, PLAYER_SPECTATOR) == 0) return 0; |
930
524b02923ede
(svn r1418) -Feature: [1098254] (dis)Allow Shares. Add patch options to allow buying/selling of shares (Hackykid)
darkvater
parents:
919
diff
changeset
|
1608 |
|
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1707
diff
changeset
|
1609 |
/* We can not buy out a real player (temporarily). TODO: well, enable it obviously */ |
4848
56549aa3e234
(svn r6774) -Codechange: Rename the badly named OWNER_SPECTATOR to PLAYER_SPECTATOR and
Darkvater
parents:
4845
diff
changeset
|
1610 |
if (GetAmountOwnedBy(p, PLAYER_SPECTATOR) == 1 && !p->is_ai) return 0; |
1019
6363b8a4273e
(svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents:
997
diff
changeset
|
1611 |
|
0 | 1612 |
cost = CalculateCompanyValue(p) >> 2; |
1613 |
if (flags & DC_EXEC) { |
|
2498
befad2fe53d2
(svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents:
2475
diff
changeset
|
1614 |
PlayerID* b = p->share_owners; |
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1707
diff
changeset
|
1615 |
int i; |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1707
diff
changeset
|
1616 |
|
4848
56549aa3e234
(svn r6774) -Codechange: Rename the badly named OWNER_SPECTATOR to PLAYER_SPECTATOR and
Darkvater
parents:
4845
diff
changeset
|
1617 |
while (*b != PLAYER_SPECTATOR) b++; /* share owners is guaranteed to contain at least one PLAYER_SPECTATOR */ |
0 | 1618 |
*b = _current_player; |
1619 |
||
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1707
diff
changeset
|
1620 |
for (i = 0; p->share_owners[i] == _current_player;) { |
0 | 1621 |
if (++i == 4) { |
1622 |
p->bankrupt_value = 0; |
|
1623 |
DoAcquireCompany(p); |
|
1624 |
break; |
|
1625 |
} |
|
1626 |
} |
|
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
1627 |
InvalidateWindow(WC_COMPANY, p1); |
0 | 1628 |
} |
1629 |
return cost; |
|
1630 |
} |
|
1631 |
||
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1707
diff
changeset
|
1632 |
/** Sell shares in an opposing company. |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3421
diff
changeset
|
1633 |
* @param tile unused |
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1707
diff
changeset
|
1634 |
* @param p1 player to sell the shares from |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1707
diff
changeset
|
1635 |
* @param p2 unused |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1707
diff
changeset
|
1636 |
*/ |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3421
diff
changeset
|
1637 |
int32 CmdSellShareInCompany(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 1638 |
{ |
1639 |
Player *p; |
|
200
03b8104d1479
(svn r201) -Fix: [1025836] Company values bigger dan int32 were put to negative
truelight
parents:
193
diff
changeset
|
1640 |
int64 cost; |
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1707
diff
changeset
|
1641 |
|
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1707
diff
changeset
|
1642 |
/* Check if buying shares is allowed (protection against modified clients */ |
4850
b4e9be22945f
(svn r6776) -Codechange: Use IsValidPlayer() function to determine of a PlayerID is an
Darkvater
parents:
4848
diff
changeset
|
1643 |
if (!IsValidPlayer((PlayerID)p1) || !_patches.allow_shares) return CMD_ERROR; |
0 | 1644 |
|
1645 |
SET_EXPENSES_TYPE(EXPENSES_OTHER); |
|
1962
51ee4f459268
(svn r2468) -Codechange: Got rid of DEREF_PLAYER and replaced it by GetPlayer
celestar
parents:
1935
diff
changeset
|
1646 |
p = GetPlayer(p1); |
0 | 1647 |
|
653
3c902c647791
(svn r1086) -Fix: [Network] [ 1084774 ] Fixed quick-share-sell bug
truelight
parents:
630
diff
changeset
|
1648 |
/* Those lines are here for network-protection (clients can be slow) */ |
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1707
diff
changeset
|
1649 |
if (GetAmountOwnedBy(p, _current_player) == 0) return 0; |
653
3c902c647791
(svn r1086) -Fix: [Network] [ 1084774 ] Fixed quick-share-sell bug
truelight
parents:
630
diff
changeset
|
1650 |
|
0 | 1651 |
/* adjust it a little to make it less profitable to sell and buy */ |
1652 |
cost = CalculateCompanyValue(p) >> 2; |
|
1653 |
cost = -(cost - (cost >> 7)); |
|
1654 |
||
1655 |
if (flags & DC_EXEC) { |
|
2498
befad2fe53d2
(svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents:
2475
diff
changeset
|
1656 |
PlayerID* b = p->share_owners; |
0 | 1657 |
while (*b != _current_player) b++; /* share owners is guaranteed to contain player */ |
4848
56549aa3e234
(svn r6774) -Codechange: Rename the badly named OWNER_SPECTATOR to PLAYER_SPECTATOR and
Darkvater
parents:
4845
diff
changeset
|
1658 |
*b = PLAYER_SPECTATOR; |
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
1659 |
InvalidateWindow(WC_COMPANY, p1); |
0 | 1660 |
} |
1661 |
return cost; |
|
1662 |
} |
|
1663 |
||
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1707
diff
changeset
|
1664 |
/** Buy up another company. |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1707
diff
changeset
|
1665 |
* When a competing company is gone bankrupt you get the chance to purchase |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1707
diff
changeset
|
1666 |
* that company. |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1707
diff
changeset
|
1667 |
* @todo currently this only works for AI players |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3421
diff
changeset
|
1668 |
* @param tile unused |
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1707
diff
changeset
|
1669 |
* @param p1 player/company to buy up |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1707
diff
changeset
|
1670 |
* @param p2 unused |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1707
diff
changeset
|
1671 |
*/ |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3421
diff
changeset
|
1672 |
int32 CmdBuyCompany(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 1673 |
{ |
1674 |
Player *p; |
|
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1707
diff
changeset
|
1675 |
|
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1707
diff
changeset
|
1676 |
/* Disable takeovers in multiplayer games */ |
4850
b4e9be22945f
(svn r6776) -Codechange: Use IsValidPlayer() function to determine of a PlayerID is an
Darkvater
parents:
4848
diff
changeset
|
1677 |
if (!IsValidPlayer((PlayerID)p1) || _networking) return CMD_ERROR; |
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1707
diff
changeset
|
1678 |
|
0 | 1679 |
SET_EXPENSES_TYPE(EXPENSES_OTHER); |
1962
51ee4f459268
(svn r2468) -Codechange: Got rid of DEREF_PLAYER and replaced it by GetPlayer
celestar
parents:
1935
diff
changeset
|
1680 |
p = GetPlayer(p1); |
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1707
diff
changeset
|
1681 |
|
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1707
diff
changeset
|
1682 |
if (!p->is_ai) return CMD_ERROR; |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1707
diff
changeset
|
1683 |
|
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1707
diff
changeset
|
1684 |
if (flags & DC_EXEC) { |
0 | 1685 |
DoAcquireCompany(p); |
1686 |
} |
|
1687 |
return p->bankrupt_value; |
|
1688 |
} |
|
1689 |
||
1690 |
// Prices |
|
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1067
diff
changeset
|
1691 |
static void SaveLoad_PRIC(void) |
0 | 1692 |
{ |
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1693 |
SlArray(&_price, NUM_PRICES, SLE_INT32); |
0 | 1694 |
SlArray(&_price_frac, NUM_PRICES, SLE_UINT16); |
1695 |
} |
|
1696 |
||
1697 |
// Cargo payment rates |
|
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1067
diff
changeset
|
1698 |
static void SaveLoad_CAPR(void) |
0 | 1699 |
{ |
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1700 |
SlArray(&_cargo_payment_rates, NUM_CARGO, SLE_INT32); |
0 | 1701 |
SlArray(&_cargo_payment_rates_frac, NUM_CARGO, SLE_UINT16); |
1702 |
} |
|
1703 |
||
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1797
diff
changeset
|
1704 |
static const SaveLoad _economy_desc[] = { |
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1705 |
SLE_VAR(Economy, max_loan, SLE_INT32), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1706 |
SLE_VAR(Economy, max_loan_unround, SLE_INT32), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1707 |
SLE_VAR(Economy, fluct, SLE_FILE_I16 | SLE_VAR_I32), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1708 |
SLE_VAR(Economy, interest_rate, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1709 |
SLE_VAR(Economy, infl_amount, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1710 |
SLE_VAR(Economy, infl_amount_pr, SLE_UINT8), |
0 | 1711 |
SLE_END() |
1712 |
}; |
|
1713 |
||
1714 |
// Economy variables |
|
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1067
diff
changeset
|
1715 |
static void SaveLoad_ECMY(void) |
0 | 1716 |
{ |
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1797
diff
changeset
|
1717 |
SlObject(&_economy, _economy_desc); |
0 | 1718 |
} |
1719 |
||
1720 |
const ChunkHandler _economy_chunk_handlers[] = { |
|
1721 |
{ 'PRIC', SaveLoad_PRIC, SaveLoad_PRIC, CH_RIFF | CH_AUTO_LENGTH}, |
|
1722 |
{ 'CAPR', SaveLoad_CAPR, SaveLoad_CAPR, CH_RIFF | CH_AUTO_LENGTH}, |
|
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1723 |
{ 'SUBS', Save_SUBS, Load_SUBS, CH_ARRAY}, |
0 | 1724 |
{ 'ECMY', SaveLoad_ECMY, SaveLoad_ECMY, CH_RIFF | CH_LAST}, |
1725 |
}; |