author | celestar |
Tue, 19 Jun 2007 07:21:01 +0000 | |
branch | gamebalance |
changeset 9913 | e79cd19772dd |
parent 9912 | 1ac8aac92385 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6445
diff
changeset
|
3 |
/** @file economy.cpp */ |
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6445
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" |
9908
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9907
diff
changeset
|
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" |
9912
1ac8aac92385
(svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents:
9911
diff
changeset
|
33 |
#include "roadveh.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
|
34 |
#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
|
35 |
#include "newgrf_engine.h" |
4701 | 36 |
#include "newgrf_sound.h" |
5211
651c9272ad22
(svn r7326) -Feature: Add support for gradual (un)loading of vehicles (Maedhros)
peter1138
parents:
5077
diff
changeset
|
37 |
#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
|
38 |
#include "unmovable.h" |
4261
2ec8f5a9747b
(svn r5887) -Cleanup: move date related functions, defines and variables to date.[ch]
rubidium
parents:
4260
diff
changeset
|
39 |
#include "date.h" |
6417
26acff62d001
(svn r8826) -Codechange: Replace _cargoc's separate arrays with a regular struct array (with accessor) and implement new initialization method using cargo labels.
peter1138
parents:
6324
diff
changeset
|
40 |
#include "cargotype.h" |
6516
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6501
diff
changeset
|
41 |
#include "player_face.h" |
9911
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
42 |
#include "group.h" |
0 | 43 |
|
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6445
diff
changeset
|
44 |
/* Score info */ |
2261
3f78323707bb
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2218
diff
changeset
|
45 |
const ScoreInfo _score_info[] = { |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3655
diff
changeset
|
46 |
{ SCORE_VEHICLES, 120, 100 }, |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3655
diff
changeset
|
47 |
{ SCORE_STATIONS, 80, 100 }, |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3655
diff
changeset
|
48 |
{ SCORE_MIN_PROFIT, 10000, 100 }, |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3655
diff
changeset
|
49 |
{ SCORE_MIN_INCOME, 50000, 50 }, |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3655
diff
changeset
|
50 |
{ SCORE_MAX_INCOME, 100000, 100 }, |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3655
diff
changeset
|
51 |
{ SCORE_DELIVERED, 40000, 400 }, |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3655
diff
changeset
|
52 |
{ SCORE_CARGO, 8, 50 }, |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3655
diff
changeset
|
53 |
{ SCORE_MONEY, 10000000, 50 }, |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3655
diff
changeset
|
54 |
{ SCORE_LOAN, 250000, 50 }, |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3655
diff
changeset
|
55 |
{ SCORE_TOTAL, 0, 0 } |
2261
3f78323707bb
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2218
diff
changeset
|
56 |
}; |
3f78323707bb
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2218
diff
changeset
|
57 |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
58 |
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
|
59 |
|
2639 | 60 |
int64 CalculateCompanyValue(const Player* p) |
2475 | 61 |
{ |
62 |
PlayerID owner = p->index; |
|
200
03b8104d1479
(svn r201) -Fix: [1025836] Company values bigger dan int32 were put to negative
truelight
parents:
193
diff
changeset
|
63 |
int64 value; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
64 |
|
0 | 65 |
{ |
66 |
Station *st; |
|
67 |
uint num = 0; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
68 |
|
0 | 69 |
FOR_ALL_STATIONS(st) { |
9913
e79cd19772dd
(svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents:
9912
diff
changeset
|
70 |
if (st->owner == owner) num += CountBitsSet(st->facilities); |
0 | 71 |
} |
72 |
||
9903
dc85aaa556ae
(svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents:
9901
diff
changeset
|
73 |
value = num * _eco->GetPrice(CEconomy::STATION_VALUE) * 25; |
0 | 74 |
} |
75 |
||
76 |
{ |
|
77 |
Vehicle *v; |
|
78 |
||
79 |
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
|
80 |
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
|
81 |
|
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
82 |
if (v->type == VEH_TRAIN || |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
83 |
v->type == VEH_ROAD || |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
84 |
(v->type == VEH_AIRCRAFT && IsNormalAircraft(v)) || |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
85 |
v->type == VEH_SHIP) { |
0 | 86 |
value += v->value * 3 >> 1; |
87 |
} |
|
88 |
} |
|
89 |
} |
|
90 |
||
997
71cf4e50d259
(svn r1495) -Fix: Loan does not count against the company value
celestar
parents:
970
diff
changeset
|
91 |
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
|
92 |
|
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
|
93 |
return max(value, 1LL); |
0 | 94 |
} |
95 |
||
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6445
diff
changeset
|
96 |
/** if update is set to true, the economy is updated with this score |
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6445
diff
changeset
|
97 |
* (also the house is updated, should only be true in the on-tick event) |
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6445
diff
changeset
|
98 |
* @param update the economy with calculated score |
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6445
diff
changeset
|
99 |
* @param p player been evaluated |
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6445
diff
changeset
|
100 |
* @return actual score of this player |
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6445
diff
changeset
|
101 |
* */ |
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
|
102 |
int UpdateCompanyRatingAndValue(Player *p, bool update) |
0 | 103 |
{ |
104 |
byte owner = p->index; |
|
116
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
105 |
int score = 0; |
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
106 |
|
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
107 |
memset(_score_part[owner], 0, sizeof(_score_part[owner])); |
0 | 108 |
|
109 |
/* Count vehicles */ |
|
110 |
{ |
|
111 |
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
|
112 |
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
|
113 |
bool min_profit_first = true; |
0 | 114 |
uint num = 0; |
115 |
||
116 |
FOR_ALL_VEHICLES(v) { |
|
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3655
diff
changeset
|
117 |
if (v->owner != owner) continue; |
9912
1ac8aac92385
(svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents:
9911
diff
changeset
|
118 |
if (IsPlayerBuildableVehicleType(v->type) && v->IsPrimaryVehicle()) { |
0 | 119 |
num++; |
120 |
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
|
121 |
/* 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
|
122 |
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
|
123 |
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
|
124 |
min_profit_first = false; |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3655
diff
changeset
|
125 |
} else if (min_profit > v->profit_last_year) { |
0 | 126 |
min_profit = v->profit_last_year; |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3655
diff
changeset
|
127 |
} |
0 | 128 |
} |
129 |
} |
|
130 |
} |
|
131 |
||
116
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
132 |
_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
|
133 |
/* 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
|
134 |
if (min_profit > 0) |
bbcdd50795e3
(svn r1911) Put back an "if" i accidently removed in r1898
tron
parents:
1394
diff
changeset
|
135 |
_score_part[owner][SCORE_MIN_PROFIT] = min_profit; |
0 | 136 |
} |
137 |
||
138 |
/* Count stations */ |
|
139 |
{ |
|
140 |
uint num = 0; |
|
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3017
diff
changeset
|
141 |
const Station* st; |
0 | 142 |
|
143 |
FOR_ALL_STATIONS(st) { |
|
9913
e79cd19772dd
(svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents:
9912
diff
changeset
|
144 |
if (st->owner == owner) num += CountBitsSet(st->facilities); |
0 | 145 |
} |
116
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
146 |
_score_part[owner][SCORE_STATIONS] = num; |
0 | 147 |
} |
148 |
||
149 |
/* Generate statistics depending on recent income statistics */ |
|
150 |
{ |
|
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3017
diff
changeset
|
151 |
const PlayerEconomyEntry* pee; |
0 | 152 |
int numec; |
153 |
int32 min_income; |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
154 |
int32 max_income; |
0 | 155 |
|
156 |
numec = min(p->num_valid_stat_ent, 12); |
|
157 |
if (numec != 0) { |
|
158 |
min_income = 0x7FFFFFFF; |
|
159 |
max_income = 0; |
|
160 |
pee = p->old_economy; |
|
161 |
do { |
|
162 |
min_income = min(min_income, pee->income + pee->expenses); |
|
163 |
max_income = max(max_income, pee->income + pee->expenses); |
|
164 |
} while (++pee,--numec); |
|
165 |
||
166 |
if (min_income > 0) |
|
116
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
167 |
_score_part[owner][SCORE_MIN_INCOME] = min_income; |
0 | 168 |
|
116
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
169 |
_score_part[owner][SCORE_MAX_INCOME] = max_income; |
0 | 170 |
} |
171 |
} |
|
172 |
||
173 |
/* Generate score depending on amount of transported cargo */ |
|
174 |
{ |
|
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3017
diff
changeset
|
175 |
const PlayerEconomyEntry* pee; |
0 | 176 |
int numec; |
177 |
uint32 total_delivered; |
|
178 |
||
179 |
numec = min(p->num_valid_stat_ent, 4); |
|
180 |
if (numec != 0) { |
|
181 |
pee = p->old_economy; |
|
182 |
total_delivered = 0; |
|
183 |
do { |
|
184 |
total_delivered += pee->delivered_cargo; |
|
185 |
} while (++pee,--numec); |
|
186 |
||
116
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
187 |
_score_part[owner][SCORE_DELIVERED] = total_delivered; |
0 | 188 |
} |
189 |
} |
|
116
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
190 |
|
0 | 191 |
/* Generate score for variety of cargo */ |
192 |
{ |
|
9913
e79cd19772dd
(svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents:
9912
diff
changeset
|
193 |
uint num = CountBitsSet(p->cargo_types); |
116
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
194 |
_score_part[owner][SCORE_CARGO] = num; |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3017
diff
changeset
|
195 |
if (update) p->cargo_types = 0; |
0 | 196 |
} |
197 |
||
198 |
/* Generate score for player money */ |
|
199 |
{ |
|
200 |
int32 money = p->player_money; |
|
201 |
if (money > 0) { |
|
116
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
202 |
_score_part[owner][SCORE_MONEY] = money; |
0 | 203 |
} |
204 |
} |
|
205 |
||
206 |
/* Generate score for loan */ |
|
207 |
{ |
|
2261
3f78323707bb
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2218
diff
changeset
|
208 |
_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
|
209 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
210 |
|
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6445
diff
changeset
|
211 |
/* 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
|
212 |
{ |
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
213 |
int total_score = 0; |
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
214 |
int s; |
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
215 |
score = 0; |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
216 |
for (ScoreID i = SCORE_BEGIN; i < SCORE_END; i++) { |
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6445
diff
changeset
|
217 |
/* Skip the total */ |
116
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
218 |
if (i == SCORE_TOTAL) continue; |
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6445
diff
changeset
|
219 |
/* Check the score */ |
2261
3f78323707bb
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2218
diff
changeset
|
220 |
s = (_score_part[owner][i] >= _score_info[i].needed) ? |
3f78323707bb
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2218
diff
changeset
|
221 |
_score_info[i].score : |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3017
diff
changeset
|
222 |
_score_part[owner][i] * _score_info[i].score / _score_info[i].needed; |
116
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
223 |
if (s < 0) s = 0; |
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
224 |
score += s; |
2261
3f78323707bb
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2218
diff
changeset
|
225 |
total_score += _score_info[i].score; |
116
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
226 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
227 |
|
116
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
228 |
_score_part[owner][SCORE_TOTAL] = score; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
229 |
|
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6445
diff
changeset
|
230 |
/* We always want the score scaled to SCORE_MAX (1000) */ |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3017
diff
changeset
|
231 |
if (total_score != SCORE_MAX) score = score * SCORE_MAX / total_score; |
0 | 232 |
} |
233 |
||
116
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
234 |
if (update) { |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3655
diff
changeset
|
235 |
p->old_economy[0].performance_history = score; |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3655
diff
changeset
|
236 |
UpdateCompanyHQ(p, score); |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3655
diff
changeset
|
237 |
p->old_economy[0].company_value = CalculateCompanyValue(p); |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3655
diff
changeset
|
238 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
239 |
|
116
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
240 |
InvalidateWindow(WC_PERFORMANCE_DETAIL, 0); |
147
d0c8100d18cf
(svn r148) -Feature: Company HQ can now be moved somewhere else (cost 1% of company value). Water floods HQ.
darkvater
parents:
116
diff
changeset
|
241 |
return score; |
0 | 242 |
} |
243 |
||
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6445
diff
changeset
|
244 |
/* use PLAYER_SPECTATOR as new_player to delete the player. */ |
1797
a19c4181f1b7
(svn r2301) - CodeChange: prettyify ChangeOwnerShipOfPlayerItems() a bit
Darkvater
parents:
1793
diff
changeset
|
245 |
void ChangeOwnershipOfPlayerItems(PlayerID old_player, PlayerID new_player) |
0 | 246 |
{ |
5284
3c42e8e18392
(svn r7433) -Fix (r2301): Town ratings were not reset when a company went bankrupt.
peter1138
parents:
5251
diff
changeset
|
247 |
Town *t; |
1797
a19c4181f1b7
(svn r2301) - CodeChange: prettyify ChangeOwnerShipOfPlayerItems() a bit
Darkvater
parents:
1793
diff
changeset
|
248 |
PlayerID old = _current_player; |
9908
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9907
diff
changeset
|
249 |
|
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9907
diff
changeset
|
250 |
assert(old_player != new_player); |
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9907
diff
changeset
|
251 |
|
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9907
diff
changeset
|
252 |
{ |
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9907
diff
changeset
|
253 |
Player *p; |
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9907
diff
changeset
|
254 |
uint i; |
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9907
diff
changeset
|
255 |
|
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9907
diff
changeset
|
256 |
/* See if the old_player had shares in other companies */ |
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9907
diff
changeset
|
257 |
_current_player = old_player; |
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9907
diff
changeset
|
258 |
FOR_ALL_PLAYERS(p) { |
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9907
diff
changeset
|
259 |
for (i = 0; i < 4; i++) { |
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9907
diff
changeset
|
260 |
if (p->share_owners[i] == old_player) { |
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9907
diff
changeset
|
261 |
/* Sell his shares */ |
9913
e79cd19772dd
(svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents:
9912
diff
changeset
|
262 |
CommandCost res = DoCommand(0, p->index, 0, DC_EXEC, CMD_SELL_SHARE_IN_COMPANY); |
9908
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9907
diff
changeset
|
263 |
/* Because we are in a DoCommand, we can't just execute an other one and |
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9907
diff
changeset
|
264 |
* expect the money to be removed. We need to do it ourself! */ |
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9907
diff
changeset
|
265 |
SubtractMoneyFromPlayer(res); |
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9907
diff
changeset
|
266 |
} |
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9907
diff
changeset
|
267 |
} |
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9907
diff
changeset
|
268 |
} |
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9907
diff
changeset
|
269 |
|
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9907
diff
changeset
|
270 |
/* Sell all the shares that people have on this company */ |
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9907
diff
changeset
|
271 |
p = GetPlayer(old_player); |
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9907
diff
changeset
|
272 |
for (i = 0; i < 4; i++) { |
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9907
diff
changeset
|
273 |
_current_player = p->share_owners[i]; |
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9907
diff
changeset
|
274 |
if (_current_player != PLAYER_SPECTATOR) { |
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9907
diff
changeset
|
275 |
/* Sell the shares */ |
9913
e79cd19772dd
(svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents:
9912
diff
changeset
|
276 |
CommandCost res = DoCommand(0, old_player, 0, DC_EXEC, CMD_SELL_SHARE_IN_COMPANY); |
9908
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9907
diff
changeset
|
277 |
/* Because we are in a DoCommand, we can't just execute an other one and |
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9907
diff
changeset
|
278 |
* expect the money to be removed. We need to do it ourself! */ |
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9907
diff
changeset
|
279 |
SubtractMoneyFromPlayer(res); |
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9907
diff
changeset
|
280 |
} |
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9907
diff
changeset
|
281 |
} |
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9907
diff
changeset
|
282 |
} |
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9907
diff
changeset
|
283 |
|
0 | 284 |
_current_player = old_player; |
285 |
||
4260
8a9824f6e501
(svn r5886) -Fix [FS#273]: Incomplete removal of player owned property due to lack of money.
Darkvater
parents:
4077
diff
changeset
|
286 |
/* 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
|
287 |
* 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
|
288 |
* 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
|
289 |
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
|
290 |
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
|
291 |
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
|
292 |
} |
8a9824f6e501
(svn r5886) -Fix [FS#273]: Incomplete removal of player owned property due to lack of money.
Darkvater
parents:
4077
diff
changeset
|
293 |
|
4848
56549aa3e234
(svn r6774) -Codechange: Rename the badly named OWNER_SPECTATOR to PLAYER_SPECTATOR and
Darkvater
parents:
4845
diff
changeset
|
294 |
if (new_player == PLAYER_SPECTATOR) { |
0 | 295 |
Subsidy *s; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
296 |
|
1797
a19c4181f1b7
(svn r2301) - CodeChange: prettyify ChangeOwnerShipOfPlayerItems() a bit
Darkvater
parents:
1793
diff
changeset
|
297 |
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
|
298 |
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
|
299 |
if (GetStation(s->to)->owner == old_player) s->cargo_type = CT_INVALID; |
0 | 300 |
} |
301 |
} |
|
302 |
} |
|
303 |
||
1797
a19c4181f1b7
(svn r2301) - CodeChange: prettyify ChangeOwnerShipOfPlayerItems() a bit
Darkvater
parents:
1793
diff
changeset
|
304 |
/* 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
|
305 |
FOR_ALL_TOWNS(t) { |
3c42e8e18392
(svn r7433) -Fix (r2301): Town ratings were not reset when a company went bankrupt.
peter1138
parents:
5251
diff
changeset
|
306 |
/* 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
|
307 |
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
|
308 |
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
|
309 |
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
|
310 |
// 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
|
311 |
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
|
312 |
} else { |
8a9824f6e501
(svn r5886) -Fix [FS#273]: Incomplete removal of player owned property due to lack of money.
Darkvater
parents:
4077
diff
changeset
|
313 |
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
|
314 |
t->ratings[new_player] = t->ratings[old_player]; |
1797
a19c4181f1b7
(svn r2301) - CodeChange: prettyify ChangeOwnerShipOfPlayerItems() a bit
Darkvater
parents:
1793
diff
changeset
|
315 |
} |
4260
8a9824f6e501
(svn r5886) -Fix [FS#273]: Incomplete removal of player owned property due to lack of money.
Darkvater
parents:
4077
diff
changeset
|
316 |
} |
5284
3c42e8e18392
(svn r7433) -Fix (r2301): Town ratings were not reset when a company went bankrupt.
peter1138
parents:
5251
diff
changeset
|
317 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
318 |
|
5284
3c42e8e18392
(svn r7433) -Fix (r2301): Town ratings were not reset when a company went bankrupt.
peter1138
parents:
5251
diff
changeset
|
319 |
/* 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
|
320 |
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
|
321 |
CLRBIT(t->have_ratings, old_player); |
0 | 322 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
323 |
|
0 | 324 |
{ |
325 |
int num_train = 0; |
|
326 |
int num_road = 0; |
|
327 |
int num_ship = 0; |
|
328 |
int num_aircraft = 0; |
|
329 |
Vehicle *v; |
|
330 |
||
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6445
diff
changeset
|
331 |
/* Determine Ids for the new vehicles */ |
0 | 332 |
FOR_ALL_VEHICLES(v) { |
333 |
if (v->owner == new_player) { |
|
1797
a19c4181f1b7
(svn r2301) - CodeChange: prettyify ChangeOwnerShipOfPlayerItems() a bit
Darkvater
parents:
1793
diff
changeset
|
334 |
switch (v->type) { |
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
335 |
case VEH_TRAIN: if (IsFrontEngine(v)) num_train++; break; |
9912
1ac8aac92385
(svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents:
9911
diff
changeset
|
336 |
case VEH_ROAD: if (IsRoadVehFront(v)) num_road++; break; |
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
337 |
case VEH_SHIP: num_ship++; break; |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
338 |
case VEH_AIRCRAFT: if (IsNormalAircraft(v)) num_aircraft++; break; |
1797
a19c4181f1b7
(svn r2301) - CodeChange: prettyify ChangeOwnerShipOfPlayerItems() a bit
Darkvater
parents:
1793
diff
changeset
|
339 |
default: break; |
a19c4181f1b7
(svn r2301) - CodeChange: prettyify ChangeOwnerShipOfPlayerItems() a bit
Darkvater
parents:
1793
diff
changeset
|
340 |
} |
0 | 341 |
} |
342 |
} |
|
343 |
||
344 |
FOR_ALL_VEHICLES(v) { |
|
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
345 |
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
|
346 |
if (new_player == PLAYER_SPECTATOR) { |
0 | 347 |
DeleteWindowById(WC_VEHICLE_VIEW, v->index); |
348 |
DeleteWindowById(WC_VEHICLE_DETAILS, v->index); |
|
349 |
DeleteWindowById(WC_VEHICLE_ORDERS, v->index); |
|
9913
e79cd19772dd
(svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents:
9912
diff
changeset
|
350 |
|
e79cd19772dd
(svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents:
9912
diff
changeset
|
351 |
if (v->IsPrimaryVehicle() || (v->type == VEH_TRAIN && IsFreeWagon(v))) { |
e79cd19772dd
(svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents:
9912
diff
changeset
|
352 |
switch (v->type) { |
e79cd19772dd
(svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents:
9912
diff
changeset
|
353 |
default: NOT_REACHED(); |
e79cd19772dd
(svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents:
9912
diff
changeset
|
354 |
|
e79cd19772dd
(svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents:
9912
diff
changeset
|
355 |
case VEH_TRAIN: { |
e79cd19772dd
(svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents:
9912
diff
changeset
|
356 |
Vehicle *u = v; |
e79cd19772dd
(svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents:
9912
diff
changeset
|
357 |
do { |
e79cd19772dd
(svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents:
9912
diff
changeset
|
358 |
Vehicle *next = GetNextVehicle(u); |
e79cd19772dd
(svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents:
9912
diff
changeset
|
359 |
DeleteVehicle(u); |
e79cd19772dd
(svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents:
9912
diff
changeset
|
360 |
u = next; |
e79cd19772dd
(svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents:
9912
diff
changeset
|
361 |
} while (u != NULL); |
e79cd19772dd
(svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents:
9912
diff
changeset
|
362 |
} break; |
e79cd19772dd
(svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents:
9912
diff
changeset
|
363 |
|
e79cd19772dd
(svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents:
9912
diff
changeset
|
364 |
case VEH_ROAD: |
e79cd19772dd
(svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents:
9912
diff
changeset
|
365 |
case VEH_SHIP: |
e79cd19772dd
(svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents:
9912
diff
changeset
|
366 |
DeleteVehicle(v); |
e79cd19772dd
(svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents:
9912
diff
changeset
|
367 |
break; |
e79cd19772dd
(svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents:
9912
diff
changeset
|
368 |
|
e79cd19772dd
(svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents:
9912
diff
changeset
|
369 |
case VEH_AIRCRAFT: |
e79cd19772dd
(svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents:
9912
diff
changeset
|
370 |
DeleteVehicleChain(v); |
e79cd19772dd
(svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents:
9912
diff
changeset
|
371 |
break; |
e79cd19772dd
(svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents:
9912
diff
changeset
|
372 |
} |
e79cd19772dd
(svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents:
9912
diff
changeset
|
373 |
} |
0 | 374 |
} else { |
375 |
v->owner = new_player; |
|
9911
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
376 |
v->group_id = DEFAULT_GROUP; |
4621
79238ae21c0d
(svn r6479) -Fix r6424: FS#348 Plane autoreplace glitch
bjarni
parents:
4549
diff
changeset
|
377 |
if (IsEngineCountable(v)) GetPlayer(new_player)->num_engines[v->engine_type]++; |
2989 | 378 |
switch (v->type) { |
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
379 |
case VEH_TRAIN: if (IsFrontEngine(v)) v->unitnumber = ++num_train; break; |
9912
1ac8aac92385
(svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents:
9911
diff
changeset
|
380 |
case VEH_ROAD: if (IsRoadVehFront(v)) v->unitnumber = ++num_road; break; |
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
381 |
case VEH_SHIP: v->unitnumber = ++num_ship; break; |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
382 |
case VEH_AIRCRAFT: if (IsNormalAircraft(v)) v->unitnumber = ++num_aircraft; break; |
9911
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
383 |
default: NOT_REACHED(); |
2989 | 384 |
} |
0 | 385 |
} |
386 |
} |
|
387 |
} |
|
388 |
} |
|
389 |
||
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6445
diff
changeset
|
390 |
/* Change ownership of tiles */ |
0 | 391 |
{ |
1797
a19c4181f1b7
(svn r2301) - CodeChange: prettyify ChangeOwnerShipOfPlayerItems() a bit
Darkvater
parents:
1793
diff
changeset
|
392 |
TileIndex tile = 0; |
0 | 393 |
do { |
394 |
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
|
395 |
} while (++tile != MapSize()); |
0 | 396 |
} |
397 |
||
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
|
398 |
/* 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
|
399 |
if (new_player != PLAYER_SPECTATOR) ChangeWindowOwner(old_player, new_player); |
0 | 400 |
|
401 |
_current_player = old; |
|
402 |
||
403 |
MarkWholeScreenDirty(); |
|
404 |
} |
|
405 |
||
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
406 |
static void ChangeNetworkOwner(PlayerID current_player, PlayerID new_player) |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
407 |
{ |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
408 |
#ifdef ENABLE_NETWORK |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
409 |
if (!_networking) return; |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
410 |
|
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
411 |
if (current_player == _local_player) { |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
412 |
_network_playas = new_player; |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
413 |
SetLocalPlayer(new_player); |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
414 |
} |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
415 |
|
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
416 |
if (!_network_server) return; |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
417 |
|
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
418 |
/* The server has to handle all administrative issues, for example |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
419 |
* updating and notifying all clients of what has happened */ |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
420 |
NetworkTCPSocketHandler *cs; |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
421 |
NetworkClientInfo *ci = NetworkFindClientInfoFromIndex(NETWORK_SERVER_INDEX); |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
422 |
|
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
423 |
/* The server has just changed from player */ |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
424 |
if (current_player == ci->client_playas) { |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
425 |
ci->client_playas = new_player; |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
426 |
NetworkUpdateClientInfo(NETWORK_SERVER_INDEX); |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
427 |
} |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
428 |
|
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
429 |
/* Find all clients that were in control of this company, and mark them as new_player */ |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
430 |
FOR_ALL_CLIENTS(cs) { |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
431 |
ci = DEREF_CLIENT_INFO(cs); |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
432 |
if (current_player == ci->client_playas) { |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
433 |
ci->client_playas = new_player; |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
434 |
NetworkUpdateClientInfo(ci->client_index); |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
435 |
} |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
436 |
} |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
437 |
#endif /* ENABLE_NETWORK */ |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
438 |
} |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
439 |
|
0 | 440 |
static void PlayersCheckBankrupt(Player *p) |
441 |
{ |
|
2475 | 442 |
PlayerID owner; |
200
03b8104d1479
(svn r201) -Fix: [1025836] Company values bigger dan int32 were put to negative
truelight
parents:
193
diff
changeset
|
443 |
int64 val; |
0 | 444 |
|
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6445
diff
changeset
|
445 |
/* If the player has money again, it does not go bankrupt */ |
0 | 446 |
if (p->player_money >= 0) { |
447 |
p->quarters_of_bankrupcy = 0; |
|
448 |
return; |
|
449 |
} |
|
450 |
||
451 |
p->quarters_of_bankrupcy++; |
|
452 |
||
453 |
owner = p->index; |
|
454 |
||
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
455 |
switch (p->quarters_of_bankrupcy) { |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
456 |
case 2: |
4873
7cb19235cf60
(svn r6803) -Codechange: Substitute magic numbers by an enum for the news windows
Darkvater
parents:
4854
diff
changeset
|
457 |
AddNewsItem( (StringID)(owner | NB_BTROUBLE), |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
458 |
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
|
459 |
break; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
460 |
case 3: { |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
461 |
/* 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
|
462 |
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
|
463 |
if (IsHumanPlayer(owner)) { |
4873
7cb19235cf60
(svn r6803) -Codechange: Substitute magic numbers by an enum for the news windows
Darkvater
parents:
4854
diff
changeset
|
464 |
AddNewsItem( (StringID)(owner | NB_BTROUBLE), |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
465 |
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
|
466 |
break; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
467 |
} |
0 | 468 |
|
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6445
diff
changeset
|
469 |
/* Check if the company has any value.. if not, declare it bankrupt |
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6445
diff
changeset
|
470 |
* right now */ |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
471 |
val = CalculateCompanyValue(p); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
472 |
if (val > 0) { |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
473 |
p->bankrupt_value = val; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
474 |
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
|
475 |
p->bankrupt_timeout = 0; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
476 |
break; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
477 |
} |
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6445
diff
changeset
|
478 |
/* Else, falltrue to case 4... */ |
0 | 479 |
} |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
480 |
case 4: { |
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6445
diff
changeset
|
481 |
/* Close everything the owner has open */ |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
482 |
DeletePlayerWindows(owner); |
0 | 483 |
|
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6445
diff
changeset
|
484 |
/* Show bankrupt news */ |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
485 |
SetDParam(0, p->name_1); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
486 |
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
|
487 |
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
|
488 |
|
5067
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4880
diff
changeset
|
489 |
if (IsHumanPlayer(owner)) { |
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4880
diff
changeset
|
490 |
/* 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
|
491 |
* 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
|
492 |
* 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
|
493 |
if (!_networking) { |
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4880
diff
changeset
|
494 |
p->bankrupt_asked = 0xFF; |
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4880
diff
changeset
|
495 |
p->bankrupt_timeout = 0x456; |
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4880
diff
changeset
|
496 |
break; |
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4880
diff
changeset
|
497 |
} |
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4880
diff
changeset
|
498 |
|
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
499 |
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
|
500 |
} |
687
e8d646a00eb1
(svn r1128) -Fix: [Network] Going bankrupt of human-players was corrupted in networkgames
truelight
parents:
679
diff
changeset
|
501 |
|
5067
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4880
diff
changeset
|
502 |
/* Remove the player */ |
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4880
diff
changeset
|
503 |
ChangeOwnershipOfPlayerItems(owner, PLAYER_SPECTATOR); |
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4880
diff
changeset
|
504 |
/* 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
|
505 |
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
|
506 |
|
5067
870dfdcef898
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
Darkvater
parents:
4880
diff
changeset
|
507 |
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
|
508 |
AI_PlayerDied(owner); |
0 | 509 |
} |
510 |
} |
|
511 |
} |
|
512 |
||
513 |
void DrawNewsBankrupcy(Window *w) |
|
514 |
{ |
|
515 |
Player *p; |
|
516 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
517 |
DrawNewsBorder(w); |
0 | 518 |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
519 |
p = GetPlayer((PlayerID)GB(WP(w,news_d).ni->string_id, 0, 4)); |
0 | 520 |
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
|
521 |
GfxFillRect(3, 23, 3 + 91, 23 + 118, PALETTE_TO_STRUCT_GREY | (1 << USE_COLORTABLE)); |
0 | 522 |
|
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
523 |
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
|
524 |
SetDParam(1, p->president_name_2); |
0 | 525 |
|
526 |
DrawStringMultiCenter(49, 148, STR_7058_PRESIDENT, 94); |
|
527 |
||
4873
7cb19235cf60
(svn r6803) -Codechange: Substitute magic numbers by an enum for the news windows
Darkvater
parents:
4854
diff
changeset
|
528 |
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
|
529 |
case NB_BTROUBLE: |
0 | 530 |
DrawStringCentered(w->width>>1, 1, STR_7056_TRANSPORT_COMPANY_IN_TROUBLE, 0); |
531 |
||
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
532 |
SetDParam(0, p->name_1); |
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
533 |
SetDParam(1, p->name_2); |
0 | 534 |
|
535 |
DrawStringMultiCenter( |
|
536 |
((w->width - 101) >> 1) + 98, |
|
537 |
90, |
|
538 |
STR_7057_WILL_BE_SOLD_OFF_OR_DECLARED, |
|
539 |
w->width - 101); |
|
540 |
break; |
|
541 |
||
4873
7cb19235cf60
(svn r6803) -Codechange: Substitute magic numbers by an enum for the news windows
Darkvater
parents:
4854
diff
changeset
|
542 |
case NB_BMERGER: { |
0 | 543 |
int32 price; |
544 |
||
545 |
DrawStringCentered(w->width>>1, 1, STR_7059_TRANSPORT_COMPANY_MERGER, 0); |
|
546 |
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
|
547 |
SetDParam(2, p->name_1); |
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
548 |
SetDParam(3, p->name_2); |
0 | 549 |
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
|
550 |
SetDParam(4, price); |
0 | 551 |
DrawStringMultiCenter( |
552 |
((w->width - 101) >> 1) + 98, |
|
553 |
90, |
|
554 |
price==0 ? STR_707F_HAS_BEEN_TAKEN_OVER_BY : STR_705A_HAS_BEEN_SOLD_TO_FOR, |
|
555 |
w->width - 101); |
|
556 |
break; |
|
557 |
} |
|
558 |
||
4873
7cb19235cf60
(svn r6803) -Codechange: Substitute magic numbers by an enum for the news windows
Darkvater
parents:
4854
diff
changeset
|
559 |
case NB_BBANKRUPT: |
0 | 560 |
DrawStringCentered(w->width>>1, 1, STR_705C_BANKRUPT, 0); |
561 |
COPY_IN_DPARAM(0,WP(w,news_d).ni->params, 2); |
|
562 |
DrawStringMultiCenter( |
|
563 |
((w->width - 101) >> 1) + 98, |
|
564 |
90, |
|
565 |
STR_705D_HAS_BEEN_CLOSED_DOWN_BY, |
|
566 |
w->width - 101); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
567 |
break; |
0 | 568 |
|
4873
7cb19235cf60
(svn r6803) -Codechange: Substitute magic numbers by an enum for the news windows
Darkvater
parents:
4854
diff
changeset
|
569 |
case NB_BNEWCOMPANY: |
0 | 570 |
DrawStringCentered(w->width>>1, 1, STR_705E_NEW_TRANSPORT_COMPANY_LAUNCHED, 0); |
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
571 |
SetDParam(0, p->name_1); |
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
572 |
SetDParam(1, p->name_2); |
0 | 573 |
COPY_IN_DPARAM(2,WP(w,news_d).ni->params, 2); |
574 |
DrawStringMultiCenter( |
|
575 |
((w->width - 101) >> 1) + 98, |
|
576 |
90, |
|
577 |
STR_705F_STARTS_CONSTRUCTION_NEAR, |
|
578 |
w->width - 101); |
|
579 |
break; |
|
580 |
||
581 |
default: |
|
582 |
NOT_REACHED(); |
|
583 |
} |
|
584 |
} |
|
585 |
||
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
|
586 |
StringID GetNewsStringBankrupcy(const NewsItem *ni) |
0 | 587 |
{ |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
588 |
const Player *p = GetPlayer((PlayerID)GB(ni->string_id, 0, 4)); |
0 | 589 |
|
4873
7cb19235cf60
(svn r6803) -Codechange: Substitute magic numbers by an enum for the news windows
Darkvater
parents:
4854
diff
changeset
|
590 |
switch (ni->string_id & 0xF0) { |
7cb19235cf60
(svn r6803) -Codechange: Substitute magic numbers by an enum for the news windows
Darkvater
parents:
4854
diff
changeset
|
591 |
case NB_BTROUBLE: |
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
592 |
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
|
593 |
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
|
594 |
SetDParam(2, p->name_1); |
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
595 |
SetDParam(3, p->name_2); |
0 | 596 |
return STR_02B6; |
4873
7cb19235cf60
(svn r6803) -Codechange: Substitute magic numbers by an enum for the news windows
Darkvater
parents:
4854
diff
changeset
|
597 |
case NB_BMERGER: |
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
598 |
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
|
599 |
SetDParam(1, STR_705A_HAS_BEEN_SOLD_TO_FOR); |
0 | 600 |
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
|
601 |
SetDParam(4, p->name_1); |
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
602 |
SetDParam(5, p->name_2); |
0 | 603 |
COPY_IN_DPARAM(6,ni->params + 2, 1); |
604 |
return STR_02B6; |
|
4873
7cb19235cf60
(svn r6803) -Codechange: Substitute magic numbers by an enum for the news windows
Darkvater
parents:
4854
diff
changeset
|
605 |
case NB_BBANKRUPT: |
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
606 |
SetDParam(0, STR_705C_BANKRUPT); |
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
607 |
SetDParam(1, STR_705D_HAS_BEEN_CLOSED_DOWN_BY); |
0 | 608 |
COPY_IN_DPARAM(2,ni->params, 2); |
609 |
return STR_02B6; |
|
4873
7cb19235cf60
(svn r6803) -Codechange: Substitute magic numbers by an enum for the news windows
Darkvater
parents:
4854
diff
changeset
|
610 |
case NB_BNEWCOMPANY: |
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
611 |
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
|
612 |
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
|
613 |
SetDParam(2, p->name_1); |
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
614 |
SetDParam(3, p->name_2); |
0 | 615 |
COPY_IN_DPARAM(4,ni->params, 2); |
616 |
return STR_02B6; |
|
617 |
default: |
|
618 |
NOT_REACHED(); |
|
619 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
620 |
|
0 | 621 |
/* useless, but avoids compiler warning this way */ |
622 |
return 0; |
|
623 |
} |
|
624 |
||
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
625 |
static void PlayersGenStatistics() |
0 | 626 |
{ |
627 |
Station *st; |
|
628 |
Player *p; |
|
629 |
||
630 |
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
|
631 |
_current_player = st->owner; |
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
632 |
SET_EXPENSES_TYPE(EXPENSES_PROPERTY); |
9903
dc85aaa556ae
(svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents:
9901
diff
changeset
|
633 |
SubtractMoneyFromPlayer(_eco->GetPrice(CEconomy::STATION_VALUE) >> 1); |
0 | 634 |
} |
635 |
||
636 |
if (!HASBIT(1<<0|1<<3|1<<6|1<<9, _cur_month)) |
|
637 |
return; |
|
638 |
||
639 |
FOR_ALL_PLAYERS(p) { |
|
640 |
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
|
641 |
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
|
642 |
p->old_economy[0] = p->cur_economy; |
0 | 643 |
memset(&p->cur_economy, 0, sizeof(p->cur_economy)); |
644 |
||
5677
525f85bee8f9
(svn r7630) -Fix: At the end of the quarter the old economy numbers were shifted up, and
Darkvater
parents:
5566
diff
changeset
|
645 |
if (p->num_valid_stat_ent != 24) p->num_valid_stat_ent++; |
0 | 646 |
|
116
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
33
diff
changeset
|
647 |
UpdateCompanyRatingAndValue(p, true); |
0 | 648 |
PlayersCheckBankrupt(p); |
649 |
||
5677
525f85bee8f9
(svn r7630) -Fix: At the end of the quarter the old economy numbers were shifted up, and
Darkvater
parents:
5566
diff
changeset
|
650 |
if (p->block_preview != 0) p->block_preview--; |
0 | 651 |
} |
652 |
} |
|
653 |
||
654 |
InvalidateWindow(WC_INCOME_GRAPH, 0); |
|
655 |
InvalidateWindow(WC_OPERATING_PROFIT, 0); |
|
656 |
InvalidateWindow(WC_DELIVERED_CARGO, 0); |
|
657 |
InvalidateWindow(WC_PERFORMANCE_HISTORY, 0); |
|
658 |
InvalidateWindow(WC_COMPANY_VALUE, 0); |
|
659 |
InvalidateWindow(WC_COMPANY_LEAGUE, 0); |
|
660 |
} |
|
661 |
||
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
662 |
static void PlayersPayInterest() |
0 | 663 |
{ |
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
|
664 |
const Player* p; |
0 | 665 |
int interest = _economy.interest_rate * 54; |
666 |
||
667 |
FOR_ALL_PLAYERS(p) { |
|
2639 | 668 |
if (!p->is_active) continue; |
0 | 669 |
|
670 |
_current_player = p->index; |
|
671 |
SET_EXPENSES_TYPE(EXPENSES_LOAN_INT); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
672 |
|
0 | 673 |
SubtractMoneyFromPlayer(BIGMULUS(p->current_loan, interest, 16)); |
674 |
||
675 |
SET_EXPENSES_TYPE(EXPENSES_OTHER); |
|
9903
dc85aaa556ae
(svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents:
9901
diff
changeset
|
676 |
SubtractMoneyFromPlayer(_eco->GetPrice(CEconomy::STATION_VALUE) >> 2); |
0 | 677 |
} |
678 |
} |
|
679 |
||
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
680 |
static void HandleEconomyFluctuations() |
0 | 681 |
{ |
2639 | 682 |
if (_opt.diff.economy == 0) return; |
0 | 683 |
|
684 |
if (--_economy.fluct == 0) { |
|
2642 | 685 |
_economy.fluct = -(int)GB(Random(), 0, 2); |
0 | 686 |
AddNewsItem(STR_7073_WORLD_RECESSION_FINANCIAL, NEWS_FLAGS(NM_NORMAL,0,NT_ECONOMY,0), 0, 0); |
687 |
} else if (_economy.fluct == -12) { |
|
2642 | 688 |
_economy.fluct = GB(Random(), 0, 8) + 312; |
0 | 689 |
AddNewsItem(STR_7074_RECESSION_OVER_UPTURN_IN, NEWS_FLAGS(NM_NORMAL,0,NT_ECONOMY,0), 0, 0); |
690 |
} |
|
691 |
} |
|
692 |
||
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
693 |
void StartupEconomy() |
0 | 694 |
{ |
695 |
_economy.interest_rate = _opt.diff.initial_interest; |
|
696 |
_economy.infl_amount = _opt.diff.initial_interest; |
|
697 |
_economy.infl_amount_pr = max(0, _opt.diff.initial_interest - 1); |
|
698 |
_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
|
699 |
_economy.fluct = GB(Random(), 0, 8) + 168; |
0 | 700 |
} |
701 |
||
2630 | 702 |
Pair SetupSubsidyDecodeParam(const Subsidy* s, bool mode) |
0 | 703 |
{ |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
704 |
TileIndex tile; |
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
705 |
TileIndex tile2; |
0 | 706 |
Pair tp; |
707 |
||
2272
fc701f21b2be
(svn r2794) Fix a comment and get rid of some parentheses using DeMorgan's law
tron
parents:
2261
diff
changeset
|
708 |
/* if mode is false, use the singular form */ |
6417
26acff62d001
(svn r8826) -Codechange: Replace _cargoc's separate arrays with a regular struct array (with accessor) and implement new initialization method using cargo labels.
peter1138
parents:
6324
diff
changeset
|
709 |
const CargoSpec *cs = GetCargo(s->cargo_type); |
26acff62d001
(svn r8826) -Codechange: Replace _cargoc's separate arrays with a regular struct array (with accessor) and implement new initialization method using cargo labels.
peter1138
parents:
6324
diff
changeset
|
710 |
SetDParam(0, mode ? cs->name_plural : cs->name); |
0 | 711 |
|
712 |
if (s->age < 12) { |
|
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
713 |
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
|
714 |
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
|
715 |
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
|
716 |
tile = GetIndustry(s->from)->xy; |
0 | 717 |
|
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
718 |
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
|
719 |
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
|
720 |
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
|
721 |
tile2 = GetIndustry(s->to)->xy; |
0 | 722 |
} 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
|
723 |
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
|
724 |
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
|
725 |
tile2 = GetTown(s->to)->xy; |
0 | 726 |
} |
727 |
} 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
|
728 |
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
|
729 |
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
|
730 |
tile = GetTown(s->from)->xy; |
0 | 731 |
|
2070
26c657906f25
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2063
diff
changeset
|
732 |
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
|
733 |
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
|
734 |
tile2 = GetTown(s->to)->xy; |
0 | 735 |
} |
736 |
} 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
|
737 |
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
|
738 |
tile = GetStation(s->from)->xy; |
0 | 739 |
|
2070
26c657906f25
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2063
diff
changeset
|
740 |
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
|
741 |
tile2 = GetStation(s->to)->xy; |
0 | 742 |
} |
743 |
||
744 |
tp.a = tile; |
|
745 |
tp.b = tile2; |
|
746 |
||
747 |
return tp; |
|
748 |
} |
|
749 |
||
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
|
750 |
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
|
751 |
{ |
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
|
752 |
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
|
753 |
|
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
|
754 |
for (s = _subsidies; s != endof(_subsidies); s++) { |
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
755 |
if (s->cargo_type != CT_INVALID && s->age < 12) { |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
756 |
const CargoSpec *cs = GetCargo(s->cargo_type); |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
757 |
if (((cs->town_effect == TE_PASSENGERS || cs->town_effect == TE_MAIL) && (index == s->from || index == s->to)) || |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
758 |
((cs->town_effect == TE_GOODS || cs->town_effect == TE_FOOD) && index == s->to)) { |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
759 |
s->cargo_type = CT_INVALID; |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
760 |
} |
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
|
761 |
} |
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
|
762 |
} |
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
|
763 |
} |
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
|
764 |
|
4330
7306bda145ab
(svn r6005) -Cleanup: introduce IndustryID and use it
rubidium
parents:
4329
diff
changeset
|
765 |
void DeleteSubsidyWithIndustry(IndustryID index) |
0 | 766 |
{ |
767 |
Subsidy *s; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
768 |
|
2952 | 769 |
for (s = _subsidies; s != endof(_subsidies); s++) { |
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
770 |
if (s->cargo_type != CT_INVALID && s->age < 12) { |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
771 |
const CargoSpec *cs = GetCargo(s->cargo_type); |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
772 |
if (cs->town_effect != TE_PASSENGERS && cs->town_effect != TE_MAIL && |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
773 |
(index == s->from || (cs->town_effect != TE_GOODS && cs->town_effect != TE_FOOD && index == s->to))) { |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
774 |
s->cargo_type = CT_INVALID; |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
775 |
} |
0 | 776 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
777 |
} |
0 | 778 |
} |
779 |
||
4330
7306bda145ab
(svn r6005) -Cleanup: introduce IndustryID and use it
rubidium
parents:
4329
diff
changeset
|
780 |
void DeleteSubsidyWithStation(StationID index) |
0 | 781 |
{ |
782 |
Subsidy *s; |
|
783 |
bool dirty = false; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
784 |
|
2952 | 785 |
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
|
786 |
if (s->cargo_type != CT_INVALID && s->age >= 12 && |
0 | 787 |
(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
|
788 |
s->cargo_type = CT_INVALID; |
0 | 789 |
dirty = true; |
790 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
791 |
} |
0 | 792 |
|
793 |
if (dirty) |
|
794 |
InvalidateWindow(WC_SUBSIDIES_LIST, 0); |
|
795 |
} |
|
796 |
||
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
797 |
struct FoundRoute { |
0 | 798 |
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
|
799 |
CargoID cargo; |
0 | 800 |
void *from; |
801 |
void *to; |
|
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
802 |
}; |
0 | 803 |
|
804 |
static void FindSubsidyPassengerRoute(FoundRoute *fr) |
|
805 |
{ |
|
806 |
Town *from,*to; |
|
807 |
||
808 |
fr->distance = (uint)-1; |
|
809 |
||
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
|
810 |
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
|
811 |
if (from == NULL || from->population < 400) return; |
0 | 812 |
|
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
|
813 |
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
|
814 |
if (from == to || to == NULL || to->population < 400 || to->pct_pass_transported > 42) |
0 | 815 |
return; |
816 |
||
1245
768d9bc95aaa
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1098
diff
changeset
|
817 |
fr->distance = DistanceManhattan(from->xy, to->xy); |
0 | 818 |
} |
819 |
||
820 |
static void FindSubsidyCargoRoute(FoundRoute *fr) |
|
821 |
{ |
|
822 |
Industry *i; |
|
9911
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
823 |
const IndustrySpec *ind; |
0 | 824 |
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
|
825 |
CargoID cargo; |
0 | 826 |
|
827 |
fr->distance = (uint)-1; |
|
828 |
||
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
|
829 |
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
|
830 |
if (i == NULL) return; |
9911
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
831 |
ind = GetIndustrySpec(i->type); |
0 | 832 |
|
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6445
diff
changeset
|
833 |
/* Randomize cargo type */ |
9911
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
834 |
if (HASBIT(Random(), 0) && ind->produced_cargo[1] != CT_INVALID) { |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
835 |
cargo = ind->produced_cargo[1]; |
9912
1ac8aac92385
(svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents:
9911
diff
changeset
|
836 |
trans = i->last_month_pct_transported[1]; |
1ac8aac92385
(svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents:
9911
diff
changeset
|
837 |
total = i->last_month_production[1]; |
0 | 838 |
} else { |
9911
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
839 |
cargo = ind->produced_cargo[0]; |
9912
1ac8aac92385
(svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents:
9911
diff
changeset
|
840 |
trans = i->last_month_pct_transported[0]; |
1ac8aac92385
(svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents:
9911
diff
changeset
|
841 |
total = i->last_month_production[0]; |
0 | 842 |
} |
843 |
||
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6445
diff
changeset
|
844 |
/* Quit if no production in this industry |
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6445
diff
changeset
|
845 |
* or if the cargo type is passengers |
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6445
diff
changeset
|
846 |
* or if the pct transported is already large enough */ |
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
847 |
if (total == 0 || trans > 42 || cargo == CT_INVALID) return; |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
848 |
|
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
849 |
const CargoSpec *cs = GetCargo(cargo); |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
850 |
if (cs->town_effect == TE_PASSENGERS) return; |
0 | 851 |
|
852 |
fr->cargo = cargo; |
|
853 |
||
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
854 |
if (cs->town_effect == TE_GOODS || cs->town_effect == TE_FOOD) { |
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6445
diff
changeset
|
855 |
/* 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
|
856 |
Town *t = GetRandomTown(); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
857 |
|
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6445
diff
changeset
|
858 |
/* 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
|
859 |
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
|
860 |
|
1245
768d9bc95aaa
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1098
diff
changeset
|
861 |
fr->distance = DistanceManhattan(i->xy, t->xy); |
0 | 862 |
fr->to = t; |
863 |
} else { |
|
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6445
diff
changeset
|
864 |
/* 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
|
865 |
Industry *i2 = GetRandomIndustry(); |
9911
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
866 |
if (i2 == NULL) { |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
867 |
return; |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
868 |
} |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
869 |
|
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
870 |
ind = GetIndustrySpec(i2->type); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
871 |
|
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6445
diff
changeset
|
872 |
/* The industry must accept the cargo */ |
9911
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
873 |
if (i == i2 || |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
874 |
(cargo != ind->accepts_cargo[0] && |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
875 |
cargo != ind->accepts_cargo[1] && |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
876 |
cargo != ind->accepts_cargo[2])) { |
0 | 877 |
return; |
9911
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
878 |
} |
1245
768d9bc95aaa
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1098
diff
changeset
|
879 |
fr->distance = DistanceManhattan(i->xy, i2->xy); |
0 | 880 |
fr->to = i2; |
881 |
} |
|
882 |
} |
|
883 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
884 |
static bool CheckSubsidyDuplicate(Subsidy *s) |
0 | 885 |
{ |
2630 | 886 |
const Subsidy* ss; |
0 | 887 |
|
2639 | 888 |
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
|
889 |
if (s != ss && |
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
890 |
ss->from == s->from && |
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
891 |
ss->to == s->to && |
0 | 892 |
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
|
893 |
s->cargo_type = CT_INVALID; |
0 | 894 |
return true; |
895 |
} |
|
896 |
} |
|
897 |
return false; |
|
898 |
} |
|
899 |
||
239 | 900 |
|
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
901 |
static void SubsidyMonthlyHandler() |
0 | 902 |
{ |
903 |
Subsidy *s; |
|
904 |
Pair pair; |
|
905 |
Station *st; |
|
906 |
uint n; |
|
907 |
FoundRoute fr; |
|
908 |
bool modified = false; |
|
909 |
||
2952 | 910 |
for (s = _subsidies; s != endof(_subsidies); s++) { |
911 |
if (s->cargo_type == CT_INVALID) continue; |
|
0 | 912 |
|
913 |
if (s->age == 12-1) { |
|
914 |
pair = SetupSubsidyDecodeParam(s, 1); |
|
915 |
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
|
916 |
s->cargo_type = CT_INVALID; |
0 | 917 |
modified = true; |
918 |
} 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
|
919 |
st = GetStation(s->to); |
0 | 920 |
if (st->owner == _local_player) { |
921 |
pair = SetupSubsidyDecodeParam(s, 1); |
|
922 |
AddNewsItem(STR_202F_SUBSIDY_WITHDRAWN_SERVICE, NEWS_FLAGS(NM_NORMAL, NF_TILE, NT_SUBSIDIES, 0), pair.a, pair.b); |
|
923 |
} |
|
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 |
modified = true; |
926 |
} else { |
|
927 |
s->age++; |
|
928 |
} |
|
929 |
} |
|
930 |
||
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6445
diff
changeset
|
931 |
/* 25% chance to go on */ |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
932 |
if (CHANCE16(1,4)) { |
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6445
diff
changeset
|
933 |
/* Find a free slot*/ |
0 | 934 |
s = _subsidies; |
2469
1bfbb0dc0b75
(svn r2995) Replace 0xFF/0xFFFF with CT_INVALID/OWNER_SPECTATOR/INVALID_STATION where appropriate
tron
parents:
2436
diff
changeset
|
935 |
while (s->cargo_type != CT_INVALID) { |
0 | 936 |
if (++s == endof(_subsidies)) |
937 |
goto no_add; |
|
938 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
939 |
|
0 | 940 |
n = 1000; |
941 |
do { |
|
942 |
FindSubsidyPassengerRoute(&fr); |
|
943 |
if (fr.distance <= 70) { |
|
944 |
s->cargo_type = CT_PASSENGERS; |
|
945 |
s->from = ((Town*)fr.from)->index; |
|
946 |
s->to = ((Town*)fr.to)->index; |
|
947 |
goto add_subsidy; |
|
948 |
} |
|
949 |
FindSubsidyCargoRoute(&fr); |
|
950 |
if (fr.distance <= 70) { |
|
951 |
s->cargo_type = fr.cargo; |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
863
diff
changeset
|
952 |
s->from = ((Industry*)fr.from)->index; |
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
953 |
{ |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
954 |
const CargoSpec *cs = GetCargo(fr.cargo); |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
955 |
s->to = (cs->town_effect == TE_GOODS || cs->town_effect == TE_FOOD) ? ((Town*)fr.to)->index : ((Industry*)fr.to)->index; |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
956 |
} |
0 | 957 |
add_subsidy: |
958 |
if (!CheckSubsidyDuplicate(s)) { |
|
959 |
s->age = 0; |
|
960 |
pair = SetupSubsidyDecodeParam(s, 0); |
|
961 |
AddNewsItem(STR_2030_SERVICE_SUBSIDY_OFFERED, NEWS_FLAGS(NM_NORMAL, NF_TILE, NT_SUBSIDIES, 0), pair.a, pair.b); |
|
962 |
modified = true; |
|
963 |
break; |
|
964 |
} |
|
965 |
} |
|
239 | 966 |
} while (n--); |
0 | 967 |
} |
968 |
no_add:; |
|
969 |
if (modified) |
|
970 |
InvalidateWindow(WC_SUBSIDIES_LIST, 0); |
|
971 |
} |
|
972 |
||
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
|
973 |
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
|
974 |
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
|
975 |
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
|
976 |
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
|
977 |
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
|
978 |
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
|
979 |
SLE_CONDVAR(Subsidy, to, SLE_UINT16, 5, SL_MAX_VERSION), |
0 | 980 |
SLE_END() |
981 |
}; |
|
982 |
||
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
983 |
static void Save_SUBS() |
0 | 984 |
{ |
985 |
int i; |
|
986 |
Subsidy *s; |
|
987 |
||
2952 | 988 |
for (i = 0; i != lengthof(_subsidies); i++) { |
0 | 989 |
s = &_subsidies[i]; |
2469
1bfbb0dc0b75
(svn r2995) Replace 0xFF/0xFFFF with CT_INVALID/OWNER_SPECTATOR/INVALID_STATION where appropriate
tron
parents:
2436
diff
changeset
|
990 |
if (s->cargo_type != CT_INVALID) { |
0 | 991 |
SlSetArrayIndex(i); |
992 |
SlObject(s, _subsidies_desc); |
|
993 |
} |
|
994 |
} |
|
995 |
} |
|
996 |
||
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
997 |
static void Load_SUBS() |
0 | 998 |
{ |
999 |
int index; |
|
1000 |
while ((index = SlIterateArray()) != -1) |
|
1001 |
SlObject(&_subsidies[index], _subsidies_desc); |
|
1002 |
} |
|
1003 |
||
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
|
1004 |
int32 GetTransportedGoodsIncome(uint num_pieces, uint dist, byte transit_days, CargoID cargo_type) |
0 | 1005 |
{ |
6417
26acff62d001
(svn r8826) -Codechange: Replace _cargoc's separate arrays with a regular struct array (with accessor) and implement new initialization method using cargo labels.
peter1138
parents:
6324
diff
changeset
|
1006 |
const CargoSpec *cs = GetCargo(cargo_type); |
0 | 1007 |
byte f; |
1008 |
||
9908
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9907
diff
changeset
|
1009 |
/* Use callback to calculate cargo profit, if available */ |
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9907
diff
changeset
|
1010 |
if (HASBIT(cs->callback_mask, CBM_CARGO_PROFIT_CALC)) { |
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9907
diff
changeset
|
1011 |
uint32 var18 = min(dist, 0xFFFF) | (min(num_pieces, 0xFF) << 16) | (transit_days << 24); |
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9907
diff
changeset
|
1012 |
uint16 callback = GetCargoCallback(CBID_CARGO_PROFIT_CALC, 0, var18, cs); |
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9907
diff
changeset
|
1013 |
if (callback != CALLBACK_FAILED) { |
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9907
diff
changeset
|
1014 |
int result = GB(callback, 0, 14); |
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9907
diff
changeset
|
1015 |
|
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9907
diff
changeset
|
1016 |
/* Simulate a 15 bit signed value */ |
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9907
diff
changeset
|
1017 |
if (HASBIT(callback, 14)) result = 0x4000 - result; |
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9907
diff
changeset
|
1018 |
|
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9907
diff
changeset
|
1019 |
/* "The result should be a signed multiplier that gets multiplied |
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9907
diff
changeset
|
1020 |
* by the amount of cargo moved and the price factor, then gets |
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9907
diff
changeset
|
1021 |
* divided by 8192." */ |
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9907
diff
changeset
|
1022 |
return result * num_pieces * _cargo_payment_rates[cargo_type] / 8192; |
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9907
diff
changeset
|
1023 |
} |
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9907
diff
changeset
|
1024 |
} |
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9907
diff
changeset
|
1025 |
|
0 | 1026 |
/* zero the distance if it's the bank and very short transport. */ |
9906
6f41b8713b65
(svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents:
9903
diff
changeset
|
1027 |
if (_opt.landscape == LT_TEMPERATE && cs->label == 'VALU' && dist < 10) |
0 | 1028 |
dist = 0; |
1029 |
||
1030 |
f = 255; |
|
6417
26acff62d001
(svn r8826) -Codechange: Replace _cargoc's separate arrays with a regular struct array (with accessor) and implement new initialization method using cargo labels.
peter1138
parents:
6324
diff
changeset
|
1031 |
if (transit_days > cs->transit_days[0]) { |
26acff62d001
(svn r8826) -Codechange: Replace _cargoc's separate arrays with a regular struct array (with accessor) and implement new initialization method using cargo labels.
peter1138
parents:
6324
diff
changeset
|
1032 |
transit_days -= cs->transit_days[0]; |
0 | 1033 |
f -= transit_days; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
1034 |
|
6417
26acff62d001
(svn r8826) -Codechange: Replace _cargoc's separate arrays with a regular struct array (with accessor) and implement new initialization method using cargo labels.
peter1138
parents:
6324
diff
changeset
|
1035 |
if (transit_days > cs->transit_days[1]) { |
26acff62d001
(svn r8826) -Codechange: Replace _cargoc's separate arrays with a regular struct array (with accessor) and implement new initialization method using cargo labels.
peter1138
parents:
6324
diff
changeset
|
1036 |
transit_days -= cs->transit_days[1]; |
0 | 1037 |
|
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
|
1038 |
if (f < transit_days) { |
0 | 1039 |
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
|
1040 |
} else { |
0 | 1041 |
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
|
1042 |
} |
0 | 1043 |
} |
1044 |
} |
|
1045 |
if (f < 31) f = 31; |
|
1046 |
||
9907
3b068c3a1c74
(svn r9675) [gamebalance] -Sync: r9420:9520 from trunk
celestar
parents:
9906
diff
changeset
|
1047 |
return BIGMULSS(dist * f * num_pieces, _cargo_payment_rates[cargo_type], 21); |
0 | 1048 |
} |
1049 |
||
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
|
1050 |
static void DeliverGoodsToIndustry(TileIndex xy, CargoID cargo_type, int num_pieces) |
0 | 1051 |
{ |
9911
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1052 |
Industry *best = NULL; |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1053 |
Industry *ind; |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1054 |
const IndustrySpec *indspec; |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1055 |
uint best_dist; |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1056 |
uint accepted_cargo_index = 0; ///< unlikely value, just for warning removing |
0 | 1057 |
|
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6445
diff
changeset
|
1058 |
/* Check if there's an industry close to the station that accepts the cargo |
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6445
diff
changeset
|
1059 |
* XXX - Think of something better to |
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6445
diff
changeset
|
1060 |
* 1) Only deliver to industries which are withing the catchment radius |
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6445
diff
changeset
|
1061 |
* 2) Distribute between industries if more then one is present */ |
9911
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1062 |
best_dist = (_patches.station_spread + 8) * 2; |
830
8114845804c9
(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents:
820
diff
changeset
|
1063 |
FOR_ALL_INDUSTRIES(ind) { |
9911
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1064 |
indspec = GetIndustrySpec(ind->type); |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1065 |
uint i; |
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
|
1066 |
|
9911
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1067 |
if (indspec->produced_cargo[0] == CT_INVALID) continue; |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1068 |
|
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1069 |
for (i = 0; i < lengthof(indspec->accepts_cargo); i++) { |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1070 |
if (cargo_type == indspec->accepts_cargo[i] && |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1071 |
(indspec->input_cargo_multiplier[i][0] != 0 || indspec->input_cargo_multiplier[i][1] != 0)) { |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1072 |
break; |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1073 |
} |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1074 |
} |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1075 |
|
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1076 |
/* Check if matching cargo has been found */ |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1077 |
if (i == lengthof(indspec->accepts_cargo)) continue; |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1078 |
|
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1079 |
uint dist = DistanceManhattan(ind->xy, xy); |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1080 |
|
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1081 |
if (dist < best_dist) { |
0 | 1082 |
best = ind; |
9911
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1083 |
best_dist = dist; |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1084 |
accepted_cargo_index = i; |
0 | 1085 |
} |
1086 |
} |
|
1087 |
||
1088 |
/* Found one? */ |
|
1089 |
if (best != NULL) { |
|
9911
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1090 |
indspec = GetIndustrySpec(best->type); |
0 | 1091 |
best->was_cargo_delivered = true; |
9911
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1092 |
best->cargo_waiting[0] = min(best->cargo_waiting[0] + (num_pieces * indspec->input_cargo_multiplier[accepted_cargo_index][0] / 256), 0xFFFF); |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1093 |
best->cargo_waiting[1] = min(best->cargo_waiting[1] + (num_pieces * indspec->input_cargo_multiplier[accepted_cargo_index][1] / 256), 0xFFFF); |
0 | 1094 |
} |
1095 |
} |
|
1096 |
||
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
|
1097 |
static bool CheckSubsidised(Station *from, Station *to, CargoID cargo_type) |
0 | 1098 |
{ |
1099 |
Subsidy *s; |
|
1100 |
TileIndex xy; |
|
1101 |
Pair pair; |
|
1102 |
Player *p; |
|
1103 |
||
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6445
diff
changeset
|
1104 |
/* check if there is an already existing subsidy that applies to us */ |
2951 | 1105 |
for (s = _subsidies; s != endof(_subsidies); s++) { |
0 | 1106 |
if (s->cargo_type == cargo_type && |
1107 |
s->age >= 12 && |
|
1108 |
s->from == from->index && |
|
2951 | 1109 |
s->to == to->index) { |
0 | 1110 |
return true; |
2951 | 1111 |
} |
0 | 1112 |
} |
1113 |
||
1114 |
/* check if there's a new subsidy that applies.. */ |
|
2951 | 1115 |
for (s = _subsidies; s != endof(_subsidies); s++) { |
0 | 1116 |
if (s->cargo_type == cargo_type && s->age < 12) { |
1117 |
/* Check distance from source */ |
|
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
1118 |
const CargoSpec *cs = GetCargo(cargo_type); |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
1119 |
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
|
1120 |
xy = GetTown(s->from)->xy; |
0 | 1121 |
} else { |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
863
diff
changeset
|
1122 |
xy = (GetIndustry(s->from))->xy; |
0 | 1123 |
} |
2951 | 1124 |
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
|
1125 |
|
0 | 1126 |
/* Check distance from dest */ |
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
1127 |
switch (cs->town_effect) { |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
1128 |
case TE_PASSENGERS: |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
1129 |
case TE_MAIL: |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
1130 |
case TE_GOODS: |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
1131 |
case TE_FOOD: |
2989 | 1132 |
xy = GetTown(s->to)->xy; |
1133 |
break; |
|
1134 |
||
1135 |
default: |
|
1136 |
xy = GetIndustry(s->to)->xy; |
|
1137 |
break; |
|
0 | 1138 |
} |
2951 | 1139 |
if (DistanceMax(xy, to->xy) > 9) continue; |
0 | 1140 |
|
1141 |
/* Found a subsidy, change the values to indicate that it's in use */ |
|
1142 |
s->age = 12; |
|
1143 |
s->from = from->index; |
|
1144 |
s->to = to->index; |
|
1145 |
||
1146 |
/* Add a news item */ |
|
1147 |
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
|
1148 |
InjectDParam(2); |
0 | 1149 |
|
1962
51ee4f459268
(svn r2468) -Codechange: Got rid of DEREF_PLAYER and replaced it by GetPlayer
celestar
parents:
1935
diff
changeset
|
1150 |
p = GetPlayer(_current_player); |
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
1151 |
SetDParam(0, p->name_1); |
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
1152 |
SetDParam(1, p->name_2); |
0 | 1153 |
AddNewsItem( |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
1154 |
STR_2031_SERVICE_SUBSIDY_AWARDED + _opt.diff.subsidy_multiplier, |
0 | 1155 |
NEWS_FLAGS(NM_NORMAL, NF_TILE, NT_SUBSIDIES, 0), |
2951 | 1156 |
pair.a, pair.b |
1157 |
); |
|
0 | 1158 |
|
1159 |
InvalidateWindow(WC_SUBSIDIES_LIST, 0); |
|
1160 |
return true; |
|
1161 |
} |
|
1162 |
} |
|
1163 |
return false; |
|
1164 |
} |
|
1165 |
||
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
|
1166 |
static int32 DeliverGoods(int num_pieces, CargoID cargo_type, StationID source, StationID dest, TileIndex source_tile, byte days_in_transit) |
0 | 1167 |
{ |
1168 |
bool subsidised; |
|
1169 |
Station *s_from, *s_to; |
|
1170 |
int32 profit; |
|
1171 |
||
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3655
diff
changeset
|
1172 |
assert(num_pieces > 0); |
0 | 1173 |
|
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6445
diff
changeset
|
1174 |
/* Update player statistics */ |
0 | 1175 |
{ |
1962
51ee4f459268
(svn r2468) -Codechange: Got rid of DEREF_PLAYER and replaced it by GetPlayer
celestar
parents:
1935
diff
changeset
|
1176 |
Player *p = GetPlayer(_current_player); |
0 | 1177 |
p->cur_economy.delivered_cargo += num_pieces; |
1178 |
SETBIT(p->cargo_types, cargo_type); |
|
1179 |
} |
|
1180 |
||
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6445
diff
changeset
|
1181 |
/* Get station pointers. */ |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
863
diff
changeset
|
1182 |
s_from = GetStation(source); |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
863
diff
changeset
|
1183 |
s_to = GetStation(dest); |
0 | 1184 |
|
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6445
diff
changeset
|
1185 |
/* Check if a subsidy applies. */ |
0 | 1186 |
subsidised = CheckSubsidised(s_from, s_to, cargo_type); |
1187 |
||
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6445
diff
changeset
|
1188 |
/* Increase town's counter for some special goods types */ |
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
1189 |
const CargoSpec *cs = GetCargo(cargo_type); |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
1190 |
if (cs->town_effect == TE_FOOD) s_to->town->new_act_food += num_pieces; |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
1191 |
if (cs->town_effect == TE_WATER) s_to->town->new_act_water += num_pieces; |
0 | 1192 |
|
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6445
diff
changeset
|
1193 |
/* Give the goods to the industry. */ |
0 | 1194 |
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
|
1195 |
|
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6445
diff
changeset
|
1196 |
/* 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
|
1197 |
profit = GetTransportedGoodsIncome(num_pieces, DistanceManhattan(source_tile, s_to->xy), days_in_transit, cargo_type); |
0 | 1198 |
|
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6445
diff
changeset
|
1199 |
/* Modify profit if a subsidy is in effect */ |
0 | 1200 |
if (subsidised) { |
2989 | 1201 |
switch (_opt.diff.subsidy_multiplier) { |
3655
ed8ce86fb219
(svn r4570) - Fix: subsidy calculation was too high, broken in r3564
peter1138
parents:
3613
diff
changeset
|
1202 |
case 0: profit += profit >> 1; break; |
ed8ce86fb219
(svn r4570) - Fix: subsidy calculation was too high, broken in r3564
peter1138
parents:
3613
diff
changeset
|
1203 |
case 1: profit *= 2; break; |
ed8ce86fb219
(svn r4570) - Fix: subsidy calculation was too high, broken in r3564
peter1138
parents:
3613
diff
changeset
|
1204 |
case 2: profit *= 3; break; |
ed8ce86fb219
(svn r4570) - Fix: subsidy calculation was too high, broken in r3564
peter1138
parents:
3613
diff
changeset
|
1205 |
default: profit *= 4; break; |
0 | 1206 |
} |
1207 |
} |
|
1208 |
||
1209 |
return profit; |
|
1210 |
} |
|
1211 |
||
9911
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1212 |
/** |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1213 |
* Performs the vehicle payment _and_ marks the vehicle to be unloaded. |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1214 |
* @param front_v the vehicle to be unloaded |
523
1184a22723ad
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1215 |
*/ |
9911
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1216 |
void VehiclePayment(Vehicle *front_v) |
2951 | 1217 |
{ |
9911
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1218 |
int result = 0; |
523
1184a22723ad
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1219 |
|
9911
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1220 |
int profit = 0; |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1221 |
int total_veh_profit = 0; // accumulates the profit across the vehicle chain (used by trains) |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1222 |
int32 route_profit = 0; // the grand total amount for the route. A-D of transfer chain A-B-C-D |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1223 |
int virtual_profit = 0; // virtual profit of one vehicle element for feeder systems |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1224 |
int virtual_profit_total = 0; // virtual profit for entire vehicle chain |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1225 |
int total_cargo_feeder_share = 0; // the feeder cash amount for the goods being loaded/unloaded in this load step |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1226 |
|
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1227 |
int all_vehicles_cargo_feeder_share = front_v->cargo_feeder_share; // used to hold transfer value of complete vehicle chain - used by trains |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1228 |
|
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1229 |
StationID last_visited = front_v->last_station_visited; |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1230 |
Station *st = GetStation(last_visited); |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1231 |
|
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1232 |
/* The owner of the train wants to be paid */ |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1233 |
PlayerID old_player = _current_player; |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1234 |
_current_player = front_v->owner; |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1235 |
|
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1236 |
/* At this moment loading cannot be finished */ |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1237 |
CLRBIT(front_v->vehicle_flags, VF_LOADING_FINISHED); |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1238 |
|
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1239 |
/* Start unloading in at the first possible moment */ |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1240 |
front_v->load_unload_time_rem = 1; |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1241 |
|
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1242 |
for (Vehicle *v = front_v; v != NULL; v = v->next) { |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1243 |
/* No cargo to unload */ |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1244 |
if (v->cargo_cap == 0 || v->cargo_count == 0) continue; |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1245 |
|
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1246 |
/* All cargo has already been paid for, no need to pay again */ |
9913
e79cd19772dd
(svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents:
9912
diff
changeset
|
1247 |
if (v->cargo_count == v->cargo_paid_for) { |
e79cd19772dd
(svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents:
9912
diff
changeset
|
1248 |
SETBIT(v->vehicle_flags, VF_CARGO_UNLOADING); |
e79cd19772dd
(svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents:
9912
diff
changeset
|
1249 |
continue; |
e79cd19772dd
(svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents:
9912
diff
changeset
|
1250 |
} |
9911
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1251 |
|
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1252 |
GoodsEntry *ge = &st->goods[v->cargo_type]; |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1253 |
|
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1254 |
if (v->cargo_source != last_visited && |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1255 |
HASBIT(ge->waiting_acceptance, 15) && |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1256 |
(front_v->current_order.flags & OF_TRANSFER) == 0) { |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1257 |
/* Deliver goods to the station */ |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1258 |
st->time_since_unload = 0; |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1259 |
|
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1260 |
/* handle end of route payment */ |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1261 |
profit += DeliverGoods(v->cargo_count - v->cargo_paid_for, v->cargo_type, v->cargo_source, last_visited, v->cargo_source_xy, v->cargo_days); |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1262 |
v->cargo_paid_for = v->cargo_count; |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1263 |
route_profit = profit; // display amount paid for final route delivery, A-D of a chain A-B-C-D |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1264 |
total_veh_profit = profit - all_vehicles_cargo_feeder_share; // whole vehicle is not payed for transfers picked up earlier |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1265 |
total_cargo_feeder_share = -all_vehicles_cargo_feeder_share; // total of transfer fees in vehicle chain needs to be zero at end of unload |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1266 |
|
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1267 |
v->cargo_feeder_share = 0; // clear transfer cost per vehicle |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1268 |
result |= 1; |
9913
e79cd19772dd
(svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents:
9912
diff
changeset
|
1269 |
|
e79cd19772dd
(svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents:
9912
diff
changeset
|
1270 |
SETBIT(v->vehicle_flags, VF_CARGO_UNLOADING); |
9911
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1271 |
} else if (front_v->current_order.flags & (OF_UNLOAD | OF_TRANSFER)) { |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1272 |
if ((front_v->current_order.flags & OF_TRANSFER) != 0) { |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1273 |
virtual_profit = GetTransportedGoodsIncome( |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1274 |
v->cargo_count - v->cargo_paid_for, |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1275 |
/* pay transfer vehicle for only the part of transfer it has done: ie. cargo_loaded_at_xy to here */ |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1276 |
DistanceManhattan(v->cargo_loaded_at_xy, GetStation(last_visited)->xy), |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1277 |
v->cargo_days, |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1278 |
v->cargo_type); |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1279 |
|
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1280 |
front_v->profit_this_year += virtual_profit; |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1281 |
ge->feeder_profit += v->cargo_feeder_share + virtual_profit; // transfer cargo transfer fees to station |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1282 |
total_cargo_feeder_share -= v->cargo_feeder_share; // accumulate deduction of feeder shares |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1283 |
v->cargo_feeder_share = 0; // clear transfer cost |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1284 |
|
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1285 |
/* keep total of cargo unloaded (pending) for accurate cargoshare calculation on load */ |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1286 |
SB(ge->unload_pending, 0, 12, GB(ge->unload_pending, 0, 12) + v->cargo_count); |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1287 |
|
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1288 |
virtual_profit_total += virtual_profit; // accumulate transfer profits for whole vehicle |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1289 |
v->cargo_paid_for = v->cargo_count; // record how much of the cargo has been paid for to eliminate double counting |
2951 | 1290 |
} |
9911
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1291 |
result |= 2; |
9913
e79cd19772dd
(svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents:
9912
diff
changeset
|
1292 |
|
e79cd19772dd
(svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents:
9912
diff
changeset
|
1293 |
SETBIT(v->vehicle_flags, VF_CARGO_UNLOADING); |
523
1184a22723ad
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1294 |
} |
1184a22723ad
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1295 |
} |
1184a22723ad
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1296 |
|
9911
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1297 |
/* Ensure a negative total is only applied to the vehicle if there is value to reduce. */ |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1298 |
front_v->cargo_feeder_share = max(front_v->cargo_feeder_share + total_cargo_feeder_share, 0); |
523
1184a22723ad
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1299 |
|
9911
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1300 |
if (virtual_profit_total > 0) { |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1301 |
ShowFeederIncomeAnimation(front_v->x_pos, front_v->y_pos, front_v->z_pos, virtual_profit_total); |
523
1184a22723ad
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1302 |
} |
1184a22723ad
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1303 |
|
9911
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1304 |
if (route_profit != 0) { |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1305 |
front_v->profit_this_year += total_veh_profit; |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1306 |
SubtractMoneyFromPlayer(-route_profit); |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1307 |
|
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1308 |
if (IsLocalPlayer() && !PlayVehicleSound(front_v, VSE_LOAD_UNLOAD)) { |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1309 |
SndPlayVehicleFx(SND_14_CASHTILL, front_v); |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1310 |
} |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1311 |
|
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1312 |
ShowCostOrIncomeAnimation(front_v->x_pos, front_v->y_pos, front_v->z_pos, -total_veh_profit); |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1313 |
} |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1314 |
|
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1315 |
_current_player = old_player; |
523
1184a22723ad
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1316 |
} |
1184a22723ad
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1317 |
|
9911
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1318 |
/** |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1319 |
* Loads/unload the vehicle if possible. |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1320 |
* @param v the vehicle to be (un)loaded |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1321 |
* @param cargo_left the amount of each cargo type that is |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1322 |
* virtually left on the platform to be |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1323 |
* picked up by another vehicle when all |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1324 |
* previous vehicles have loaded. |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1325 |
*/ |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1326 |
static void LoadUnloadVehicle(Vehicle *v, int *cargo_left) |
0 | 1327 |
{ |
9911
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1328 |
assert(v->current_order.type == OT_LOADING); |
6524 | 1329 |
|
9911
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1330 |
/* We have not waited enough time till the next round of loading/unloading */ |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1331 |
if (--v->load_unload_time_rem != 0) { |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1332 |
if (_patches.improved_load && HASBIT(v->current_order.flags, OFB_FULL_LOAD)) { |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1333 |
/* 'Reserve' this cargo for this vehicle, because we were first. */ |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1334 |
for (; v != NULL; v = v->next) { |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1335 |
if (v->cargo_cap != 0) cargo_left[v->cargo_type] -= v->cargo_cap - v->cargo_count; |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1336 |
} |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1337 |
} |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1338 |
return; |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1339 |
} |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1340 |
|
9912
1ac8aac92385
(svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents:
9911
diff
changeset
|
1341 |
if (v->type == VEH_TRAIN && !IsTileType(v->tile, MP_STATION)) { |
1ac8aac92385
(svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents:
9911
diff
changeset
|
1342 |
/* The train reversed in the station. Take the "easy" way |
1ac8aac92385
(svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents:
9911
diff
changeset
|
1343 |
* out and let the train just leave as it always did. */ |
1ac8aac92385
(svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents:
9911
diff
changeset
|
1344 |
SETBIT(v->vehicle_flags, VF_LOADING_FINISHED); |
1ac8aac92385
(svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents:
9911
diff
changeset
|
1345 |
return; |
1ac8aac92385
(svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents:
9911
diff
changeset
|
1346 |
} |
1ac8aac92385
(svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents:
9911
diff
changeset
|
1347 |
|
9911
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1348 |
int unloading_time = 0; |
0 | 1349 |
Vehicle *u = v; |
1350 |
int result = 0; |
|
9911
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1351 |
int cap; |
0 | 1352 |
|
9911
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1353 |
bool completely_empty = true; |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1354 |
bool anything_unloaded = false; |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1355 |
bool anything_loaded = false; |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1356 |
uint32 cargo_not_full = 0; |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1357 |
uint32 cargo_full = 0; |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1358 |
int total_cargo_feeder_share = 0; // the feeder cash amount for the goods being loaded/unloaded in this load step |
0 | 1359 |
|
1360 |
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
|
1361 |
|
6524 | 1362 |
StationID last_visited = v->last_station_visited; |
1363 |
Station *st = GetStation(last_visited); |
|
1364 |
||
9911
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1365 |
for (; v != NULL; v = v->next) { |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1366 |
if (v->cargo_cap == 0) continue; |
0 | 1367 |
|
9911
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1368 |
byte load_amount = EngInfo(v->engine_type)->load_amount; |
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
1369 |
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
|
1370 |
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
|
1371 |
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
|
1372 |
} |
2639 | 1373 |
|
9911
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1374 |
GoodsEntry *ge = &st->goods[v->cargo_type]; |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1375 |
int count = GB(ge->waiting_acceptance, 0, 12); |
5211
651c9272ad22
(svn r7326) -Feature: Add support for gradual (un)loading of vehicles (Maedhros)
peter1138
parents:
5077
diff
changeset
|
1376 |
|
9911
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1377 |
if (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
|
1378 |
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
|
1379 |
|
2639 | 1380 |
if (v->cargo_source != last_visited && ge->waiting_acceptance & 0x8000 && !(u->current_order.flags & OF_TRANSFER)) { |
0 | 1381 |
result |= 1; |
2639 | 1382 |
} else if (u->current_order.flags & (OF_UNLOAD | OF_TRANSFER)) { |
9911
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1383 |
if (count == 0) { |
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6445
diff
changeset
|
1384 |
/* No goods waiting at station */ |
9911
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1385 |
ge->enroute_time = v->cargo_days; |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1386 |
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
|
1387 |
ge->enroute_from_xy = v->cargo_source_xy; |
0 | 1388 |
} else { |
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6445
diff
changeset
|
1389 |
/* 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
|
1390 |
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
|
1391 |
|
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
|
1392 |
if (last_visited != ge->enroute_from) { |
9911
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1393 |
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
|
1394 |
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
|
1395 |
} |
0 | 1396 |
} |
9911
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1397 |
/* Update amount of waiting cargo. There is, however, no sense in |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1398 |
* updating the count variable because this vehicle will not be |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1399 |
* able to take the cargo. */ |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1400 |
SB(ge->waiting_acceptance, 0, 12, min(amount_unloaded + count, 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
|
1401 |
|
6524 | 1402 |
/* if there is not enough to unload from pending, ensure it does not go -ve |
1403 |
* else deduct amount actually unloaded from unload_pending */ |
|
6525
52bebe2b485e
(svn r8979) -Fix (r8978): unsigned vs signed comparisons.
rubidium
parents:
6524
diff
changeset
|
1404 |
SB(ge->unload_pending, 0, 12, max(GB(ge->unload_pending, 0, 12) - amount_unloaded, 0U)); |
6524 | 1405 |
|
0 | 1406 |
result |= 2; |
9911
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1407 |
} else { |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1408 |
/* The order changed while unloading (unset unload/transfer) or the |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1409 |
* station does not accept goods anymore. */ |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1410 |
CLRBIT(v->vehicle_flags, VF_CARGO_UNLOADING); |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1411 |
continue; |
0 | 1412 |
} |
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
|
1413 |
|
9911
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1414 |
/* Deliver goods to the station */ |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1415 |
st->time_since_unload = 0; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
1416 |
|
9911
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1417 |
unloading_time += amount_unloaded; |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1418 |
|
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1419 |
v->cargo_count -= amount_unloaded; |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1420 |
v->cargo_paid_for -= min(amount_unloaded, v->cargo_paid_for); |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1421 |
|
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1422 |
anything_unloaded = true; |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1423 |
if (_patches.gradual_loading && v->cargo_count != 0) { |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1424 |
completely_empty = false; |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1425 |
} else { |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1426 |
/* We have finished unloading (cargo count == 0) */ |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1427 |
CLRBIT(v->vehicle_flags, VF_CARGO_UNLOADING); |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1428 |
} |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1429 |
|
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1430 |
continue; |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1431 |
} |
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
|
1432 |
|
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
|
1433 |
/* 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
|
1434 |
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
|
1435 |
|
9911
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1436 |
/* Do not pick up goods that we unloaded */ |
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
1437 |
if (u->current_order.flags & OF_UNLOAD) continue; |
0 | 1438 |
|
1439 |
/* update stats */ |
|
9911
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1440 |
int t; |
2989 | 1441 |
switch (u->type) { |
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
1442 |
case VEH_TRAIN: t = u->u.rail.cached_max_speed; break; |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
1443 |
case VEH_ROAD: t = u->max_speed / 2; break; |
2989 | 1444 |
default: t = u->max_speed; break; |
1445 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
1446 |
|
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6445
diff
changeset
|
1447 |
/* if last speed is 0, we treat that as if no vehicle has ever visited the station. */ |
9911
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1448 |
ge->days_since_pickup = 0; |
2989 | 1449 |
ge->last_speed = min(t, 255); |
4329
9759d5c52010
(svn r6002) -Cleanup: remove the now redundant BASE_YEAR constant.
rubidium
parents:
4293
diff
changeset
|
1450 |
ge->last_age = _cur_year - v->build_year; |
0 | 1451 |
|
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6445
diff
changeset
|
1452 |
/* If there's goods waiting at the station, and the vehicle |
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6445
diff
changeset
|
1453 |
* 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
|
1454 |
if (count != 0 && |
0 | 1455 |
(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
|
1456 |
|
523
1184a22723ad
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1457 |
/* 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
|
1458 |
* the same cargo type at this station */ |
9912
1ac8aac92385
(svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents:
9911
diff
changeset
|
1459 |
if (_patches.improved_load && cargo_left[v->cargo_type] <= 0) { |
9911
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1460 |
SETBIT(cargo_not_full, v->cargo_type); |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1461 |
continue; |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1462 |
} |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1463 |
|
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1464 |
if (cap > count) cap = count; |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1465 |
if (_patches.gradual_loading) cap = min(cap, load_amount); |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1466 |
if (_patches.improved_load) { |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1467 |
/* Don't load stuff that is already 'reserved' for other vehicles */ |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1468 |
cap = min(cargo_left[v->cargo_type], cap); |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1469 |
cargo_left[v->cargo_type] -= cap; |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1470 |
} |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1471 |
|
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1472 |
if (v->cargo_count == 0) TriggerVehicle(v, VEHICLE_TRIGGER_NEW_CARGO); |
523
1184a22723ad
(svn r853) -Feature: Implement improved vehicle loading algorithm
tron
parents:
507
diff
changeset
|
1473 |
|
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
|
1474 |
/* 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
|
1475 |
* 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
|
1476 |
* 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
|
1477 |
* 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
|
1478 |
* the whole vehicle chain is really totally empty, the |
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6445
diff
changeset
|
1479 |
* 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
|
1480 |
* 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
|
1481 |
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
|
1482 |
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
|
1483 |
|
6524 | 1484 |
/* cargoshare is proportioned by the amount due to unload |
1485 |
* Otherwise, with gradual loading, 100% of credits would be taken immediately, |
|
1486 |
* even if the cargo volume represents a tiny percent of the whole. |
|
1487 |
* ge->unload_pending holds the amount that has been credited, but has not yet been unloaded. |
|
1488 |
*/ |
|
1489 |
int cargoshare = cap * 10000 / (ge->waiting_acceptance + ge->unload_pending); |
|
1490 |
int feeder_profit_share = ge->feeder_profit * cargoshare / 10000; |
|
0 | 1491 |
v->cargo_count += cap; |
1492 |
ge->waiting_acceptance -= cap; |
|
6524 | 1493 |
|
1494 |
total_cargo_feeder_share += feeder_profit_share; // store cost for later payment when cargo unloaded |
|
1495 |
v->cargo_loaded_at_xy = st->xy; // retains location of where the cargo was picked up for intermediate payments |
|
1496 |
||
1935
f43f062c9498
(svn r2441) -Feature: You can now give transfer order to set up feeder systems
celestar
parents:
1905
diff
changeset
|
1497 |
ge->feeder_profit -= feeder_profit_share; |
0 | 1498 |
unloading_time += cap; |
1499 |
st->time_since_load = 0; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
147
diff
changeset
|
1500 |
|
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6445
diff
changeset
|
1501 |
/* 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
|
1502 |
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
|
1503 |
v->cargo_source_xy = ge->enroute_from_xy; |
0 | 1504 |
v->cargo_days = ge->enroute_time; |
1505 |
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
|
1506 |
st->last_vehicle_type = v->type; |
0 | 1507 |
} |
9911
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1508 |
|
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1509 |
if (v->cargo_count == v->cargo_cap) { |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1510 |
SETBIT(cargo_full, v->cargo_type); |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1511 |
} else { |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1512 |
SETBIT(cargo_not_full, v->cargo_type); |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1513 |
} |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1514 |
} |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1515 |
|
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1516 |
/* We update these variables here, so gradual loading still fills |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1517 |
* all wagons at the same time instead of using the same 'improved' |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1518 |
* loading algorithm for the wagons (only fill wagon when there is |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1519 |
* enough to fill the previous wagons) */ |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1520 |
if (_patches.improved_load && HASBIT(u->current_order.flags, OFB_FULL_LOAD)) { |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1521 |
/* Update left cargo */ |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1522 |
for (v = u; v != NULL; v = v->next) { |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1523 |
if (v->cargo_cap != 0) cargo_left[v->cargo_type] -= v->cargo_cap - v->cargo_count; |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1524 |
} |
0 | 1525 |
} |
1526 |
||
5211
651c9272ad22
(svn r7326) -Feature: Add support for gradual (un)loading of vehicles (Maedhros)
peter1138
parents:
5077
diff
changeset
|
1527 |
v = u; |
1935
f43f062c9498
(svn r2441) -Feature: You can now give transfer order to set up feeder systems
celestar
parents:
1905
diff
changeset
|
1528 |
|
9911
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1529 |
v->cargo_feeder_share += total_cargo_feeder_share; |
6524 | 1530 |
|
9911
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1531 |
if (anything_loaded || anything_unloaded) { |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1532 |
if (_patches.gradual_loading) { |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1533 |
/* The time it takes to load one 'slice' of cargo or passengers depends |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1534 |
* on the vehicle type - the values here are those found in TTDPatch */ |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1535 |
const uint gradual_loading_wait_time[] = { 40, 20, 10, 20 }; |
5211
651c9272ad22
(svn r7326) -Feature: Add support for gradual (un)loading of vehicles (Maedhros)
peter1138
parents:
5077
diff
changeset
|
1536 |
|
9911
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1537 |
unloading_time = gradual_loading_wait_time[v->type]; |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1538 |
} |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1539 |
} else { |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1540 |
bool finished_loading = true; |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1541 |
if (HASBIT(v->current_order.flags, OFB_FULL_LOAD)) { |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1542 |
if (_patches.full_load_any) { |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1543 |
/* if the aircraft carries passengers and is NOT full, then |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1544 |
* continue loading, no matter how much mail is in */ |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1545 |
if ((v->type == VEH_AIRCRAFT && IsCargoInClass(v->cargo_type, CC_PASSENGERS) && v->cargo_cap != v->cargo_count) || |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1546 |
(cargo_not_full && (cargo_full & ~cargo_not_full) == 0)) { // There are stull non-full cargos |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1547 |
finished_loading = false; |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1548 |
} |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1549 |
} else if (cargo_not_full != 0) { |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1550 |
finished_loading = 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
|
1551 |
} |
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
|
1552 |
} |
9911
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1553 |
unloading_time = 20; |
0 | 1554 |
|
9911
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1555 |
SB(v->vehicle_flags, VF_LOADING_FINISHED, 1, finished_loading); |
2951 | 1556 |
} |
1935
f43f062c9498
(svn r2441) -Feature: You can now give transfer order to set up feeder systems
celestar
parents:
1905
diff
changeset
|
1557 |
|
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
1558 |
if (v->type == VEH_TRAIN) { |
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6445
diff
changeset
|
1559 |
/* Each platform tile is worth 2 rail vehicles. */ |
6324
ebf3649bd88f
(svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents:
6206
diff
changeset
|
1560 |
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
|
1561 |
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
|
1562 |
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
|
1563 |
unloading_time += (overhang * unloading_time) / 8; |
0 | 1564 |
} |
1565 |
} |
|
1566 |
||
1567 |
v->load_unload_time_rem = unloading_time; |
|
1568 |
||
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
|
1569 |
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
|
1570 |
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
|
1571 |
} |
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
|
1572 |
|
0 | 1573 |
if (result != 0) { |
9911
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1574 |
InvalidateWindow(v->GetVehicleListWindowClass(), v->owner); |
0 | 1575 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
9911
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1576 |
|
9912
1ac8aac92385
(svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents:
9911
diff
changeset
|
1577 |
st->MarkTilesDirty(true); |
9911
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1578 |
v->MarkDirty(); |
0 | 1579 |
|
2951 | 1580 |
if (result & 2) InvalidateWindow(WC_STATION_VIEW, last_visited); |
9911
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1581 |
} |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1582 |
} |
0 | 1583 |
|
9911
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1584 |
/** |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1585 |
* Load/unload the vehicles in this station according to the order |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1586 |
* they entered. |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1587 |
* @param st the station to do the loading/unloading for |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1588 |
*/ |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1589 |
void LoadUnloadStation(Station *st) |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1590 |
{ |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1591 |
int cargo_left[NUM_CARGO]; |
0 | 1592 |
|
9911
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1593 |
for (uint i = 0; i < NUM_CARGO; i++) cargo_left[i] = GB(st->goods[i].waiting_acceptance, 0, 12); |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1594 |
|
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1595 |
std::list<Vehicle *>::iterator iter; |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1596 |
for (iter = st->loading_vehicles.begin(); iter != st->loading_vehicles.end(); ++iter) { |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1597 |
Vehicle *v = *iter; |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1598 |
if (!(v->vehstatus & (VS_STOPPED | VS_CRASHED))) LoadUnloadVehicle(v, cargo_left); |
0 | 1599 |
} |
1600 |
} |
|
1601 |
||
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
1602 |
void PlayersMonthlyLoop() |
0 | 1603 |
{ |
1604 |
PlayersGenStatistics(); |
|
1605 |
PlayersPayInterest(); |
|
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6445
diff
changeset
|
1606 |
/* Reset the _current_player flag */ |
206 | 1607 |
_current_player = OWNER_NONE; |
0 | 1608 |
HandleEconomyFluctuations(); |
1609 |
SubsidyMonthlyHandler(); |
|
1610 |
} |
|
1611 |
||
1612 |
static void DoAcquireCompany(Player *p) |
|
1613 |
{ |
|
1614 |
Player *owner; |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
1615 |
int i; |
200
03b8104d1479
(svn r201) -Fix: [1025836] Company values bigger dan int32 were put to negative
truelight
parents:
193
diff
changeset
|
1616 |
int64 value; |
0 | 1617 |
|
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
1618 |
SetDParam(0, p->name_1); |
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
1619 |
SetDParam(1, p->name_2); |
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
523
diff
changeset
|
1620 |
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
|
1621 |
AddNewsItem( (StringID)(_current_player | NB_BMERGER), NEWS_FLAGS(NM_CALLBACK, 0, NT_COMPANY_INFO, DNC_BANKRUPCY),0,0); |
0 | 1622 |
|
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6445
diff
changeset
|
1623 |
/* 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
|
1624 |
PlayerID pi = p->index; |
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
1625 |
ChangeNetworkOwner(pi, _current_player); |
0 | 1626 |
ChangeOwnershipOfPlayerItems(pi, _current_player); |
1627 |
||
1628 |
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
|
1629 |
owner = GetPlayer(_current_player); |
0 | 1630 |
owner->current_loan += p->current_loan; |
1631 |
} |
|
1632 |
||
1633 |
value = CalculateCompanyValue(p) >> 2; |
|
2952 | 1634 |
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
|
1635 |
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
|
1636 |
owner = GetPlayer(p->share_owners[i]); |
0 | 1637 |
owner->money64 += value; |
1638 |
owner->yearly_expenses[0][EXPENSES_OTHER] += value; |
|
1639 |
UpdatePlayerMoney32(owner); |
|
1640 |
} |
|
1641 |
} |
|
1642 |
||
1643 |
p->is_active = false; |
|
1644 |
||
1645 |
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
|
1646 |
RebuildVehicleLists(); //Updates the open windows to add the newly acquired vehicles to the lists |
0 | 1647 |
} |
1648 |
||
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
1649 |
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
|
1650 |
|
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1707
diff
changeset
|
1651 |
/** 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
|
1652 |
* @param tile unused |
9908
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9907
diff
changeset
|
1653 |
* @param flags type of operation |
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1707
diff
changeset
|
1654 |
* @param p1 player to buy the shares from |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1707
diff
changeset
|
1655 |
* @param p2 unused |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1707
diff
changeset
|
1656 |
*/ |
9913
e79cd19772dd
(svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents:
9912
diff
changeset
|
1657 |
CommandCost CmdBuyShareInCompany(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 1658 |
{ |
1659 |
Player *p; |
|
9913
e79cd19772dd
(svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents:
9912
diff
changeset
|
1660 |
CommandCost cost; |
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1707
diff
changeset
|
1661 |
|
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1707
diff
changeset
|
1662 |
/* 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
|
1663 |
if (!IsValidPlayer((PlayerID)p1) || !_patches.allow_shares) return CMD_ERROR; |
0 | 1664 |
|
1665 |
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
|
1666 |
p = GetPlayer((PlayerID)p1); |
1019
6363b8a4273e
(svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents:
997
diff
changeset
|
1667 |
|
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1707
diff
changeset
|
1668 |
/* Protect new companies from hostile takeovers */ |
4329
9759d5c52010
(svn r6002) -Cleanup: remove the now redundant BASE_YEAR constant.
rubidium
parents:
4293
diff
changeset
|
1669 |
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
|
1670 |
|
599
80e49e323483
(svn r1023) -Fix: [Network] [ 1083692 ] You can no longer buy out a company in MP
truelight
parents:
555
diff
changeset
|
1671 |
/* 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
|
1672 |
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
|
1673 |
|
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1707
diff
changeset
|
1674 |
/* 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
|
1675 |
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
|
1676 |
|
0 | 1677 |
cost = CalculateCompanyValue(p) >> 2; |
1678 |
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
|
1679 |
PlayerByte* b = p->share_owners; |
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1707
diff
changeset
|
1680 |
int i; |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1707
diff
changeset
|
1681 |
|
4848
56549aa3e234
(svn r6774) -Codechange: Rename the badly named OWNER_SPECTATOR to PLAYER_SPECTATOR and
Darkvater
parents:
4845
diff
changeset
|
1682 |
while (*b != PLAYER_SPECTATOR) b++; /* share owners is guaranteed to contain at least one PLAYER_SPECTATOR */ |
0 | 1683 |
*b = _current_player; |
1684 |
||
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1707
diff
changeset
|
1685 |
for (i = 0; p->share_owners[i] == _current_player;) { |
0 | 1686 |
if (++i == 4) { |
1687 |
p->bankrupt_value = 0; |
|
1688 |
DoAcquireCompany(p); |
|
1689 |
break; |
|
1690 |
} |
|
1691 |
} |
|
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
|
1692 |
InvalidateWindow(WC_COMPANY, p1); |
0 | 1693 |
} |
1694 |
return cost; |
|
1695 |
} |
|
1696 |
||
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1707
diff
changeset
|
1697 |
/** 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
|
1698 |
* @param tile unused |
9908
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9907
diff
changeset
|
1699 |
* @param flags type of operation |
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1707
diff
changeset
|
1700 |
* @param p1 player to sell the shares from |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1707
diff
changeset
|
1701 |
* @param p2 unused |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1707
diff
changeset
|
1702 |
*/ |
9913
e79cd19772dd
(svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents:
9912
diff
changeset
|
1703 |
CommandCost CmdSellShareInCompany(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 1704 |
{ |
1705 |
Player *p; |
|
200
03b8104d1479
(svn r201) -Fix: [1025836] Company values bigger dan int32 were put to negative
truelight
parents:
193
diff
changeset
|
1706 |
int64 cost; |
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1707
diff
changeset
|
1707 |
|
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1707
diff
changeset
|
1708 |
/* 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
|
1709 |
if (!IsValidPlayer((PlayerID)p1) || !_patches.allow_shares) return CMD_ERROR; |
0 | 1710 |
|
1711 |
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
|
1712 |
p = GetPlayer((PlayerID)p1); |
0 | 1713 |
|
653
3c902c647791
(svn r1086) -Fix: [Network] [ 1084774 ] Fixed quick-share-sell bug
truelight
parents:
630
diff
changeset
|
1714 |
/* 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
|
1715 |
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
|
1716 |
|
0 | 1717 |
/* adjust it a little to make it less profitable to sell and buy */ |
1718 |
cost = CalculateCompanyValue(p) >> 2; |
|
1719 |
cost = -(cost - (cost >> 7)); |
|
1720 |
||
1721 |
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
|
1722 |
PlayerByte* b = p->share_owners; |
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6445
diff
changeset
|
1723 |
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
|
1724 |
*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
|
1725 |
InvalidateWindow(WC_COMPANY, p1); |
0 | 1726 |
} |
1727 |
return cost; |
|
1728 |
} |
|
1729 |
||
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1707
diff
changeset
|
1730 |
/** Buy up another company. |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1707
diff
changeset
|
1731 |
* 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
|
1732 |
* that company. |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1707
diff
changeset
|
1733 |
* @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
|
1734 |
* @param tile unused |
9908
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9907
diff
changeset
|
1735 |
* @param flags type of operation |
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1707
diff
changeset
|
1736 |
* @param p1 player/company to buy up |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1707
diff
changeset
|
1737 |
* @param p2 unused |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1707
diff
changeset
|
1738 |
*/ |
9913
e79cd19772dd
(svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents:
9912
diff
changeset
|
1739 |
CommandCost CmdBuyCompany(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 1740 |
{ |
1741 |
Player *p; |
|
9908
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9907
diff
changeset
|
1742 |
PlayerID pid = (PlayerID)p1; |
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1707
diff
changeset
|
1743 |
|
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1707
diff
changeset
|
1744 |
/* Disable takeovers in multiplayer games */ |
9908
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9907
diff
changeset
|
1745 |
if (!IsValidPlayer(pid) || _networking) return CMD_ERROR; |
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9907
diff
changeset
|
1746 |
|
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9907
diff
changeset
|
1747 |
/* Do not allow players to take over themselves */ |
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9907
diff
changeset
|
1748 |
if (pid == _current_player) return CMD_ERROR; |
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1707
diff
changeset
|
1749 |
|
0 | 1750 |
SET_EXPENSES_TYPE(EXPENSES_OTHER); |
9908
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9907
diff
changeset
|
1751 |
p = GetPlayer(pid); |
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1707
diff
changeset
|
1752 |
|
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1707
diff
changeset
|
1753 |
if (!p->is_ai) return CMD_ERROR; |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1707
diff
changeset
|
1754 |
|
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1707
diff
changeset
|
1755 |
if (flags & DC_EXEC) { |
0 | 1756 |
DoAcquireCompany(p); |
1757 |
} |
|
1758 |
return p->bankrupt_value; |
|
1759 |
} |
|
1760 |
||
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6445
diff
changeset
|
1761 |
/** Prices */ |
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
1762 |
static void SaveLoad_PRIC() |
0 | 1763 |
{ |
9903
dc85aaa556ae
(svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents:
9901
diff
changeset
|
1764 |
_eco->SaveLoad_PRIC(); |
0 | 1765 |
} |
1766 |
||
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6445
diff
changeset
|
1767 |
/** Cargo payment rates */ |
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
1768 |
static void SaveLoad_CAPR() |
0 | 1769 |
{ |
9909
dce9a6923bb7
(svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents:
9908
diff
changeset
|
1770 |
uint num_cargo = CheckSavegameVersion(55) ? 12 : NUM_CARGO; |
dce9a6923bb7
(svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents:
9908
diff
changeset
|
1771 |
SlArray(&_cargo_payment_rates, num_cargo, SLE_INT32); |
dce9a6923bb7
(svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents:
9908
diff
changeset
|
1772 |
SlArray(&_cargo_payment_rates_frac, num_cargo, SLE_UINT16); |
0 | 1773 |
} |
1774 |
||
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
|
1775 |
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
|
1776 |
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
|
1777 |
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
|
1778 |
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
|
1779 |
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
|
1780 |
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
|
1781 |
SLE_VAR(Economy, infl_amount_pr, SLE_UINT8), |
0 | 1782 |
SLE_END() |
1783 |
}; |
|
1784 |
||
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6445
diff
changeset
|
1785 |
/** Economy variables */ |
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6525
diff
changeset
|
1786 |
static void SaveLoad_ECMY() |
0 | 1787 |
{ |
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
|
1788 |
SlObject(&_economy, _economy_desc); |
0 | 1789 |
} |
1790 |
||
9901
a922f277ebfd
(svn r9408) [gamebalance] -Feature: The new economic data is stored in the savegame from now on. I'll try to make sure that intra-branch compability is maintained in the future for easier testing. Newer trunk games (as soon as trunk bumps the saveload revision) will not load however.
celestar
parents:
9895
diff
changeset
|
1791 |
/** Economy variables */ |
a922f277ebfd
(svn r9408) [gamebalance] -Feature: The new economic data is stored in the savegame from now on. I'll try to make sure that intra-branch compability is maintained in the future for easier testing. Newer trunk games (as soon as trunk bumps the saveload revision) will not load however.
celestar
parents:
9895
diff
changeset
|
1792 |
static void SaveLoad_ECO2() |
a922f277ebfd
(svn r9408) [gamebalance] -Feature: The new economic data is stored in the savegame from now on. I'll try to make sure that intra-branch compability is maintained in the future for easier testing. Newer trunk games (as soon as trunk bumps the saveload revision) will not load however.
celestar
parents:
9895
diff
changeset
|
1793 |
{ |
a922f277ebfd
(svn r9408) [gamebalance] -Feature: The new economic data is stored in the savegame from now on. I'll try to make sure that intra-branch compability is maintained in the future for easier testing. Newer trunk games (as soon as trunk bumps the saveload revision) will not load however.
celestar
parents:
9895
diff
changeset
|
1794 |
SlObject(_eco, CEconomy::eco_desc); |
a922f277ebfd
(svn r9408) [gamebalance] -Feature: The new economic data is stored in the savegame from now on. I'll try to make sure that intra-branch compability is maintained in the future for easier testing. Newer trunk games (as soon as trunk bumps the saveload revision) will not load however.
celestar
parents:
9895
diff
changeset
|
1795 |
} |
a922f277ebfd
(svn r9408) [gamebalance] -Feature: The new economic data is stored in the savegame from now on. I'll try to make sure that intra-branch compability is maintained in the future for easier testing. Newer trunk games (as soon as trunk bumps the saveload revision) will not load however.
celestar
parents:
9895
diff
changeset
|
1796 |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
1797 |
extern const ChunkHandler _economy_chunk_handlers[] = { |
0 | 1798 |
{ 'PRIC', SaveLoad_PRIC, SaveLoad_PRIC, CH_RIFF | CH_AUTO_LENGTH}, |
1799 |
{ '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
|
1800 |
{ 'SUBS', Save_SUBS, Load_SUBS, CH_ARRAY}, |
9901
a922f277ebfd
(svn r9408) [gamebalance] -Feature: The new economic data is stored in the savegame from now on. I'll try to make sure that intra-branch compability is maintained in the future for easier testing. Newer trunk games (as soon as trunk bumps the saveload revision) will not load however.
celestar
parents:
9895
diff
changeset
|
1801 |
{ 'ECO2', SaveLoad_ECO2, SaveLoad_ECO2, CH_RIFF}, |
0 | 1802 |
{ 'ECMY', SaveLoad_ECMY, SaveLoad_ECMY, CH_RIFF | CH_LAST}, |
1803 |
}; |