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