author | tron |
Wed, 24 Nov 2004 13:19:48 +0000 | |
changeset 500 | ef288590e096 |
parent 497 | 2d6d31173813 |
child 507 | 8aa8100b0b22 |
permissions | -rw-r--r-- |
0 | 1 |
#include "stdafx.h" |
2 |
#include "ttd.h" |
|
3 |
#include "station.h" |
|
4 |
#include "gfx.h" |
|
5 |
#include "window.h" |
|
6 |
#include "viewport.h" |
|
7 |
#include "command.h" |
|
8 |
#include "town.h" |
|
9 |
#include "vehicle.h" |
|
10 |
#include "news.h" |
|
11 |
#include "saveload.h" |
|
12 |
#include "economy.h" |
|
13 |
#include "player.h" |
|
14 |
#include "airport.h" |
|
405
6830ae7a0d5d
(svn r602) -newgrf: Move DrawTileSeqStruct & co and struct SpriteGroup to sprite.h (pasky)
darkvater
parents:
403
diff
changeset
|
15 |
#include "sprite.h" |
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
149
diff
changeset
|
16 |
#include "table/directions.h" |
0 | 17 |
|
18 |
// FIXME -- need to be embedded into Airport variable. Is dynamically |
|
19 |
// deducteable from graphics-tile array, so will not be needed |
|
20 |
const byte _airport_size_x[5] = {4, 6, 1, 6, 7 }; |
|
21 |
const byte _airport_size_y[5] = {3, 6, 1, 6, 7 }; |
|
22 |
||
23 |
void ShowAircraftDepotWindow(uint tile); |
|
24 |
extern void UpdateAirplanesOnNewStation(Station *st); |
|
25 |
||
26 |
static void MarkStationDirty(Station *st) |
|
27 |
{ |
|
28 |
if (st->sign.width_1 != 0) { |
|
29 |
InvalidateWindowWidget(WC_STATION_VIEW, st->index, 1); |
|
30 |
||
31 |
MarkAllViewportsDirty( |
|
32 |
st->sign.left - 6, |
|
33 |
st->sign.top, |
|
34 |
st->sign.left + (st->sign.width_1 << 2) + 12, |
|
35 |
st->sign.top + 48); |
|
36 |
} |
|
37 |
} |
|
38 |
||
39 |
#define CHECK_STATIONS_ERR ((Station*)-1) |
|
40 |
||
41 |
static Station *GetStationAround(uint tile, int w, int h, int closest_station) |
|
42 |
{ |
|
43 |
// check around to see if there's any stations there |
|
44 |
BEGIN_TILE_LOOP(tile_cur, w + 2, h + 2, tile - TILE_XY(1,1)) |
|
45 |
if (IS_TILETYPE(tile_cur, MP_STATION)) { |
|
46 |
int t; |
|
47 |
t = _map2[tile_cur]; |
|
28
635ad4c62bec
(svn r29) -Fix You cannot take ownership of an oilrig by building right next to it
darkvater
parents:
27
diff
changeset
|
48 |
{ |
635ad4c62bec
(svn r29) -Fix You cannot take ownership of an oilrig by building right next to it
darkvater
parents:
27
diff
changeset
|
49 |
Station *st = DEREF_STATION(t); |
635ad4c62bec
(svn r29) -Fix You cannot take ownership of an oilrig by building right next to it
darkvater
parents:
27
diff
changeset
|
50 |
// you cannot take control of an oilrig!! |
635ad4c62bec
(svn r29) -Fix You cannot take ownership of an oilrig by building right next to it
darkvater
parents:
27
diff
changeset
|
51 |
if (st->airport_type == AT_OILRIG && st->facilities == (FACIL_AIRPORT|FACIL_DOCK)) |
635ad4c62bec
(svn r29) -Fix You cannot take ownership of an oilrig by building right next to it
darkvater
parents:
27
diff
changeset
|
52 |
continue; |
635ad4c62bec
(svn r29) -Fix You cannot take ownership of an oilrig by building right next to it
darkvater
parents:
27
diff
changeset
|
53 |
} |
635ad4c62bec
(svn r29) -Fix You cannot take ownership of an oilrig by building right next to it
darkvater
parents:
27
diff
changeset
|
54 |
|
0 | 55 |
if (closest_station == -1) { |
56 |
closest_station = t; |
|
57 |
} else if (closest_station != t) { |
|
58 |
_error_message = STR_3006_ADJOINS_MORE_THAN_ONE_EXISTING; |
|
59 |
return CHECK_STATIONS_ERR; |
|
60 |
} |
|
61 |
} |
|
62 |
END_TILE_LOOP(tile_cur, w + 2, h + 2, tile - TILE_XY(1,1)) |
|
63 |
return (closest_station == -1) ? NULL : DEREF_STATION(closest_station); |
|
64 |
} |
|
65 |
||
55
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
43
diff
changeset
|
66 |
TileIndex GetStationTileForVehicle(Vehicle *v, Station *st) |
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
43
diff
changeset
|
67 |
{ |
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
43
diff
changeset
|
68 |
switch (v->type) { |
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
43
diff
changeset
|
69 |
case VEH_Train: return st->train_tile; |
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
43
diff
changeset
|
70 |
case VEH_Aircraft: return st->airport_tile; |
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
43
diff
changeset
|
71 |
case VEH_Ship: return st->dock_tile; |
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
43
diff
changeset
|
72 |
case VEH_Road: return (v->cargo_type == CT_PASSENGERS) ? st->bus_tile : st->lorry_tile; |
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
43
diff
changeset
|
73 |
default: |
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
43
diff
changeset
|
74 |
assert(false); |
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
43
diff
changeset
|
75 |
return 0; |
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
43
diff
changeset
|
76 |
} |
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
43
diff
changeset
|
77 |
} |
0 | 78 |
|
79 |
static bool CheckStationSpreadOut(Station *st, uint tile, int w, int h) |
|
80 |
{ |
|
81 |
byte station_index = st->index; |
|
82 |
uint i; |
|
83 |
uint x1 = GET_TILE_X(tile); |
|
84 |
uint y1 = GET_TILE_Y(tile); |
|
85 |
uint x2 = x1 + w - 1; |
|
86 |
uint y2 = y1 + h - 1; |
|
87 |
uint t; |
|
88 |
||
89 |
for(i=0; i!=TILES_X*TILES_Y; i++) { |
|
90 |
if (IS_TILETYPE(i, MP_STATION) && _map2[i] == station_index) { |
|
91 |
t = GET_TILE_X(i); |
|
92 |
if (t < x1) x1 = t; |
|
93 |
if (t > x2) x2 = t; |
|
94 |
||
95 |
t = GET_TILE_Y(i); |
|
96 |
if (t < y1) y1 = t; |
|
97 |
if (t > y2) y2 = t; |
|
98 |
} |
|
99 |
} |
|
100 |
||
101 |
if (y2-y1 >= _patches.station_spread || x2-x1 >= _patches.station_spread) { |
|
102 |
_error_message = STR_306C_STATION_TOO_SPREAD_OUT; |
|
103 |
return false; |
|
104 |
} |
|
105 |
||
106 |
return true; |
|
107 |
} |
|
108 |
||
109 |
static Station *AllocateStation() |
|
110 |
{ |
|
111 |
Station *st, *a_free = NULL; |
|
112 |
int count; |
|
113 |
int num_free = 0; |
|
114 |
int i; |
|
115 |
||
116 |
for(st = _stations, count = lengthof(_stations); count != 0; count--, st++) { |
|
117 |
if (st->xy == 0) { |
|
118 |
num_free++; |
|
119 |
if (a_free==NULL) |
|
120 |
a_free = st; |
|
121 |
} |
|
122 |
} |
|
123 |
||
124 |
if (a_free == NULL || |
|
125 |
(num_free < 30 && IS_HUMAN_PLAYER(_current_player))) { |
|
126 |
_error_message = STR_3008_TOO_MANY_STATIONS_LOADING; |
|
127 |
return NULL; |
|
128 |
} |
|
129 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
130 |
i = a_free->index; |
0 | 131 |
memset(a_free, 0, sizeof(Station)); |
132 |
a_free->index = i; |
|
133 |
return a_free; |
|
134 |
} |
|
135 |
||
136 |
||
137 |
static int CountMapSquareAround(uint tile, byte type, byte min, byte max) { |
|
138 |
static const TileIndexDiff _count_square_table[7*7+1] = { |
|
139 |
TILE_XY(-3,-3), 1, 1, 1, 1, 1, 1, |
|
140 |
TILE_XY(-6,1), 1, 1, 1, 1, 1, 1, |
|
141 |
TILE_XY(-6,1), 1, 1, 1, 1, 1, 1, |
|
142 |
TILE_XY(-6,1), 1, 1, 1, 1, 1, 1, |
|
143 |
TILE_XY(-6,1), 1, 1, 1, 1, 1, 1, |
|
144 |
TILE_XY(-6,1), 1, 1, 1, 1, 1, 1, |
|
145 |
TILE_XY(-6,1), 1, 1, 1, 1, 1, 1, |
|
146 |
0, |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
147 |
}; |
0 | 148 |
int j; |
149 |
const TileIndexDiff *p = _count_square_table; |
|
150 |
int num = 0; |
|
151 |
||
152 |
while ( (j=*p++) != 0 ) { |
|
153 |
tile = TILE_MASK(tile + j); |
|
154 |
||
155 |
if (IS_TILETYPE(tile, type) && _map5[tile] >= min && _map5[tile] <= max) |
|
156 |
num++; |
|
157 |
} |
|
158 |
||
159 |
return num; |
|
160 |
} |
|
161 |
||
162 |
#define M(x) ((x) - STR_SV_STNAME) |
|
163 |
||
164 |
static bool GenerateStationName(Station *st, uint tile, int flag) |
|
165 |
{ |
|
166 |
static const uint32 _gen_station_name_bits[] = { |
|
167 |
0, /* 0 */ |
|
168 |
1 << M(STR_SV_STNAME_AIRPORT), /* 1 */ |
|
169 |
1 << M(STR_SV_STNAME_OILFIELD), /* 2 */ |
|
170 |
1 << M(STR_SV_STNAME_DOCKS), /* 3 */ |
|
171 |
0x1FF << M(STR_SV_STNAME_BUOY_1), /* 4 */ |
|
172 |
1 << M(STR_SV_STNAME_HELIPORT), /* 5 */ |
|
173 |
}; |
|
174 |
||
175 |
Town *t = st->town; |
|
176 |
uint32 free_names = (uint32)-1; |
|
177 |
int found; |
|
178 |
uint z,z2; |
|
179 |
unsigned long tmp; |
|
180 |
||
181 |
{ |
|
182 |
Station *s; |
|
183 |
||
184 |
FOR_ALL_STATIONS(s) { |
|
185 |
if (s != st && s->xy != 0 && s->town==t) { |
|
186 |
uint str = M(s->string_id); |
|
187 |
if (str <= 0x20) { |
|
188 |
if (str == M(STR_SV_STNAME_FOREST)) |
|
189 |
str = M(STR_SV_STNAME_WOODS); |
|
190 |
CLRBIT(free_names, str); |
|
191 |
} |
|
192 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
193 |
} |
0 | 194 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
195 |
|
0 | 196 |
/* check default names */ |
197 |
tmp = free_names & _gen_station_name_bits[flag]; |
|
198 |
if (tmp != 0) { |
|
199 |
found = FindFirstBit(tmp); |
|
200 |
goto done; |
|
201 |
} |
|
202 |
||
203 |
/* check mine? */ |
|
204 |
if (HASBIT(free_names, M(STR_SV_STNAME_MINES))) { |
|
205 |
if (CountMapSquareAround(tile, MP_INDUSTRY, 0, 6) >= 2 || |
|
206 |
CountMapSquareAround(tile, MP_INDUSTRY, 0x64, 0x73) >= 2 || |
|
207 |
CountMapSquareAround(tile, MP_INDUSTRY, 0x2F, 0x33) >= 2 || |
|
208 |
CountMapSquareAround(tile, MP_INDUSTRY, 0x48, 0x58) >= 2 || |
|
209 |
CountMapSquareAround(tile, MP_INDUSTRY, 0x5B, 0x63) >= 2) { |
|
210 |
found = M(STR_SV_STNAME_MINES); |
|
211 |
goto done; |
|
212 |
} |
|
213 |
} |
|
214 |
||
215 |
/* check close enough to town to get central as name? */ |
|
216 |
if (GetTileDist1D(tile,t->xy) < 8) { |
|
217 |
found = M(STR_SV_STNAME); |
|
218 |
if (HASBIT(free_names, M(STR_SV_STNAME))) goto done; |
|
219 |
||
220 |
found = M(STR_SV_STNAME_CENTRAL); |
|
221 |
if (HASBIT(free_names, M(STR_SV_STNAME_CENTRAL))) goto done; |
|
222 |
} |
|
223 |
||
224 |
/* Check lakeside */ |
|
225 |
if (HASBIT(free_names, M(STR_SV_STNAME_LAKESIDE)) && |
|
226 |
!CheckDistanceFromEdge(tile, 20) && |
|
227 |
CountMapSquareAround(tile, MP_WATER, 0, 0) >= 5) { |
|
228 |
found = M(STR_SV_STNAME_LAKESIDE); |
|
229 |
goto done; |
|
230 |
} |
|
231 |
||
232 |
/* Check woods */ |
|
233 |
if (HASBIT(free_names, M(STR_SV_STNAME_WOODS)) && ( |
|
234 |
CountMapSquareAround(tile, MP_TREES, 0, 255) >= 8 || |
|
235 |
CountMapSquareAround(tile, MP_INDUSTRY, 0x10, 0x11) >= 2 )) { |
|
236 |
found = (_opt.landscape==LT_DESERT) ? M(STR_SV_STNAME_FOREST) : M(STR_SV_STNAME_WOODS); |
|
237 |
goto done; |
|
238 |
} |
|
239 |
||
240 |
/* check elevation compared to town */ |
|
241 |
z = GetTileZ(tile); |
|
242 |
z2 = GetTileZ(t->xy); |
|
243 |
if (z < z2) { |
|
244 |
found = M(STR_SV_STNAME_VALLEY); |
|
245 |
if (HASBIT(free_names, M(STR_SV_STNAME_VALLEY))) goto done; |
|
246 |
} else if (z > z2) { |
|
247 |
found = M(STR_SV_STNAME_HEIGHTS); |
|
248 |
if (HASBIT(free_names, M(STR_SV_STNAME_HEIGHTS))) goto done; |
|
249 |
} |
|
250 |
||
251 |
/* check direction compared to town */ |
|
252 |
{ |
|
253 |
static const int8 _direction_and_table[] = { |
|
254 |
~( (1<<M(STR_SV_STNAME_WEST)) | (1<<M(STR_SV_STNAME_EAST)) | (1<<M(STR_SV_STNAME_NORTH)) ), |
|
255 |
~( (1<<M(STR_SV_STNAME_SOUTH)) | (1<<M(STR_SV_STNAME_WEST)) | (1<<M(STR_SV_STNAME_NORTH)) ), |
|
256 |
~( (1<<M(STR_SV_STNAME_SOUTH)) | (1<<M(STR_SV_STNAME_EAST)) | (1<<M(STR_SV_STNAME_NORTH)) ), |
|
257 |
~( (1<<M(STR_SV_STNAME_SOUTH)) | (1<<M(STR_SV_STNAME_WEST)) | (1<<M(STR_SV_STNAME_EAST)) ), |
|
258 |
}; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
259 |
|
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
260 |
free_names &= _direction_and_table[ |
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
261 |
(GET_TILE_X(tile) < GET_TILE_X(t->xy)) + |
0 | 262 |
(GET_TILE_Y(tile) < GET_TILE_Y(t->xy))*2]; |
263 |
} |
|
264 |
||
265 |
tmp = free_names & ((1<<1)|(1<<2)|(1<<3)|(1<<4)|(1<<6)|(1<<7)|(1<<12)|(1<<26)|(1<<27)|(1<<28)|(1<<29)|(1<<30)); |
|
266 |
if (tmp == 0) { |
|
267 |
_error_message = STR_3007_TOO_MANY_STATIONS_LOADING; |
|
268 |
return false; |
|
269 |
} |
|
270 |
found = FindFirstBit(tmp); |
|
271 |
||
272 |
done: |
|
273 |
st->string_id = found + STR_SV_STNAME; |
|
274 |
return true; |
|
275 |
} |
|
276 |
#undef M |
|
277 |
||
278 |
static Station *GetClosestStationFromTile(uint tile, uint threshold, byte owner) |
|
279 |
{ |
|
280 |
Station *st, *best_station = NULL; |
|
281 |
uint cur_dist; |
|
282 |
||
283 |
FOR_ALL_STATIONS(st) { |
|
284 |
cur_dist = GetTileDist(tile, st->xy); |
|
285 |
if (cur_dist < threshold && (owner == 0xFF || st->owner == owner)) { |
|
286 |
threshold = cur_dist; |
|
287 |
best_station = st; |
|
288 |
} |
|
289 |
} |
|
290 |
||
291 |
return best_station; |
|
292 |
} |
|
293 |
||
294 |
static void StationInitialize(Station *st, TileIndex tile) |
|
295 |
{ |
|
296 |
int i; |
|
297 |
GoodsEntry *ge; |
|
298 |
||
299 |
st->xy = tile; |
|
300 |
st->bus_tile = st->lorry_tile = st->airport_tile = st->dock_tile = st->train_tile = 0; |
|
301 |
st->had_vehicle_of_type = 0; |
|
302 |
st->time_since_load = 255; |
|
303 |
st->time_since_unload = 255; |
|
304 |
st->delete_ctr = 0; |
|
305 |
st->facilities = 0; |
|
306 |
||
307 |
st->last_vehicle = INVALID_VEHICLE; |
|
308 |
||
309 |
for(i=0,ge=st->goods; i!=NUM_CARGO; i++, ge++) { |
|
310 |
ge->waiting_acceptance = 0; |
|
311 |
ge->days_since_pickup = 0; |
|
312 |
ge->enroute_from = 0xFF; |
|
313 |
ge->rating = 175; |
|
314 |
ge->last_speed = 0; |
|
315 |
ge->last_age = 0xFF; |
|
316 |
} |
|
243
9a40daa560ae
(svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents:
222
diff
changeset
|
317 |
|
9a40daa560ae
(svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents:
222
diff
changeset
|
318 |
_global_station_sort_dirty = true; // build a new station |
0 | 319 |
} |
320 |
||
321 |
// Update the virtual coords needed to draw the station sign. |
|
322 |
// st = Station to update for. |
|
323 |
static void UpdateStationVirtCoord(Station *st) |
|
324 |
{ |
|
325 |
Point pt = RemapCoords2(GET_TILE_X(st->xy) * 16, GET_TILE_Y(st->xy) * 16); |
|
326 |
pt.y -= 32; |
|
327 |
if (st->facilities&FACIL_AIRPORT && st->airport_type==AT_OILRIG) pt.y -= 16; |
|
328 |
||
329 |
SET_DPARAM16(0, st->index); |
|
330 |
SET_DPARAM8(1, st->facilities); |
|
331 |
UpdateViewportSignPos(&st->sign, pt.x, pt.y, STR_305C_0); |
|
332 |
} |
|
333 |
||
334 |
// Update the virtual coords needed to draw the station sign for all stations. |
|
335 |
void UpdateAllStationVirtCoord() |
|
336 |
{ |
|
337 |
Station *st; |
|
338 |
FOR_ALL_STATIONS(st) { |
|
339 |
if (st->xy != 0) |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
340 |
UpdateStationVirtCoord(st); |
0 | 341 |
} |
342 |
} |
|
343 |
||
344 |
// Update the station virt coords while making the modified parts dirty. |
|
345 |
static void UpdateStationVirtCoordDirty(Station *st) |
|
346 |
{ |
|
347 |
MarkStationDirty(st); |
|
348 |
UpdateStationVirtCoord(st); |
|
349 |
MarkStationDirty(st); |
|
350 |
} |
|
351 |
||
352 |
// Get a mask of the cargo types that the station accepts. |
|
353 |
static uint GetAcceptanceMask(Station *st) |
|
354 |
{ |
|
355 |
uint mask = 0; |
|
356 |
uint cur_mask = 1; |
|
357 |
int i; |
|
358 |
for(i=0; i!=NUM_CARGO; i++,cur_mask*=2) { |
|
359 |
if (st->goods[i].waiting_acceptance & 0x8000) |
|
360 |
mask |= cur_mask; |
|
361 |
} |
|
362 |
return mask; |
|
363 |
} |
|
364 |
||
365 |
// Items contains the two cargo names that are to be accepted or rejected. |
|
366 |
// msg is the string id of the message to display. |
|
367 |
static void ShowRejectOrAcceptNews(Station *st, uint32 items, StringID msg) |
|
368 |
{ |
|
369 |
if (items) { |
|
370 |
SET_DPARAM32(2, items >> 16); |
|
371 |
SET_DPARAM32(1, items & 0xFFFF); |
|
372 |
SET_DPARAM16(0, st->index); |
|
373 |
AddNewsItem(msg + ((items >> 16)?1:0), NEWS_FLAGS(NM_SMALL, NF_VIEWPORT|NF_TILE, NT_ACCEPTANCE, 0), st->xy, 0); |
|
374 |
} |
|
375 |
} |
|
376 |
||
377 |
// Get a list of the cargo types being produced around the tile. |
|
378 |
void GetProductionAroundTiles(uint *produced, uint tile, int w, int h) |
|
379 |
{ |
|
380 |
int x,y; |
|
381 |
int x1,y1,x2,y2; |
|
382 |
int xc,yc; |
|
383 |
byte cargos[2]; |
|
384 |
||
385 |
memset(produced, 0, NUM_CARGO * sizeof(uint)); |
|
386 |
||
387 |
x = GET_TILE_X(tile); |
|
388 |
y = GET_TILE_Y(tile); |
|
389 |
||
390 |
// expand the region by 4 tiles on each side |
|
391 |
// while making sure that we remain inside the board. |
|
392 |
x2 = min(x + w+4, TILE_X_MAX+1); |
|
393 |
x1 = max(x-4, 0); |
|
394 |
||
395 |
y2 = min(y + h+4, TILE_Y_MAX+1); |
|
396 |
y1 = max(y-4, 0); |
|
397 |
||
398 |
assert(x1 < x2); |
|
399 |
assert(y1 < y2); |
|
400 |
assert(w > 0); |
|
401 |
assert(h > 0); |
|
402 |
||
403 |
yc = y1; |
|
404 |
do { |
|
405 |
xc = x1; |
|
406 |
do { |
|
407 |
if (!(IS_INSIDE_1D(xc, x, w) && IS_INSIDE_1D(yc, y, h))) { |
|
408 |
GetProducedCargoProc *gpc; |
|
409 |
uint tile = TILE_XY(xc, yc); |
|
410 |
gpc = _tile_type_procs[GET_TILETYPE(tile)]->get_produced_cargo_proc; |
|
411 |
if (gpc != NULL) { |
|
412 |
cargos[0] = cargos[1] = 0xFF; |
|
413 |
gpc(tile, cargos); |
|
414 |
if (cargos[0] != 0xFF) { |
|
415 |
produced[cargos[0]]++; |
|
416 |
if (cargos[1] != 0xFF) { |
|
417 |
produced[cargos[1]]++; |
|
418 |
} |
|
419 |
} |
|
420 |
} |
|
421 |
} |
|
422 |
} while (++xc != x2); |
|
423 |
} while (++yc != y2); |
|
424 |
} |
|
425 |
||
426 |
// Get a list of the cargo types that are accepted around the tile. |
|
427 |
void GetAcceptanceAroundTiles(uint *accepts, uint tile, int w, int h) |
|
428 |
{ |
|
429 |
int x,y; |
|
430 |
int x1,y1,x2,y2; |
|
431 |
int xc,yc; |
|
473
0da86c59e3ae
(svn r724) Remove restriction that a tile can only accept 3 cargo types.
tron
parents:
457
diff
changeset
|
432 |
|
0da86c59e3ae
(svn r724) Remove restriction that a tile can only accept 3 cargo types.
tron
parents:
457
diff
changeset
|
433 |
memset(accepts, 0, sizeof(AcceptedCargo)); |
0 | 434 |
|
435 |
x = GET_TILE_X(tile); |
|
436 |
y = GET_TILE_Y(tile); |
|
437 |
||
438 |
// expand the region by 4 tiles on each side |
|
439 |
// while making sure that we remain inside the board. |
|
440 |
x2 = min(x + w + 4, TILE_X_MAX+1); |
|
441 |
y2 = min(y + h + 4, TILE_Y_MAX+1); |
|
442 |
x1 = max(x-4, 0); |
|
443 |
y1 = max(y-4, 0); |
|
444 |
||
445 |
assert(x1 < x2); |
|
446 |
assert(y1 < y2); |
|
447 |
assert(w > 0); |
|
448 |
assert(h > 0); |
|
449 |
||
450 |
yc = y1; |
|
451 |
do { |
|
452 |
xc = x1; |
|
453 |
do { |
|
454 |
uint tile = TILE_XY(xc, yc); |
|
455 |
if (!IS_TILETYPE(tile, MP_STATION)) { |
|
473
0da86c59e3ae
(svn r724) Remove restriction that a tile can only accept 3 cargo types.
tron
parents:
457
diff
changeset
|
456 |
AcceptedCargo ac; |
0da86c59e3ae
(svn r724) Remove restriction that a tile can only accept 3 cargo types.
tron
parents:
457
diff
changeset
|
457 |
int i; |
0da86c59e3ae
(svn r724) Remove restriction that a tile can only accept 3 cargo types.
tron
parents:
457
diff
changeset
|
458 |
|
0da86c59e3ae
(svn r724) Remove restriction that a tile can only accept 3 cargo types.
tron
parents:
457
diff
changeset
|
459 |
GetAcceptedCargo(tile, ac); |
0da86c59e3ae
(svn r724) Remove restriction that a tile can only accept 3 cargo types.
tron
parents:
457
diff
changeset
|
460 |
for (i = 0; i < NUM_CARGO; ++i) |
0da86c59e3ae
(svn r724) Remove restriction that a tile can only accept 3 cargo types.
tron
parents:
457
diff
changeset
|
461 |
accepts[i] += ac[i]; |
0 | 462 |
} |
463 |
} while (++xc != x2); |
|
464 |
} while (++yc != y2); |
|
465 |
} |
|
466 |
||
467 |
// Update the acceptance for a station. |
|
468 |
// show_msg controls whether to display a message that acceptance was changed. |
|
469 |
static void UpdateStationAcceptance(Station *st, bool show_msg) |
|
470 |
{ |
|
471 |
uint old_acc, new_acc; |
|
472 |
TileIndex span[1+1+2+2+1]; |
|
473 |
int i; |
|
474 |
int min_x, min_y, max_x, max_y; |
|
475 |
uint accepts[NUM_CARGO]; |
|
476 |
||
477 |
// Don't update acceptance for a buoy |
|
478 |
if (st->had_vehicle_of_type & HVOT_BUOY) |
|
479 |
return; |
|
480 |
||
481 |
/* old accepted goods types */ |
|
482 |
old_acc = GetAcceptanceMask(st); |
|
483 |
||
484 |
// Put all the tiles that span an area in the table. |
|
485 |
span[3] = span[5] = 0; |
|
486 |
span[0] = st->bus_tile; |
|
487 |
span[1] = st->lorry_tile; |
|
488 |
span[2] = st->train_tile; |
|
489 |
if (st->train_tile != 0) { |
|
490 |
span[3] = st->train_tile + TILE_XY(st->trainst_w-1, st->trainst_h-1); |
|
491 |
} |
|
492 |
span[4] = st->airport_tile; |
|
493 |
if (st->airport_tile != 0) { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
494 |
span[5] = st->airport_tile + TILE_XY(_airport_size_x[st->airport_type]-1, _airport_size_y[st->airport_type]-1); |
0 | 495 |
} |
496 |
span[6] = st->dock_tile; |
|
497 |
||
498 |
// Construct a rectangle from those points |
|
499 |
min_x = min_y = 0x7FFFFFFF; |
|
500 |
max_x = max_y = 0; |
|
501 |
||
502 |
for(i=0; i!=7; i++) { |
|
503 |
uint tile = span[i]; |
|
504 |
if (tile) { |
|
505 |
min_x = min(min_x,GET_TILE_X(tile)); |
|
506 |
max_x = max(max_x,GET_TILE_X(tile)); |
|
507 |
min_y = min(min_y,GET_TILE_Y(tile)); |
|
508 |
max_y = max(max_y,GET_TILE_Y(tile)); |
|
509 |
} |
|
510 |
} |
|
511 |
||
512 |
// And retrieve the acceptance. |
|
513 |
if (max_x != 0) { |
|
514 |
GetAcceptanceAroundTiles(accepts, TILE_XY(min_x, min_y), max_x - min_x + 1, max_y-min_y+1); |
|
515 |
} else { |
|
516 |
memset(accepts, 0, sizeof(accepts)); |
|
517 |
} |
|
518 |
||
519 |
// Adjust in case our station only accepts fewer kinds of goods |
|
520 |
for(i=0; i!=NUM_CARGO; i++) { |
|
521 |
uint amt = min(accepts[i], 15); |
|
522 |
||
523 |
// Make sure the station can accept the goods type. |
|
524 |
if ((i != CT_PASSENGERS && !(st->facilities & (byte)~FACIL_BUS_STOP)) || |
|
525 |
(i == CT_PASSENGERS && !(st->facilities & (byte)~FACIL_TRUCK_STOP))) |
|
526 |
amt = 0; |
|
527 |
||
528 |
st->goods[i].waiting_acceptance = (st->goods[i].waiting_acceptance & ~0xF000) + (amt << 12); |
|
529 |
} |
|
530 |
||
531 |
// Only show a message in case the acceptance was actually changed. |
|
532 |
new_acc = GetAcceptanceMask(st); |
|
533 |
if (old_acc == new_acc) |
|
534 |
return; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
535 |
|
0 | 536 |
// show a message to report that the acceptance was changed? |
537 |
if (show_msg && st->owner == _local_player && st->facilities) { |
|
538 |
uint32 accept=0, reject=0; /* these contain two string ids each */ |
|
539 |
const StringID *str = _cargoc.names_s; |
|
540 |
||
541 |
do { |
|
542 |
if (new_acc & 1) { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
543 |
if (!(old_acc & 1)) accept = (accept << 16) | *str; |
0 | 544 |
} else { |
545 |
if (old_acc & 1) reject = (reject << 16) | *str; |
|
546 |
} |
|
547 |
} while (str++,(new_acc>>=1) != (old_acc>>=1)); |
|
548 |
||
549 |
ShowRejectOrAcceptNews(st, accept, STR_3040_NOW_ACCEPTS); |
|
550 |
ShowRejectOrAcceptNews(st, reject, STR_303E_NO_LONGER_ACCEPTS); |
|
551 |
} |
|
552 |
||
553 |
// redraw the station view since acceptance changed |
|
554 |
InvalidateWindowWidget(WC_STATION_VIEW, st->index, 4); |
|
555 |
} |
|
556 |
||
557 |
// This is called right after a station was deleted. |
|
558 |
// It checks if the whole station is free of substations, and if so, the station will be |
|
559 |
// deleted after a little while. |
|
560 |
static void DeleteStationIfEmpty(Station *st) { |
|
561 |
if (st->facilities == 0) { |
|
562 |
st->delete_ctr = 0; |
|
28
635ad4c62bec
(svn r29) -Fix You cannot take ownership of an oilrig by building right next to it
darkvater
parents:
27
diff
changeset
|
563 |
InvalidateWindow(WC_STATION_LIST, st->owner); |
27
87c8058a69b5
(svn r28) -Fix removing station merged with oilrig, will reset oilrigs ownership
darkvater
parents:
22
diff
changeset
|
564 |
} |
0 | 565 |
} |
566 |
||
567 |
// Tries to clear the given area. Returns the cost in case of success. |
|
568 |
// Or an error code if it failed. |
|
569 |
int32 CheckFlatLandBelow(uint tile, uint w, uint h, uint flags, uint invalid_dirs, int *station) |
|
570 |
{ |
|
571 |
int32 cost = 0, ret; |
|
572 |
||
573 |
uint tileh; |
|
574 |
int z, allowed_z = -1, flat_z; |
|
575 |
||
576 |
BEGIN_TILE_LOOP(tile_cur, w, h, tile) |
|
577 |
if (!EnsureNoVehicle(tile_cur)) |
|
578 |
return CMD_ERROR; |
|
579 |
||
580 |
tileh = GetTileSlope(tile_cur, &z); |
|
581 |
||
582 |
// steep slopes are completely prohibited |
|
84
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
71
diff
changeset
|
583 |
if (tileh & 0x10 || (((!_patches.ainew_active && _is_ai_player) || !_patches.build_on_slopes) && tileh != 0)) { |
0 | 584 |
_error_message = STR_0007_FLAT_LAND_REQUIRED; |
585 |
return CMD_ERROR; |
|
586 |
} |
|
587 |
||
588 |
flat_z = z; |
|
589 |
if (tileh) { |
|
590 |
// need to check so the entrance to the station is not pointing at a slope. |
|
591 |
if ((invalid_dirs&1 && !(tileh & 0xC) && (uint)w_cur == w) || |
|
592 |
(invalid_dirs&2 && !(tileh & 6) && h_cur == 1) || |
|
593 |
(invalid_dirs&4 && !(tileh & 3) && w_cur == 1) || |
|
594 |
(invalid_dirs&8 && !(tileh & 9) && (uint)h_cur == h)) { |
|
595 |
_error_message = STR_0007_FLAT_LAND_REQUIRED; |
|
596 |
return CMD_ERROR; |
|
597 |
} |
|
598 |
cost += _price.terraform; |
|
599 |
flat_z += 8; |
|
600 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
601 |
|
0 | 602 |
// get corresponding flat level and make sure that all parts of the station have the same level. |
603 |
if (allowed_z == -1) { |
|
604 |
// first tile |
|
605 |
allowed_z = flat_z; |
|
606 |
} else if (allowed_z != flat_z) { |
|
607 |
_error_message = STR_0007_FLAT_LAND_REQUIRED; |
|
608 |
return CMD_ERROR; |
|
609 |
} |
|
610 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
611 |
// if station is set, then we have special handling to allow building on top of already existing stations. |
0 | 612 |
// so station points to -1 if we can build on any station. or it points to a station if we're only allowed to build |
613 |
// on exactly that station. |
|
614 |
if (station && IS_TILETYPE(tile_cur, MP_STATION)) { |
|
615 |
if (_map5[tile] >= 8) { |
|
616 |
_error_message = STR_0007_FLAT_LAND_REQUIRED; |
|
617 |
return CMD_ERROR; |
|
618 |
} else { |
|
619 |
int st = _map2[tile_cur]; |
|
620 |
if (*station == -1) |
|
621 |
*station = st; |
|
622 |
else if (*station != st) { |
|
623 |
_error_message = STR_3006_ADJOINS_MORE_THAN_ONE_EXISTING; |
|
624 |
return CMD_ERROR; |
|
625 |
} |
|
626 |
} |
|
627 |
} else { |
|
628 |
ret = DoCommandByTile(tile_cur, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
|
629 |
if (ret == CMD_ERROR) return CMD_ERROR; |
|
630 |
cost += ret; |
|
631 |
} |
|
632 |
END_TILE_LOOP(tile_cur, w, h, tile) |
|
633 |
||
634 |
return cost; |
|
635 |
} |
|
636 |
||
637 |
static bool CanExpandRailroadStation(Station *st, uint *fin, int direction) |
|
638 |
{ |
|
639 |
uint curw = st->trainst_w, curh = st->trainst_h; |
|
640 |
uint tile = fin[0]; |
|
641 |
uint w = fin[1]; |
|
642 |
uint h = fin[2]; |
|
643 |
||
644 |
if (_patches.nonuniform_stations) { |
|
645 |
// determine new size of train station region.. |
|
646 |
int x = min(GET_TILE_X(st->train_tile), GET_TILE_X(tile)); |
|
647 |
int y = min(GET_TILE_Y(st->train_tile), GET_TILE_Y(tile)); |
|
648 |
curw = max(GET_TILE_X(st->train_tile) + curw, GET_TILE_X(tile) + w) - x; |
|
649 |
curh = max(GET_TILE_Y(st->train_tile) + curh, GET_TILE_Y(tile) + h) - y; |
|
650 |
tile = TILE_XY(x,y); |
|
651 |
} else { |
|
652 |
// check so the direction is the same |
|
653 |
if ((_map5[st->train_tile] & 1) != direction) return false; |
|
654 |
||
655 |
// check if the new station adjoins the old station in either direction |
|
656 |
if (curw == w && st->train_tile == tile + TILE_XY(0, h)) { |
|
657 |
// above |
|
658 |
curh += h; |
|
659 |
} else if (curw == w && st->train_tile == tile - TILE_XY(0, curh)) { |
|
660 |
// below |
|
661 |
tile -= TILE_XY(0, curh); |
|
662 |
curh += h; |
|
663 |
} else if (curh == h && st->train_tile == tile + TILE_XY(w, 0)) { |
|
664 |
// to the left |
|
665 |
curw += w; |
|
666 |
} else if (curh == h && st->train_tile == tile - TILE_XY(curw, 0)) { |
|
667 |
// to the right |
|
668 |
tile -= TILE_XY(curw, 0); |
|
669 |
curw += w; |
|
670 |
} else |
|
671 |
return false; |
|
672 |
} |
|
673 |
// make sure the final size is not too big. |
|
28
635ad4c62bec
(svn r29) -Fix You cannot take ownership of an oilrig by building right next to it
darkvater
parents:
27
diff
changeset
|
674 |
if (curw > _patches.station_spread || curh > _patches.station_spread) return false; |
0 | 675 |
|
676 |
// now tile contains the new value for st->train_tile |
|
677 |
// curw, curh contain the new value for width and height |
|
678 |
fin[0] = tile; |
|
679 |
fin[1] = curw; |
|
680 |
fin[2] = curh; |
|
681 |
return true; |
|
682 |
} |
|
683 |
||
684 |
static byte FORCEINLINE *CreateSingle(byte *layout, int n) |
|
685 |
{ |
|
686 |
int i = n; |
|
687 |
do *layout++ = 0; while (--i); |
|
688 |
layout[((n-1) >> 1)-n] = 2; |
|
689 |
return layout; |
|
690 |
} |
|
691 |
||
692 |
static byte FORCEINLINE *CreateMulti(byte *layout, int n, byte b) |
|
693 |
{ |
|
694 |
int i = n; |
|
695 |
do *layout++ = b; while (--i); |
|
696 |
if (n > 4) { |
|
697 |
layout[0-n] = 0; |
|
698 |
layout[n-1-n] = 0; |
|
699 |
} |
|
700 |
return layout; |
|
701 |
} |
|
702 |
||
703 |
// stolen from TTDPatch |
|
449
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
704 |
static void GetStationLayout(byte *layout, int numtracks, int plat_len, struct StationSpec *spec) |
0 | 705 |
{ |
449
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
706 |
if (spec != NULL && spec->lengths >= plat_len && spec->platforms[plat_len - 1] >= numtracks |
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
707 |
&& spec->layouts[plat_len - 1][numtracks - 1]) { |
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
708 |
/* Custom layout defined, follow it. */ |
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
709 |
memcpy(layout, spec->layouts[plat_len - 1][numtracks - 1], |
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
710 |
plat_len * numtracks); |
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
711 |
return; |
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
712 |
} |
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
713 |
|
0 | 714 |
if (plat_len == 1) { |
715 |
CreateSingle(layout, numtracks); |
|
716 |
} else { |
|
717 |
if (numtracks & 1) |
|
718 |
layout = CreateSingle(layout, plat_len); |
|
719 |
numtracks>>=1; |
|
720 |
||
721 |
while (--numtracks >= 0) { |
|
722 |
layout = CreateMulti(layout, plat_len, 4); |
|
723 |
layout = CreateMulti(layout, plat_len, 6); |
|
724 |
} |
|
725 |
} |
|
726 |
} |
|
727 |
||
728 |
/* build railroad station |
|
729 |
* p1 & 1 - orientation |
|
730 |
* (p1 >> 8) & 0xFF - numtracks |
|
731 |
* (p1 >> 16) & 0xFF - platform length |
|
449
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
732 |
* p2 & 0xF - railtype |
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
733 |
* p2 & 0x10 - set for custom station |
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
734 |
* p2 >> 8 - custom station id |
0 | 735 |
*/ |
736 |
||
737 |
int32 CmdBuildRailroadStation(int x_org, int y_org, uint32 flags, uint32 p1, uint32 p2) |
|
738 |
{ |
|
739 |
/* unpack params */ |
|
740 |
int w_org,h_org; |
|
741 |
uint tile_org; |
|
742 |
int32 cost, ret; |
|
743 |
Station *st; |
|
744 |
int est; |
|
745 |
int plat_len, numtracks; |
|
746 |
int direction; |
|
747 |
uint finalvalues[3]; |
|
748 |
||
749 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
750 |
||
751 |
tile_org = TILE_FROM_XY(x_org,y_org); |
|
752 |
||
753 |
/* Does the authority allow this? */ |
|
754 |
if (!(flags & DC_NO_TOWN_RATING) && !CheckIfAuthorityAllows(tile_org)) |
|
755 |
return CMD_ERROR; |
|
756 |
||
757 |
{ |
|
758 |
/* unpack parameters */ |
|
759 |
direction = p1 & 1; |
|
760 |
plat_len = (p1 >> 16) & 0xFF; |
|
761 |
numtracks = (p1 >> 8) & 0xFF; |
|
762 |
/* w = length, h = num_tracks */ |
|
763 |
if (direction) { |
|
764 |
h_org = plat_len; |
|
765 |
w_org = numtracks; |
|
766 |
} else { |
|
767 |
w_org = plat_len; |
|
768 |
h_org = numtracks; |
|
769 |
} |
|
770 |
} |
|
771 |
||
772 |
// these values are those that will be stored in train_tile and station_platforms |
|
773 |
finalvalues[0] = tile_org; |
|
774 |
finalvalues[1] = w_org; |
|
775 |
finalvalues[2] = h_org; |
|
776 |
||
777 |
// Make sure the area below consists of clear tiles. (OR tiles belonging to a certain rail station) |
|
778 |
est = -1; |
|
313
6660bb7b38f1
(svn r319) -Fix: [ 1029064 ] Building a station acted weird in some rare situations
truelight
parents:
243
diff
changeset
|
779 |
// If DC_EXEC is in flag, do not want to pass it to CheckFlatLandBelow, because of a nice bug |
6660bb7b38f1
(svn r319) -Fix: [ 1029064 ] Building a station acted weird in some rare situations
truelight
parents:
243
diff
changeset
|
780 |
// for detail info, see: https://sourceforge.net/tracker/index.php?func=detail&aid=1029064&group_id=103924&atid=636365 |
6660bb7b38f1
(svn r319) -Fix: [ 1029064 ] Building a station acted weird in some rare situations
truelight
parents:
243
diff
changeset
|
781 |
if ((ret=CheckFlatLandBelow(tile_org, w_org, h_org, flags&~DC_EXEC, 5 << direction, _patches.nonuniform_stations ? &est : NULL)) == CMD_ERROR) return CMD_ERROR; |
0 | 782 |
cost = ret + (numtracks * _price.train_station_track + _price.train_station_length) * plat_len; |
783 |
||
784 |
// Make sure there are no similar stations around us. |
|
785 |
st = GetStationAround(tile_org, w_org, h_org, est); |
|
786 |
if (st == CHECK_STATIONS_ERR) return CMD_ERROR; |
|
787 |
||
788 |
// See if there is a deleted station close to us. |
|
789 |
if (st == NULL) { |
|
790 |
st = GetClosestStationFromTile(tile_org, 8, _current_player); |
|
791 |
if (st != NULL && st->facilities) st = NULL; |
|
792 |
} |
|
793 |
||
794 |
if (st != NULL) { |
|
795 |
// Reuse an existing station. |
|
796 |
if (st->owner != OWNER_NONE && st->owner != _current_player) |
|
797 |
return_cmd_error(STR_3009_TOO_CLOSE_TO_ANOTHER_STATION); |
|
798 |
||
799 |
if (st->train_tile != 0) { |
|
84
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
71
diff
changeset
|
800 |
// check if we want to expanding an already existing station? |
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
71
diff
changeset
|
801 |
if ((!_patches.ainew_active && _is_ai_player) || !_patches.join_stations || !CanExpandRailroadStation(st, finalvalues, direction)) |
0 | 802 |
return_cmd_error(STR_3005_TOO_CLOSE_TO_ANOTHER_RAILROAD); |
803 |
} |
|
804 |
||
805 |
if (!CheckStationSpreadOut(st, tile_org, w_org, h_org)) |
|
806 |
return CMD_ERROR; |
|
807 |
||
808 |
} else { |
|
809 |
// Create a new station |
|
810 |
st = AllocateStation(); |
|
811 |
if (st == NULL) |
|
812 |
return CMD_ERROR; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
813 |
|
0 | 814 |
st->town = ClosestTownFromTile(tile_org, (uint)-1); |
815 |
if (_current_player < MAX_PLAYERS && flags&DC_EXEC) |
|
816 |
SETBIT(st->town->have_ratings, _current_player); |
|
817 |
||
818 |
if (!GenerateStationName(st, tile_org, 0)) |
|
819 |
return CMD_ERROR; |
|
820 |
||
821 |
if (flags & DC_EXEC) |
|
822 |
StationInitialize(st, tile_org); |
|
823 |
} |
|
824 |
||
825 |
if (flags & DC_EXEC) { |
|
826 |
int tile_delta; |
|
827 |
byte *layout_ptr; |
|
828 |
uint station_index = st->index; |
|
449
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
829 |
struct StationSpec *statspec; |
0 | 830 |
|
313
6660bb7b38f1
(svn r319) -Fix: [ 1029064 ] Building a station acted weird in some rare situations
truelight
parents:
243
diff
changeset
|
831 |
// Now really clear the land below the station |
6660bb7b38f1
(svn r319) -Fix: [ 1029064 ] Building a station acted weird in some rare situations
truelight
parents:
243
diff
changeset
|
832 |
// It should never return CMD_ERROR.. but you never know ;) |
6660bb7b38f1
(svn r319) -Fix: [ 1029064 ] Building a station acted weird in some rare situations
truelight
parents:
243
diff
changeset
|
833 |
// (a bit strange function name for it, but it really does clear the land, when DC_EXEC is in flags) |
6660bb7b38f1
(svn r319) -Fix: [ 1029064 ] Building a station acted weird in some rare situations
truelight
parents:
243
diff
changeset
|
834 |
if (CheckFlatLandBelow(tile_org, w_org, h_org, flags, 5 << direction, _patches.nonuniform_stations ? &est : NULL) == CMD_ERROR) return CMD_ERROR; |
6660bb7b38f1
(svn r319) -Fix: [ 1029064 ] Building a station acted weird in some rare situations
truelight
parents:
243
diff
changeset
|
835 |
|
0 | 836 |
st->train_tile = finalvalues[0]; |
837 |
if (!st->facilities) st->xy = finalvalues[0]; |
|
838 |
st->facilities |= FACIL_TRAIN; |
|
839 |
st->owner = _current_player; |
|
840 |
||
841 |
st->trainst_w = finalvalues[1]; |
|
842 |
st->trainst_h = finalvalues[2]; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
843 |
|
71
1b8e15a10515
(svn r72) -Add: build_date of station (viewable with Query tool)
truelight
parents:
65
diff
changeset
|
844 |
st->build_date = _date; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
845 |
|
0 | 846 |
tile_delta = direction ? TILE_XY(0,1) : TILE_XY(1,0); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
847 |
|
449
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
848 |
statspec = (p2 & 0x10) != 0 ? GetCustomStation(STAT_CLASS_DFLT, p2 >> 8) : NULL; |
0 | 849 |
layout_ptr = alloca(numtracks * plat_len); |
449
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
850 |
GetStationLayout(layout_ptr, numtracks, plat_len, statspec); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
851 |
|
0 | 852 |
do { |
853 |
int tile = tile_org; |
|
854 |
int w = plat_len; |
|
855 |
do { |
|
856 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
857 |
ModifyTile(tile, |
0 | 858 |
MP_SETTYPE(MP_STATION) | MP_MAPOWNER_CURRENT | |
449
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
859 |
MP_MAP2 | MP_MAP5 | MP_MAP3LO | MP_MAP3HI, |
0 | 860 |
station_index, /* map2 parameter */ |
449
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
861 |
p2 & 0xFF, /* map3lo parameter */ |
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
862 |
p2 >> 8, /* map3hi parameter */ |
0 | 863 |
(*layout_ptr++) + direction /* map5 parameter */ |
864 |
); |
|
865 |
||
866 |
tile += tile_delta; |
|
867 |
} while (--w); |
|
868 |
tile_org += tile_delta ^ TILE_XY(1,1); |
|
869 |
} while (--numtracks); |
|
870 |
||
871 |
UpdateStationVirtCoordDirty(st); |
|
872 |
UpdateStationAcceptance(st, false); |
|
873 |
InvalidateWindow(WC_STATION_LIST, st->owner); |
|
874 |
} |
|
875 |
||
876 |
return cost; |
|
877 |
} |
|
878 |
||
879 |
static bool TileBelongsToRailStation(Station *st, uint tile) |
|
880 |
{ |
|
881 |
return IS_TILETYPE(tile, MP_STATION) && _map2[tile] == st->index && _map5[tile] < 8; |
|
882 |
} |
|
883 |
||
884 |
static void MakeRailwayStationAreaSmaller(Station *st) |
|
885 |
{ |
|
886 |
uint w = st->trainst_w; |
|
887 |
uint h = st->trainst_h; |
|
888 |
uint tile = st->train_tile; |
|
889 |
uint i; |
|
890 |
||
891 |
restart: |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
892 |
|
0 | 893 |
// too small? |
894 |
if (w != 0 && h != 0) { |
|
895 |
// check the left side, x = constant, y changes |
|
896 |
for(i=0; !TileBelongsToRailStation(st, tile + TILE_XY(0,i)) ;) |
|
897 |
// the left side is unused? |
|
898 |
if (++i==h) { tile += TILE_XY(1, 0); w--; goto restart; } |
|
899 |
||
900 |
// check the right side, x = constant, y changes |
|
901 |
for(i=0; !TileBelongsToRailStation(st, tile + TILE_XY(w-1,i)) ;) |
|
902 |
// the right side is unused? |
|
903 |
if (++i==h) { w--; goto restart; } |
|
904 |
||
905 |
// check the upper side, y = constant, x changes |
|
906 |
for(i=0; !TileBelongsToRailStation(st, tile + TILE_XY(i,0)) ;) |
|
907 |
// the left side is unused? |
|
908 |
if (++i==w) { tile += TILE_XY(0, 1); h--; goto restart; } |
|
909 |
||
910 |
// check the lower side, y = constant, x changes |
|
911 |
for(i=0; !TileBelongsToRailStation(st, tile + TILE_XY(i,h-1)) ;) |
|
912 |
// the left side is unused? |
|
913 |
if (++i==w) { h--; goto restart; } |
|
914 |
} else { |
|
915 |
tile = 0; |
|
916 |
} |
|
917 |
||
918 |
st->trainst_w = w; |
|
919 |
st->trainst_h = h; |
|
920 |
st->train_tile = tile; |
|
921 |
} |
|
922 |
||
923 |
// remove a single tile from a railroad station |
|
924 |
int32 CmdRemoveFromRailroadStation(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
925 |
{ |
|
926 |
uint tile = TILE_FROM_XY(x, y); |
|
927 |
Station *st; |
|
928 |
||
929 |
// make sure the specified tile belongs to the current player, and that it is a railroad station. |
|
930 |
if (!IS_TILETYPE(tile, MP_STATION) || _map5[tile] >= 8 || !_patches.nonuniform_stations) return CMD_ERROR; |
|
931 |
st = DEREF_STATION(_map2[tile]); |
|
149
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
123
diff
changeset
|
932 |
if (_current_player != OWNER_WATER && (!CheckOwnership(st->owner) || !EnsureNoVehicle(tile))) return CMD_ERROR; |
0 | 933 |
|
934 |
// if we reached here, it means we can actually delete it. do that. |
|
935 |
if (flags & DC_EXEC) { |
|
936 |
DoClearSquare(tile); |
|
937 |
// now we need to make the "spanned" area of the railway station smaller if we deleted something at the edges. |
|
938 |
// we also need to adjust train_tile. |
|
939 |
MakeRailwayStationAreaSmaller(st); |
|
940 |
||
941 |
// if we deleted the whole station, delete the train facility. |
|
942 |
if (st->train_tile == 0) { |
|
943 |
st->facilities &= ~FACIL_TRAIN; |
|
944 |
UpdateStationVirtCoordDirty(st); |
|
945 |
DeleteStationIfEmpty(st); |
|
946 |
} |
|
947 |
} |
|
948 |
return _price.remove_rail_station; |
|
949 |
} |
|
950 |
||
951 |
// determine the number of platforms for the station |
|
952 |
uint GetStationPlatforms(Station *st, uint tile) |
|
953 |
{ |
|
954 |
uint t; |
|
955 |
int dir,delta; |
|
956 |
int len; |
|
957 |
assert(TileBelongsToRailStation(st, tile)); |
|
958 |
||
959 |
len = 0; |
|
960 |
dir = _map5[tile]&1; |
|
961 |
delta = dir ? TILE_XY(0,1) : TILE_XY(1,0); |
|
962 |
||
963 |
// find starting tile.. |
|
964 |
t = tile; |
|
965 |
do { t -= delta; len++; } while (TileBelongsToRailStation(st, t) && (_map5[t]&1) == dir); |
|
966 |
||
967 |
// find ending tile |
|
968 |
t = tile; |
|
969 |
do { t += delta; len++; }while (TileBelongsToRailStation(st, t) && (_map5[t]&1) == dir); |
|
970 |
||
971 |
return len - 1; |
|
972 |
} |
|
973 |
||
974 |
||
449
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
975 |
/* TODO: Custom classes! */ |
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
976 |
/* Indexed by class, just STAT_CLASS_DFLT and STAT_CLASS_WAYP supported. */ |
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
977 |
static int _statspec_highest_id[2] = {-1, -1}; |
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
978 |
static struct StationSpec _station_spec[2][256]; |
399
ad3dcbfd2d48
(svn r591) -newgrf: Store whole struct StationSpec in SetCustomStation(), not just the rendering data. This will be needed for variational stationspecs (pasky).
darkvater
parents:
389
diff
changeset
|
979 |
|
400
d0608455bb77
(svn r592) -newgrf: Dynamically allocate global custom station IDs (pasky).
darkvater
parents:
399
diff
changeset
|
980 |
void SetCustomStation(byte local_stid, struct StationSpec *spec) |
399
ad3dcbfd2d48
(svn r591) -newgrf: Store whole struct StationSpec in SetCustomStation(), not just the rendering data. This will be needed for variational stationspecs (pasky).
darkvater
parents:
389
diff
changeset
|
981 |
{ |
449
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
982 |
enum StationClass sclass; |
400
d0608455bb77
(svn r592) -newgrf: Dynamically allocate global custom station IDs (pasky).
darkvater
parents:
399
diff
changeset
|
983 |
int stid = -1; |
d0608455bb77
(svn r592) -newgrf: Dynamically allocate global custom station IDs (pasky).
darkvater
parents:
399
diff
changeset
|
984 |
|
449
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
985 |
assert(spec->sclass == STAT_CLASS_DFLT || spec->sclass == STAT_CLASS_WAYP); |
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
986 |
sclass = spec->sclass - 1; |
400
d0608455bb77
(svn r592) -newgrf: Dynamically allocate global custom station IDs (pasky).
darkvater
parents:
399
diff
changeset
|
987 |
|
d0608455bb77
(svn r592) -newgrf: Dynamically allocate global custom station IDs (pasky).
darkvater
parents:
399
diff
changeset
|
988 |
if (spec->localidx != 0) { |
d0608455bb77
(svn r592) -newgrf: Dynamically allocate global custom station IDs (pasky).
darkvater
parents:
399
diff
changeset
|
989 |
/* Already allocated, try to resolve to global stid */ |
d0608455bb77
(svn r592) -newgrf: Dynamically allocate global custom station IDs (pasky).
darkvater
parents:
399
diff
changeset
|
990 |
int i; |
d0608455bb77
(svn r592) -newgrf: Dynamically allocate global custom station IDs (pasky).
darkvater
parents:
399
diff
changeset
|
991 |
|
449
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
992 |
for (i = 0; i <= _statspec_highest_id[sclass]; i++) { |
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
993 |
if (_station_spec[sclass][i].grfid == spec->grfid |
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
994 |
&& _station_spec[sclass][i].localidx == local_stid + 1) { |
400
d0608455bb77
(svn r592) -newgrf: Dynamically allocate global custom station IDs (pasky).
darkvater
parents:
399
diff
changeset
|
995 |
stid = i; |
408
63a8c0505aab
(svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents:
405
diff
changeset
|
996 |
/* FIXME: Release original SpriteGroup to |
63a8c0505aab
(svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents:
405
diff
changeset
|
997 |
* prevent leaks. But first we need to |
63a8c0505aab
(svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents:
405
diff
changeset
|
998 |
* refcount the SpriteGroup. --pasky */ |
400
d0608455bb77
(svn r592) -newgrf: Dynamically allocate global custom station IDs (pasky).
darkvater
parents:
399
diff
changeset
|
999 |
break; |
d0608455bb77
(svn r592) -newgrf: Dynamically allocate global custom station IDs (pasky).
darkvater
parents:
399
diff
changeset
|
1000 |
} |
d0608455bb77
(svn r592) -newgrf: Dynamically allocate global custom station IDs (pasky).
darkvater
parents:
399
diff
changeset
|
1001 |
} |
d0608455bb77
(svn r592) -newgrf: Dynamically allocate global custom station IDs (pasky).
darkvater
parents:
399
diff
changeset
|
1002 |
} |
d0608455bb77
(svn r592) -newgrf: Dynamically allocate global custom station IDs (pasky).
darkvater
parents:
399
diff
changeset
|
1003 |
|
d0608455bb77
(svn r592) -newgrf: Dynamically allocate global custom station IDs (pasky).
darkvater
parents:
399
diff
changeset
|
1004 |
if (stid == -1) { |
d0608455bb77
(svn r592) -newgrf: Dynamically allocate global custom station IDs (pasky).
darkvater
parents:
399
diff
changeset
|
1005 |
/* Allocate new one. */ |
449
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
1006 |
if (_statspec_highest_id[sclass] >= 255) { |
400
d0608455bb77
(svn r592) -newgrf: Dynamically allocate global custom station IDs (pasky).
darkvater
parents:
399
diff
changeset
|
1007 |
error("Too many custom stations allocated."); |
d0608455bb77
(svn r592) -newgrf: Dynamically allocate global custom station IDs (pasky).
darkvater
parents:
399
diff
changeset
|
1008 |
return; |
d0608455bb77
(svn r592) -newgrf: Dynamically allocate global custom station IDs (pasky).
darkvater
parents:
399
diff
changeset
|
1009 |
} |
449
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
1010 |
stid = ++_statspec_highest_id[sclass]; |
400
d0608455bb77
(svn r592) -newgrf: Dynamically allocate global custom station IDs (pasky).
darkvater
parents:
399
diff
changeset
|
1011 |
spec->localidx = local_stid + 1; |
d0608455bb77
(svn r592) -newgrf: Dynamically allocate global custom station IDs (pasky).
darkvater
parents:
399
diff
changeset
|
1012 |
} |
d0608455bb77
(svn r592) -newgrf: Dynamically allocate global custom station IDs (pasky).
darkvater
parents:
399
diff
changeset
|
1013 |
|
449
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
1014 |
//debug("Registering station #%d of class %d", stid, sclass); |
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
1015 |
memcpy(&_station_spec[sclass][stid], spec, sizeof(*spec)); |
399
ad3dcbfd2d48
(svn r591) -newgrf: Store whole struct StationSpec in SetCustomStation(), not just the rendering data. This will be needed for variational stationspecs (pasky).
darkvater
parents:
389
diff
changeset
|
1016 |
} |
ad3dcbfd2d48
(svn r591) -newgrf: Store whole struct StationSpec in SetCustomStation(), not just the rendering data. This will be needed for variational stationspecs (pasky).
darkvater
parents:
389
diff
changeset
|
1017 |
|
438
79b5df3f394a
(svn r647) Cleanup custom station classes handling. (pasky)
miham
parents:
433
diff
changeset
|
1018 |
struct StationSpec *GetCustomStation(enum StationClass sclass, byte stid) |
389
2d394eeba5e5
(svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents:
384
diff
changeset
|
1019 |
{ |
449
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
1020 |
assert(sclass == STAT_CLASS_DFLT || sclass == STAT_CLASS_WAYP); |
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
1021 |
sclass--; |
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
1022 |
//debug("Asking for station #%d of class %d", stid, sclass); |
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
1023 |
if (stid > _statspec_highest_id[sclass]) |
389
2d394eeba5e5
(svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents:
384
diff
changeset
|
1024 |
return NULL; |
449
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
1025 |
return &_station_spec[sclass][stid]; |
403
bfb365c74e80
(svn r600) -newgrf: Relocation offset for custom station sprites is now stored separately, making it possible to show different sprites in waypoint selection dialog (pasky).
darkvater
parents:
400
diff
changeset
|
1026 |
} |
bfb365c74e80
(svn r600) -newgrf: Relocation offset for custom station sprites is now stored separately, making it possible to show different sprites in waypoint selection dialog (pasky).
darkvater
parents:
400
diff
changeset
|
1027 |
|
413
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1028 |
static struct RealSpriteGroup * |
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1029 |
ResolveStationSpriteGroup(struct SpriteGroup *spritegroup, struct Station *stat) |
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1030 |
{ |
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1031 |
switch (spritegroup->type) { |
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1032 |
case SGT_REAL: |
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1033 |
return &spritegroup->g.real; |
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1034 |
|
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1035 |
case SGT_DETERMINISTIC: { |
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1036 |
struct DeterministicSpriteGroup *dsg = &spritegroup->g.determ; |
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1037 |
struct SpriteGroup *target; |
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1038 |
int value = -1; |
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1039 |
|
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1040 |
if ((dsg->variable >> 6) == 0) { |
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1041 |
/* General property */ |
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1042 |
value = GetDeterministicSpriteValue(dsg->variable); |
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1043 |
|
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1044 |
} else { |
433
00c1c7a58672
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
1045 |
if (stat == NULL) { |
00c1c7a58672
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
1046 |
/* We are in a build dialog of something, |
00c1c7a58672
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
1047 |
* and we are checking for something undefined. |
00c1c7a58672
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
1048 |
* That means we should get the first target |
00c1c7a58672
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
1049 |
* (NOT the default one). */ |
00c1c7a58672
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
1050 |
if (dsg->num_ranges > 0) { |
00c1c7a58672
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
1051 |
target = &dsg->ranges[0].group; |
00c1c7a58672
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
1052 |
} else { |
00c1c7a58672
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
1053 |
target = dsg->default_group; |
00c1c7a58672
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
1054 |
} |
00c1c7a58672
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
1055 |
return ResolveStationSpriteGroup(target, NULL); |
00c1c7a58672
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
1056 |
} |
00c1c7a58672
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
1057 |
|
413
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1058 |
/* Station-specific property. */ |
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1059 |
if (dsg->var_scope == VSG_SCOPE_PARENT) { |
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1060 |
/* TODO: Town structure. */ |
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1061 |
|
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1062 |
} else /* VSG_SELF */ { |
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1063 |
if (dsg->variable == 0x40 |
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1064 |
|| dsg->variable == 0x41) { |
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1065 |
/* FIXME: This is ad hoc only |
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1066 |
* for waypoints. */ |
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1067 |
value = 0x01010000; |
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1068 |
} else { |
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1069 |
/* TODO: Only small fraction done. */ |
426
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
413
diff
changeset
|
1070 |
// TTDPatch runs on little-endian arch; |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
413
diff
changeset
|
1071 |
// Variable is 0x70 + offset in the TTD's station structure |
413
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1072 |
switch (dsg->variable - 0x70) { |
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1073 |
case 0x80: |
433
00c1c7a58672
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
1074 |
value = stat->facilities; |
413
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1075 |
break; |
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1076 |
case 0x81: |
433
00c1c7a58672
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
1077 |
value = stat->airport_type; |
413
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1078 |
break; |
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1079 |
case 0x82: |
433
00c1c7a58672
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
1080 |
value = stat->truck_stop_status; |
413
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1081 |
break; |
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1082 |
case 0x83: |
433
00c1c7a58672
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
1083 |
value = stat->bus_stop_status; |
413
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1084 |
break; |
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1085 |
case 0x86: |
433
00c1c7a58672
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
1086 |
value = stat->airport_flags & 0xFFFF; |
413
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1087 |
break; |
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1088 |
case 0x87: |
433
00c1c7a58672
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
1089 |
value = stat->airport_flags & 0xFF; |
413
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1090 |
break; |
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1091 |
case 0x8A: |
433
00c1c7a58672
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
1092 |
value = stat->build_date; |
413
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1093 |
break; |
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1094 |
} |
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1095 |
} |
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1096 |
} |
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1097 |
} |
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1098 |
|
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1099 |
target = value != -1 ? EvalDeterministicSpriteGroup(dsg, value) : dsg->default_group; |
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1100 |
return ResolveStationSpriteGroup(target, stat); |
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1101 |
} |
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1102 |
|
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1103 |
default: |
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:
438
diff
changeset
|
1104 |
case SGT_RANDOMIZED: |
413
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1105 |
error("I don't know how to handle random spritegroups yet!"); |
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1106 |
return NULL; |
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1107 |
} |
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1108 |
} |
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1109 |
|
408
63a8c0505aab
(svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents:
405
diff
changeset
|
1110 |
uint32 GetCustomStationRelocation(struct StationSpec *spec, struct Station *stat, byte ctype) |
403
bfb365c74e80
(svn r600) -newgrf: Relocation offset for custom station sprites is now stored separately, making it possible to show different sprites in waypoint selection dialog (pasky).
darkvater
parents:
400
diff
changeset
|
1111 |
{ |
408
63a8c0505aab
(svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents:
405
diff
changeset
|
1112 |
struct RealSpriteGroup *rsg; |
63a8c0505aab
(svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents:
405
diff
changeset
|
1113 |
|
413
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1114 |
rsg = ResolveStationSpriteGroup(&spec->spritegroup[ctype], stat); |
408
63a8c0505aab
(svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents:
405
diff
changeset
|
1115 |
|
63a8c0505aab
(svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents:
405
diff
changeset
|
1116 |
if (rsg->sprites_per_set != 0) { |
63a8c0505aab
(svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents:
405
diff
changeset
|
1117 |
if (rsg->loading_count != 0) { |
63a8c0505aab
(svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents:
405
diff
changeset
|
1118 |
return rsg->loading[0]; |
63a8c0505aab
(svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents:
405
diff
changeset
|
1119 |
} else if (rsg->loading_count != 0) { |
63a8c0505aab
(svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents:
405
diff
changeset
|
1120 |
return rsg->loaded[0]; |
63a8c0505aab
(svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents:
405
diff
changeset
|
1121 |
} |
403
bfb365c74e80
(svn r600) -newgrf: Relocation offset for custom station sprites is now stored separately, making it possible to show different sprites in waypoint selection dialog (pasky).
darkvater
parents:
400
diff
changeset
|
1122 |
} |
408
63a8c0505aab
(svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents:
405
diff
changeset
|
1123 |
|
63a8c0505aab
(svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents:
405
diff
changeset
|
1124 |
error("Custom station 0x%08x::0x%02x has no sprites associated.", |
63a8c0505aab
(svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents:
405
diff
changeset
|
1125 |
spec->grfid, spec->localidx); |
452
520e4ed6945d
(svn r662) [newgrf] Moved grfspecial.c to newgrf.c/newgrf.h
dominik
parents:
449
diff
changeset
|
1126 |
/* This is what gets subscribed of dtss->image in newgrf.c, |
408
63a8c0505aab
(svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents:
405
diff
changeset
|
1127 |
* so it's probably kinda "default offset". Try to use it as |
63a8c0505aab
(svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents:
405
diff
changeset
|
1128 |
* emergency measure. */ |
63a8c0505aab
(svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents:
405
diff
changeset
|
1129 |
return 0x42D; |
389
2d394eeba5e5
(svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents:
384
diff
changeset
|
1130 |
} |
2d394eeba5e5
(svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents:
384
diff
changeset
|
1131 |
|
438
79b5df3f394a
(svn r647) Cleanup custom station classes handling. (pasky)
miham
parents:
433
diff
changeset
|
1132 |
int GetCustomStationsCount(enum StationClass sclass) |
389
2d394eeba5e5
(svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents:
384
diff
changeset
|
1133 |
{ |
449
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
1134 |
assert(sclass == STAT_CLASS_DFLT || sclass == STAT_CLASS_WAYP); |
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
1135 |
sclass--; |
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
1136 |
return _statspec_highest_id[sclass] + 1; |
389
2d394eeba5e5
(svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents:
384
diff
changeset
|
1137 |
} |
2d394eeba5e5
(svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents:
384
diff
changeset
|
1138 |
|
2d394eeba5e5
(svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents:
384
diff
changeset
|
1139 |
|
149
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
123
diff
changeset
|
1140 |
static int32 RemoveRailroadStation(Station *st, TileIndex tile, uint32 flags) |
0 | 1141 |
{ |
1142 |
int w,h; |
|
1143 |
int32 cost; |
|
1144 |
||
149
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
123
diff
changeset
|
1145 |
/* if there is flooding and non-uniform stations are enabled, remove platforms tile by tile */ |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
123
diff
changeset
|
1146 |
if (_current_player == OWNER_WATER && _patches.nonuniform_stations) |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
123
diff
changeset
|
1147 |
return DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_REMOVE_FROM_RAILROAD_STATION); |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
123
diff
changeset
|
1148 |
|
0 | 1149 |
/* Current player owns the station? */ |
1150 |
if (_current_player != OWNER_WATER && !CheckOwnership(st->owner)) |
|
1151 |
return CMD_ERROR; |
|
1152 |
||
1153 |
/* determine width and height of platforms */ |
|
1154 |
tile = st->train_tile; |
|
1155 |
w = st->trainst_w; |
|
1156 |
h = st->trainst_h; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1157 |
|
0 | 1158 |
assert(w != 0 && h != 0); |
1159 |
||
1160 |
/* cost is area * constant */ |
|
1161 |
cost = w*h*_price.remove_rail_station; |
|
1162 |
||
1163 |
/* clear all areas of the station */ |
|
1164 |
do { |
|
1165 |
int w_bak = w; |
|
1166 |
do { |
|
1167 |
// for nonuniform stations, only remove tiles that are actually train station tiles |
|
1168 |
if (TileBelongsToRailStation(st, tile)) { |
|
1169 |
if (!EnsureNoVehicle(tile)) |
|
1170 |
return CMD_ERROR; |
|
1171 |
if (flags & DC_EXEC) |
|
1172 |
DoClearSquare(tile); |
|
1173 |
} |
|
1174 |
tile += TILE_XY(1, 0); |
|
1175 |
} while (--w); |
|
1176 |
w = w_bak; |
|
1177 |
tile = tile + TILE_XY(-w, 1); |
|
1178 |
} while (--h); |
|
1179 |
||
1180 |
if (flags & DC_EXEC) { |
|
1181 |
st->train_tile = 0; |
|
1182 |
st->facilities &= ~FACIL_TRAIN; |
|
1183 |
||
1184 |
UpdateStationVirtCoordDirty(st); |
|
1185 |
DeleteStationIfEmpty(st); |
|
1186 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1187 |
|
0 | 1188 |
return cost; |
1189 |
} |
|
1190 |
||
1191 |
int32 DoConvertStationRail(uint tile, uint totype, bool exec) |
|
1192 |
{ |
|
1193 |
Station *st; |
|
1194 |
||
1195 |
st = DEREF_STATION(_map2[tile]); |
|
1196 |
if (!CheckOwnership(st->owner) || !EnsureNoVehicle(tile)) return CMD_ERROR; |
|
1197 |
||
1198 |
// tile is not a railroad station? |
|
1199 |
if (_map5[tile] >= 8) return CMD_ERROR; |
|
1200 |
||
1201 |
// tile is already of requested type? |
|
1202 |
if ( (uint)(_map3_lo[tile] & 0xF) == totype) return CMD_ERROR; |
|
1203 |
||
1204 |
if (exec) { |
|
1205 |
// change type. |
|
1206 |
_map3_lo[tile] = (_map3_lo[tile] & 0xF0) + totype; |
|
1207 |
MarkTileDirtyByTile(tile); |
|
1208 |
} |
|
1209 |
||
1210 |
return _price.build_rail >> 1; |
|
1211 |
} |
|
1212 |
||
1213 |
/* Build a bus station |
|
1214 |
* p1 - direction |
|
1215 |
* p2 - unused |
|
1216 |
*/ |
|
1217 |
||
1218 |
int32 CmdBuildBusStation(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
1219 |
{ |
|
1220 |
uint tile; |
|
1221 |
int32 cost; |
|
1222 |
Station *st; |
|
1223 |
||
1224 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
1225 |
||
1226 |
tile = TILE_FROM_XY(x,y); |
|
1227 |
||
1228 |
if (!(flags & DC_NO_TOWN_RATING) && !CheckIfAuthorityAllows(tile)) |
|
1229 |
return CMD_ERROR; |
|
1230 |
||
1231 |
if ((cost=CheckFlatLandBelow(tile, 1, 1, flags, 1 << p1, NULL)) == CMD_ERROR) |
|
1232 |
return CMD_ERROR; |
|
1233 |
||
1234 |
st = GetStationAround(tile, 1, 1, -1); |
|
1235 |
if (st == CHECK_STATIONS_ERR) |
|
1236 |
return CMD_ERROR; |
|
1237 |
||
1238 |
/* Find a station close to us */ |
|
1239 |
if (st == NULL) { |
|
1240 |
st = GetClosestStationFromTile(tile, 8, _current_player); |
|
1241 |
if (st!=NULL && st->facilities) st = NULL; |
|
1242 |
} |
|
1243 |
||
1244 |
if (st != NULL) { |
|
1245 |
if (st->owner != OWNER_NONE && st->owner != _current_player) |
|
1246 |
return_cmd_error(STR_3009_TOO_CLOSE_TO_ANOTHER_STATION); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1247 |
|
0 | 1248 |
if (!CheckStationSpreadOut(st, tile, 1, 1)) |
1249 |
return CMD_ERROR; |
|
1250 |
||
1251 |
if (st->bus_tile != 0) |
|
1252 |
return_cmd_error(STR_3044_TOO_CLOSE_TO_ANOTHER_BUS); |
|
1253 |
} else { |
|
1254 |
Town *t; |
|
1255 |
||
1256 |
st = AllocateStation(); |
|
1257 |
if (st == NULL) |
|
1258 |
return CMD_ERROR; |
|
1259 |
||
1260 |
st->town = t = ClosestTownFromTile(tile, (uint)-1); |
|
1261 |
||
1262 |
if (_current_player < MAX_PLAYERS && flags&DC_EXEC) |
|
1263 |
SETBIT(t->have_ratings, _current_player); |
|
1264 |
||
1265 |
st->sign.width_1 = 0; |
|
1266 |
||
1267 |
if (!GenerateStationName(st, tile, 0)) |
|
1268 |
return CMD_ERROR; |
|
1269 |
||
1270 |
if (flags & DC_EXEC) |
|
1271 |
StationInitialize(st, tile); |
|
1272 |
} |
|
1273 |
||
1274 |
cost += _price.build_bus_station; |
|
1275 |
||
1276 |
if (flags & DC_EXEC) { |
|
1277 |
st->bus_tile = tile; |
|
1278 |
if (!st->facilities) st->xy = tile; |
|
1279 |
st->facilities |= FACIL_BUS_STOP; |
|
1280 |
st->bus_stop_status = 3; |
|
1281 |
st->owner = _current_player; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1282 |
|
71
1b8e15a10515
(svn r72) -Add: build_date of station (viewable with Query tool)
truelight
parents:
65
diff
changeset
|
1283 |
st->build_date = _date; |
0 | 1284 |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1285 |
ModifyTile(tile, |
0 | 1286 |
MP_SETTYPE(MP_STATION) | MP_MAPOWNER_CURRENT | |
1287 |
MP_MAP2 | MP_MAP5 | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR, |
|
1288 |
st->index, /* map2 parameter */ |
|
1289 |
p1 + 0x47 /* map5 parameter */ |
|
1290 |
); |
|
1291 |
||
1292 |
UpdateStationVirtCoordDirty(st); |
|
1293 |
UpdateStationAcceptance(st, false); |
|
1294 |
InvalidateWindow(WC_STATION_LIST, st->owner); |
|
1295 |
} |
|
1296 |
return cost; |
|
1297 |
} |
|
1298 |
||
1299 |
// Remove a bus station |
|
1300 |
static int32 RemoveBusStation(Station *st, uint32 flags) |
|
1301 |
{ |
|
1302 |
uint tile; |
|
1303 |
||
1304 |
if (_current_player != OWNER_WATER && !CheckOwnership(st->owner)) |
|
1305 |
return CMD_ERROR; |
|
1306 |
||
1307 |
tile = st->bus_tile; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1308 |
|
0 | 1309 |
if (!EnsureNoVehicle(tile)) |
1310 |
return CMD_ERROR; |
|
1311 |
||
1312 |
if (flags & DC_EXEC) { |
|
1313 |
DoClearSquare(tile); |
|
1314 |
||
1315 |
st->bus_tile = 0; |
|
1316 |
st->facilities &= ~FACIL_BUS_STOP; |
|
1317 |
||
1318 |
UpdateStationVirtCoordDirty(st); |
|
1319 |
DeleteStationIfEmpty(st); |
|
1320 |
} |
|
1321 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1322 |
return _price.remove_bus_station; |
0 | 1323 |
} |
1324 |
||
1325 |
||
1326 |
/* Build a truck station |
|
1327 |
* p1 - direction |
|
1328 |
* p2 - unused |
|
1329 |
*/ |
|
1330 |
int32 CmdBuildTruckStation(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
1331 |
{ |
|
1332 |
uint tile; |
|
1333 |
int32 cost = 0; |
|
1334 |
Station *st; |
|
1335 |
||
1336 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
1337 |
||
1338 |
tile = TILE_FROM_XY(x,y); |
|
1339 |
||
1340 |
if (!(flags & DC_NO_TOWN_RATING) && !CheckIfAuthorityAllows(tile)) |
|
1341 |
return CMD_ERROR; |
|
1342 |
||
1343 |
if ((cost=CheckFlatLandBelow(tile, 1, 1, flags, 1 << p1, NULL)) == CMD_ERROR) |
|
1344 |
return CMD_ERROR; |
|
1345 |
||
1346 |
st = GetStationAround(tile, 1, 1, -1); |
|
1347 |
if (st == CHECK_STATIONS_ERR) |
|
1348 |
return CMD_ERROR; |
|
1349 |
||
1350 |
/* Find a station close to us */ |
|
1351 |
if (st == NULL) { |
|
1352 |
st = GetClosestStationFromTile(tile, 8, _current_player); |
|
1353 |
if (st!=NULL && st->facilities) st = NULL; |
|
1354 |
} |
|
1355 |
||
1356 |
if (st != NULL) { |
|
1357 |
if (st->owner != OWNER_NONE && st->owner != _current_player) |
|
1358 |
return_cmd_error(STR_3009_TOO_CLOSE_TO_ANOTHER_STATION); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1359 |
|
0 | 1360 |
if (!CheckStationSpreadOut(st, tile, 1, 1)) |
1361 |
return CMD_ERROR; |
|
1362 |
||
1363 |
if (st->lorry_tile != 0) |
|
1364 |
return_cmd_error(STR_3045_TOO_CLOSE_TO_ANOTHER_TRUCK); |
|
1365 |
} else { |
|
1366 |
Town *t; |
|
1367 |
||
1368 |
st = AllocateStation(); |
|
1369 |
if (st == NULL) |
|
1370 |
return CMD_ERROR; |
|
1371 |
||
1372 |
st->town = t = ClosestTownFromTile(tile, (uint)-1); |
|
1373 |
||
1374 |
if (_current_player < MAX_PLAYERS && flags&DC_EXEC) |
|
1375 |
SETBIT(t->have_ratings, _current_player); |
|
1376 |
||
1377 |
st->sign.width_1 = 0; |
|
1378 |
||
1379 |
if (!GenerateStationName(st, tile, 0)) |
|
1380 |
return CMD_ERROR; |
|
1381 |
||
1382 |
if (flags & DC_EXEC) |
|
1383 |
StationInitialize(st, tile); |
|
1384 |
} |
|
1385 |
||
1386 |
cost += _price.build_truck_station; |
|
1387 |
||
1388 |
if (flags & DC_EXEC) { |
|
1389 |
st->lorry_tile = tile; |
|
1390 |
if (!st->facilities) st->xy = tile; |
|
1391 |
st->facilities |= FACIL_TRUCK_STOP; |
|
1392 |
st->truck_stop_status = 3; |
|
1393 |
st->owner = _current_player; |
|
1394 |
||
71
1b8e15a10515
(svn r72) -Add: build_date of station (viewable with Query tool)
truelight
parents:
65
diff
changeset
|
1395 |
st->build_date = _date; |
1b8e15a10515
(svn r72) -Add: build_date of station (viewable with Query tool)
truelight
parents:
65
diff
changeset
|
1396 |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1397 |
ModifyTile(tile, |
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1398 |
MP_SETTYPE(MP_STATION) | MP_MAPOWNER_CURRENT | |
0 | 1399 |
MP_MAP2 | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR | MP_MAP5, |
1400 |
st->index, /* map2 parameter */ |
|
1401 |
p1 + 0x43 /* map5 parameter */ |
|
1402 |
); |
|
1403 |
||
1404 |
UpdateStationVirtCoordDirty(st); |
|
1405 |
UpdateStationAcceptance(st, false); |
|
1406 |
InvalidateWindow(WC_STATION_LIST, st->owner); |
|
1407 |
} |
|
1408 |
return cost; |
|
1409 |
} |
|
1410 |
||
1411 |
// Remove a truck station |
|
1412 |
static int32 RemoveTruckStation(Station *st, uint32 flags) |
|
1413 |
{ |
|
1414 |
uint tile; |
|
1415 |
||
1416 |
if (_current_player != OWNER_WATER && !CheckOwnership(st->owner)) |
|
1417 |
return CMD_ERROR; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1418 |
|
0 | 1419 |
tile = st->lorry_tile; |
1420 |
||
1421 |
if (!EnsureNoVehicle(tile)) |
|
1422 |
return CMD_ERROR; |
|
1423 |
||
1424 |
if (flags & DC_EXEC) { |
|
1425 |
DoClearSquare(tile); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1426 |
|
0 | 1427 |
st->lorry_tile = 0; |
1428 |
st->facilities &= ~FACIL_TRUCK_STOP; |
|
1429 |
||
1430 |
UpdateStationVirtCoordDirty(st); |
|
1431 |
DeleteStationIfEmpty(st); |
|
1432 |
} |
|
1433 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1434 |
return _price.remove_truck_station; |
0 | 1435 |
} |
1436 |
||
1437 |
// FIXME -- need to move to its corresponding Airport variable |
|
1438 |
// Country Airfield (small) |
|
1439 |
static const byte _airport_map5_tiles_country[] = { |
|
1440 |
54, 53, 52, 65, |
|
1441 |
58, 57, 56, 55, |
|
1442 |
64, 63, 63, 62 |
|
1443 |
}; |
|
1444 |
||
1445 |
// City Airport (large) |
|
1446 |
static const byte _airport_map5_tiles_town[] = { |
|
1447 |
31, 9, 33, 9, 9, 32, |
|
1448 |
27, 36, 29, 34, 8, 10, |
|
1449 |
30, 11, 35, 13, 20, 21, |
|
1450 |
51, 12, 14, 17, 19, 28, |
|
1451 |
38, 13, 15, 16, 18, 39, |
|
1452 |
26, 22, 23, 24, 25, 26 |
|
1453 |
}; |
|
1454 |
||
1455 |
// Metropolitain Airport (large) - 2 runways |
|
1456 |
static const byte _airport_map5_tiles_metropolitan[] = { |
|
1457 |
31, 9, 33, 9, 9, 32, |
|
1458 |
27, 36, 29, 34, 8, 10, |
|
1459 |
30, 11, 35, 13, 20, 21, |
|
1460 |
102, 8, 8, 8, 8, 28, |
|
1461 |
83, 84, 84, 84, 84, 83, |
|
1462 |
26, 23, 23, 23, 23, 26 |
|
1463 |
}; |
|
1464 |
||
1465 |
// International Airport (large) - 2 runways |
|
1466 |
static const byte _airport_map5_tiles_international[] = { |
|
1467 |
88, 89, 89, 89, 89, 89, 88, |
|
1468 |
51, 8, 8, 8, 8, 8, 32, |
|
1469 |
30, 8, 11, 27, 11, 8, 10, |
|
1470 |
32, 8, 11, 27, 11, 8, 114, |
|
1471 |
87, 8, 11, 85, 11, 8, 114, |
|
1472 |
87, 8, 8, 8, 8, 8, 90, |
|
1473 |
26, 23, 23, 23, 23, 23, 26 |
|
1474 |
}; |
|
1475 |
||
1476 |
// Heliport |
|
1477 |
static const byte _airport_map5_tiles_heliport[] = { |
|
1478 |
66, |
|
1479 |
}; |
|
1480 |
||
1481 |
static const byte * const _airport_map5_tiles[] = { |
|
1482 |
_airport_map5_tiles_country, // Country Airfield (small) |
|
1483 |
_airport_map5_tiles_town, // City Airport (large) |
|
1484 |
_airport_map5_tiles_heliport, // Heliport |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1485 |
_airport_map5_tiles_metropolitan, // Metropolitain Airport (large) |
0 | 1486 |
_airport_map5_tiles_international, // International Airport (xlarge) |
1487 |
}; |
|
1488 |
||
1489 |
/* Place an Airport |
|
1490 |
* p1 - airport type |
|
1491 |
* p2 - unused |
|
1492 |
*/ |
|
1493 |
int32 CmdBuildAirport(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
1494 |
{ |
|
1495 |
uint tile; |
|
1496 |
Town *t; |
|
1497 |
Station *st; |
|
1498 |
int32 cost; |
|
1499 |
int w,h; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1500 |
bool airport_upgrade = true; |
0 | 1501 |
|
1502 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
1503 |
||
1504 |
tile = TILE_FROM_XY(x,y); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1505 |
|
0 | 1506 |
if (!(flags & DC_NO_TOWN_RATING) && !CheckIfAuthorityAllows(tile)) |
1507 |
return CMD_ERROR; |
|
1508 |
||
1509 |
t = ClosestTownFromTile(tile, (uint)-1); |
|
1510 |
||
1511 |
/* Check if local auth refuses a new airport */ |
|
1512 |
{ |
|
1513 |
uint num = 0; |
|
1514 |
FOR_ALL_STATIONS(st) { |
|
1515 |
if (st->xy != 0 && st->town == t && st->facilities&FACIL_AIRPORT && st->airport_type != AT_OILRIG) |
|
1516 |
num++; |
|
1517 |
} |
|
1518 |
if (num >= 2) { |
|
1519 |
SET_DPARAM16(0, t->index); |
|
1520 |
return_cmd_error(STR_2035_LOCAL_AUTHORITY_REFUSES); |
|
1521 |
} |
|
1522 |
} |
|
1523 |
||
1524 |
w = _airport_size_x[p1]; |
|
1525 |
h = _airport_size_y[p1]; |
|
1526 |
||
1527 |
cost = CheckFlatLandBelow(tile, w, h, flags, 0, NULL); |
|
1528 |
if (cost == CMD_ERROR) |
|
1529 |
return CMD_ERROR; |
|
1530 |
||
1531 |
st = GetStationAround(tile, w, h, -1); |
|
1532 |
if (st == CHECK_STATIONS_ERR) |
|
1533 |
return CMD_ERROR; |
|
1534 |
||
1535 |
/* Find a station close to us */ |
|
1536 |
if (st == NULL) { |
|
1537 |
st = GetClosestStationFromTile(tile, 8, _current_player); |
|
1538 |
if (st!=NULL && st->facilities) st = NULL; |
|
1539 |
} |
|
1540 |
||
1541 |
if (st != NULL) { |
|
1542 |
if (st->owner != OWNER_NONE && st->owner != _current_player) |
|
1543 |
return_cmd_error(STR_3009_TOO_CLOSE_TO_ANOTHER_STATION); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1544 |
|
0 | 1545 |
if (!CheckStationSpreadOut(st, tile, 1, 1)) |
1546 |
return CMD_ERROR; |
|
1547 |
||
1548 |
if (st->airport_tile != 0) |
|
1549 |
return_cmd_error(STR_300D_TOO_CLOSE_TO_ANOTHER_AIRPORT); |
|
1550 |
} else { |
|
1551 |
Town *t; |
|
1552 |
||
1553 |
airport_upgrade = false; |
|
1554 |
||
1555 |
st = AllocateStation(); |
|
1556 |
if (st == NULL) |
|
1557 |
return CMD_ERROR; |
|
1558 |
||
1559 |
st->town = t = ClosestTownFromTile(tile, (uint)-1); |
|
1560 |
||
1561 |
if (_current_player < MAX_PLAYERS && flags&DC_EXEC) |
|
1562 |
SETBIT(t->have_ratings, _current_player); |
|
1563 |
||
1564 |
st->sign.width_1 = 0; |
|
1565 |
||
1566 |
// if airport type equals Heliport then generate |
|
1567 |
// type 5 name, which is heliport, otherwise airport names (1) |
|
1568 |
if (!GenerateStationName(st, tile, p1 == AT_HELIPORT ? 5 : 1)) |
|
1569 |
return CMD_ERROR; |
|
1570 |
||
1571 |
if (flags & DC_EXEC) |
|
1572 |
StationInitialize(st, tile); |
|
1573 |
} |
|
1574 |
||
1575 |
cost += _price.build_airport * w * h; |
|
1576 |
||
1577 |
if (flags & DC_EXEC) { |
|
1578 |
st->owner = _current_player; |
|
1579 |
if (_current_player == _local_player && p1 <= AT_INTERNATIONAL) { |
|
1580 |
_last_built_aircraft_depot_tile = tile + GetAirport(p1)->airport_depots[0]; |
|
1581 |
} |
|
1582 |
||
1583 |
st->airport_tile = tile; |
|
1584 |
if (!st->facilities) st->xy = tile; |
|
1585 |
st->facilities |= FACIL_AIRPORT; |
|
1586 |
st->airport_type = (byte)p1; |
|
1587 |
st->airport_flags = 0; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1588 |
|
71
1b8e15a10515
(svn r72) -Add: build_date of station (viewable with Query tool)
truelight
parents:
65
diff
changeset
|
1589 |
st->build_date = _date; |
0 | 1590 |
|
1591 |
/* if airport was demolished while planes were en-route to it, the positions can no longer |
|
1592 |
be the same (v->u.air.pos), since different airports have different indexes. So update |
|
1593 |
all planes en-route to this airport. Only update if |
|
1594 |
1. airport is upgraded |
|
1595 |
2. airport is added to existing station (unfortunately unavoideable) |
|
1596 |
*/ |
|
1597 |
if (airport_upgrade) {UpdateAirplanesOnNewStation(st);} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1598 |
|
0 | 1599 |
{ |
1600 |
const byte *b = _airport_map5_tiles[p1]; |
|
1601 |
BEGIN_TILE_LOOP(tile_cur,w,h,tile) |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1602 |
ModifyTile(tile_cur, |
0 | 1603 |
MP_SETTYPE(MP_STATION) | MP_MAPOWNER_CURRENT | |
1604 |
MP_MAP2 | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR | MP_MAP5, |
|
1605 |
st->index, *b++); |
|
1606 |
END_TILE_LOOP(tile_cur,w,h,tile) |
|
1607 |
} |
|
1608 |
||
1609 |
UpdateStationVirtCoordDirty(st); |
|
1610 |
UpdateStationAcceptance(st, false); |
|
1611 |
InvalidateWindow(WC_STATION_LIST, st->owner); |
|
1612 |
} |
|
1613 |
||
1614 |
return cost; |
|
1615 |
} |
|
1616 |
||
1617 |
static int32 RemoveAirport(Station *st, uint32 flags) |
|
1618 |
{ |
|
1619 |
uint tile; |
|
1620 |
int w,h; |
|
1621 |
int32 cost; |
|
1622 |
||
1623 |
if (_current_player != OWNER_WATER && !CheckOwnership(st->owner)) |
|
1624 |
return CMD_ERROR; |
|
1625 |
||
1626 |
tile = st->airport_tile; |
|
1627 |
||
1628 |
w = _airport_size_x[st->airport_type]; |
|
1629 |
h = _airport_size_y[st->airport_type]; |
|
1630 |
||
1631 |
cost = w * h * _price.remove_airport; |
|
1632 |
||
1633 |
{ |
|
1634 |
BEGIN_TILE_LOOP(tile_cur,w,h,tile) |
|
1635 |
if (!EnsureNoVehicle(tile_cur)) |
|
1636 |
return CMD_ERROR; |
|
1637 |
||
1638 |
if (flags & DC_EXEC) { |
|
1639 |
DeleteAnimatedTile(tile_cur); |
|
1640 |
DoClearSquare(tile_cur); |
|
1641 |
} |
|
1642 |
END_TILE_LOOP(tile_cur, w,h,tile) |
|
1643 |
} |
|
1644 |
||
1645 |
if (flags & DC_EXEC) { |
|
1646 |
if (st->airport_type <= AT_INTERNATIONAL) |
|
1647 |
DeleteWindowById(WC_VEHICLE_DEPOT, tile + GetAirport(st->airport_type)->airport_depots[0]); |
|
1648 |
st->airport_tile = 0; |
|
1649 |
st->facilities &= ~FACIL_AIRPORT; |
|
1650 |
||
1651 |
UpdateStationVirtCoordDirty(st); |
|
1652 |
DeleteStationIfEmpty(st); |
|
1653 |
} |
|
1654 |
||
1655 |
return cost; |
|
1656 |
} |
|
1657 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1658 |
/* Build a buoy |
0 | 1659 |
* p1,p2 unused |
1660 |
*/ |
|
1661 |
||
1662 |
int32 CmdBuildBuoy(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
1663 |
{ |
|
1664 |
TileInfo ti; |
|
1665 |
Station *st; |
|
1666 |
||
1667 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
1668 |
||
1669 |
FindLandscapeHeight(&ti, x, y); |
|
1670 |
||
1671 |
if (ti.type != MP_WATER || ti.tileh != 0 || ti.map5 != 0 || ti.tile == 0) |
|
1672 |
return_cmd_error(STR_304B_SITE_UNSUITABLE); |
|
1673 |
||
1674 |
st = AllocateStation(); |
|
1675 |
if (st == NULL) |
|
1676 |
return CMD_ERROR; |
|
1677 |
||
1678 |
st->town = ClosestTownFromTile(ti.tile, (uint)-1); |
|
1679 |
st->sign.width_1 = 0; |
|
1680 |
||
1681 |
if (!GenerateStationName(st, ti.tile, 4)) |
|
1682 |
return CMD_ERROR; |
|
1683 |
||
1684 |
if (flags & DC_EXEC) { |
|
1685 |
StationInitialize(st, ti.tile); |
|
1686 |
st->dock_tile = ti.tile; |
|
1687 |
st->facilities |= FACIL_DOCK; |
|
1688 |
st->had_vehicle_of_type |= HVOT_BUOY; |
|
1689 |
st->owner = OWNER_NONE; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1690 |
|
71
1b8e15a10515
(svn r72) -Add: build_date of station (viewable with Query tool)
truelight
parents:
65
diff
changeset
|
1691 |
st->build_date = _date; |
0 | 1692 |
|
1693 |
ModifyTile(ti.tile, |
|
1694 |
MP_SETTYPE(MP_STATION) | |
|
1695 |
MP_MAP2 | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR | MP_MAPOWNER | MP_MAP5, |
|
1696 |
st->index, /* map2 */ |
|
1697 |
OWNER_NONE, /* map_owner */ |
|
1698 |
0x52 /* map5 */ |
|
1699 |
); |
|
1700 |
||
1701 |
UpdateStationVirtCoordDirty(st); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1702 |
|
0 | 1703 |
UpdateStationAcceptance(st, false); |
1704 |
InvalidateWindow(WC_STATION_LIST, st->owner); |
|
1705 |
} |
|
1706 |
||
1707 |
return _price.build_dock; |
|
1708 |
} |
|
1709 |
||
1710 |
static int32 RemoveBuoy(Station *st, uint32 flags) |
|
1711 |
{ |
|
1712 |
uint tile; |
|
1713 |
||
1714 |
if (_current_player >= MAX_PLAYERS) { |
|
1715 |
/* XXX: strange stuff */ |
|
1716 |
return_cmd_error(INVALID_STRING_ID); |
|
1717 |
} |
|
1718 |
||
1719 |
tile = st->dock_tile; |
|
1720 |
||
1721 |
if (!EnsureNoVehicle(tile)) |
|
1722 |
return CMD_ERROR; |
|
1723 |
||
1724 |
if (flags & DC_EXEC) { |
|
1725 |
st->dock_tile = 0; |
|
1726 |
st->facilities &= ~FACIL_DOCK; |
|
1727 |
st->had_vehicle_of_type &= ~HVOT_BUOY; |
|
1728 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1729 |
ModifyTile(tile, |
0 | 1730 |
MP_SETTYPE(MP_WATER) | |
1731 |
MP_MAP2_CLEAR | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR | MP_MAPOWNER | MP_MAP5 | MP_MAP2_CLEAR, |
|
1732 |
OWNER_WATER, /* map_owner */ |
|
1733 |
0 /* map5 */ |
|
1734 |
); |
|
1735 |
||
1736 |
UpdateStationVirtCoordDirty(st); |
|
1737 |
DeleteStationIfEmpty(st); |
|
1738 |
} |
|
1739 |
||
1740 |
return _price.remove_truck_station; |
|
1741 |
} |
|
1742 |
||
1743 |
static const TileIndexDiff _dock_tileoffs_chkaround[4] = { |
|
1744 |
TILE_XY(-1,0), |
|
1745 |
0,0, |
|
1746 |
TILE_XY(0,-1), |
|
1747 |
}; |
|
1748 |
static const byte _dock_w_chk[4] = { 2,1,2,1 }; |
|
1749 |
static const byte _dock_h_chk[4] = { 1,2,1,2 }; |
|
1750 |
||
1751 |
int32 CmdBuildDock(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
1752 |
{ |
|
1753 |
TileInfo ti; |
|
1754 |
int direction; |
|
1755 |
int32 cost; |
|
1756 |
uint tile, tile_cur; |
|
1757 |
Station *st; |
|
1758 |
||
1759 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
1760 |
||
1761 |
FindLandscapeHeight(&ti, x, y); |
|
1762 |
||
1763 |
if ((direction=0,ti.tileh) != 3 && |
|
1764 |
(direction++,ti.tileh) != 9 && |
|
1765 |
(direction++,ti.tileh) != 12 && |
|
1766 |
(direction++,ti.tileh) != 6) |
|
1767 |
return_cmd_error(STR_304B_SITE_UNSUITABLE); |
|
1768 |
||
1769 |
if (!EnsureNoVehicle(ti.tile)) |
|
1770 |
return CMD_ERROR; |
|
1771 |
||
1772 |
cost = DoCommandByTile(ti.tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
|
1773 |
if (cost == CMD_ERROR) |
|
1774 |
return CMD_ERROR; |
|
1775 |
||
1776 |
tile_cur = (tile=ti.tile) + _tileoffs_by_dir[direction]; |
|
1777 |
||
1778 |
if (!EnsureNoVehicle(tile_cur)) |
|
1779 |
return CMD_ERROR; |
|
1780 |
||
1781 |
FindLandscapeHeightByTile(&ti, tile_cur); |
|
1782 |
if (ti.tileh != 0 || ti.type != MP_WATER) |
|
1783 |
return_cmd_error(STR_304B_SITE_UNSUITABLE); |
|
1784 |
||
1785 |
cost = DoCommandByTile(tile_cur, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
|
1786 |
if (cost == CMD_ERROR) |
|
1787 |
return CMD_ERROR; |
|
1788 |
||
1789 |
tile_cur = tile_cur + _tileoffs_by_dir[direction]; |
|
1790 |
FindLandscapeHeightByTile(&ti, tile_cur); |
|
1791 |
if (ti.tileh != 0 || ti.type != MP_WATER) |
|
1792 |
return_cmd_error(STR_304B_SITE_UNSUITABLE); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1793 |
|
0 | 1794 |
/* middle */ |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1795 |
st = GetStationAround(tile + _dock_tileoffs_chkaround[direction], |
0 | 1796 |
_dock_w_chk[direction], _dock_h_chk[direction], -1); |
1797 |
if (st == CHECK_STATIONS_ERR) |
|
1798 |
return CMD_ERROR; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1799 |
|
0 | 1800 |
/* Find a station close to us */ |
1801 |
if (st == NULL) { |
|
1802 |
st = GetClosestStationFromTile(tile, 8, _current_player); |
|
1803 |
if (st!=NULL && st->facilities) st = NULL; |
|
1804 |
} |
|
1805 |
||
1806 |
if (st != NULL) { |
|
1807 |
if (st->owner != OWNER_NONE && st->owner != _current_player) |
|
1808 |
return_cmd_error(STR_3009_TOO_CLOSE_TO_ANOTHER_STATION); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1809 |
|
0 | 1810 |
if (!CheckStationSpreadOut(st, tile, 1, 1)) |
1811 |
return CMD_ERROR; |
|
1812 |
||
1813 |
if (st->dock_tile != 0) |
|
1814 |
return_cmd_error(STR_304C_TOO_CLOSE_TO_ANOTHER_DOCK); |
|
1815 |
} else { |
|
1816 |
Town *t; |
|
1817 |
||
1818 |
st = AllocateStation(); |
|
1819 |
if (st == NULL) |
|
1820 |
return CMD_ERROR; |
|
1821 |
||
1822 |
st->town = t = ClosestTownFromTile(tile, (uint)-1); |
|
1823 |
||
1824 |
if (_current_player < MAX_PLAYERS && flags&DC_EXEC) |
|
1825 |
SETBIT(t->have_ratings, _current_player); |
|
1826 |
||
1827 |
st->sign.width_1 = 0; |
|
1828 |
||
1829 |
if (!GenerateStationName(st, tile, 3)) |
|
1830 |
return CMD_ERROR; |
|
1831 |
||
1832 |
if (flags & DC_EXEC) |
|
1833 |
StationInitialize(st, tile); |
|
1834 |
} |
|
1835 |
||
1836 |
if (flags & DC_EXEC) { |
|
1837 |
st->dock_tile = tile; |
|
1838 |
if (!st->facilities) st->xy = tile; |
|
1839 |
st->facilities |= FACIL_DOCK; |
|
1840 |
st->owner = _current_player; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1841 |
|
71
1b8e15a10515
(svn r72) -Add: build_date of station (viewable with Query tool)
truelight
parents:
65
diff
changeset
|
1842 |
st->build_date = _date; |
0 | 1843 |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1844 |
ModifyTile(tile, |
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1845 |
MP_SETTYPE(MP_STATION) | MP_MAPOWNER_CURRENT | |
0 | 1846 |
MP_MAP2 | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR | |
1847 |
MP_MAP5, |
|
1848 |
st->index, |
|
1849 |
direction + 0x4C); |
|
1850 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1851 |
ModifyTile(tile + _tileoffs_by_dir[direction], |
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1852 |
MP_SETTYPE(MP_STATION) | MP_MAPOWNER_CURRENT | |
0 | 1853 |
MP_MAP2 | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR | |
1854 |
MP_MAP5, |
|
1855 |
st->index, |
|
1856 |
(direction&1) + 0x50); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1857 |
|
0 | 1858 |
UpdateStationVirtCoordDirty(st); |
1859 |
UpdateStationAcceptance(st, false); |
|
1860 |
InvalidateWindow(WC_STATION_LIST, st->owner); |
|
1861 |
} |
|
1862 |
return _price.build_dock; |
|
1863 |
} |
|
1864 |
||
1865 |
static int32 RemoveDock(Station *st, uint32 flags) |
|
1866 |
{ |
|
1867 |
uint tile1, tile2; |
|
1868 |
||
1869 |
if (!CheckOwnership(st->owner)) |
|
1870 |
return CMD_ERROR; |
|
1871 |
||
1872 |
tile1 = st->dock_tile; |
|
1873 |
tile2 = tile1 + _tileoffs_by_dir[_map5[tile1] - 0x4C]; |
|
1874 |
||
1875 |
if (!EnsureNoVehicle(tile1)) |
|
1876 |
return CMD_ERROR; |
|
1877 |
||
1878 |
if (!EnsureNoVehicle(tile2)) |
|
1879 |
return CMD_ERROR; |
|
1880 |
||
1881 |
if (flags & DC_EXEC) { |
|
1882 |
DoClearSquare(tile1); |
|
1883 |
||
1884 |
// convert the water tile to water. |
|
1885 |
ModifyTile(tile2, MP_SETTYPE(MP_WATER) | MP_MAPOWNER | MP_MAP5 | MP_MAP2_CLEAR | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR, OWNER_WATER, 0); |
|
1886 |
||
1887 |
st->dock_tile = 0; |
|
1888 |
st->facilities &= ~FACIL_DOCK; |
|
1889 |
||
1890 |
UpdateStationVirtCoordDirty(st); |
|
1891 |
DeleteStationIfEmpty(st); |
|
1892 |
} |
|
1893 |
||
1894 |
return _price.remove_dock; |
|
1895 |
} |
|
1896 |
||
1897 |
#include "table/station_land.h" |
|
1898 |
||
1899 |
||
449
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
1900 |
extern uint16 _custom_sprites_base; |
0 | 1901 |
|
1902 |
static void DrawTile_Station(TileInfo *ti) |
|
1903 |
{ |
|
1904 |
uint32 image_or_modificator; |
|
449
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
1905 |
uint32 image; |
0 | 1906 |
const DrawTileSeqStruct *dtss; |
449
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
1907 |
const DrawTileSprites *t = NULL; |
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
1908 |
byte railtype = _map3_lo[ti->tile] & 0xF; |
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
1909 |
uint32 relocation = 0; |
0 | 1910 |
|
1911 |
{ |
|
1912 |
uint owner = _map_owner[ti->tile]; |
|
1913 |
image_or_modificator = 0x315 << 16; /* NOTE: possible bug in ttd here? */ |
|
1914 |
if (owner < MAX_PLAYERS) |
|
1915 |
image_or_modificator = PLAYER_SPRITE_COLOR(owner); |
|
1916 |
} |
|
1917 |
||
1918 |
// don't show foundation for docks (docks are between 76 (0x4C) and 81 (0x51)) |
|
1919 |
if (ti->tileh != 0 && (ti->map5 < 0x4C || ti->map5 > 0x51)) |
|
1920 |
DrawFoundation(ti, ti->tileh); |
|
1921 |
||
449
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
1922 |
if (_map3_lo[ti->tile] & 0x10) { |
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
1923 |
// look for customization |
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
1924 |
struct StationSpec *statspec = GetCustomStation(STAT_CLASS_DFLT, _map3_hi[ti->tile]); |
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
1925 |
|
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
1926 |
//debug("Cust-o-mized %p", statspec); |
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
1927 |
|
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
1928 |
if (statspec != NULL) { |
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
1929 |
Station *st = DEREF_STATION(_map2[ti->tile]); |
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
1930 |
|
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
1931 |
relocation = GetCustomStationRelocation(statspec, st, 0); |
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
1932 |
//debug("Relocation %d", relocation); |
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
1933 |
t = &statspec->renderdata[ti->map5]; |
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
1934 |
} |
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
1935 |
} |
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
1936 |
|
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
1937 |
if (t == NULL) t = &_station_display_datas[ti->map5]; |
384
bf1303e754ff
(svn r576) -newgrf: Cleanup horrible table/(station|unmovable)_land.h DrawTileSeqStruct hacks needed for custom station supports (pasky)
darkvater
parents:
354
diff
changeset
|
1938 |
|
bf1303e754ff
(svn r576) -newgrf: Cleanup horrible table/(station|unmovable)_land.h DrawTileSeqStruct hacks needed for custom station supports (pasky)
darkvater
parents:
354
diff
changeset
|
1939 |
image = t->ground_sprite; |
0 | 1940 |
if (image & 0x8000) |
1941 |
image |= image_or_modificator; |
|
449
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
1942 |
|
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
1943 |
// station_land array has been increased from 82 elements to 114 |
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
1944 |
// but this is something else. If AI builds station with 114 it looks all weird |
457
f656a2ff7b6c
(svn r667) Fix bug in rendering stations from savegames
tron
parents:
452
diff
changeset
|
1945 |
image += railtype * ((image & 0x3FFF) < _custom_sprites_base ? TRACKTYPE_SPRITE_PITCH : 1); |
449
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
1946 |
DrawGroundSprite(image); |
0 | 1947 |
|
384
bf1303e754ff
(svn r576) -newgrf: Cleanup horrible table/(station|unmovable)_land.h DrawTileSeqStruct hacks needed for custom station supports (pasky)
darkvater
parents:
354
diff
changeset
|
1948 |
foreach_draw_tile_seq(dtss, t->seq) { |
449
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
1949 |
image = dtss->image + relocation; |
457
f656a2ff7b6c
(svn r667) Fix bug in rendering stations from savegames
tron
parents:
452
diff
changeset
|
1950 |
// For custom sprites, there's no railtype-based pitching. |
f656a2ff7b6c
(svn r667) Fix bug in rendering stations from savegames
tron
parents:
452
diff
changeset
|
1951 |
image += railtype * ((image & 0x3FFF) < _custom_sprites_base ? TRACKTYPE_SPRITE_PITCH : 0); |
384
bf1303e754ff
(svn r576) -newgrf: Cleanup horrible table/(station|unmovable)_land.h DrawTileSeqStruct hacks needed for custom station supports (pasky)
darkvater
parents:
354
diff
changeset
|
1952 |
if (_display_opt & DO_TRANS_BUILDINGS) { |
497
2d6d31173813
(svn r787) Invert the sense of the DO_TRANS_BUILDINGS flag to be consistent with its own name and all other DO_* flags.
tron
parents:
494
diff
changeset
|
1953 |
image = (image & 0x3FFF) | 0x03224000; |
2d6d31173813
(svn r787) Invert the sense of the DO_TRANS_BUILDINGS flag to be consistent with its own name and all other DO_* flags.
tron
parents:
494
diff
changeset
|
1954 |
} else { |
384
bf1303e754ff
(svn r576) -newgrf: Cleanup horrible table/(station|unmovable)_land.h DrawTileSeqStruct hacks needed for custom station supports (pasky)
darkvater
parents:
354
diff
changeset
|
1955 |
if (image&0x8000) image |= image_or_modificator; |
bf1303e754ff
(svn r576) -newgrf: Cleanup horrible table/(station|unmovable)_land.h DrawTileSeqStruct hacks needed for custom station supports (pasky)
darkvater
parents:
354
diff
changeset
|
1956 |
} |
bf1303e754ff
(svn r576) -newgrf: Cleanup horrible table/(station|unmovable)_land.h DrawTileSeqStruct hacks needed for custom station supports (pasky)
darkvater
parents:
354
diff
changeset
|
1957 |
|
0 | 1958 |
if ((byte)dtss->delta_z != 0x80) { |
1959 |
AddSortableSpriteToDraw(image, ti->x + dtss->delta_x, ti->y + dtss->delta_y, dtss->width, dtss->height, dtss->unk, ti->z + dtss->delta_z); |
|
1960 |
} else { |
|
1961 |
AddChildSpriteScreen(image, dtss->delta_x, dtss->delta_y); |
|
1962 |
} |
|
1963 |
} |
|
1964 |
} |
|
1965 |
||
1966 |
void StationPickerDrawSprite(int x, int y, int railtype, int image) |
|
1967 |
{ |
|
1968 |
uint32 ormod, img; |
|
1969 |
const DrawTileSeqStruct *dtss; |
|
384
bf1303e754ff
(svn r576) -newgrf: Cleanup horrible table/(station|unmovable)_land.h DrawTileSeqStruct hacks needed for custom station supports (pasky)
darkvater
parents:
354
diff
changeset
|
1970 |
const DrawTileSprites *t; |
0 | 1971 |
|
1972 |
/* baseimage */ |
|
1973 |
railtype *= TRACKTYPE_SPRITE_PITCH; |
|
1974 |
||
1975 |
ormod = PLAYER_SPRITE_COLOR(_local_player); |
|
1976 |
||
384
bf1303e754ff
(svn r576) -newgrf: Cleanup horrible table/(station|unmovable)_land.h DrawTileSeqStruct hacks needed for custom station supports (pasky)
darkvater
parents:
354
diff
changeset
|
1977 |
t = &_station_display_datas[image]; |
bf1303e754ff
(svn r576) -newgrf: Cleanup horrible table/(station|unmovable)_land.h DrawTileSeqStruct hacks needed for custom station supports (pasky)
darkvater
parents:
354
diff
changeset
|
1978 |
|
bf1303e754ff
(svn r576) -newgrf: Cleanup horrible table/(station|unmovable)_land.h DrawTileSeqStruct hacks needed for custom station supports (pasky)
darkvater
parents:
354
diff
changeset
|
1979 |
img = t->ground_sprite; |
0 | 1980 |
if (img & 0x8000) |
1981 |
img |= ormod; |
|
354
d9a179673155
(svn r542) -Fix: Display correct rail type in "build railway station" window
tron
parents:
313
diff
changeset
|
1982 |
DrawSprite(img + railtype, x, y); |
0 | 1983 |
|
384
bf1303e754ff
(svn r576) -newgrf: Cleanup horrible table/(station|unmovable)_land.h DrawTileSeqStruct hacks needed for custom station supports (pasky)
darkvater
parents:
354
diff
changeset
|
1984 |
foreach_draw_tile_seq(dtss, t->seq) { |
0 | 1985 |
Point pt = RemapCoords(dtss->delta_x, dtss->delta_y, dtss->delta_z); |
1986 |
DrawSprite((dtss->image | ormod) + railtype, x + pt.x, y + pt.y); |
|
1987 |
} |
|
1988 |
} |
|
1989 |
||
1990 |
static uint GetSlopeZ_Station(TileInfo *ti) |
|
1991 |
{ |
|
1992 |
uint z = ti->z; |
|
1993 |
if (ti->tileh != 0) |
|
1994 |
z += 8; |
|
1995 |
return z; |
|
1996 |
} |
|
1997 |
||
39 | 1998 |
static uint GetSlopeTileh_Station(TileInfo *ti) |
1999 |
{ |
|
2000 |
return 0; |
|
2001 |
} |
|
2002 |
||
473
0da86c59e3ae
(svn r724) Remove restriction that a tile can only accept 3 cargo types.
tron
parents:
457
diff
changeset
|
2003 |
static void GetAcceptedCargo_Station(uint tile, AcceptedCargo ac) |
0 | 2004 |
{ |
2005 |
/* not used */ |
|
2006 |
} |
|
2007 |
||
2008 |
static void GetTileDesc_Station(uint tile, TileDesc *td) |
|
2009 |
{ |
|
2010 |
byte m5; |
|
2011 |
StringID str; |
|
2012 |
||
2013 |
td->owner = _map_owner[tile]; |
|
71
1b8e15a10515
(svn r72) -Add: build_date of station (viewable with Query tool)
truelight
parents:
65
diff
changeset
|
2014 |
td->build_date = DEREF_STATION(_map2[tile])->build_date; |
0 | 2015 |
|
2016 |
m5 = _map5[tile]; |
|
2017 |
(str=STR_305E_RAILROAD_STATION, m5 < 8) || |
|
2018 |
(str=STR_305F_AIRCRAFT_HANGAR, m5==32 || m5==45) || // hangars |
|
2019 |
(str=STR_3060_AIRPORT, m5 < 0x43 || (m5 >= 83 && m5 <= 114)) || |
|
2020 |
(str=STR_3061_TRUCK_LOADING_AREA, m5 < 0x47) || |
|
2021 |
(str=STR_3062_BUS_STATION, m5 < 0x4B) || |
|
2022 |
(str=STR_4807_OIL_RIG, m5 == 0x4B) || |
|
2023 |
(str=STR_3063_SHIP_DOCK, m5 != 0x52) || |
|
2024 |
(str=STR_3069_BUOY, true); |
|
2025 |
td->str = str; |
|
2026 |
} |
|
2027 |
||
2028 |
||
2029 |
static const byte _tile_track_status_rail[8] = { 1,2,1,2,1,2,1,2 }; |
|
2030 |
||
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
149
diff
changeset
|
2031 |
static uint32 GetTileTrackStatus_Station(uint tile, TransportType mode) { |
0 | 2032 |
uint i = _map5[tile]; |
2033 |
uint j = 0; |
|
2034 |
||
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
149
diff
changeset
|
2035 |
if (mode == TRANSPORT_RAIL) { |
0 | 2036 |
if (i < 8) |
2037 |
j = _tile_track_status_rail[i]; |
|
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
149
diff
changeset
|
2038 |
j += (j << 8); |
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
149
diff
changeset
|
2039 |
} else if (mode == TRANSPORT_WATER) { |
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
149
diff
changeset
|
2040 |
// buoy is coded as a station, it is always on open water |
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
149
diff
changeset
|
2041 |
// (0x3F, all tracks available) |
0 | 2042 |
if (i == 0x52) j = 0x3F; |
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
149
diff
changeset
|
2043 |
j += (j << 8); |
0 | 2044 |
} |
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
149
diff
changeset
|
2045 |
return j; |
0 | 2046 |
} |
2047 |
||
2048 |
static void TileLoop_Station(uint tile) |
|
2049 |
{ |
|
2050 |
//FIXME -- GetTileTrackStatus_Station -> animated stationtiles |
|
2051 |
// hardcoded.....not good |
|
2052 |
// 0x27 - large big airport (39) |
|
2053 |
// 0x66 - radar metropolitan airport (102) |
|
2054 |
// 0x5A - radar international airport (90) |
|
2055 |
// 0x3A - flag small airport (58) |
|
2056 |
if (_map5[tile] == 39 || _map5[tile] == 58 || _map5[tile] == 90 || _map5[tile] == 102) |
|
2057 |
AddAnimatedTile(tile); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2058 |
|
0 | 2059 |
// treat a bouy tile as water. |
2060 |
else if (_map5[tile] == 0x52) |
|
2061 |
TileLoop_Water(tile); |
|
43
3b93861c5478
(svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents:
39
diff
changeset
|
2062 |
|
3b93861c5478
(svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents:
39
diff
changeset
|
2063 |
// treat a oilrig (the station part) as water |
3b93861c5478
(svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents:
39
diff
changeset
|
2064 |
else if (_map5[tile] == 0x4B) |
3b93861c5478
(svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents:
39
diff
changeset
|
2065 |
TileLoop_Water(tile); |
3b93861c5478
(svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents:
39
diff
changeset
|
2066 |
|
0 | 2067 |
} |
2068 |
||
2069 |
||
2070 |
static void AnimateTile_Station(uint tile) |
|
2071 |
{ |
|
2072 |
byte m5 = _map5[tile]; |
|
2073 |
//FIXME -- AnimateTile_Station -> not nice code, lots of things double |
|
2074 |
// again hardcoded...was a quick hack |
|
2075 |
||
2076 |
// turning radar / windsack on airport |
|
2077 |
if (m5 >= 39 && m5 <= 50) { // turning radar (39 - 50) |
|
2078 |
if (_tick_counter & 3) |
|
2079 |
return; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2080 |
|
0 | 2081 |
if (++m5 == 50+1) |
2082 |
m5 = 39; |
|
2083 |
||
2084 |
_map5[tile] = m5; |
|
2085 |
MarkTileDirtyByTile(tile); |
|
2086 |
//added - begin |
|
2087 |
} else if (m5 >= 90 && m5 <= 113) { // turning radar with ground under it (different fences) (90 - 101 | 102 - 113) |
|
2088 |
if (_tick_counter & 3) |
|
2089 |
return; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2090 |
|
0 | 2091 |
m5++; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2092 |
|
0 | 2093 |
if (m5 == 101+1) {m5 = 90;} // radar with fences in south |
2094 |
else if (m5 == 113+1) {m5 = 102;} // radar with fences in north |
|
2095 |
||
2096 |
_map5[tile] = m5; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2097 |
MarkTileDirtyByTile(tile); |
0 | 2098 |
//added - end |
2099 |
} else if (m5 >= 0x3A && m5 <= 0x3D) { // windsack (58 - 61) |
|
2100 |
if (_tick_counter & 1) |
|
2101 |
return; |
|
2102 |
||
2103 |
if (++m5 == 0x3D+1) |
|
2104 |
m5 = 0x3A; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2105 |
|
0 | 2106 |
_map5[tile] = m5; |
2107 |
MarkTileDirtyByTile(tile); |
|
2108 |
} |
|
2109 |
} |
|
2110 |
||
2111 |
static void ClickTile_Station(uint tile) |
|
2112 |
{ |
|
2113 |
// 0x20 - hangar large airport (32) |
|
2114 |
// 0x41 - hangar small airport (65) |
|
2115 |
if (_map5[tile] == 32 || _map5[tile] == 65) { |
|
2116 |
ShowAircraftDepotWindow(tile); |
|
2117 |
} else { |
|
2118 |
ShowStationViewWindow(_map2[tile]); |
|
2119 |
} |
|
2120 |
} |
|
2121 |
||
500
ef288590e096
(svn r793) Merge INLINE -> inline replacement (revision 376)
tron
parents:
497
diff
changeset
|
2122 |
static inline bool IsTrainStationTile(uint tile) { |
0 | 2123 |
return IS_TILETYPE(tile, MP_STATION) && IS_BYTE_INSIDE(_map5[tile], 0, 8); |
2124 |
} |
|
2125 |
||
2126 |
static const byte _enter_station_speedtable[12] = { |
|
2127 |
215, 195, 175, 155, 135, 115, 95, 75, 55, 35, 15, 0 |
|
2128 |
}; |
|
2129 |
||
2130 |
static uint32 VehicleEnter_Station(Vehicle *v, uint tile, int x, int y) |
|
2131 |
{ |
|
2132 |
byte station_id; |
|
2133 |
byte dir; |
|
2134 |
uint16 spd; |
|
2135 |
||
2136 |
if (v->type == VEH_Train) { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2137 |
if (IS_BYTE_INSIDE(_map5[tile], 0, 8) && v->subtype == 0 && |
0 | 2138 |
!IsTrainStationTile(tile + _tileoffs_by_dir[v->direction >> 1])) { |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2139 |
|
0 | 2140 |
station_id = _map2[tile]; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2141 |
if ((!(v->next_order & OF_NON_STOP) && !_patches.new_nonstop) || |
0 | 2142 |
(((v->next_order & OT_MASK) == OT_GOTO_STATION && v->next_order_param == station_id))) { |
2143 |
||
2144 |
if (!(_patches.new_nonstop && (v->next_order & OF_NON_STOP)) && v->next_order != OT_LEAVESTATION && v->last_station_visited != station_id) { |
|
2145 |
x &= 0xF; |
|
2146 |
y &= 0xF; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2147 |
|
0 | 2148 |
dir = v->direction & 6; |
2149 |
if (dir & 2) intswap(x,y); |
|
2150 |
if (y == 8) { |
|
2151 |
if (dir != 2 && dir != 4) { |
|
2152 |
x = (~x)&0xF; |
|
2153 |
} |
|
2154 |
if (x == 12) return 2 | (station_id << 8); /* enter station */ |
|
2155 |
if (x < 12) { |
|
2156 |
v->vehstatus |= VS_TRAIN_SLOWING; |
|
2157 |
spd = _enter_station_speedtable[x]; |
|
2158 |
if (spd < v->cur_speed) |
|
2159 |
v->cur_speed = spd; |
|
2160 |
} |
|
2161 |
} |
|
2162 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2163 |
} |
0 | 2164 |
} |
2165 |
} else if (v->type == VEH_Road) { |
|
2166 |
if (v->u.road.state < 16 && (v->u.road.state&4)==0 && v->u.road.frame==0) { |
|
2167 |
Station *st = DEREF_STATION(_map2[tile]); |
|
2168 |
byte m5 = _map5[tile]; |
|
2169 |
byte *b, bb,state; |
|
2170 |
||
2171 |
if (IS_BYTE_INSIDE(m5, 0x43, 0x4B)) { |
|
2172 |
b = (m5 >= 0x47) ? &st->bus_stop_status : &st->truck_stop_status; |
|
2173 |
||
2174 |
bb = *b; |
|
2175 |
||
2176 |
/* bb bits 1..0 describe current the two parking spots. |
|
2177 |
0 means occupied, 1 means free. */ |
|
2178 |
||
2179 |
// Station busy? |
|
2180 |
if (bb & 0x80 || (bb&3) == 0) |
|
2181 |
return 8; |
|
2182 |
||
2183 |
state = v->u.road.state + 32; |
|
2184 |
if (bb & 1) { |
|
2185 |
bb &= ~1; |
|
2186 |
} else { |
|
2187 |
bb &= ~2; |
|
2188 |
state += 2; |
|
2189 |
} |
|
2190 |
*b = bb; |
|
2191 |
v->u.road.state = state; |
|
2192 |
} |
|
2193 |
} |
|
2194 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2195 |
|
0 | 2196 |
return 0; |
2197 |
} |
|
2198 |
||
2199 |
static void DeleteStation(Station *st) |
|
2200 |
{ |
|
2201 |
int index; |
|
2202 |
st->xy = 0; |
|
2203 |
||
2204 |
DeleteName(st->string_id); |
|
2205 |
MarkStationDirty(st); |
|
243
9a40daa560ae
(svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents:
222
diff
changeset
|
2206 |
_global_station_sort_dirty = true; // delete station, remove sign |
65
f9f866bc609c
(svn r66) -Fix Station list updated on station deletion/station rename
darkvater
parents:
59
diff
changeset
|
2207 |
InvalidateWindowClasses(WC_STATION_LIST); |
0 | 2208 |
|
2209 |
index = st->index; |
|
2210 |
DeleteWindowById(WC_STATION_VIEW, index); |
|
2211 |
DeleteCommandFromVehicleSchedule((index << 8) + OT_GOTO_STATION); |
|
2212 |
DeleteSubsidyWithStation(index); |
|
2213 |
} |
|
2214 |
||
2215 |
void DeleteAllPlayerStations() |
|
2216 |
{ |
|
2217 |
Station *st; |
|
2218 |
||
2219 |
FOR_ALL_STATIONS(st) { |
|
2220 |
if (st->xy && st->owner < MAX_PLAYERS) |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2221 |
DeleteStation(st); |
0 | 2222 |
} |
2223 |
} |
|
2224 |
||
2225 |
/* this function is called for one station each tick */ |
|
2226 |
static void StationHandleBigTick(Station *st) |
|
2227 |
{ |
|
2228 |
UpdateStationAcceptance(st, true); |
|
2229 |
||
2230 |
if (st->facilities == 0) { |
|
2231 |
if (++st->delete_ctr >= 8) |
|
2232 |
DeleteStation(st); |
|
2233 |
} |
|
2234 |
} |
|
2235 |
||
500
ef288590e096
(svn r793) Merge INLINE -> inline replacement (revision 376)
tron
parents:
497
diff
changeset
|
2236 |
static inline void byte_inc_sat(byte *p) { byte b = *p + 1; if (b != 0) *p = b; } |
0 | 2237 |
|
2238 |
static byte _rating_boost[3] = { 0, 31, 63}; |
|
2239 |
||
2240 |
static void UpdateStationRating(Station *st) |
|
2241 |
{ |
|
2242 |
GoodsEntry *ge; |
|
2243 |
int rating, index; |
|
2244 |
int waiting; |
|
2245 |
bool waiting_changed = false; |
|
2246 |
||
2247 |
byte_inc_sat(&st->time_since_load); |
|
2248 |
byte_inc_sat(&st->time_since_unload); |
|
2249 |
||
2250 |
ge = st->goods; |
|
2251 |
do { |
|
2252 |
if (ge->enroute_from != 0xFF) { |
|
2253 |
byte_inc_sat(&ge->enroute_time); |
|
2254 |
byte_inc_sat(&ge->days_since_pickup); |
|
2255 |
||
2256 |
rating = 0; |
|
2257 |
||
2258 |
{ |
|
2259 |
int b = ge->last_speed; |
|
2260 |
if ((b-=85) >= 0) |
|
2261 |
rating += b >> 2; |
|
2262 |
} |
|
2263 |
||
2264 |
{ |
|
2265 |
byte age = ge->last_age; |
|
2266 |
(age >= 3) || |
|
2267 |
(rating += 10, age >= 2) || |
|
2268 |
(rating += 10, age >= 1) || |
|
2269 |
(rating += 13, true); |
|
2270 |
} |
|
2271 |
||
2272 |
{ |
|
2273 |
if (!IS_HUMAN_PLAYER(st->owner) && st->owner != OWNER_NONE) |
|
2274 |
rating += _rating_boost[_opt.diff.competitor_intelligence]; |
|
2275 |
} |
|
2276 |
||
2277 |
if (st->owner < 8 && HASBIT(st->town->statues, st->owner)) |
|
2278 |
rating += 26; |
|
2279 |
||
2280 |
{ |
|
2281 |
byte days = ge->days_since_pickup; |
|
2282 |
if (st->last_vehicle != INVALID_VEHICLE && |
|
2283 |
(&_vehicles[st->last_vehicle])->type == VEH_Ship) |
|
2284 |
days >>= 2; |
|
2285 |
(days > 21) || |
|
2286 |
(rating += 25, days > 12) || |
|
2287 |
(rating += 25, days > 6) || |
|
2288 |
(rating += 45, days > 3) || |
|
2289 |
(rating += 35, true); |
|
2290 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2291 |
|
0 | 2292 |
{ |
2293 |
waiting = ge->waiting_acceptance & 0xFFF; |
|
2294 |
(rating -= 90, waiting > 1500) || |
|
2295 |
(rating += 55, waiting > 1000) || |
|
2296 |
(rating += 35, waiting > 600) || |
|
2297 |
(rating += 10, waiting > 300) || |
|
2298 |
(rating += 20, waiting > 100) || |
|
2299 |
(rating += 10, true); |
|
2300 |
} |
|
2301 |
||
2302 |
{ |
|
2303 |
int or = ge->rating; // old rating |
|
2304 |
||
2305 |
// only modify rating in steps of -2, -1, 0, 1 or 2 |
|
2306 |
ge->rating = rating = or + clamp(clamp(rating, 0, 255) - or, -2, 2); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2307 |
|
0 | 2308 |
// if rating is <= 64 and more than 200 items waiting, remove some random amount of goods from the station |
2309 |
if (rating <= 64 && waiting >= 200) { |
|
2310 |
int dec = Random() & 0x1F; |
|
2311 |
if (waiting < 400) dec &= 7; |
|
2312 |
waiting -= dec + 1; |
|
2313 |
waiting_changed = true; |
|
2314 |
} |
|
2315 |
||
2316 |
// if rating is <= 127 and there are any items waiting, maybe remove some goods. |
|
2317 |
if (rating <= 127 && waiting != 0) { |
|
2318 |
uint32 r = Random(); |
|
2319 |
if ( (uint)rating <= (r & 0x7F) ) { |
|
2320 |
waiting = max(waiting - ((r >> 8)&3) - 1, 0); |
|
2321 |
waiting_changed = true; |
|
2322 |
} |
|
2323 |
} |
|
2324 |
||
2325 |
if (waiting_changed) |
|
2326 |
ge->waiting_acceptance = (ge->waiting_acceptance & ~0xFFF) + waiting; |
|
2327 |
} |
|
2328 |
} |
|
2329 |
} while (++ge != endof(st->goods)); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2330 |
|
0 | 2331 |
index = st->index; |
2332 |
||
2333 |
if (waiting_changed) |
|
2334 |
InvalidateWindow(WC_STATION_VIEW, index); |
|
2335 |
else |
|
2336 |
InvalidateWindowWidget(WC_STATION_VIEW, index, 5); |
|
2337 |
} |
|
2338 |
||
2339 |
/* called for every station each tick */ |
|
2340 |
static void StationHandleSmallTick(Station *st) |
|
2341 |
{ |
|
2342 |
byte b; |
|
2343 |
||
2344 |
if (st->facilities == 0) |
|
2345 |
return; |
|
2346 |
||
2347 |
b = st->delete_ctr + 1; |
|
2348 |
if (b >= 185) b = 0; |
|
2349 |
st->delete_ctr = b; |
|
2350 |
||
2351 |
if (b == 0) |
|
2352 |
UpdateStationRating(st); |
|
2353 |
} |
|
2354 |
||
2355 |
void OnTick_Station() |
|
2356 |
{ |
|
2357 |
int i; |
|
2358 |
Station *st; |
|
2359 |
||
2360 |
if (_game_mode == GM_EDITOR) |
|
2361 |
return; |
|
2362 |
||
2363 |
i = _station_tick_ctr; |
|
2364 |
if (++_station_tick_ctr == lengthof(_stations)) |
|
2365 |
_station_tick_ctr = 0; |
|
2366 |
||
2367 |
st = DEREF_STATION(i); |
|
2368 |
if (st->xy != 0) |
|
2369 |
StationHandleBigTick(st); |
|
2370 |
||
2371 |
FOR_ALL_STATIONS(st) { |
|
2372 |
if (st->xy != 0) |
|
2373 |
StationHandleSmallTick(st); |
|
2374 |
} |
|
2375 |
||
2376 |
} |
|
2377 |
||
2378 |
void StationMonthlyLoop() |
|
2379 |
{ |
|
2380 |
} |
|
2381 |
||
2382 |
||
2383 |
void ModifyStationRatingAround(TileIndex tile, byte owner, int amount, uint radius) |
|
2384 |
{ |
|
2385 |
Station *st; |
|
2386 |
GoodsEntry *ge; |
|
2387 |
int i; |
|
2388 |
||
2389 |
FOR_ALL_STATIONS(st) { |
|
2390 |
if (st->xy != 0 && st->owner == owner && GetTileDist(tile, st->xy) <= radius) { |
|
2391 |
ge = st->goods; |
|
2392 |
for(i=0; i!=NUM_CARGO; i++,ge++) { |
|
2393 |
if (ge->enroute_from != 0xFF) { |
|
2394 |
ge->rating = clamp(ge->rating + amount, 0, 255); |
|
2395 |
} |
|
2396 |
} |
|
2397 |
} |
|
2398 |
} |
|
2399 |
} |
|
2400 |
||
2401 |
static void UpdateStationWaiting(Station *st, int type, uint amount) |
|
2402 |
{ |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2403 |
st->goods[type].waiting_acceptance = |
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2404 |
(st->goods[type].waiting_acceptance & ~0xFFF) + |
0 | 2405 |
min(0xFFF, (st->goods[type].waiting_acceptance & 0xFFF) + amount); |
2406 |
||
2407 |
st->goods[type].enroute_time = 0; |
|
2408 |
st->goods[type].enroute_from = st->index; |
|
2409 |
InvalidateWindow(WC_STATION_VIEW, st->index); |
|
2410 |
} |
|
2411 |
||
2412 |
int32 CmdRenameStation(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
2413 |
{ |
|
2414 |
StringID str,old_str; |
|
2415 |
Station *st; |
|
2416 |
||
2417 |
str = AllocateName((byte*)_decode_parameters, 6); |
|
2418 |
if (str == 0) |
|
2419 |
return CMD_ERROR; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2420 |
|
0 | 2421 |
if (flags & DC_EXEC) { |
2422 |
st = DEREF_STATION(p1); |
|
2423 |
old_str = st->string_id; |
|
2424 |
st->string_id = str; |
|
2425 |
UpdateStationVirtCoord(st); |
|
2426 |
DeleteName(old_str); |
|
243
9a40daa560ae
(svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents:
222
diff
changeset
|
2427 |
_station_sort_dirty[st->owner] = true; // rename a station |
0 | 2428 |
MarkWholeScreenDirty(); |
2429 |
} else { |
|
2430 |
DeleteName(str); |
|
2431 |
} |
|
2432 |
||
2433 |
return 0; |
|
2434 |
} |
|
2435 |
||
2436 |
||
2437 |
uint MoveGoodsToStation(uint tile, int w, int h, int type, uint amount) |
|
2438 |
{ |
|
2439 |
Station *around_ptr[8]; |
|
2440 |
byte around[8], st_index; |
|
2441 |
int i; |
|
2442 |
Station *st; |
|
2443 |
uint moved; |
|
2444 |
uint best_rating, best_rating2; |
|
2445 |
Station *st1, *st2; |
|
2446 |
int t; |
|
2447 |
||
2448 |
memset(around, 0xff, sizeof(around)); |
|
2449 |
||
2450 |
w += 8; |
|
2451 |
h += 8; |
|
2452 |
||
2453 |
BEGIN_TILE_LOOP(cur_tile, w, h, tile - TILE_XY(4,4)) |
|
2454 |
cur_tile = TILE_MASK(cur_tile); |
|
2455 |
if (IS_TILETYPE(cur_tile, MP_STATION)) { |
|
2456 |
st_index = _map2[cur_tile]; |
|
2457 |
for(i=0; i!=8; i++) { |
|
2458 |
if (around[i] == 0xFF) { |
|
2459 |
st = DEREF_STATION(st_index); |
|
2460 |
if ((st->had_vehicle_of_type & HVOT_BUOY) == 0 && |
|
121
c2f18f4d8be1
(svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents:
84
diff
changeset
|
2461 |
( !st->town->exclusive_counter || (st->town->exclusivity == st->owner) ) && // check exclusive transport rights |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2462 |
st->goods[type].rating != 0 && |
0 | 2463 |
(!_patches.selectgoods || st->goods[type].last_speed) && // if last_speed is 0, no vehicle has been there. |
22 | 2464 |
((st->facilities & (byte)~FACIL_BUS_STOP)!=0 || type==CT_PASSENGERS) && // if we have other fac. than a bus stop, or the cargo is passengers |
2465 |
((st->facilities & (byte)~FACIL_TRUCK_STOP)!=0 || type!=CT_PASSENGERS)) { // if we have other fac. than a cargo bay or the cargo is not passengers |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2466 |
|
0 | 2467 |
around[i] = st_index; |
2468 |
around_ptr[i] = st; |
|
2469 |
} |
|
2470 |
break; |
|
2471 |
} else if (around[i] == st_index) |
|
2472 |
break; |
|
2473 |
} |
|
2474 |
} |
|
2475 |
END_TILE_LOOP(cur_tile, w, h, tile - TILE_XY(4,4)) |
|
2476 |
||
2477 |
/* no stations around at all? */ |
|
2478 |
if (around[0] == 0xFF) |
|
2479 |
return 0; |
|
2480 |
||
2481 |
if (around[1] == 0xFF) { |
|
2482 |
/* only one station around */ |
|
2483 |
moved = (amount * around_ptr[0]->goods[type].rating >> 8) + 1; |
|
2484 |
UpdateStationWaiting(around_ptr[0], type, moved); |
|
2485 |
return moved; |
|
2486 |
} |
|
2487 |
||
2488 |
/* several stations around, find the two with the highest rating */ |
|
2489 |
st2 = st1 = NULL; |
|
2490 |
best_rating = best_rating2 = 0; |
|
2491 |
for(i=0; i!=8 && around[i] != 0xFF; i++) { |
|
2492 |
if (around_ptr[i]->goods[type].rating >= best_rating) { |
|
2493 |
best_rating2 = best_rating; |
|
2494 |
st2 = st1; |
|
2495 |
||
2496 |
best_rating = around_ptr[i]->goods[type].rating; |
|
2497 |
st1 = around_ptr[i]; |
|
2498 |
} else if (around_ptr[i]->goods[type].rating >= best_rating2) { |
|
2499 |
best_rating2 = around_ptr[i]->goods[type].rating; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2500 |
st2 = around_ptr[i]; |
0 | 2501 |
} |
2502 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2503 |
|
0 | 2504 |
assert(st1 != NULL); |
2505 |
assert(st2 != NULL); |
|
2506 |
assert(best_rating != 0 || best_rating2 != 0); |
|
2507 |
||
2508 |
/* the 2nd highest one gets a penalty */ |
|
2509 |
best_rating2 >>= 1; |
|
2510 |
||
2511 |
/* amount given to station 1 */ |
|
2512 |
t = (best_rating * (amount + 1)) / (best_rating + best_rating2); |
|
2513 |
||
2514 |
moved = 0; |
|
2515 |
if (t != 0) { |
|
2516 |
moved = (t * best_rating >> 8) + 1; |
|
2517 |
amount -= t; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2518 |
UpdateStationWaiting(st1, type, moved); |
0 | 2519 |
} |
2520 |
||
2521 |
assert(amount >= 0); |
|
2522 |
||
2523 |
if (amount != 0) { |
|
2524 |
moved += (amount = (amount * best_rating2 >> 8) + 1); |
|
2525 |
UpdateStationWaiting(st2, type, amount); |
|
2526 |
} |
|
2527 |
||
2528 |
return moved; |
|
2529 |
} |
|
2530 |
||
2531 |
void BuildOilRig(uint tile) |
|
2532 |
{ |
|
2533 |
Station *st; |
|
2534 |
int j; |
|
2535 |
||
2536 |
FOR_ALL_STATIONS(st) { |
|
2537 |
if (st->xy == 0) { |
|
2538 |
st->town = ClosestTownFromTile(tile, (uint)-1); |
|
2539 |
st->sign.width_1 = 0; |
|
2540 |
if (!GenerateStationName(st, tile, 2)) |
|
2541 |
return; |
|
2542 |
||
2543 |
_map_type_and_height[tile] &= 0xF; |
|
2544 |
_map_type_and_height[tile] |= MP_STATION << 4; |
|
2545 |
_map5[tile] = 0x4B; |
|
2546 |
_map_owner[tile] = OWNER_NONE; |
|
2547 |
_map3_lo[tile] = 0; |
|
2548 |
_map3_hi[tile] = 0; |
|
2549 |
_map2[tile] = st->index; |
|
2550 |
||
27
87c8058a69b5
(svn r28) -Fix removing station merged with oilrig, will reset oilrigs ownership
darkvater
parents:
22
diff
changeset
|
2551 |
st->owner = OWNER_NONE; |
0 | 2552 |
st->airport_flags = 0; |
2553 |
st->airport_type = AT_OILRIG; |
|
2554 |
st->xy = tile; |
|
2555 |
st->bus_tile = 0; |
|
2556 |
st->lorry_tile = 0; |
|
2557 |
st->airport_tile = tile; |
|
2558 |
st->dock_tile = tile; |
|
2559 |
st->train_tile = 0; |
|
2560 |
st->had_vehicle_of_type = 0; |
|
2561 |
st->time_since_load = 255; |
|
2562 |
st->time_since_unload = 255; |
|
2563 |
st->delete_ctr = 0; |
|
2564 |
st->last_vehicle = INVALID_VEHICLE; |
|
2565 |
st->facilities = FACIL_AIRPORT | FACIL_DOCK; |
|
71
1b8e15a10515
(svn r72) -Add: build_date of station (viewable with Query tool)
truelight
parents:
65
diff
changeset
|
2566 |
st->build_date = _date; |
0 | 2567 |
for(j=0; j!=NUM_CARGO; j++) { |
2568 |
st->goods[j].waiting_acceptance = 0; |
|
2569 |
st->goods[j].days_since_pickup = 0; |
|
2570 |
st->goods[j].enroute_from = 0xFF; |
|
2571 |
st->goods[j].rating = 175; |
|
2572 |
st->goods[j].last_speed = 0; |
|
2573 |
st->goods[j].last_age = 255; |
|
2574 |
} |
|
2575 |
||
2576 |
UpdateStationVirtCoordDirty(st); |
|
2577 |
UpdateStationAcceptance(st, false); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2578 |
return; |
0 | 2579 |
} |
2580 |
} |
|
2581 |
} |
|
2582 |
||
2583 |
void DeleteOilRig(uint tile) |
|
2584 |
{ |
|
2585 |
Station *st = DEREF_STATION(_map2[tile]); |
|
2586 |
||
2587 |
DoClearSquare(tile); |
|
2588 |
||
2589 |
st->dock_tile = 0; |
|
2590 |
st->airport_tile = 0; |
|
2591 |
st->facilities &= ~(FACIL_AIRPORT | FACIL_DOCK); |
|
2592 |
st->airport_flags = 0; |
|
2593 |
UpdateStationVirtCoordDirty(st); |
|
2594 |
DeleteStation(st); |
|
2595 |
} |
|
2596 |
||
2597 |
static void ChangeTileOwner_Station(uint tile, byte old_player, byte new_player) |
|
2598 |
{ |
|
2599 |
if (_map_owner[tile] != old_player) |
|
2600 |
return; |
|
2601 |
||
2602 |
if (new_player != 255) { |
|
2603 |
Station *st = DEREF_STATION(_map2[tile]); |
|
2604 |
_map_owner[tile] = new_player; |
|
2605 |
st->owner = new_player; |
|
243
9a40daa560ae
(svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents:
222
diff
changeset
|
2606 |
_global_station_sort_dirty = true; // transfer ownership of station to another player |
65
f9f866bc609c
(svn r66) -Fix Station list updated on station deletion/station rename
darkvater
parents:
59
diff
changeset
|
2607 |
InvalidateWindowClasses(WC_STATION_LIST); |
0 | 2608 |
} else { |
2609 |
DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); |
|
2610 |
} |
|
2611 |
} |
|
2612 |
||
2613 |
static int32 ClearTile_Station(uint tile, byte flags) { |
|
2614 |
byte m5 = _map5[tile]; |
|
2615 |
Station *st; |
|
2616 |
||
2617 |
if (flags & DC_AUTO) { |
|
2618 |
if (m5 < 8) return_cmd_error(STR_300B_MUST_DEMOLISH_RAILROAD); |
|
2619 |
if (m5 < 0x43 || (m5 >= 83 && m5 <= 114)) return_cmd_error(STR_300E_MUST_DEMOLISH_AIRPORT_FIRST); |
|
2620 |
if (m5 < 0x47) return_cmd_error(STR_3047_MUST_DEMOLISH_TRUCK_STATION); |
|
2621 |
if (m5 < 0x4B) return_cmd_error(STR_3046_MUST_DEMOLISH_BUS_STATION); |
|
2622 |
if (m5 == 0x52) return_cmd_error(STR_306A_BUOY_IN_THE_WAY); |
|
2623 |
if (m5 != 0x4B && m5 < 0x53) return_cmd_error(STR_304D_MUST_DEMOLISH_DOCK_FIRST); |
|
2624 |
SET_DPARAM16(0, STR_4807_OIL_RIG); |
|
2625 |
return_cmd_error(STR_4800_IN_THE_WAY); |
|
2626 |
} |
|
2627 |
||
2628 |
st = DEREF_STATION(_map2[tile]); |
|
2629 |
||
2630 |
if (m5 < 8) |
|
149
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
123
diff
changeset
|
2631 |
return RemoveRailroadStation(st, tile, flags); |
0 | 2632 |
|
2633 |
// original airports < 67, new airports between 83 - 114 |
|
2634 |
if (m5 < 0x43 || ( m5 >= 83 && m5 <= 114) ) |
|
2635 |
return RemoveAirport(st, flags); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2636 |
|
0 | 2637 |
if (m5 < 0x47) |
2638 |
return RemoveTruckStation(st, flags); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2639 |
|
0 | 2640 |
if (m5 < 0x4B) |
2641 |
return RemoveBusStation(st, flags); |
|
2642 |
||
2643 |
if (m5 == 0x52) |
|
2644 |
return RemoveBuoy(st, flags); |
|
2645 |
||
2646 |
if (m5 != 0x4B && m5 < 0x53) |
|
2647 |
return RemoveDock(st, flags); |
|
2648 |
||
2649 |
return CMD_ERROR; |
|
2650 |
||
2651 |
} |
|
2652 |
||
2653 |
void InitializeStations() |
|
2654 |
{ |
|
2655 |
int i; |
|
243
9a40daa560ae
(svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents:
222
diff
changeset
|
2656 |
|
0 | 2657 |
memset(_stations, 0, sizeof(_stations)); |
243
9a40daa560ae
(svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents:
222
diff
changeset
|
2658 |
for(i = 0; i != lengthof(_stations); i++) |
0 | 2659 |
_stations[i].index=i; |
243
9a40daa560ae
(svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents:
222
diff
changeset
|
2660 |
|
0 | 2661 |
_station_tick_ctr = 0; |
243
9a40daa560ae
(svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents:
222
diff
changeset
|
2662 |
|
9a40daa560ae
(svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents:
222
diff
changeset
|
2663 |
// set stations to be sorted on load of savegame |
9a40daa560ae
(svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents:
222
diff
changeset
|
2664 |
memset(_station_sort_dirty, true, sizeof(_station_sort_dirty)); |
9a40daa560ae
(svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents:
222
diff
changeset
|
2665 |
_global_station_sort_dirty = true; // load of savegame |
0 | 2666 |
} |
2667 |
||
2668 |
||
2669 |
const TileTypeProcs _tile_type_station_procs = { |
|
2670 |
DrawTile_Station, /* draw_tile_proc */ |
|
2671 |
GetSlopeZ_Station, /* get_slope_z_proc */ |
|
2672 |
ClearTile_Station, /* clear_tile_proc */ |
|
2673 |
GetAcceptedCargo_Station, /* get_accepted_cargo_proc */ |
|
2674 |
GetTileDesc_Station, /* get_tile_desc_proc */ |
|
2675 |
GetTileTrackStatus_Station, /* get_tile_track_status_proc */ |
|
2676 |
ClickTile_Station, /* click_tile_proc */ |
|
2677 |
AnimateTile_Station, /* animate_tile_proc */ |
|
2678 |
TileLoop_Station, /* tile_loop_clear */ |
|
2679 |
ChangeTileOwner_Station, /* change_tile_owner_clear */ |
|
2680 |
NULL, /* get_produced_cargo_proc */ |
|
2681 |
VehicleEnter_Station, /* vehicle_enter_tile_proc */ |
|
2682 |
NULL, /* vehicle_leave_tile_proc */ |
|
39 | 2683 |
GetSlopeTileh_Station, /* get_slope_tileh_proc */ |
0 | 2684 |
}; |
2685 |
||
2686 |
||
2687 |
static const byte _station_desc[] = { |
|
2688 |
SLE_VAR(Station,xy, SLE_UINT16), |
|
2689 |
SLE_VAR(Station,bus_tile, SLE_UINT16), |
|
2690 |
SLE_VAR(Station,lorry_tile, SLE_UINT16), |
|
2691 |
SLE_VAR(Station,train_tile, SLE_UINT16), |
|
2692 |
SLE_VAR(Station,airport_tile, SLE_UINT16), |
|
2693 |
SLE_VAR(Station,dock_tile, SLE_UINT16), |
|
2694 |
SLE_REF(Station,town, REF_TOWN), |
|
2695 |
SLE_VAR(Station,trainst_w, SLE_UINT8), |
|
2696 |
SLE_CONDVAR(Station,trainst_h, SLE_UINT8, 2, 255), |
|
2697 |
||
2698 |
// alpha_order was stored here in savegame format 0 - 3 |
|
2699 |
SLE_CONDARR(NullStruct,null,SLE_FILE_U8 | SLE_VAR_NULL, 1, 0, 3), |
|
2700 |
||
2701 |
SLE_VAR(Station,string_id, SLE_STRINGID), |
|
2702 |
SLE_VAR(Station,had_vehicle_of_type,SLE_UINT16), |
|
2703 |
||
2704 |
SLE_VAR(Station,time_since_load, SLE_UINT8), |
|
2705 |
SLE_VAR(Station,time_since_unload, SLE_UINT8), |
|
2706 |
SLE_VAR(Station,delete_ctr, SLE_UINT8), |
|
2707 |
SLE_VAR(Station,owner, SLE_UINT8), |
|
2708 |
SLE_VAR(Station,facilities, SLE_UINT8), |
|
2709 |
SLE_VAR(Station,airport_type, SLE_UINT8), |
|
2710 |
SLE_VAR(Station,truck_stop_status, SLE_UINT8), |
|
2711 |
SLE_VAR(Station,bus_stop_status, SLE_UINT8), |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2712 |
|
123
d550772c61e6
(svn r124) Prepared code for removal of block_months variable in next major savegame version
dominik
parents:
121
diff
changeset
|
2713 |
// blocked_months was stored here in savegame format 0 - 4.0 |
d550772c61e6
(svn r124) Prepared code for removal of block_months variable in next major savegame version
dominik
parents:
121
diff
changeset
|
2714 |
SLE_CONDVAR(Station,blocked_months_obsolete, SLE_UINT8, 0, 4), |
0 | 2715 |
|
2716 |
SLE_CONDVAR(Station,airport_flags, SLE_VAR_U32 | SLE_FILE_U16, 0, 2), |
|
2717 |
SLE_CONDVAR(Station,airport_flags, SLE_UINT32, 3, 255), |
|
2718 |
||
2719 |
SLE_VAR(Station,last_vehicle, SLE_UINT16), |
|
2720 |
||
2721 |
SLE_CONDVAR(Station,class_id, SLE_UINT8, 3, 255), |
|
2722 |
SLE_CONDVAR(Station,stat_id, SLE_UINT8, 3, 255), |
|
2723 |
SLE_CONDVAR(Station,build_date, SLE_UINT16, 3, 255), |
|
2724 |
||
2725 |
// reserve extra space in savegame here. (currently 32 bytes) |
|
2726 |
SLE_CONDARR(NullStruct,null,SLE_FILE_U8 | SLE_VAR_NULL, 32, 2, 255), |
|
2727 |
||
2728 |
SLE_END() |
|
2729 |
}; |
|
2730 |
||
2731 |
static const byte _goods_desc[] = { |
|
2732 |
SLE_VAR(GoodsEntry,waiting_acceptance,SLE_UINT16), |
|
2733 |
SLE_VAR(GoodsEntry,days_since_pickup, SLE_UINT8), |
|
2734 |
SLE_VAR(GoodsEntry,rating, SLE_UINT8), |
|
2735 |
SLE_VAR(GoodsEntry,enroute_from, SLE_UINT8), |
|
2736 |
SLE_VAR(GoodsEntry,enroute_time, SLE_UINT8), |
|
2737 |
SLE_VAR(GoodsEntry,last_speed, SLE_UINT8), |
|
2738 |
SLE_VAR(GoodsEntry,last_age, SLE_UINT8), |
|
2739 |
||
2740 |
SLE_END() |
|
2741 |
}; |
|
2742 |
||
2743 |
||
2744 |
static void SaveLoad_STNS(Station *st) |
|
2745 |
{ |
|
2746 |
int i; |
|
2747 |
SlObject(st, _station_desc); |
|
2748 |
for(i=0; i!=NUM_CARGO; i++) |
|
2749 |
SlObject(&st->goods[i], _goods_desc); |
|
2750 |
} |
|
2751 |
||
2752 |
static void Save_STNS() |
|
2753 |
{ |
|
2754 |
Station *st; |
|
2755 |
// Write the vehicles |
|
2756 |
FOR_ALL_STATIONS(st) { |
|
2757 |
if (st->xy != 0) { |
|
2758 |
SlSetArrayIndex(st->index); |
|
2759 |
SlAutolength((AutolengthProc*)SaveLoad_STNS, st); |
|
2760 |
} |
|
2761 |
} |
|
2762 |
} |
|
2763 |
||
2764 |
static void Load_STNS() |
|
2765 |
{ |
|
2766 |
int index; |
|
2767 |
while ((index = SlIterateArray()) != -1) { |
|
2768 |
Station *st = &_stations[index]; |
|
2769 |
SaveLoad_STNS(st); |
|
2770 |
||
2771 |
// this means it's an oldstyle savegame without support for nonuniform stations |
|
2772 |
if (st->train_tile && st->trainst_h == 0) { |
|
2773 |
int w = st->trainst_w >> 4; |
|
2774 |
int h = st->trainst_w & 0xF; |
|
2775 |
if (_map5[st->train_tile]&1) intswap(w,h); |
|
2776 |
st->trainst_w = w; |
|
2777 |
st->trainst_h = h; |
|
2778 |
} |
|
2779 |
} |
|
2780 |
} |
|
2781 |
||
2782 |
const ChunkHandler _station_chunk_handlers[] = { |
|
2783 |
{ 'STNS', Save_STNS, Load_STNS, CH_ARRAY | CH_LAST}, |
|
2784 |
}; |
|
2785 |