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