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