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