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