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