author | dominik |
Fri, 21 Jan 2005 18:36:17 +0000 | |
changeset 1081 | 0d79fc43fae2 |
parent 1067 | 3ba7987a004e |
child 1093 | 4fdc46eaf423 |
permissions | -rw-r--r-- |
0 | 1 |
#include "stdafx.h" |
2 |
#include "ttd.h" |
|
507
04b5403aaf6b
(svn r815) Include strings.h only in the files which need it.
tron
parents:
499
diff
changeset
|
3 |
#include "table/strings.h" |
679
04ca2cd69420
(svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
653
diff
changeset
|
4 |
#include "map.h" |
0 | 5 |
#include "news.h" |
6 |
#include "player.h" |
|
7 |
#include "station.h" |
|
8 |
#include "vehicle.h" |
|
9 |
#include "window.h" |
|
10 |
#include "gfx.h" |
|
11 |
#include "command.h" |
|
12 |
#include "saveload.h" |
|
13 |
#include "economy.h" |
|
14 |
#include "industry.h" |
|
15 |
#include "town.h" |
|
239 | 16 |
#include "network.h" |
337
cbe0c766c947
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
260
diff
changeset
|
17 |
#include "sound.h" |
445
beafc0fb8f12
(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
|
18 |
#include "engine.h" |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
19 |
#include "network_data.h" |
0 | 20 |
|
762
ef014856bd88
(svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents:
716
diff
changeset
|
21 |
// get a mask of the allowed currencies depending on the year |
768
c833f6f2742d
(svn r1233) Fixed several currency issues. Now currencies should work correctly again.
dominik
parents:
762
diff
changeset
|
22 |
uint GetMaskOfAllowedCurrencies(void) |
762
ef014856bd88
(svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents:
716
diff
changeset
|
23 |
{ |
ef014856bd88
(svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents:
716
diff
changeset
|
24 |
int i; |
ef014856bd88
(svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents:
716
diff
changeset
|
25 |
uint mask = 0; |
768
c833f6f2742d
(svn r1233) Fixed several currency issues. Now currencies should work correctly again.
dominik
parents:
762
diff
changeset
|
26 |
for (i = 0; i != lengthof(_currency_specs); i++) { |
762
ef014856bd88
(svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents:
716
diff
changeset
|
27 |
uint16 to_euro = _currency_specs[i].to_euro; |
ef014856bd88
(svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents:
716
diff
changeset
|
28 |
if (i == 23) mask |= (1 << 23); // always allow custom currency |
970
24abd02b1092
(svn r1465) -Fix: [1099101] starting year patch goes out of range. Clamped year between 1920-2090 as wel as adding defines for it.
darkvater
parents:
967
diff
changeset
|
29 |
if (to_euro != CF_NOEURO && to_euro != CF_ISEURO && _cur_year >= (to_euro-MAX_YEAR_BEGIN_REAL)) continue; |
24abd02b1092
(svn r1465) -Fix: [1099101] starting year patch goes out of range. Clamped year between 1920-2090 as wel as adding defines for it.
darkvater
parents:
967
diff
changeset
|
30 |
if (_cur_year < (2000-MAX_YEAR_BEGIN_REAL) && (to_euro == CF_ISEURO)) continue; |
762
ef014856bd88
(svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents:
716
diff
changeset
|
31 |
mask |= (1 << i); |
ef014856bd88
(svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents:
716
diff
changeset
|
32 |
} |
ef014856bd88
(svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents:
716
diff
changeset
|
33 |
return mask; |
ef014856bd88
(svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents:
716
diff
changeset
|
34 |
} |
ef014856bd88
(svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents:
716
diff
changeset
|
35 |
|
768
c833f6f2742d
(svn r1233) Fixed several currency issues. Now currencies should work correctly again.
dominik
parents:
762
diff
changeset
|
36 |
void CheckSwitchToEuro(void) |
762
ef014856bd88
(svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents:
716
diff
changeset
|
37 |
{ |
ef014856bd88
(svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents:
716
diff
changeset
|
38 |
if (_currency_specs[_opt.currency].to_euro != CF_NOEURO && |
ef014856bd88
(svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents:
716
diff
changeset
|
39 |
_currency_specs[_opt.currency].to_euro != CF_ISEURO && |
970
24abd02b1092
(svn r1465) -Fix: [1099101] starting year patch goes out of range. Clamped year between 1920-2090 as wel as adding defines for it.
darkvater
parents:
967
diff
changeset
|
40 |
_cur_year >= (_currency_specs[_opt.currency].to_euro-MAX_YEAR_BEGIN_REAL)) { |
762
ef014856bd88
(svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents:
716
diff
changeset
|
41 |
_opt.currency = 2; // this is the index of euro above. |
ef014856bd88
(svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents:
716
diff
changeset
|
42 |
AddNewsItem(STR_EURO_INTRODUCE, NEWS_FLAGS(NM_NORMAL,0,NT_ECONOMY,0), 0, 0); |
ef014856bd88
(svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents:
716
diff
changeset
|
43 |
} |
ef014856bd88
(svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents:
716
diff
changeset
|
44 |
} |
ef014856bd88
(svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents:
716
diff
changeset
|
45 |
|
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
|
46 |
void UpdatePlayerHouse(Player *p, uint score) |
0 | 47 |
{ |
48 |
byte val; |
|
49 |
uint tile = p->location_of_house; |
|
50 |
||
51 |
if (tile == 0) |
|
52 |
return; |
|
53 |
||
54 |
(val = 128, score < 170) || |
|
55 |
(val+= 4, score < 350) || |
|
56 |
(val+= 4, score < 520) || |
|
57 |
(val+= 4, score < 720) || |
|
58 |
(val+= 4, true); |
|
59 |
||
60 |
/* house is already big enough */ |
|
61 |
if (val <= _map5[tile]) |
|
62 |
return; |
|
63 |
||
64 |
_map5[tile + TILE_XY(0,0)] = val; |
|
65 |
_map5[tile + TILE_XY(0,1)] = ++val; |
|
66 |
_map5[tile + TILE_XY(1,0)] = ++val; |
|
67 |
_map5[tile + TILE_XY(1,1)] = ++val; |
|
68 |
||
69 |
MarkTileDirtyByTile(tile + TILE_XY(0,0)); |
|
70 |
MarkTileDirtyByTile(tile + TILE_XY(0,1)); |
|
71 |
MarkTileDirtyByTile(tile + TILE_XY(1,0)); |
|
72 |
MarkTileDirtyByTile(tile + TILE_XY(1,1)); |
|
73 |
} |
|
74 |
||
200
03b8104d1479
(svn r201) -Fix: [1025836] Company values bigger dan int32 were put to negative
truelight
parents:
193
diff
changeset
|
75 |
int64 CalculateCompanyValue(Player *p) { |
0 | 76 |
byte owner = p->index; |
200
03b8104d1479
(svn r201) -Fix: [1025836] Company values bigger dan int32 were put to negative
truelight
parents:
193
diff
changeset
|
77 |
int64 value; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
78 |
|
0 | 79 |
{ |
80 |
Station *st; |
|
81 |
uint num = 0; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
82 |
|
0 | 83 |
FOR_ALL_STATIONS(st) { |
84 |
if (st->xy != 0 && st->owner == owner) { |
|
85 |
uint facil = st->facilities; |
|
86 |
do num += (facil&1); while (facil >>= 1); |
|
87 |
} |
|
88 |
} |
|
89 |
||
90 |
value = num * _price.station_value * 25; |
|
91 |
} |
|
92 |
||
93 |
{ |
|
94 |
Vehicle *v; |
|
95 |
||
96 |
FOR_ALL_VEHICLES(v) { |
|
97 |
if (v->owner != owner) |
|
98 |
continue; |
|
99 |
if (v->type == VEH_Train || |
|
100 |
v->type == VEH_Road || |
|
101 |
(v->type == VEH_Aircraft && v->subtype<=2) || |
|
102 |
v->type == VEH_Ship) { |
|
103 |
value += v->value * 3 >> 1; |
|
104 |
} |
|
105 |
} |
|
106 |
} |
|
107 |
||
997
fa7a654d23ca
(svn r1495) -Fix: Loan does not count against the company value
celestar
parents:
970
diff
changeset
|
108 |
value += p->money64 - p->current_loan; // add real money value |
1019
6bae6c11e865
(svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents:
997
diff
changeset
|
109 |
|
997
fa7a654d23ca
(svn r1495) -Fix: Loan does not count against the company value
celestar
parents:
970
diff
changeset
|
110 |
return max(value, 1); |
0 | 111 |
} |
112 |
||
116
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
113 |
// 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
|
114 |
// (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
|
115 |
int UpdateCompanyRatingAndValue(Player *p, bool update) |
0 | 116 |
{ |
117 |
byte owner = p->index; |
|
116
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
118 |
int score = 0; |
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
119 |
|
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
120 |
memset(_score_part[owner], 0, sizeof(_score_part[owner])); |
0 | 121 |
|
122 |
/* Count vehicles */ |
|
123 |
{ |
|
124 |
Vehicle *v; |
|
125 |
int32 min_profit = MAX_INT; |
|
126 |
uint num = 0; |
|
127 |
||
128 |
FOR_ALL_VEHICLES(v) { |
|
129 |
if (v->owner != owner) |
|
130 |
continue; |
|
1067
3ba7987a004e
(svn r1568) made an enum of train subtypes to make the code more readable
bjarni
parents:
1019
diff
changeset
|
131 |
if ((v->type == VEH_Train && v->subtype == TS_Front_Engine) || |
0 | 132 |
v->type == VEH_Road || |
133 |
(v->type == VEH_Aircraft && v->subtype<=2) || |
|
134 |
v->type == VEH_Ship) { |
|
135 |
num++; |
|
136 |
if (v->age > 730) { |
|
116
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
137 |
if (min_profit > v->profit_last_year) |
0 | 138 |
min_profit = v->profit_last_year; |
139 |
} |
|
140 |
} |
|
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_VEHICLES] = num; |
0 | 144 |
|
145 |
if (min_profit != MAX_INT && min_profit > 0) |
|
116
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
146 |
_score_part[owner][SCORE_MIN_PROFIT] = min_profit; |
0 | 147 |
} |
148 |
||
149 |
/* Count stations */ |
|
150 |
{ |
|
151 |
uint num = 0; |
|
152 |
Station *st; |
|
153 |
||
154 |
FOR_ALL_STATIONS(st) { |
|
155 |
if (st->xy != 0 && st->owner == owner) { |
|
156 |
int facil = st->facilities; |
|
157 |
do num += facil&1; while (facil>>=1); |
|
158 |
} |
|
159 |
} |
|
116
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
160 |
_score_part[owner][SCORE_STATIONS] = num; |
0 | 161 |
} |
162 |
||
163 |
/* Generate statistics depending on recent income statistics */ |
|
164 |
{ |
|
165 |
PlayerEconomyEntry *pee; |
|
166 |
int numec; |
|
167 |
int32 min_income; |
|
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
168 |
int32 max_income; |
0 | 169 |
|
170 |
numec = min(p->num_valid_stat_ent, 12); |
|
171 |
if (numec != 0) { |
|
172 |
min_income = 0x7FFFFFFF; |
|
173 |
max_income = 0; |
|
174 |
pee = p->old_economy; |
|
175 |
do { |
|
176 |
min_income = min(min_income, pee->income + pee->expenses); |
|
177 |
max_income = max(max_income, pee->income + pee->expenses); |
|
178 |
} while (++pee,--numec); |
|
179 |
||
180 |
if (min_income > 0) |
|
116
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
181 |
_score_part[owner][SCORE_MIN_INCOME] = min_income; |
0 | 182 |
|
116
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
183 |
_score_part[owner][SCORE_MAX_INCOME] = max_income; |
0 | 184 |
} |
185 |
} |
|
186 |
||
187 |
/* Generate score depending on amount of transported cargo */ |
|
188 |
{ |
|
189 |
PlayerEconomyEntry *pee; |
|
190 |
int numec; |
|
191 |
uint32 total_delivered; |
|
192 |
||
193 |
numec = min(p->num_valid_stat_ent, 4); |
|
194 |
if (numec != 0) { |
|
195 |
pee = p->old_economy; |
|
196 |
total_delivered = 0; |
|
197 |
do { |
|
198 |
total_delivered += pee->delivered_cargo; |
|
199 |
} while (++pee,--numec); |
|
200 |
||
116
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
201 |
_score_part[owner][SCORE_DELIVERED] = total_delivered; |
0 | 202 |
} |
203 |
} |
|
116
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
204 |
|
0 | 205 |
/* Generate score for variety of cargo */ |
206 |
{ |
|
207 |
uint cargo = p->cargo_types; |
|
208 |
uint num = 0; |
|
209 |
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
|
210 |
_score_part[owner][SCORE_CARGO] = num; |
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
211 |
if (update) |
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
212 |
p->cargo_types = 0; |
0 | 213 |
} |
214 |
||
215 |
/* Generate score for player money */ |
|
216 |
{ |
|
217 |
int32 money = p->player_money; |
|
218 |
if (money > 0) { |
|
116
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
219 |
_score_part[owner][SCORE_MONEY] = money; |
0 | 220 |
} |
221 |
} |
|
222 |
||
223 |
/* Generate score for loan */ |
|
224 |
{ |
|
116
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
225 |
_score_part[owner][SCORE_LOAN] = score_info[SCORE_LOAN].needed - p->current_loan; |
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 |
// 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
|
229 |
{ |
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
230 |
int i; |
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
231 |
int total_score = 0; |
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
232 |
int s; |
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
233 |
score = 0; |
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
234 |
for (i=0;i<NUM_SCORE;i++) { |
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
235 |
// Skip the total |
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
236 |
if (i == SCORE_TOTAL) continue; |
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
237 |
// Check the score |
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
238 |
s = (_score_part[owner][i] >= score_info[i].needed) ? score_info[i].score : ((_score_part[owner][i] * score_info[i].score) / score_info[i].needed); |
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
239 |
if (s < 0) s = 0; |
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
240 |
score += s; |
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
241 |
total_score += score_info[i].score; |
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
242 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
243 |
|
116
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
244 |
_score_part[owner][SCORE_TOTAL] = score; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
245 |
|
116
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
246 |
// We always want the score scaled to SCORE_MAX (1000) |
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
247 |
if (total_score != SCORE_MAX) |
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
248 |
score = score * SCORE_MAX / total_score; |
0 | 249 |
} |
250 |
||
116
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
251 |
if (update) { |
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
252 |
p->old_economy[0].performance_history = score; |
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
253 |
UpdatePlayerHouse(p, score); |
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
254 |
p->old_economy[0].company_value = CalculateCompanyValue(p); |
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
255 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
256 |
|
116
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
257 |
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
|
258 |
return score; |
0 | 259 |
} |
260 |
||
261 |
// use 255 as new_player to delete the player. |
|
262 |
void ChangeOwnershipOfPlayerItems(byte old_player, byte new_player) |
|
263 |
{ |
|
264 |
byte old = _current_player; |
|
265 |
_current_player = old_player; |
|
266 |
||
267 |
if (new_player == 255) { |
|
268 |
Subsidy *s; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
269 |
|
0 | 270 |
for(s=_subsidies; s != endof(_subsidies); s++) { |
271 |
if (s->cargo_type != 0xff && s->age >= 12) { |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
863
diff
changeset
|
272 |
Station *st = GetStation(s->to); |
0 | 273 |
if (st->owner == old_player) |
274 |
s->cargo_type = 0xff; |
|
275 |
} |
|
276 |
} |
|
277 |
} |
|
278 |
||
279 |
// take care of rating in towns |
|
280 |
{ |
|
281 |
Town *t; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
282 |
|
0 | 283 |
// if a player takes over, give the ratings to that player. |
284 |
if (new_player != 255) { |
|
285 |
FOR_ALL_TOWNS(t) if (t->xy && HASBIT(t->have_ratings, old_player)) { |
|
286 |
if (HASBIT(t->have_ratings, new_player)) { |
|
287 |
// use max of the two ratings. |
|
288 |
t->ratings[new_player] = max(t->ratings[new_player], t->ratings[old_player]); |
|
289 |
} else { |
|
290 |
SETBIT(t->have_ratings, new_player); |
|
291 |
t->ratings[new_player] = t->ratings[old_player]; |
|
292 |
} |
|
293 |
} |
|
294 |
} |
|
295 |
||
296 |
// reset rating for the towns. |
|
297 |
FOR_ALL_TOWNS(t) if (t->xy) { |
|
298 |
t->ratings[old_player] = 500; |
|
299 |
CLRBIT(t->have_ratings, old_player); |
|
300 |
} |
|
301 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
302 |
|
0 | 303 |
{ |
304 |
int num_train = 0; |
|
305 |
int num_road = 0; |
|
306 |
int num_ship = 0; |
|
307 |
int num_aircraft = 0; |
|
308 |
Vehicle *v; |
|
309 |
||
310 |
// Determine Ids for the new vehicles |
|
311 |
FOR_ALL_VEHICLES(v) { |
|
312 |
if (v->owner == new_player) { |
|
1067
3ba7987a004e
(svn r1568) made an enum of train subtypes to make the code more readable
bjarni
parents:
1019
diff
changeset
|
313 |
if (v->type == VEH_Train && v->subtype == TS_Front_Engine) |
0 | 314 |
num_train++; |
315 |
else if (v->type == VEH_Road) |
|
316 |
num_road++; |
|
317 |
else if (v->type == VEH_Ship) |
|
318 |
num_ship++; |
|
319 |
else if (v->type == VEH_Aircraft && v->subtype <= 2) |
|
320 |
num_aircraft++; |
|
321 |
} |
|
322 |
} |
|
323 |
||
324 |
FOR_ALL_VEHICLES(v) { |
|
325 |
if (v->owner == old_player && IS_BYTE_INSIDE(v->type, VEH_Train, VEH_Aircraft+1) ) { |
|
326 |
if (new_player == 255) { |
|
327 |
DeleteWindowById(WC_VEHICLE_VIEW, v->index); |
|
328 |
DeleteWindowById(WC_VEHICLE_DETAILS, v->index); |
|
329 |
DeleteWindowById(WC_VEHICLE_ORDERS, v->index); |
|
330 |
DeleteVehicle(v); |
|
331 |
} else { |
|
332 |
v->owner = new_player; |
|
1067
3ba7987a004e
(svn r1568) made an enum of train subtypes to make the code more readable
bjarni
parents:
1019
diff
changeset
|
333 |
if (v->type == VEH_Train && v->subtype == TS_Front_Engine) |
0 | 334 |
v->unitnumber = ++num_train; |
335 |
else if (v->type == VEH_Road) |
|
336 |
v->unitnumber = ++num_road; |
|
337 |
else if (v->type == VEH_Ship) |
|
338 |
v->unitnumber = ++num_ship; |
|
339 |
else if (v->type == VEH_Aircraft && v->subtype <= 2) |
|
340 |
v->unitnumber = ++num_aircraft; |
|
341 |
} |
|
342 |
} |
|
343 |
} |
|
344 |
} |
|
345 |
||
346 |
// Change ownership of tiles |
|
347 |
{ |
|
348 |
uint tile = 0; |
|
349 |
do { |
|
350 |
ChangeTileOwner(tile, old_player, new_player); |
|
863
6a1444534f62
(svn r1344) Use MapSize[XY]() (or MapSize()/MapMax[XY]() where appropriate) instead of TILES_[XY]
tron
parents:
830
diff
changeset
|
351 |
} while (++tile != MapSize()); |
0 | 352 |
} |
353 |
||
354 |
// Change color of existing windows |
|
355 |
if (new_player != 255) { |
|
356 |
Window *w; |
|
357 |
for(w=_windows; w != _last_window; w++) { |
|
358 |
if (w->caption_color == old_player) |
|
359 |
w->caption_color = new_player; |
|
360 |
} |
|
361 |
} |
|
362 |
||
780
690a9a22dacd
(svn r1247) -Fix: [ 1090313 ] Shares are now also sold when a company goes bankrupt
truelight
parents:
768
diff
changeset
|
363 |
{ |
690a9a22dacd
(svn r1247) -Fix: [ 1090313 ] Shares are now also sold when a company goes bankrupt
truelight
parents:
768
diff
changeset
|
364 |
Player *p; |
690a9a22dacd
(svn r1247) -Fix: [ 1090313 ] Shares are now also sold when a company goes bankrupt
truelight
parents:
768
diff
changeset
|
365 |
uint i; |
690a9a22dacd
(svn r1247) -Fix: [ 1090313 ] Shares are now also sold when a company goes bankrupt
truelight
parents:
768
diff
changeset
|
366 |
|
690a9a22dacd
(svn r1247) -Fix: [ 1090313 ] Shares are now also sold when a company goes bankrupt
truelight
parents:
768
diff
changeset
|
367 |
/* Check for shares */ |
690a9a22dacd
(svn r1247) -Fix: [ 1090313 ] Shares are now also sold when a company goes bankrupt
truelight
parents:
768
diff
changeset
|
368 |
FOR_ALL_PLAYERS(p) { |
690a9a22dacd
(svn r1247) -Fix: [ 1090313 ] Shares are now also sold when a company goes bankrupt
truelight
parents:
768
diff
changeset
|
369 |
for(i = 0; i < 4; i++) { |
690a9a22dacd
(svn r1247) -Fix: [ 1090313 ] Shares are now also sold when a company goes bankrupt
truelight
parents:
768
diff
changeset
|
370 |
/* 'Sell' the share if this player has any */ |
690a9a22dacd
(svn r1247) -Fix: [ 1090313 ] Shares are now also sold when a company goes bankrupt
truelight
parents:
768
diff
changeset
|
371 |
if (p->share_owners[i] == _current_player) |
690a9a22dacd
(svn r1247) -Fix: [ 1090313 ] Shares are now also sold when a company goes bankrupt
truelight
parents:
768
diff
changeset
|
372 |
p->share_owners[i] = 0xFF; |
690a9a22dacd
(svn r1247) -Fix: [ 1090313 ] Shares are now also sold when a company goes bankrupt
truelight
parents:
768
diff
changeset
|
373 |
} |
690a9a22dacd
(svn r1247) -Fix: [ 1090313 ] Shares are now also sold when a company goes bankrupt
truelight
parents:
768
diff
changeset
|
374 |
} |
690a9a22dacd
(svn r1247) -Fix: [ 1090313 ] Shares are now also sold when a company goes bankrupt
truelight
parents:
768
diff
changeset
|
375 |
p = DEREF_PLAYER(_current_player); |
690a9a22dacd
(svn r1247) -Fix: [ 1090313 ] Shares are now also sold when a company goes bankrupt
truelight
parents:
768
diff
changeset
|
376 |
/* Sell all the shares that people have on this company */ |
690a9a22dacd
(svn r1247) -Fix: [ 1090313 ] Shares are now also sold when a company goes bankrupt
truelight
parents:
768
diff
changeset
|
377 |
for(i = 0; i < 4; i++) |
690a9a22dacd
(svn r1247) -Fix: [ 1090313 ] Shares are now also sold when a company goes bankrupt
truelight
parents:
768
diff
changeset
|
378 |
p->share_owners[i] = 0xFF; |
690a9a22dacd
(svn r1247) -Fix: [ 1090313 ] Shares are now also sold when a company goes bankrupt
truelight
parents:
768
diff
changeset
|
379 |
} |
690a9a22dacd
(svn r1247) -Fix: [ 1090313 ] Shares are now also sold when a company goes bankrupt
truelight
parents:
768
diff
changeset
|
380 |
|
0 | 381 |
_current_player = old; |
382 |
||
383 |
MarkWholeScreenDirty(); |
|
384 |
} |
|
385 |
||
386 |
extern void DeletePlayerWindows(int pi); |
|
387 |
||
388 |
static void PlayersCheckBankrupt(Player *p) |
|
389 |
{ |
|
390 |
int owner; |
|
200
03b8104d1479
(svn r201) -Fix: [1025836] Company values bigger dan int32 were put to negative
truelight
parents:
193
diff
changeset
|
391 |
int64 val; |
0 | 392 |
|
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
393 |
// If the player has money again, it does not go bankrupt |
0 | 394 |
if (p->player_money >= 0) { |
395 |
p->quarters_of_bankrupcy = 0; |
|
396 |
return; |
|
397 |
} |
|
398 |
||
399 |
p->quarters_of_bankrupcy++; |
|
400 |
||
401 |
owner = p->index; |
|
402 |
||
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
403 |
switch (p->quarters_of_bankrupcy) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
404 |
case 2: |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
405 |
AddNewsItem( (StringID)(owner + 16), |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
406 |
NEWS_FLAGS(NM_CALLBACK, 0, NT_COMPANY_INFO, DNC_BANKRUPCY),0,0); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
407 |
break; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
408 |
case 3: { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
409 |
/* XXX - In multiplayer, should we ask other players if it wants to take |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
410 |
over when it is a human company? -- TrueLight */ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
411 |
if (IS_HUMAN_PLAYER(owner)) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
412 |
AddNewsItem( (StringID)(owner + 16), |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
413 |
NEWS_FLAGS(NM_CALLBACK, 0, NT_COMPANY_INFO, DNC_BANKRUPCY),0,0); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
414 |
break; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
415 |
} |
0 | 416 |
|
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
417 |
// Check if the company has any value.. if not, declare it bankrupt |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
418 |
// right now |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
419 |
val = CalculateCompanyValue(p); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
420 |
if (val > 0) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
421 |
p->bankrupt_value = val; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
422 |
p->bankrupt_asked = 1 << owner; // Don't ask the owner |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
423 |
p->bankrupt_timeout = 0; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
424 |
break; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
425 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
426 |
// Else, falltrue to case 4... |
0 | 427 |
} |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
428 |
case 4: { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
429 |
// Close everything the owner has open |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
430 |
DeletePlayerWindows(owner); |
0 | 431 |
|
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
432 |
// Show bankrupt news |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
433 |
SetDParam(0, p->name_1); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
434 |
SetDParam(1, p->name_2); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
435 |
AddNewsItem( (StringID)(owner + 16*3), NEWS_FLAGS(NM_CALLBACK, 0, NT_COMPANY_INFO, DNC_BANKRUPCY),0,0); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
436 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
437 |
// If the player is human, and it is no network play, leave the player playing |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
438 |
if (IS_HUMAN_PLAYER(owner) && !_networking) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
439 |
p->bankrupt_asked = 255; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
440 |
p->bankrupt_timeout = 0x456; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
441 |
} else { |
630
3eb6abf08860
(svn r1061) -Fix: [Network] Compiling without ENABLE_NETWORK now works again correctly
truelight
parents:
599
diff
changeset
|
442 |
#ifdef ENABLE_NETWORK |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
443 |
if (IS_HUMAN_PLAYER(owner) && _network_server) { |
687
0e42e732ad78
(svn r1128) -Fix: [Network] Going bankrupt of human-players was corrupted in networkgames
truelight
parents:
679
diff
changeset
|
444 |
// If we are the server, make sure it is clear that his player is no |
0e42e732ad78
(svn r1128) -Fix: [Network] Going bankrupt of human-players was corrupted in networkgames
truelight
parents:
679
diff
changeset
|
445 |
// longer with us! |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
446 |
NetworkClientInfo *ci; |
716
8af847728d5b
(svn r1168) -Cleanup: [Network] Cleaned the network code a bit. Added 'const'
truelight
parents:
687
diff
changeset
|
447 |
NetworkClientState *cs; |
687
0e42e732ad78
(svn r1128) -Fix: [Network] Going bankrupt of human-players was corrupted in networkgames
truelight
parents:
679
diff
changeset
|
448 |
/* Find all clients that were in control of this company */ |
0e42e732ad78
(svn r1128) -Fix: [Network] Going bankrupt of human-players was corrupted in networkgames
truelight
parents:
679
diff
changeset
|
449 |
FOR_ALL_CLIENTS(cs) { |
0e42e732ad78
(svn r1128) -Fix: [Network] Going bankrupt of human-players was corrupted in networkgames
truelight
parents:
679
diff
changeset
|
450 |
ci = DEREF_CLIENT_INFO(cs); |
0e42e732ad78
(svn r1128) -Fix: [Network] Going bankrupt of human-players was corrupted in networkgames
truelight
parents:
679
diff
changeset
|
451 |
if ((ci->client_playas-1) == owner) { |
0e42e732ad78
(svn r1128) -Fix: [Network] Going bankrupt of human-players was corrupted in networkgames
truelight
parents:
679
diff
changeset
|
452 |
ci->client_playas = OWNER_SPECTATOR; |
0e42e732ad78
(svn r1128) -Fix: [Network] Going bankrupt of human-players was corrupted in networkgames
truelight
parents:
679
diff
changeset
|
453 |
// Send the new info to all the clients |
0e42e732ad78
(svn r1128) -Fix: [Network] Going bankrupt of human-players was corrupted in networkgames
truelight
parents:
679
diff
changeset
|
454 |
NetworkUpdateClientInfo(_network_own_client_index); |
0e42e732ad78
(svn r1128) -Fix: [Network] Going bankrupt of human-players was corrupted in networkgames
truelight
parents:
679
diff
changeset
|
455 |
} |
0e42e732ad78
(svn r1128) -Fix: [Network] Going bankrupt of human-players was corrupted in networkgames
truelight
parents:
679
diff
changeset
|
456 |
} |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
457 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
458 |
// Make sure the player no longer controls the company |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
459 |
if (IS_HUMAN_PLAYER(owner) && owner == _local_player) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
460 |
// Switch the player to spectator.. |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
461 |
_local_player = OWNER_SPECTATOR; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
462 |
} |
687
0e42e732ad78
(svn r1128) -Fix: [Network] Going bankrupt of human-players was corrupted in networkgames
truelight
parents:
679
diff
changeset
|
463 |
#endif /* ENABLE_NETWORK */ |
0e42e732ad78
(svn r1128) -Fix: [Network] Going bankrupt of human-players was corrupted in networkgames
truelight
parents:
679
diff
changeset
|
464 |
|
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
465 |
// Convert everything the player owns to NO_OWNER |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
466 |
p->money64 = p->player_money = 100000000; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
467 |
ChangeOwnershipOfPlayerItems(owner, 0xFF); // 255 is no owner |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
468 |
// Register the player as not-active |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
469 |
p->is_active = false; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
470 |
} |
0 | 471 |
} |
472 |
} |
|
473 |
} |
|
474 |
||
475 |
void DrawNewsBankrupcy(Window *w) |
|
476 |
{ |
|
477 |
Player *p; |
|
478 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
479 |
DrawNewsBorder(w); |
0 | 480 |
|
481 |
p = DEREF_PLAYER(WP(w,news_d).ni->string_id & 15); |
|
482 |
DrawPlayerFace(p->face, p->player_color, 2, 23); |
|
483 |
GfxFillRect(3, 23, 3+91, 23+118, 0x4323); |
|
484 |
||
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
485 |
SetDParam(0, p->president_name_1); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
486 |
SetDParam(1, p->president_name_2); |
0 | 487 |
|
488 |
DrawStringMultiCenter(49, 148, STR_7058_PRESIDENT, 94); |
|
489 |
||
490 |
switch(WP(w,news_d).ni->string_id >> 4) { |
|
491 |
case 1: |
|
492 |
DrawStringCentered(w->width>>1, 1, STR_7056_TRANSPORT_COMPANY_IN_TROUBLE, 0); |
|
493 |
||
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
494 |
SetDParam(0, p->name_1); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
495 |
SetDParam(1, p->name_2); |
0 | 496 |
|
497 |
DrawStringMultiCenter( |
|
498 |
((w->width - 101) >> 1) + 98, |
|
499 |
90, |
|
500 |
STR_7057_WILL_BE_SOLD_OFF_OR_DECLARED, |
|
501 |
w->width - 101); |
|
502 |
break; |
|
503 |
||
504 |
case 2: { |
|
505 |
int32 price; |
|
506 |
||
507 |
DrawStringCentered(w->width>>1, 1, STR_7059_TRANSPORT_COMPANY_MERGER, 0); |
|
508 |
COPY_IN_DPARAM(0,WP(w,news_d).ni->params, 2); |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
509 |
SetDParam(2, p->name_1); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
510 |
SetDParam(3, p->name_2); |
0 | 511 |
price = WP(w,news_d).ni->params[2]; |
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
512 |
SetDParam(4, price); |
0 | 513 |
DrawStringMultiCenter( |
514 |
((w->width - 101) >> 1) + 98, |
|
515 |
90, |
|
516 |
price==0 ? STR_707F_HAS_BEEN_TAKEN_OVER_BY : STR_705A_HAS_BEEN_SOLD_TO_FOR, |
|
517 |
w->width - 101); |
|
518 |
break; |
|
519 |
} |
|
520 |
||
521 |
case 3: |
|
522 |
DrawStringCentered(w->width>>1, 1, STR_705C_BANKRUPT, 0); |
|
523 |
COPY_IN_DPARAM(0,WP(w,news_d).ni->params, 2); |
|
524 |
DrawStringMultiCenter( |
|
525 |
((w->width - 101) >> 1) + 98, |
|
526 |
90, |
|
527 |
STR_705D_HAS_BEEN_CLOSED_DOWN_BY, |
|
528 |
w->width - 101); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
529 |
break; |
0 | 530 |
|
531 |
case 4: |
|
532 |
DrawStringCentered(w->width>>1, 1, STR_705E_NEW_TRANSPORT_COMPANY_LAUNCHED, 0); |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
533 |
SetDParam(0, p->name_1); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
534 |
SetDParam(1, p->name_2); |
0 | 535 |
COPY_IN_DPARAM(2,WP(w,news_d).ni->params, 2); |
536 |
DrawStringMultiCenter( |
|
537 |
((w->width - 101) >> 1) + 98, |
|
538 |
90, |
|
539 |
STR_705F_STARTS_CONSTRUCTION_NEAR, |
|
540 |
w->width - 101); |
|
541 |
break; |
|
542 |
||
543 |
default: |
|
544 |
NOT_REACHED(); |
|
545 |
} |
|
546 |
} |
|
547 |
||
548 |
StringID GetNewsStringBankrupcy(NewsItem *ni) |
|
549 |
{ |
|
550 |
Player *p = DEREF_PLAYER(ni->string_id & 0xF); |
|
551 |
||
552 |
switch(ni->string_id >> 4) { |
|
553 |
case 1: |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
554 |
SetDParam(0, STR_7056_TRANSPORT_COMPANY_IN_TROUBLE); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
555 |
SetDParam(1, STR_7057_WILL_BE_SOLD_OFF_OR_DECLARED); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
556 |
SetDParam(2, p->name_1); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
557 |
SetDParam(3, p->name_2); |
0 | 558 |
return STR_02B6; |
559 |
case 2: |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
560 |
SetDParam(0, STR_7059_TRANSPORT_COMPANY_MERGER); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
561 |
SetDParam(1, STR_705A_HAS_BEEN_SOLD_TO_FOR); |
0 | 562 |
COPY_IN_DPARAM(2,ni->params, 2); |
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
563 |
SetDParam(4, p->name_1); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
564 |
SetDParam(5, p->name_2); |
0 | 565 |
COPY_IN_DPARAM(6,ni->params + 2, 1); |
566 |
return STR_02B6; |
|
567 |
case 3: |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
568 |
SetDParam(0, STR_705C_BANKRUPT); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
569 |
SetDParam(1, STR_705D_HAS_BEEN_CLOSED_DOWN_BY); |
0 | 570 |
COPY_IN_DPARAM(2,ni->params, 2); |
571 |
return STR_02B6; |
|
572 |
case 4: |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
573 |
SetDParam(0, STR_705E_NEW_TRANSPORT_COMPANY_LAUNCHED); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
574 |
SetDParam(1, STR_705F_STARTS_CONSTRUCTION_NEAR); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
575 |
SetDParam(2, p->name_1); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
576 |
SetDParam(3, p->name_2); |
0 | 577 |
COPY_IN_DPARAM(4,ni->params, 2); |
578 |
return STR_02B6; |
|
579 |
default: |
|
580 |
NOT_REACHED(); |
|
581 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
582 |
|
0 | 583 |
/* useless, but avoids compiler warning this way */ |
584 |
return 0; |
|
585 |
} |
|
586 |
||
587 |
static void PlayersGenStatistics() |
|
588 |
{ |
|
589 |
Station *st; |
|
590 |
Player *p; |
|
591 |
||
592 |
FOR_ALL_STATIONS(st) { |
|
593 |
if (st->xy != 0) { |
|
594 |
_current_player = st->owner; |
|
595 |
SET_EXPENSES_TYPE(EXPENSES_PROPERTY); |
|
596 |
SubtractMoneyFromPlayer(_price.station_value >> 1); |
|
597 |
} |
|
598 |
} |
|
599 |
||
600 |
if (!HASBIT(1<<0|1<<3|1<<6|1<<9, _cur_month)) |
|
601 |
return; |
|
602 |
||
603 |
FOR_ALL_PLAYERS(p) { |
|
604 |
if (p->is_active) { |
|
605 |
memmove(&p->old_economy, &p->cur_economy, sizeof(p->old_economy)); |
|
606 |
memset(&p->cur_economy, 0, sizeof(p->cur_economy)); |
|
607 |
||
608 |
if (p->num_valid_stat_ent != 24) |
|
609 |
p->num_valid_stat_ent++; |
|
610 |
||
116
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
611 |
UpdateCompanyRatingAndValue(p, true); |
0 | 612 |
PlayersCheckBankrupt(p); |
613 |
||
614 |
if (p->block_preview != 0) |
|
615 |
p->block_preview--; |
|
616 |
} |
|
617 |
} |
|
618 |
||
619 |
InvalidateWindow(WC_INCOME_GRAPH, 0); |
|
620 |
InvalidateWindow(WC_OPERATING_PROFIT, 0); |
|
621 |
InvalidateWindow(WC_DELIVERED_CARGO, 0); |
|
622 |
InvalidateWindow(WC_PERFORMANCE_HISTORY, 0); |
|
623 |
InvalidateWindow(WC_COMPANY_VALUE, 0); |
|
624 |
InvalidateWindow(WC_COMPANY_LEAGUE, 0); |
|
625 |
} |
|
626 |
||
627 |
static void AddSingleInflation(int32 *value, uint16 *frac, int32 amt) |
|
628 |
{ |
|
629 |
int64 tmp; |
|
630 |
int32 low; |
|
631 |
tmp = BIGMULS(*value, amt); |
|
632 |
*frac = (uint16)(low = (uint16)tmp + *frac); |
|
633 |
*value += (int32)(tmp >> 16) + (low >> 16); |
|
634 |
} |
|
635 |
||
636 |
static void AddInflation() |
|
637 |
{ |
|
638 |
int i; |
|
639 |
int32 inf = _economy.infl_amount * 54; |
|
640 |
||
641 |
for(i=0; i!=NUM_PRICES; i++) { |
|
642 |
AddSingleInflation( (int32*)&_price + i, _price_frac + i, inf ); |
|
643 |
} |
|
644 |
||
645 |
_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
|
646 |
|
0 | 647 |
if (_economy.max_loan + 50000 <= _economy.max_loan_unround) |
648 |
_economy.max_loan += 50000; |
|
649 |
||
650 |
inf = _economy.infl_amount_pr * 54; |
|
651 |
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
|
652 |
AddSingleInflation( |
0 | 653 |
_cargo_payment_rates + i, |
654 |
_cargo_payment_rates_frac + i, |
|
655 |
inf |
|
656 |
); |
|
657 |
} |
|
658 |
||
659 |
InvalidateWindowClasses(WC_BUILD_VEHICLE); |
|
660 |
InvalidateWindowClasses(WC_VEHICLE_DETAILS); |
|
661 |
InvalidateWindow(WC_PAYMENT_RATES, 0); |
|
662 |
} |
|
663 |
||
664 |
static void PlayersPayInterest() |
|
665 |
{ |
|
666 |
Player *p; |
|
667 |
int interest = _economy.interest_rate * 54; |
|
668 |
||
669 |
FOR_ALL_PLAYERS(p) { |
|
670 |
if (!p->is_active) |
|
671 |
continue; |
|
672 |
||
673 |
_current_player = p->index; |
|
674 |
SET_EXPENSES_TYPE(EXPENSES_LOAN_INT); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
675 |
|
0 | 676 |
SubtractMoneyFromPlayer(BIGMULUS(p->current_loan, interest, 16)); |
677 |
||
678 |
SET_EXPENSES_TYPE(EXPENSES_OTHER); |
|
679 |
SubtractMoneyFromPlayer(_price.station_value >> 2); |
|
680 |
} |
|
681 |
} |
|
682 |
||
683 |
static void HandleEconomyFluctuations() |
|
684 |
{ |
|
685 |
if (_opt.diff.economy == 0) |
|
686 |
return; |
|
687 |
||
688 |
if (--_economy.fluct == 0) { |
|
689 |
_economy.fluct = - (int)(Random()&3); |
|
690 |
AddNewsItem(STR_7073_WORLD_RECESSION_FINANCIAL, NEWS_FLAGS(NM_NORMAL,0,NT_ECONOMY,0), 0, 0); |
|
691 |
} else if (_economy.fluct == -12) { |
|
692 |
_economy.fluct = (Random()&255) + 312; |
|
693 |
AddNewsItem(STR_7074_RECESSION_OVER_UPTURN_IN, NEWS_FLAGS(NM_NORMAL,0,NT_ECONOMY,0), 0, 0); |
|
694 |
} |
|
695 |
} |
|
696 |
||
697 |
static byte _price_category[NUM_PRICES] = { |
|
698 |
0, 2, 2, 2, 2, 2, 2, 2, |
|
699 |
2, 2, 2, 2, 2, 2, 2, 2, |
|
700 |
2, 2, 2, 2, 2, 2, 2, 2, |
|
701 |
2, 2, 2, 2, 2, 2, 2, 2, |
|
702 |
2, 2, 2, 2, 2, 2, 2, 2, |
|
703 |
2, 2, 1, 1, 1, 1, 1, 1, |
|
704 |
2, |
|
705 |
}; |
|
706 |
||
707 |
static const int32 _price_base[NUM_PRICES] = { |
|
9 | 708 |
100, // station_value |
709 |
100, // build_rail |
|
710 |
95, // build_road |
|
711 |
65, // build_signals |
|
712 |
275, // build_bridge |
|
713 |
600, // build_train_depot |
|
714 |
500, // build_road_depot |
|
715 |
700, // build_ship_depot |
|
716 |
450, // build_tunnel |
|
717 |
200, // train_station_track |
|
718 |
180, // train_station_length |
|
719 |
600, // build_airport |
|
720 |
200, // build_bus_station |
|
721 |
200, // build_truck_station |
|
722 |
350, // build_dock |
|
723 |
400000, // build_railvehicle |
|
724 |
2000, // build_railwagon |
|
725 |
700000, // aircraft_base |
|
726 |
14000, // roadveh_base |
|
727 |
65000, // ship_base |
|
728 |
20, // build_trees |
|
729 |
250, // terraform |
|
730 |
20, // clear_1 |
|
731 |
40, // purchase_land |
|
732 |
200, // clear_2 |
|
733 |
500, // clear_3 |
|
734 |
20, // remove_trees |
|
735 |
-70, // remove_rail |
|
736 |
10, // remove_signals |
|
737 |
50, // clear_bridge |
|
738 |
80, // remove_train_depot |
|
739 |
80, // remove_road_depot |
|
740 |
90, // remove_ship_depot |
|
741 |
30, // clear_tunnel |
|
742 |
10000, // clear_water |
|
743 |
50, // remove_rail_station |
|
744 |
30, // remove_airport |
|
745 |
50, // remove_bus_station |
|
746 |
50, // remove_truck_station |
|
747 |
55, // remove_dock |
|
748 |
1600, // remove_house |
|
749 |
40, // remove_road |
|
750 |
5600, // running_rail[0] railroad |
|
751 |
5200, // running_rail[1] monorail |
|
752 |
4800, // running_rail[2] maglev |
|
753 |
9600, // aircraft_running |
|
754 |
1600, // roadveh_running |
|
755 |
5600, // ship_running |
|
756 |
1000000, // build_industry |
|
0 | 757 |
}; |
758 |
||
759 |
void StartupEconomy() |
|
760 |
{ |
|
761 |
int i; |
|
762 |
||
763 |
assert(sizeof(_price) == NUM_PRICES * sizeof(int32)); |
|
764 |
||
765 |
for(i=0; i!=NUM_PRICES; i++) { |
|
766 |
int32 price = _price_base[i]; |
|
767 |
if (_price_category[i] != 0) { |
|
768 |
uint mod = _price_category[i] == 1 ? _opt.diff.vehicle_costs : _opt.diff.construction_cost; |
|
769 |
if (mod < 1) { |
|
770 |
price = price * 3 >> 2; |
|
771 |
} else if (mod > 1) { |
|
772 |
price = price * 9 >> 3; |
|
773 |
} |
|
774 |
} |
|
775 |
((int32*)&_price)[i] = price; |
|
776 |
_price_frac[i] = 0; |
|
777 |
} |
|
778 |
||
779 |
_economy.interest_rate = _opt.diff.initial_interest; |
|
780 |
_economy.infl_amount = _opt.diff.initial_interest; |
|
781 |
_economy.infl_amount_pr = max(0, _opt.diff.initial_interest - 1); |
|
782 |
_economy.max_loan_unround = _economy.max_loan = _opt.diff.max_loan * 1000; |
|
783 |
_economy.fluct = (byte)(Random()) + 168; |
|
784 |
} |
|
785 |
||
786 |
Pair SetupSubsidyDecodeParam(Subsidy *s, bool mode) |
|
787 |
{ |
|
788 |
int tile, tile2; |
|
789 |
Industry *i; |
|
790 |
Town *t; |
|
791 |
Station *st; |
|
792 |
Pair tp; |
|
793 |
||
794 |
/* if mode is false, convert into plural */ |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
795 |
SetDParam(0, _cargoc.names_s[s->cargo_type] + (mode?0:32)); |
0 | 796 |
|
797 |
if (s->age < 12) { |
|
798 |
if (!(s->cargo_type == CT_PASSENGERS || s->cargo_type == CT_MAIL)) { |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
799 |
SetDParam(1, STR_2029); |
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
863
diff
changeset
|
800 |
i = GetIndustry(s->from); |
0 | 801 |
tile = i->xy; |
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
802 |
SetDParam(2, i->town->townnametype); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
803 |
SetDParam(3, i->town->townnameparts); |
0 | 804 |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
805 |
SetDParam(4, i->type + STR_4802_COAL_MINE); |
0 | 806 |
|
807 |
if (s->cargo_type != CT_GOODS && s->cargo_type != CT_FOOD) { |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
808 |
SetDParam(5, STR_2029); |
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
863
diff
changeset
|
809 |
i = GetIndustry(s->to); |
0 | 810 |
tile2 = i->xy; |
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
811 |
SetDParam(8, i->type + STR_4802_COAL_MINE); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
812 |
SetDParam(6, i->town->townnametype); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
813 |
SetDParam(7, i->town->townnameparts); |
0 | 814 |
} else { |
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
863
diff
changeset
|
815 |
t = GetTown(s->to); |
0 | 816 |
tile2 = t->xy; |
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
817 |
SetDParam(5, t->townnametype); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
818 |
SetDParam(6, t->townnameparts); |
0 | 819 |
} |
820 |
} else { |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
863
diff
changeset
|
821 |
t = GetTown(s->from); |
0 | 822 |
tile = t->xy; |
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
823 |
SetDParam(1, t->townnametype); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
824 |
SetDParam(2, t->townnameparts); |
0 | 825 |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
863
diff
changeset
|
826 |
t = GetTown(s->to); |
0 | 827 |
tile2 = t->xy; |
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
828 |
SetDParam(3, t->townnametype); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
829 |
SetDParam(4, t->townnameparts); |
0 | 830 |
} |
831 |
} else { |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
863
diff
changeset
|
832 |
st = GetStation(s->from); |
0 | 833 |
tile = st->xy; |
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
834 |
SetDParam(1, st->index); |
0 | 835 |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
863
diff
changeset
|
836 |
st = GetStation(s->to); |
0 | 837 |
tile2 = st->xy; |
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
838 |
SetDParam(2, st->index); |
0 | 839 |
} |
840 |
||
841 |
tp.a = tile; |
|
842 |
tp.b = tile2; |
|
843 |
||
844 |
return tp; |
|
845 |
} |
|
846 |
||
820
924f78b43e9e
(svn r1291) -Codechange: prepared subsidies and towns to become an uint16 (happens
truelight
parents:
816
diff
changeset
|
847 |
void DeleteSubsidyWithIndustry(uint16 index) |
0 | 848 |
{ |
849 |
Subsidy *s; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
850 |
|
0 | 851 |
for(s=_subsidies; s != endof(_subsidies); s++) { |
852 |
if (s->cargo_type != 0xFF && s->age < 12 && |
|
853 |
s->cargo_type != CT_PASSENGERS && s->cargo_type != CT_MAIL && |
|
854 |
(index == s->from || (s->cargo_type!=CT_GOODS && s->cargo_type!=CT_FOOD && index==s->to))) { |
|
855 |
s->cargo_type = 0xFF; |
|
856 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
857 |
} |
0 | 858 |
} |
859 |
||
820
924f78b43e9e
(svn r1291) -Codechange: prepared subsidies and towns to become an uint16 (happens
truelight
parents:
816
diff
changeset
|
860 |
void DeleteSubsidyWithStation(uint16 index) |
0 | 861 |
{ |
862 |
Subsidy *s; |
|
863 |
bool dirty = false; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
864 |
|
0 | 865 |
for(s=_subsidies; s != endof(_subsidies); s++) { |
866 |
if (s->cargo_type != 0xFF && s->age >= 12 && |
|
867 |
(s->from == index || s->to == index)) { |
|
868 |
s->cargo_type = 0xFF; |
|
869 |
dirty = true; |
|
870 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
871 |
} |
0 | 872 |
|
873 |
if (dirty) |
|
874 |
InvalidateWindow(WC_SUBSIDIES_LIST, 0); |
|
875 |
} |
|
876 |
||
877 |
typedef struct FoundRoute { |
|
878 |
uint distance; |
|
879 |
byte cargo; |
|
880 |
void *from; |
|
881 |
void *to; |
|
882 |
} FoundRoute; |
|
883 |
||
884 |
static void FindSubsidyPassengerRoute(FoundRoute *fr) |
|
885 |
{ |
|
886 |
Town *from,*to; |
|
887 |
||
888 |
fr->distance = (uint)-1; |
|
889 |
||
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
863
diff
changeset
|
890 |
fr->from = from = GetTown(RandomRange(_total_towns)); |
0 | 891 |
if (from->xy == 0 || from->population < 400) |
892 |
return; |
|
893 |
||
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
863
diff
changeset
|
894 |
fr->to = to = GetTown(RandomRange(_total_towns)); |
0 | 895 |
if (from==to || to->xy == 0 || to->population < 400 || to->pct_pass_transported > 42) |
896 |
return; |
|
897 |
||
898 |
fr->distance = GetTileDist(from->xy, to->xy); |
|
899 |
} |
|
900 |
||
901 |
static void FindSubsidyCargoRoute(FoundRoute *fr) |
|
902 |
{ |
|
903 |
Industry *i; |
|
904 |
int trans, total; |
|
905 |
byte cargo; |
|
906 |
||
907 |
fr->distance = (uint)-1; |
|
908 |
||
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
863
diff
changeset
|
909 |
fr->from = i = GetIndustry(RandomRange(_total_industries)); |
0 | 910 |
if (i->xy == 0) |
911 |
return; |
|
912 |
||
913 |
// Randomize cargo type |
|
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
914 |
if (Random()&1 && i->produced_cargo[1] != 0xFF) { |
0 | 915 |
cargo = i->produced_cargo[1]; |
916 |
trans = i->pct_transported[1]; |
|
917 |
total = i->total_production[1]; |
|
918 |
} else { |
|
919 |
cargo = i->produced_cargo[0]; |
|
920 |
trans = i->pct_transported[0]; |
|
921 |
total = i->total_production[0]; |
|
922 |
} |
|
923 |
||
924 |
// Quit if no production in this industry |
|
925 |
// or if the cargo type is passengers |
|
926 |
// or if the pct transported is already large enough |
|
927 |
if (total == 0 || trans > 42 || cargo == 0xFF || cargo == CT_PASSENGERS) |
|
928 |
return; |
|
929 |
||
930 |
fr->cargo = cargo; |
|
931 |
||
932 |
if (cargo == CT_GOODS || cargo == CT_FOOD) { |
|
933 |
// The destination is a town |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
863
diff
changeset
|
934 |
Town *t = GetTown(RandomRange(_total_towns)); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
935 |
|
0 | 936 |
// Only want big towns |
937 |
if (t->xy == 0 || t->population < 900) |
|
938 |
return; |
|
939 |
fr->distance = GetTileDist(i->xy, t->xy); |
|
940 |
fr->to = t; |
|
941 |
} else { |
|
942 |
// The destination is an industry |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
863
diff
changeset
|
943 |
Industry *i2 = GetIndustry(RandomRange(_total_industries)); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
944 |
|
0 | 945 |
// The industry must accept the cargo |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
946 |
if (i == i2 || i2->xy == 0 || |
0 | 947 |
(cargo != i2->accepts_cargo[0] && |
948 |
cargo != i2->accepts_cargo[1] && |
|
949 |
cargo != i2->accepts_cargo[2])) |
|
950 |
return; |
|
951 |
fr->distance = GetTileDist(i->xy, i2->xy); |
|
952 |
fr->to = i2; |
|
953 |
} |
|
954 |
} |
|
955 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
956 |
static bool CheckSubsidyDuplicate(Subsidy *s) |
0 | 957 |
{ |
958 |
Subsidy *ss; |
|
959 |
||
960 |
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
|
961 |
if (s != ss && |
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
962 |
// ss->age < 12 && |
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) { |
966 |
s->cargo_type = 0xFF; |
|
967 |
return true; |
|
968 |
} |
|
969 |
} |
|
970 |
return false; |
|
971 |
} |
|
972 |
||
239 | 973 |
void RemoteSubsidyAdd(Subsidy *s_new) |
974 |
{ |
|
975 |
Subsidy *s; |
|
976 |
Pair pair; |
|
977 |
||
978 |
// search the first free subsidy |
|
240 | 979 |
for(s=_subsidies; s != endof(_subsidies); s++) |
239 | 980 |
if (s->cargo_type == 0xFF) |
981 |
break; |
|
982 |
||
983 |
memcpy(s,s_new,sizeof(Subsidy)); |
|
984 |
||
985 |
pair = SetupSubsidyDecodeParam(s, 0); |
|
986 |
AddNewsItem(STR_2030_SERVICE_SUBSIDY_OFFERED, NEWS_FLAGS(NM_NORMAL, NF_TILE, NT_SUBSIDIES, 0), pair.a, pair.b); |
|
987 |
||
988 |
InvalidateWindow(WC_SUBSIDIES_LIST, 0); |
|
989 |
} |
|
990 |
||
0 | 991 |
static void SubsidyMonthlyHandler() |
992 |
{ |
|
993 |
Subsidy *s; |
|
994 |
Pair pair; |
|
995 |
Station *st; |
|
996 |
uint n; |
|
997 |
FoundRoute fr; |
|
998 |
bool modified = false; |
|
999 |
||
1000 |
for(s=_subsidies; s != endof(_subsidies); s++) { |
|
1001 |
if (s->cargo_type == 0xFF) |
|
1002 |
continue; |
|
1003 |
||
1004 |
if (s->age == 12-1) { |
|
1005 |
pair = SetupSubsidyDecodeParam(s, 1); |
|
1006 |
AddNewsItem(STR_202E_OFFER_OF_SUBSIDY_EXPIRED, NEWS_FLAGS(NM_NORMAL, NF_TILE, NT_SUBSIDIES, 0), pair.a, pair.b); |
|
1007 |
s->cargo_type = 0xFF; |
|
1008 |
modified = true; |
|
1009 |
} else if (s->age == 2*12-1) { |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
863
diff
changeset
|
1010 |
st = GetStation(s->to); |
0 | 1011 |
if (st->owner == _local_player) { |
1012 |
pair = SetupSubsidyDecodeParam(s, 1); |
|
1013 |
AddNewsItem(STR_202F_SUBSIDY_WITHDRAWN_SERVICE, NEWS_FLAGS(NM_NORMAL, NF_TILE, NT_SUBSIDIES, 0), pair.a, pair.b); |
|
1014 |
} |
|
1015 |
s->cargo_type = 0xFF; |
|
1016 |
modified = true; |
|
1017 |
} else { |
|
1018 |
s->age++; |
|
1019 |
} |
|
1020 |
} |
|
1021 |
||
1022 |
// 25% chance to go on |
|
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
1023 |
if (CHANCE16(1,4)) { |
0 | 1024 |
// Find a free slot |
1025 |
s = _subsidies; |
|
1026 |
while (s->cargo_type != 0xFF) { |
|
1027 |
if (++s == endof(_subsidies)) |
|
1028 |
goto no_add; |
|
1029 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
1030 |
|
0 | 1031 |
n = 1000; |
1032 |
do { |
|
1033 |
FindSubsidyPassengerRoute(&fr); |
|
1034 |
if (fr.distance <= 70) { |
|
1035 |
s->cargo_type = CT_PASSENGERS; |
|
1036 |
s->from = ((Town*)fr.from)->index; |
|
1037 |
s->to = ((Town*)fr.to)->index; |
|
1038 |
goto add_subsidy; |
|
1039 |
} |
|
1040 |
FindSubsidyCargoRoute(&fr); |
|
1041 |
if (fr.distance <= 70) { |
|
1042 |
s->cargo_type = fr.cargo; |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
863
diff
changeset
|
1043 |
s->from = ((Industry*)fr.from)->index; |
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
863
diff
changeset
|
1044 |
s->to = (fr.cargo == CT_GOODS || fr.cargo == CT_FOOD) ? ((Town*)fr.to)->index : ((Industry*)fr.to)->index; |
0 | 1045 |
add_subsidy: |
1046 |
if (!CheckSubsidyDuplicate(s)) { |
|
1047 |
s->age = 0; |
|
1048 |
pair = SetupSubsidyDecodeParam(s, 0); |
|
1049 |
AddNewsItem(STR_2030_SERVICE_SUBSIDY_OFFERED, NEWS_FLAGS(NM_NORMAL, NF_TILE, NT_SUBSIDIES, 0), pair.a, pair.b); |
|
1050 |
modified = true; |
|
1051 |
break; |
|
1052 |
} |
|
1053 |
} |
|
239 | 1054 |
} while (n--); |
0 | 1055 |
} |
1056 |
no_add:; |
|
1057 |
if (modified) |
|
1058 |
InvalidateWindow(WC_SUBSIDIES_LIST, 0); |
|
1059 |
} |
|
1060 |
||
1061 |
static const byte _subsidies_desc[] = { |
|
1062 |
SLE_VAR(Subsidy,cargo_type, SLE_UINT8), |
|
1063 |
SLE_VAR(Subsidy,age, SLE_UINT8), |
|
820
924f78b43e9e
(svn r1291) -Codechange: prepared subsidies and towns to become an uint16 (happens
truelight
parents:
816
diff
changeset
|
1064 |
SLE_CONDVAR(Subsidy,from, SLE_FILE_U8 | SLE_VAR_U16, 0, 4), |
924f78b43e9e
(svn r1291) -Codechange: prepared subsidies and towns to become an uint16 (happens
truelight
parents:
816
diff
changeset
|
1065 |
SLE_CONDVAR(Subsidy,from, SLE_UINT16, 5, 255), |
924f78b43e9e
(svn r1291) -Codechange: prepared subsidies and towns to become an uint16 (happens
truelight
parents:
816
diff
changeset
|
1066 |
SLE_CONDVAR(Subsidy,to, SLE_FILE_U8 | SLE_VAR_U16, 0, 4), |
924f78b43e9e
(svn r1291) -Codechange: prepared subsidies and towns to become an uint16 (happens
truelight
parents:
816
diff
changeset
|
1067 |
SLE_CONDVAR(Subsidy,to, SLE_UINT16, 5, 255), |
0 | 1068 |
SLE_END() |
1069 |
}; |
|
1070 |
||
1071 |
static void Save_SUBS() |
|
1072 |
{ |
|
1073 |
int i; |
|
1074 |
Subsidy *s; |
|
1075 |
||
1076 |
for(i=0; i!=lengthof(_subsidies); i++) { |
|
1077 |
s = &_subsidies[i]; |
|
1078 |
if (s->cargo_type != 0xFF) { |
|
1079 |
SlSetArrayIndex(i); |
|
1080 |
SlObject(s, _subsidies_desc); |
|
1081 |
} |
|
1082 |
} |
|
1083 |
} |
|
1084 |
||
1085 |
static void Load_SUBS() |
|
1086 |
{ |
|
1087 |
int index; |
|
1088 |
while ((index = SlIterateArray()) != -1) |
|
1089 |
SlObject(&_subsidies[index], _subsidies_desc); |
|
1090 |
} |
|
1091 |
||
1092 |
int32 GetTransportedGoodsIncome(uint num_pieces, uint dist, byte transit_days, byte cargo_type) |
|
1093 |
{ |
|
1094 |
int cargo = cargo_type; |
|
1095 |
byte f; |
|
1096 |
||
1097 |
/* zero the distance if it's the bank and very short transport. */ |
|
1098 |
if (_opt.landscape == LT_NORMAL && cargo == CT_VALUABLES && dist < 10) |
|
1099 |
dist = 0; |
|
1100 |
||
1101 |
f = 255; |
|
1102 |
if (transit_days > _cargoc.transit_days_1[cargo]) { |
|
1103 |
transit_days -= _cargoc.transit_days_1[cargo]; |
|
1104 |
f -= transit_days; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
1105 |
|
0 | 1106 |
if (transit_days > _cargoc.transit_days_2[cargo]) { |
1107 |
transit_days -= _cargoc.transit_days_2[cargo]; |
|
1108 |
||
1109 |
if (f < transit_days) |
|
1110 |
f = 0; |
|
1111 |
else |
|
1112 |
f -= transit_days; |
|
1113 |
} |
|
1114 |
} |
|
1115 |
if (f < 31) f = 31; |
|
1116 |
||
1117 |
return BIGMULSS(dist * f * num_pieces, _cargo_payment_rates[cargo], 21); |
|
1118 |
} |
|
1119 |
||
1120 |
static void DeliverGoodsToIndustry(TileIndex xy, byte cargo_type, int num_pieces) |
|
1121 |
{ |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
1122 |
Industry *ind, *best; |
0 | 1123 |
int t, u; |
1124 |
||
1125 |
/* Check if there's an industry close to the station that accepts |
|
1126 |
* the cargo */ |
|
1127 |
best = NULL; |
|
33
431df1abc34b
(svn r34) -Fix [990770] Cargo delivery area patch for bug #989322. If station sign was too far away, there were goods acceptance/delivery issues (Celstar)
darkvater
parents:
9
diff
changeset
|
1128 |
u = _patches.station_spread + 8; |
830
36c1366367e4
(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents:
820
diff
changeset
|
1129 |
FOR_ALL_INDUSTRIES(ind) { |
0 | 1130 |
if (ind->xy != 0 && (cargo_type == ind->accepts_cargo[0] || cargo_type |
1131 |
== ind->accepts_cargo[1] || cargo_type == ind->accepts_cargo[2]) && |
|
1132 |
ind->produced_cargo[0] != 0xFF && |
|
1133 |
ind->produced_cargo[0] != cargo_type && |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
1134 |
(t=GetTileDist(ind->xy, xy)) < u) { |
0 | 1135 |
u = t; |
1136 |
best = ind; |
|
1137 |
} |
|
1138 |
} |
|
1139 |
||
1140 |
/* Found one? */ |
|
1141 |
if (best != NULL) { |
|
1142 |
best->was_cargo_delivered = true; |
|
1143 |
best->cargo_waiting[0] = min(best->cargo_waiting[0] + num_pieces, 0xFFFF); |
|
1144 |
} |
|
1145 |
} |
|
1146 |
||
1147 |
static bool CheckSubsidised(Station *from, Station *to, byte cargo_type) |
|
1148 |
{ |
|
1149 |
Subsidy *s; |
|
1150 |
TileIndex xy; |
|
1151 |
Pair pair; |
|
1152 |
Player *p; |
|
1153 |
||
1154 |
// check if there is an already existing subsidy that applies to us |
|
1155 |
for(s=_subsidies; s != endof(_subsidies); s++) { |
|
1156 |
if (s->cargo_type == cargo_type && |
|
1157 |
s->age >= 12 && |
|
1158 |
s->from == from->index && |
|
1159 |
s->to == to->index) |
|
1160 |
return true; |
|
1161 |
} |
|
1162 |
||
1163 |
/* check if there's a new subsidy that applies.. */ |
|
1164 |
for(s=_subsidies; s != endof(_subsidies); s++) { |
|
1165 |
if (s->cargo_type == cargo_type && s->age < 12) { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
1166 |
|
0 | 1167 |
/* Check distance from source */ |
1168 |
if (cargo_type == CT_PASSENGERS || cargo_type == CT_MAIL) { |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
863
diff
changeset
|
1169 |
xy = GetTown(s->from)->xy; |
0 | 1170 |
} else { |
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
863
diff
changeset
|
1171 |
xy = (GetIndustry(s->from))->xy; |
0 | 1172 |
} |
1173 |
if (GetTileDist1D(xy, from->xy) > 9) |
|
1174 |
continue; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
1175 |
|
0 | 1176 |
/* Check distance from dest */ |
1177 |
if (cargo_type == CT_PASSENGERS || cargo_type == CT_MAIL || cargo_type == CT_GOODS || cargo_type == CT_FOOD) { |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
863
diff
changeset
|
1178 |
xy = GetTown(s->to)->xy; |
0 | 1179 |
} else { |
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
863
diff
changeset
|
1180 |
xy = (GetIndustry(s->to))->xy; |
0 | 1181 |
} |
1182 |
||
1183 |
if (GetTileDist1D(xy, to->xy) > 9) |
|
1184 |
continue; |
|
1185 |
||
1186 |
/* Found a subsidy, change the values to indicate that it's in use */ |
|
1187 |
s->age = 12; |
|
1188 |
s->from = from->index; |
|
1189 |
s->to = to->index; |
|
1190 |
||
1191 |
/* Add a news item */ |
|
1192 |
pair = SetupSubsidyDecodeParam(s, 0); |
|
1193 |
INJECT_DPARAM(2); |
|
1194 |
||
1195 |
p = DEREF_PLAYER(_current_player); |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
1196 |
SetDParam(0, p->name_1); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
1197 |
SetDParam(1, p->name_2); |
0 | 1198 |
AddNewsItem( |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
1199 |
STR_2031_SERVICE_SUBSIDY_AWARDED + _opt.diff.subsidy_multiplier, |
0 | 1200 |
NEWS_FLAGS(NM_NORMAL, NF_TILE, NT_SUBSIDIES, 0), |
1201 |
pair.a, pair.b); |
|
1202 |
||
1203 |
InvalidateWindow(WC_SUBSIDIES_LIST, 0); |
|
1204 |
return true; |
|
1205 |
} |
|
1206 |
} |
|
1207 |
return false; |
|
1208 |
} |
|
1209 |
||
1210 |
static int32 DeliverGoods(int num_pieces, byte cargo_type, byte source, byte dest, byte days_in_transit) |
|
1211 |
{ |
|
1212 |
bool subsidised; |
|
1213 |
Station *s_from, *s_to; |
|
1214 |
int32 profit; |
|
1215 |
||
1216 |
assert(num_pieces > 0); |
|
1217 |
||
1218 |
// Update player statistics |
|
1219 |
{ |
|
1220 |
Player *p = DEREF_PLAYER(_current_player); |
|
1221 |
p->cur_economy.delivered_cargo += num_pieces; |
|
1222 |
SETBIT(p->cargo_types, cargo_type); |
|
1223 |
} |
|
1224 |
||
1225 |
// Get station pointers. |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
863
diff
changeset
|
1226 |
s_from = GetStation(source); |
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
863
diff
changeset
|
1227 |
s_to = GetStation(dest); |
0 | 1228 |
|
1229 |
// Check if a subsidy applies. |
|
1230 |
subsidised = CheckSubsidised(s_from, s_to, cargo_type); |
|
1231 |
||
1232 |
// Increase town's counter for some special goods types |
|
1233 |
{ |
|
1234 |
Town *t = s_to->town; |
|
1235 |
if (cargo_type == CT_FOOD) t->new_act_food += num_pieces; |
|
4
cad62d5f9708
(svn r5) -Fix: townname generation of TTDLX savegames. All work
darkvater
parents:
0
diff
changeset
|
1236 |
if (cargo_type == CT_STEEL) t->new_act_water += num_pieces; |
0 | 1237 |
} |
1238 |
||
1239 |
// Give the goods to the industry. |
|
1240 |
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
|
1241 |
|
0 | 1242 |
// Determine profit |
1243 |
{ |
|
1244 |
int t = GetTileDist(s_from->xy, s_to->xy); |
|
1245 |
int r = num_pieces; |
|
1246 |
profit = 0; |
|
1247 |
do { |
|
1248 |
int u = min(r, 255); |
|
1249 |
r -= u; |
|
1250 |
profit += GetTransportedGoodsIncome(u, t, days_in_transit, cargo_type); |
|
1251 |
} while (r != 0); |
|
1252 |
} |
|
1253 |
||
1254 |
// Modify profit if a subsidy is in effect |
|
1255 |
if (subsidised) { |
|
1256 |
if (_opt.diff.subsidy_multiplier < 1) { |
|
1257 |
/* 1.5x */ |
|
1258 |
profit += profit >> 1; |
|
1259 |
} else if (_opt.diff.subsidy_multiplier == 1) { |
|
1260 |
/* 2x */ |
|
1261 |
profit *= 2; |
|
1262 |
} else if (_opt.diff.subsidy_multiplier == 2) { |
|
1263 |
/* 3x */ |
|
1264 |
profit *= 3; |
|
1265 |
} else { |
|
1266 |
/* 4x */ |
|
1267 |
profit *= 4; |
|
1268 |
} |
|
1269 |
} |
|
1270 |
||
1271 |
// Computers get 25% extra profit if they're intelligent. |
|
1272 |
if (_opt.diff.competitor_intelligence>=1 && !IS_HUMAN_PLAYER(_current_player)) |
|
1273 |
profit += profit >> 2; |
|
1274 |
||
1275 |
return profit; |
|
1276 |
} |
|
1277 |
||
523
8871819c9afd
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1278 |
/* |
8871819c9afd
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1279 |
* Returns true if Vehicle v should wait loading because other vehicle is |
8871819c9afd
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1280 |
* already loading the same cargo type |
8871819c9afd
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1281 |
* v = vehicle to load, u = GetFirstInChain(v) |
8871819c9afd
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1282 |
*/ |
8871819c9afd
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1283 |
static bool LoadWait(const Vehicle *v, const Vehicle *u) { |
8871819c9afd
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1284 |
const Vehicle *w; |
8871819c9afd
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1285 |
const Vehicle *x; |
8871819c9afd
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1286 |
bool has_any_cargo = false; |
8871819c9afd
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1287 |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
1288 |
if (!(u->current_order.flags & OF_FULL_LOAD)) return false; |
523
8871819c9afd
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1289 |
|
8871819c9afd
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1290 |
for (w = u; w != NULL; w = w->next) { |
8871819c9afd
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1291 |
if (w->cargo_count != 0) { |
8871819c9afd
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1292 |
if (v->cargo_type == w->cargo_type && |
8871819c9afd
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1293 |
u->last_station_visited == w->cargo_source) |
8871819c9afd
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1294 |
return false; |
8871819c9afd
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1295 |
has_any_cargo = true; |
8871819c9afd
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1296 |
} |
8871819c9afd
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1297 |
} |
8871819c9afd
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1298 |
|
8871819c9afd
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1299 |
FOR_ALL_VEHICLES(x) { |
1067
3ba7987a004e
(svn r1568) made an enum of train subtypes to make the code more readable
bjarni
parents:
1019
diff
changeset
|
1300 |
if ((x->type != VEH_Train || x->subtype == TS_Front_Engine) && // for all locs |
523
8871819c9afd
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1301 |
u->last_station_visited == x->last_station_visited && // at the same station |
8871819c9afd
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1302 |
!(x->vehstatus & VS_STOPPED) && // not stopped |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
1303 |
x->current_order.type == OT_LOADING && // loading |
523
8871819c9afd
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1304 |
u != x) { // not itself |
8871819c9afd
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1305 |
bool other_has_any_cargo = false; |
8871819c9afd
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1306 |
bool has_space_for_same_type = false; |
8871819c9afd
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1307 |
bool other_has_same_type = false; |
8871819c9afd
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1308 |
|
8871819c9afd
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1309 |
for (w = x; w != NULL; w = w->next) { |
8871819c9afd
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1310 |
if (w->cargo_count < w->cargo_cap && v->cargo_type == w->cargo_type) |
8871819c9afd
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1311 |
has_space_for_same_type = true; |
8871819c9afd
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1312 |
|
8871819c9afd
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1313 |
if (w->cargo_count != 0) { |
8871819c9afd
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1314 |
if (v->cargo_type == w->cargo_type && |
8871819c9afd
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1315 |
u->last_station_visited == w->cargo_source) |
8871819c9afd
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1316 |
other_has_same_type = true; |
8871819c9afd
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1317 |
other_has_any_cargo = true; |
8871819c9afd
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1318 |
} |
8871819c9afd
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1319 |
} |
8871819c9afd
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1320 |
|
8871819c9afd
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1321 |
if (has_space_for_same_type) { |
8871819c9afd
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1322 |
if (other_has_same_type) return true; |
8871819c9afd
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1323 |
if (other_has_any_cargo && !has_any_cargo) return true; |
8871819c9afd
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1324 |
} |
8871819c9afd
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1325 |
} |
8871819c9afd
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1326 |
} |
8871819c9afd
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1327 |
|
8871819c9afd
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1328 |
return false; |
8871819c9afd
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1329 |
} |
8871819c9afd
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1330 |
|
0 | 1331 |
int LoadUnloadVehicle(Vehicle *v) |
1332 |
{ |
|
1333 |
int profit = 0; |
|
1334 |
int unloading_time = 20; |
|
1335 |
Vehicle *u = v; |
|
1336 |
int result = 0; |
|
1337 |
int last_visited; |
|
1338 |
Station *st; |
|
1339 |
GoodsEntry *ge; |
|
1340 |
int t; |
|
1341 |
uint count, cap; |
|
260
4819bcce8389
(svn r266) -Fix: hopefully fixed the desync problem nicely (and reverted the
truelight
parents:
240
diff
changeset
|
1342 |
byte old_player; |
445
beafc0fb8f12
(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
|
1343 |
bool completely_empty = true; |
0 | 1344 |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
1345 |
assert(v->current_order.type == OT_LOADING); |
0 | 1346 |
|
1347 |
v->cur_speed = 0; |
|
260
4819bcce8389
(svn r266) -Fix: hopefully fixed the desync problem nicely (and reverted the
truelight
parents:
240
diff
changeset
|
1348 |
old_player = _current_player; |
0 | 1349 |
_current_player = v->owner; |
1350 |
||
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
863
diff
changeset
|
1351 |
st = GetStation(last_visited = v->last_station_visited); |
0 | 1352 |
|
499 | 1353 |
for (; v != NULL; v = v->next) { |
1354 |
if (v->cargo_cap == 0) continue; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
1355 |
|
0 | 1356 |
ge = &st->goods[v->cargo_type]; |
1357 |
||
1358 |
/* unload? */ |
|
1359 |
if (v->cargo_count != 0) { |
|
1360 |
if (v->cargo_source != (byte)last_visited && ge->waiting_acceptance & 0x8000) { |
|
1361 |
// deliver goods to the station |
|
1362 |
unloading_time += v->cargo_count; /* TTDBUG: bug in original TTD */ |
|
1363 |
profit += DeliverGoods(v->cargo_count, v->cargo_type, v->cargo_source, last_visited, v->cargo_days); |
|
1364 |
result |= 1; |
|
1365 |
v->cargo_count = 0; |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
1366 |
} else if (u->current_order.flags & OF_UNLOAD) { |
0 | 1367 |
/* unload goods and let it wait at the station */ |
1368 |
st->time_since_unload = 0; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
1369 |
|
0 | 1370 |
if ((t=ge->waiting_acceptance & 0xFFF) == 0) { |
1371 |
// No goods waiting at station |
|
1372 |
ge->enroute_time = v->cargo_days; |
|
1373 |
ge->enroute_from = v->cargo_source; |
|
1374 |
} else { |
|
1375 |
// Goods already waiting at station. Set counters to the worst value. |
|
1376 |
if (v->cargo_days >= ge->enroute_time) |
|
1377 |
ge->enroute_time = v->cargo_days; |
|
1378 |
if ((byte)last_visited != ge->enroute_from) |
|
1379 |
ge->enroute_from = v->cargo_source; |
|
1380 |
} |
|
1381 |
// Update amount of waiting cargo |
|
1382 |
ge->waiting_acceptance = (ge->waiting_acceptance &~0xFFF) | min(v->cargo_count + t, 0xFFF); |
|
1383 |
result |= 2; |
|
1384 |
v->cargo_count = 0; |
|
1385 |
} |
|
445
beafc0fb8f12
(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
|
1386 |
|
beafc0fb8f12
(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
|
1387 |
if (v->cargo_count != 0) |
beafc0fb8f12
(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
|
1388 |
completely_empty = false; |
0 | 1389 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
1390 |
|
0 | 1391 |
/* don't pick up goods that we unloaded */ |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
1392 |
if (u->current_order.flags & OF_UNLOAD) continue; |
0 | 1393 |
|
1394 |
/* update stats */ |
|
1395 |
ge->days_since_pickup = 0; |
|
1396 |
t = u->max_speed; |
|
1397 |
if (u->type == VEH_Road) t >>=1; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
1398 |
|
0 | 1399 |
// if last speed is 0, we treat that as if no vehicle has ever visited the station. |
1400 |
ge->last_speed = t < 255 ? t : 255; |
|
1401 |
ge->last_age = _cur_year - v->build_year; |
|
1402 |
||
1403 |
// If there's goods waiting at the station, and the vehicle |
|
1404 |
// has capacity for it, load it on the vehicle. |
|
1405 |
if ((count=ge->waiting_acceptance & 0xFFF) != 0 && |
|
1406 |
(cap = v->cargo_cap - v->cargo_count) != 0) { |
|
445
beafc0fb8f12
(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
|
1407 |
if (v->cargo_count == 0) |
beafc0fb8f12
(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
|
1408 |
TriggerVehicle(v, VEHICLE_TRIGGER_NEW_CARGO); |
beafc0fb8f12
(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
|
1409 |
|
523
8871819c9afd
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1410 |
/* Skip loading this vehicle if another train/vehicle is already handling |
8871819c9afd
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1411 |
* the same cargo type at this station */ |
8871819c9afd
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1412 |
if (_patches.improved_load && LoadWait(v,u)) continue; |
8871819c9afd
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1413 |
|
445
beafc0fb8f12
(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
|
1414 |
/* TODO: Regarding this, when we do gradual loading, we |
beafc0fb8f12
(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
|
1415 |
* should first unload all vehicles and then start |
beafc0fb8f12
(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
|
1416 |
* loading them. Since this will cause |
beafc0fb8f12
(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
|
1417 |
* VEHICLE_TRIGGER_EMPTY to be called at the time when |
beafc0fb8f12
(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
|
1418 |
* the whole vehicle chain is really totally empty, the |
beafc0fb8f12
(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
|
1419 |
* @completely_empty assignment can then be safely |
beafc0fb8f12
(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
|
1420 |
* removed; that's how TTDPatch behaves too. --pasky */ |
beafc0fb8f12
(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
|
1421 |
completely_empty = false; |
beafc0fb8f12
(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
|
1422 |
|
0 | 1423 |
if (cap > count) cap = count; |
1424 |
v->cargo_count += cap; |
|
1425 |
ge->waiting_acceptance -= cap; |
|
1426 |
unloading_time += cap; |
|
1427 |
st->time_since_load = 0; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
1428 |
|
0 | 1429 |
// And record the source of the cargo, and the days in travel. |
1430 |
v->cargo_source = ge->enroute_from; |
|
1431 |
v->cargo_days = ge->enroute_time; |
|
1432 |
result |= 2; |
|
1433 |
st->last_vehicle = v->index; |
|
1434 |
} |
|
1435 |
} |
|
1436 |
||
1437 |
v = u; |
|
1438 |
||
1439 |
if (v->type == VEH_Train) { |
|
1440 |
int num = - (int)GetStationPlatforms(st, v->tile) * 2; |
|
1441 |
do num++; while ( (v=v->next) != NULL); |
|
1442 |
if (num > 0) { |
|
1443 |
unloading_time <<=1; |
|
1444 |
unloading_time += num * unloading_time; |
|
1445 |
} |
|
1446 |
v = u; |
|
1447 |
} |
|
1448 |
||
1449 |
v->load_unload_time_rem = unloading_time; |
|
1450 |
||
445
beafc0fb8f12
(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 |
if (completely_empty) { |
beafc0fb8f12
(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 |
TriggerVehicle(v, VEHICLE_TRIGGER_EMPTY); |
beafc0fb8f12
(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 |
} |
beafc0fb8f12
(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 |
|
0 | 1455 |
if (result != 0) { |
1456 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
|
1457 |
||
1458 |
if (result & 2) |
|
1459 |
InvalidateWindow(WC_STATION_VIEW, last_visited); |
|
1460 |
||
1461 |
if (profit != 0) { |
|
1462 |
v->profit_this_year += profit; |
|
1463 |
SubtractMoneyFromPlayer(-profit); |
|
1464 |
||
1465 |
if (_current_player == _local_player) |
|
541 | 1466 |
SndPlayVehicleFx(SND_14_CASHTILL, v); |
0 | 1467 |
|
1468 |
ShowCostOrIncomeAnimation(v->x_pos, v->y_pos, v->z_pos, -profit); |
|
1469 |
} |
|
1470 |
} |
|
1471 |
||
260
4819bcce8389
(svn r266) -Fix: hopefully fixed the desync problem nicely (and reverted the
truelight
parents:
240
diff
changeset
|
1472 |
_current_player = old_player; |
0 | 1473 |
return result; |
1474 |
} |
|
1475 |
||
1476 |
void PlayersMonthlyLoop() |
|
1477 |
{ |
|
1478 |
PlayersGenStatistics(); |
|
1479 |
if (_patches.inflation) |
|
1480 |
AddInflation(); |
|
1481 |
PlayersPayInterest(); |
|
206 | 1482 |
// Reset the _current_player flag |
1483 |
_current_player = OWNER_NONE; |
|
0 | 1484 |
HandleEconomyFluctuations(); |
1485 |
SubsidyMonthlyHandler(); |
|
1486 |
} |
|
1487 |
||
1488 |
static void DoAcquireCompany(Player *p) |
|
1489 |
{ |
|
1490 |
Player *owner; |
|
1491 |
int i,pi; |
|
200
03b8104d1479
(svn r201) -Fix: [1025836] Company values bigger dan int32 were put to negative
truelight
parents:
193
diff
changeset
|
1492 |
int64 value; |
0 | 1493 |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
1494 |
SetDParam(0, p->name_1); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
1495 |
SetDParam(1, p->name_2); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
1496 |
SetDParam(2, p->bankrupt_value); |
0 | 1497 |
AddNewsItem( (StringID)(_current_player + 16*2), NEWS_FLAGS(NM_CALLBACK, 0, NT_COMPANY_INFO, DNC_BANKRUPCY),0,0); |
1498 |
||
1499 |
// original code does this a little bit differently |
|
1500 |
pi = p->index; |
|
1501 |
ChangeOwnershipOfPlayerItems(pi, _current_player); |
|
1502 |
||
1503 |
if (p->bankrupt_value == 0) { |
|
1504 |
owner = DEREF_PLAYER(_current_player); |
|
1505 |
owner->current_loan += p->current_loan; |
|
1506 |
} |
|
1507 |
||
1508 |
value = CalculateCompanyValue(p) >> 2; |
|
1509 |
for(i=0; i!=4; i++) { |
|
1510 |
if (p->share_owners[i] != 0xFF) { |
|
1511 |
owner = DEREF_PLAYER(p->share_owners[i]); |
|
1512 |
owner->money64 += value; |
|
1513 |
owner->yearly_expenses[0][EXPENSES_OTHER] += value; |
|
1514 |
UpdatePlayerMoney32(owner); |
|
1515 |
} |
|
1516 |
} |
|
1517 |
||
1518 |
p->is_active = false; |
|
1519 |
||
1520 |
DeletePlayerWindows(pi); |
|
967
124257e8befa
(svn r1460) -Fix: [1099225] Bug Fix - Vehicle Lists not updated at Acqusition (thx tamlin and mpetrov) This also fixes some bug but can't find i right now.
darkvater
parents:
930
diff
changeset
|
1521 |
RebuildVehicleLists(); //Updates the open windows to add the newly acquired vehicles to the lists |
0 | 1522 |
} |
1523 |
||
599
30da691a5561
(svn r1023) -Fix: [Network] [ 1083692 ] You can no longer buy out a company in MP
truelight
parents:
555
diff
changeset
|
1524 |
extern int GetAmountOwnedBy(Player *p, byte owner); |
30da691a5561
(svn r1023) -Fix: [Network] [ 1083692 ] You can no longer buy out a company in MP
truelight
parents:
555
diff
changeset
|
1525 |
|
0 | 1526 |
int32 CmdBuyShareInCompany(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
1527 |
{ |
|
1528 |
Player *p; |
|
200
03b8104d1479
(svn r201) -Fix: [1025836] Company values bigger dan int32 were put to negative
truelight
parents:
193
diff
changeset
|
1529 |
int64 cost; |
0 | 1530 |
byte *b; |
1531 |
int i; |
|
1532 |
||
1533 |
SET_EXPENSES_TYPE(EXPENSES_OTHER); |
|
1534 |
p = DEREF_PLAYER(p1); |
|
1019
6bae6c11e865
(svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents:
997
diff
changeset
|
1535 |
|
6bae6c11e865
(svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents:
997
diff
changeset
|
1536 |
|
997
fa7a654d23ca
(svn r1495) -Fix: Loan does not count against the company value
celestar
parents:
970
diff
changeset
|
1537 |
if (_cur_year - p->inaugurated_year < 6) { |
fa7a654d23ca
(svn r1495) -Fix: Loan does not count against the company value
celestar
parents:
970
diff
changeset
|
1538 |
_error_message = STR_7080_PROTECTED; |
fa7a654d23ca
(svn r1495) -Fix: Loan does not count against the company value
celestar
parents:
970
diff
changeset
|
1539 |
return CMD_ERROR; |
fa7a654d23ca
(svn r1495) -Fix: Loan does not count against the company value
celestar
parents:
970
diff
changeset
|
1540 |
} |
0 | 1541 |
|
930
ab42e283749d
(svn r1418) -Feature: [1098254] (dis)Allow Shares. Add patch options to allow buying/selling of shares (Hackykid)
darkvater
parents:
919
diff
changeset
|
1542 |
/* Check if buying shares is allowed (protection against modified clients */ |
ab42e283749d
(svn r1418) -Feature: [1098254] (dis)Allow Shares. Add patch options to allow buying/selling of shares (Hackykid)
darkvater
parents:
919
diff
changeset
|
1543 |
if (!_patches.allow_shares) |
ab42e283749d
(svn r1418) -Feature: [1098254] (dis)Allow Shares. Add patch options to allow buying/selling of shares (Hackykid)
darkvater
parents:
919
diff
changeset
|
1544 |
return CMD_ERROR; |
ab42e283749d
(svn r1418) -Feature: [1098254] (dis)Allow Shares. Add patch options to allow buying/selling of shares (Hackykid)
darkvater
parents:
919
diff
changeset
|
1545 |
|
599
30da691a5561
(svn r1023) -Fix: [Network] [ 1083692 ] You can no longer buy out a company in MP
truelight
parents:
555
diff
changeset
|
1546 |
/* Those lines are here for network-protection (clients can be slow) */ |
30da691a5561
(svn r1023) -Fix: [Network] [ 1083692 ] You can no longer buy out a company in MP
truelight
parents:
555
diff
changeset
|
1547 |
if (GetAmountOwnedBy(p, OWNER_SPECTATOR) == 0) |
30da691a5561
(svn r1023) -Fix: [Network] [ 1083692 ] You can no longer buy out a company in MP
truelight
parents:
555
diff
changeset
|
1548 |
return 0; |
930
ab42e283749d
(svn r1418) -Feature: [1098254] (dis)Allow Shares. Add patch options to allow buying/selling of shares (Hackykid)
darkvater
parents:
919
diff
changeset
|
1549 |
|
599
30da691a5561
(svn r1023) -Fix: [Network] [ 1083692 ] You can no longer buy out a company in MP
truelight
parents:
555
diff
changeset
|
1550 |
/* We can not buy out a real player in networking */ |
30da691a5561
(svn r1023) -Fix: [Network] [ 1083692 ] You can no longer buy out a company in MP
truelight
parents:
555
diff
changeset
|
1551 |
if (GetAmountOwnedBy(p, OWNER_SPECTATOR) == 1 && !p->is_ai) |
30da691a5561
(svn r1023) -Fix: [Network] [ 1083692 ] You can no longer buy out a company in MP
truelight
parents:
555
diff
changeset
|
1552 |
return 0; |
1019
6bae6c11e865
(svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents:
997
diff
changeset
|
1553 |
|
0 | 1554 |
cost = CalculateCompanyValue(p) >> 2; |
1555 |
if (flags & DC_EXEC) { |
|
1556 |
b = p->share_owners; |
|
1557 |
while (*b != 0xFF) b++; /* share owners is guaranteed to contain at least one 0xFF */ |
|
1558 |
*b = _current_player; |
|
1559 |
||
1560 |
for(i=0;p->share_owners[i] == _current_player;) { |
|
1561 |
if (++i == 4) { |
|
1562 |
p->bankrupt_value = 0; |
|
1563 |
DoAcquireCompany(p); |
|
1564 |
break; |
|
1565 |
} |
|
1566 |
} |
|
1567 |
InvalidateWindow(WC_COMPANY, (int)p1); |
|
1568 |
} |
|
1569 |
return cost; |
|
1570 |
} |
|
1571 |
||
1572 |
int32 CmdSellShareInCompany(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
1573 |
{ |
|
1574 |
Player *p; |
|
200
03b8104d1479
(svn r201) -Fix: [1025836] Company values bigger dan int32 were put to negative
truelight
parents:
193
diff
changeset
|
1575 |
int64 cost; |
0 | 1576 |
byte *b; |
1577 |
||
1578 |
SET_EXPENSES_TYPE(EXPENSES_OTHER); |
|
1579 |
p = DEREF_PLAYER(p1); |
|
1580 |
||
930
ab42e283749d
(svn r1418) -Feature: [1098254] (dis)Allow Shares. Add patch options to allow buying/selling of shares (Hackykid)
darkvater
parents:
919
diff
changeset
|
1581 |
/* Check if selling shares is allowed (protection against modified clients */ |
ab42e283749d
(svn r1418) -Feature: [1098254] (dis)Allow Shares. Add patch options to allow buying/selling of shares (Hackykid)
darkvater
parents:
919
diff
changeset
|
1582 |
if (!_patches.allow_shares) |
ab42e283749d
(svn r1418) -Feature: [1098254] (dis)Allow Shares. Add patch options to allow buying/selling of shares (Hackykid)
darkvater
parents:
919
diff
changeset
|
1583 |
return CMD_ERROR; |
1019
6bae6c11e865
(svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents:
997
diff
changeset
|
1584 |
|
653
989ae721eb8b
(svn r1086) -Fix: [Network] [ 1084774 ] Fixed quick-share-sell bug
truelight
parents:
630
diff
changeset
|
1585 |
/* Those lines are here for network-protection (clients can be slow) */ |
989ae721eb8b
(svn r1086) -Fix: [Network] [ 1084774 ] Fixed quick-share-sell bug
truelight
parents:
630
diff
changeset
|
1586 |
if (GetAmountOwnedBy(p, _current_player) == 0) |
989ae721eb8b
(svn r1086) -Fix: [Network] [ 1084774 ] Fixed quick-share-sell bug
truelight
parents:
630
diff
changeset
|
1587 |
return 0; |
989ae721eb8b
(svn r1086) -Fix: [Network] [ 1084774 ] Fixed quick-share-sell bug
truelight
parents:
630
diff
changeset
|
1588 |
|
0 | 1589 |
/* adjust it a little to make it less profitable to sell and buy */ |
1590 |
cost = CalculateCompanyValue(p) >> 2; |
|
1591 |
cost = -(cost - (cost >> 7)); |
|
1592 |
||
1593 |
if (flags & DC_EXEC) { |
|
1594 |
b = p->share_owners; |
|
1595 |
while (*b != _current_player) b++; /* share owners is guaranteed to contain player */ |
|
1596 |
*b = 0xFF; |
|
1597 |
InvalidateWindow(WC_COMPANY, (int)p1); |
|
1598 |
} |
|
1599 |
return cost; |
|
1600 |
} |
|
1601 |
||
1602 |
int32 CmdBuyCompany(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
1603 |
{ |
|
1604 |
Player *p; |
|
1605 |
SET_EXPENSES_TYPE(EXPENSES_OTHER); |
|
1606 |
p = DEREF_PLAYER(p1); |
|
1607 |
if (flags & 1) { |
|
1608 |
DoAcquireCompany(p); |
|
1609 |
} |
|
1610 |
return p->bankrupt_value; |
|
1611 |
} |
|
1612 |
||
1613 |
// Prices |
|
1614 |
static void SaveLoad_PRIC() |
|
1615 |
{ |
|
1616 |
SlArray(&_price, NUM_PRICES, SLE_INT32); |
|
1617 |
SlArray(&_price_frac, NUM_PRICES, SLE_UINT16); |
|
1618 |
} |
|
1619 |
||
1620 |
// Cargo payment rates |
|
1621 |
static void SaveLoad_CAPR() |
|
1622 |
{ |
|
1623 |
SlArray(&_cargo_payment_rates, NUM_CARGO, SLE_INT32); |
|
1624 |
SlArray(&_cargo_payment_rates_frac, NUM_CARGO, SLE_UINT16); |
|
1625 |
} |
|
1626 |
||
1627 |
static const byte _economy_desc[] = { |
|
1628 |
SLE_VAR(Economy,max_loan, SLE_INT32), |
|
1629 |
SLE_VAR(Economy,max_loan_unround, SLE_INT32), |
|
1630 |
SLE_VAR(Economy,fluct, SLE_FILE_I16 | SLE_VAR_I32), |
|
1631 |
SLE_VAR(Economy,interest_rate, SLE_UINT8), |
|
1632 |
SLE_VAR(Economy,infl_amount, SLE_UINT8), |
|
1633 |
SLE_VAR(Economy,infl_amount_pr, SLE_UINT8), |
|
1634 |
SLE_END() |
|
1635 |
}; |
|
1636 |
||
1637 |
// Economy variables |
|
1638 |
static void SaveLoad_ECMY() |
|
1639 |
{ |
|
1640 |
SlObject(&_economy, &_economy_desc); |
|
1641 |
} |
|
1642 |
||
1643 |
const ChunkHandler _economy_chunk_handlers[] = { |
|
1644 |
{ 'PRIC', SaveLoad_PRIC, SaveLoad_PRIC, CH_RIFF | CH_AUTO_LENGTH}, |
|
1645 |
{ 'CAPR', SaveLoad_CAPR, SaveLoad_CAPR, CH_RIFF | CH_AUTO_LENGTH}, |
|
1646 |
{ 'SUBS', Save_SUBS, Load_SUBS, CH_ARRAY}, |
|
1647 |
{ 'ECMY', SaveLoad_ECMY, SaveLoad_ECMY, CH_RIFF | CH_LAST}, |
|
1648 |
}; |
|
1649 |
||
1650 |
||
1651 |
||
1652 |