author | darkvater |
Sun, 14 Nov 2004 14:10:03 +0000 | |
changeset 399 | ad3dcbfd2d48 |
parent 395 | 4c990f33dab7 |
child 403 | bfb365c74e80 |
permissions | -rw-r--r-- |
0 | 1 |
#include "stdafx.h" |
2 |
#include "ttd.h" |
|
3 |
#include "vehicle.h" |
|
4 |
#include "viewport.h" |
|
5 |
#include "command.h" |
|
6 |
#include "pathfind.h" |
|
7 |
#include "town.h" |
|
337
66647f97e7c0
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
283
diff
changeset
|
8 |
#include "sound.h" |
389
2d394eeba5e5
(svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents:
337
diff
changeset
|
9 |
#include "station.h" |
0 | 10 |
|
11 |
void ShowTrainDepotWindow(uint tile); |
|
12 |
||
22 | 13 |
enum { /* These values are bitmasks for the map5 byte */ |
0 | 14 |
RAIL_TYPE_NORMAL = 0, |
15 |
RAIL_TYPE_SIGNALS = 0x40, |
|
16 |
RAIL_TYPE_SPECIAL = 0x80, // If this bit is set, then it's not a regular track. |
|
17 |
RAIL_TYPE_DEPOT = 0xC0, |
|
18 |
RAIL_TYPE_MASK = 0xC0, |
|
19 |
||
20 |
RAIL_BIT_DIAG1 = 1, // 0 |
|
21 |
RAIL_BIT_DIAG2 = 2, // 1 |
|
22 |
RAIL_BIT_UPPER = 4, // 2 |
|
23 |
RAIL_BIT_LOWER = 8, // 3 |
|
24 |
RAIL_BIT_LEFT = 16, // 4 |
|
25 |
RAIL_BIT_RIGHT = 32, // 5 |
|
26 |
RAIL_BIT_MASK = 0x3F, |
|
27 |
||
28 |
RAIL_DEPOT_TRACK_MASK = 1, |
|
29 |
RAIL_DEPOT_DIR = 3, |
|
30 |
RAIL_DEPOT_UNUSED_BITS = 0x3C, |
|
31 |
||
395
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
393
diff
changeset
|
32 |
RAIL_TYPE_WAYPOINT = 0xC4, |
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
393
diff
changeset
|
33 |
RAIL_WAYPOINT_TRACK_MASK = 1, |
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
393
diff
changeset
|
34 |
RAIL_WAYPOINT_UNUSED_BITS = 0x3E, |
0 | 35 |
}; |
36 |
||
37 |
#define IS_RAIL_DEPOT(x) (((x) & (RAIL_TYPE_DEPOT|RAIL_DEPOT_UNUSED_BITS)) == RAIL_TYPE_DEPOT) |
|
395
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
393
diff
changeset
|
38 |
#define IS_RAIL_WAYPOINT(x) (((x) & (RAIL_TYPE_WAYPOINT|RAIL_WAYPOINT_UNUSED_BITS)) == RAIL_TYPE_WAYPOINT) |
0 | 39 |
|
40 |
/* Format of rail map5 byte. |
|
41 |
* 00 abcdef => Normal rail |
|
42 |
* 01 abcdef => Rail with signals |
|
43 |
* 10 ?????? => Unused |
|
44 |
* 11 ????dd => Depot |
|
22 | 45 |
* |
46 |
* abcdef is a bitmask, which contains ones for all present tracks. Below the |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
47 |
* value for each track is given. |
0 | 48 |
*/ |
49 |
||
50 |
/* 4 |
|
51 |
* --------- |
|
52 |
* |\ /| |
|
53 |
* | \ 1/ | |
|
54 |
* | \ / | |
|
55 |
* | \ / | |
|
56 |
* 16| \ |32 |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
57 |
* | / \2 | |
0 | 58 |
* | / \ | |
59 |
* | / \ | |
|
60 |
* |/ \| |
|
61 |
* --------- |
|
62 |
* 8 |
|
63 |
*/ |
|
64 |
||
65 |
||
66 |
// Constants for lower part of Map2 byte. |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
67 |
enum RailMap2Lower4 { |
0 | 68 |
RAIL_MAP2LO_GROUND_MASK = 0xF, |
69 |
RAIL_GROUND_BROWN = 0, |
|
70 |
RAIL_GROUND_GREEN = 1, |
|
71 |
RAIL_GROUND_FENCE_NW = 2, |
|
72 |
RAIL_GROUND_FENCE_SE = 3, |
|
73 |
RAIL_GROUND_FENCE_SENW = 4, |
|
74 |
RAIL_GROUND_FENCE_NE = 5, |
|
75 |
RAIL_GROUND_FENCE_SW = 6, |
|
76 |
RAIL_GROUND_FENCE_NESW = 7, |
|
77 |
RAIL_GROUND_FENCE_VERT1 = 8, |
|
78 |
RAIL_GROUND_FENCE_VERT2 = 9, |
|
79 |
RAIL_GROUND_FENCE_HORIZ1 = 10, |
|
80 |
RAIL_GROUND_FENCE_HORIZ2 = 11, |
|
81 |
RAIL_GROUND_ICE_DESERT = 12, |
|
82 |
}; |
|
83 |
||
84 |
||
22 | 85 |
/* MAP2 byte: abcd???? => Signal On? Same coding as map3lo |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
86 |
* MAP3LO byte: abcd???? => Signal Exists? |
22 | 87 |
* a and b are for diagonals, upper and left, |
88 |
* one for each direction. (ie a == NE->SW, b == |
|
89 |
* SW->NE, or v.v., I don't know. b and c are |
|
90 |
* similar for lower and right. |
|
0 | 91 |
* MAP2 byte: ????abcd => Type of ground. |
92 |
* MAP3LO byte: ????abcd => Type of rail. |
|
93 |
* MAP5: 00abcdef => rail |
|
94 |
* 01abcdef => rail w/ signals |
|
95 |
* 10uuuuuu => unused |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
96 |
* 11uuuudd => rail depot |
0 | 97 |
*/ |
98 |
||
99 |
static bool CheckTrackCombination(byte map5, byte trackbits, byte flags) |
|
100 |
{ |
|
101 |
_error_message = STR_1001_IMPOSSIBLE_TRACK_COMBINATION; |
|
102 |
||
103 |
if ((map5&RAIL_TYPE_MASK) == RAIL_TYPE_SIGNALS) { |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
104 |
|
0 | 105 |
if (map5 & trackbits) { |
106 |
_error_message = STR_1007_ALREADY_BUILT; |
|
107 |
return false; |
|
108 |
} |
|
109 |
||
110 |
map5 |= trackbits; |
|
111 |
return (map5 == (RAIL_TYPE_SIGNALS|RAIL_BIT_UPPER|RAIL_BIT_LOWER) || map5 == (RAIL_TYPE_SIGNALS|RAIL_BIT_LEFT|RAIL_BIT_RIGHT)); |
|
112 |
||
113 |
} else if ((map5&RAIL_TYPE_MASK) == RAIL_TYPE_NORMAL) { |
|
114 |
_error_message = STR_1007_ALREADY_BUILT; |
|
115 |
if (map5 & trackbits) |
|
116 |
return false; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
117 |
|
0 | 118 |
// Computer players are not allowed to intersect pieces of rail. |
119 |
if (!(flags&DC_NO_RAIL_OVERLAP)) |
|
120 |
return true; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
121 |
|
0 | 122 |
map5 |= trackbits; |
123 |
return (map5 == (RAIL_BIT_UPPER|RAIL_BIT_LOWER) || map5 == (RAIL_BIT_LEFT|RAIL_BIT_RIGHT)); |
|
124 |
} else { |
|
125 |
return false; |
|
126 |
} |
|
127 |
} |
|
128 |
||
129 |
||
13
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
130 |
static const byte _valid_tileh_slopes[4][15] = { |
0 | 131 |
|
132 |
// set of normal ones |
|
133 |
{ |
|
134 |
RAIL_BIT_DIAG1|RAIL_BIT_DIAG2|RAIL_BIT_UPPER|RAIL_BIT_LOWER|RAIL_BIT_LEFT|RAIL_BIT_RIGHT, |
|
135 |
RAIL_BIT_RIGHT, |
|
136 |
RAIL_BIT_UPPER, |
|
137 |
RAIL_BIT_DIAG1, |
|
138 |
||
139 |
RAIL_BIT_LEFT, |
|
140 |
0, |
|
141 |
RAIL_BIT_DIAG2, |
|
142 |
RAIL_BIT_LOWER, |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
143 |
|
0 | 144 |
RAIL_BIT_LOWER, |
145 |
RAIL_BIT_DIAG2, |
|
146 |
0, |
|
147 |
RAIL_BIT_LEFT, |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
148 |
|
0 | 149 |
RAIL_BIT_DIAG1, |
150 |
RAIL_BIT_UPPER, |
|
151 |
RAIL_BIT_RIGHT, |
|
152 |
}, |
|
153 |
||
154 |
// allowed rail for an evenly raised platform |
|
155 |
{ |
|
156 |
0, |
|
157 |
RAIL_BIT_LEFT, |
|
158 |
RAIL_BIT_LOWER, |
|
159 |
RAIL_BIT_DIAG2 | RAIL_BIT_LOWER | RAIL_BIT_LEFT, |
|
160 |
||
161 |
RAIL_BIT_RIGHT, |
|
162 |
RAIL_BIT_DIAG1|RAIL_BIT_DIAG2|RAIL_BIT_UPPER|RAIL_BIT_LOWER|RAIL_BIT_LEFT|RAIL_BIT_RIGHT, |
|
163 |
RAIL_BIT_DIAG1 | RAIL_BIT_LOWER | RAIL_BIT_RIGHT, |
|
164 |
RAIL_BIT_DIAG1|RAIL_BIT_DIAG2|RAIL_BIT_UPPER|RAIL_BIT_LOWER|RAIL_BIT_LEFT|RAIL_BIT_RIGHT, |
|
165 |
||
166 |
RAIL_BIT_UPPER, |
|
167 |
RAIL_BIT_DIAG1 | RAIL_BIT_UPPER | RAIL_BIT_LEFT, |
|
168 |
RAIL_BIT_DIAG1|RAIL_BIT_DIAG2|RAIL_BIT_UPPER|RAIL_BIT_LOWER|RAIL_BIT_LEFT|RAIL_BIT_RIGHT, |
|
169 |
RAIL_BIT_DIAG1|RAIL_BIT_DIAG2|RAIL_BIT_UPPER|RAIL_BIT_LOWER|RAIL_BIT_LEFT|RAIL_BIT_RIGHT, |
|
170 |
||
171 |
RAIL_BIT_DIAG2 | RAIL_BIT_UPPER | RAIL_BIT_RIGHT, |
|
172 |
RAIL_BIT_DIAG1|RAIL_BIT_DIAG2|RAIL_BIT_UPPER|RAIL_BIT_LOWER|RAIL_BIT_LEFT|RAIL_BIT_RIGHT, |
|
173 |
RAIL_BIT_DIAG1|RAIL_BIT_DIAG2|RAIL_BIT_UPPER|RAIL_BIT_LOWER|RAIL_BIT_LEFT|RAIL_BIT_RIGHT, |
|
174 |
}, |
|
175 |
||
176 |
// allowed rail on coast tile |
|
177 |
{ |
|
178 |
0, |
|
179 |
RAIL_BIT_LEFT, |
|
180 |
RAIL_BIT_LOWER, |
|
181 |
RAIL_BIT_DIAG2|RAIL_BIT_LEFT|RAIL_BIT_LOWER, |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
182 |
|
0 | 183 |
RAIL_BIT_RIGHT, |
184 |
RAIL_BIT_DIAG1|RAIL_BIT_DIAG2|RAIL_BIT_UPPER|RAIL_BIT_LOWER|RAIL_BIT_LEFT|RAIL_BIT_RIGHT, |
|
185 |
RAIL_BIT_DIAG1|RAIL_BIT_RIGHT|RAIL_BIT_LOWER, |
|
186 |
RAIL_BIT_DIAG1|RAIL_BIT_DIAG2|RAIL_BIT_UPPER|RAIL_BIT_LOWER|RAIL_BIT_LEFT|RAIL_BIT_RIGHT, |
|
187 |
||
188 |
RAIL_BIT_UPPER, |
|
189 |
RAIL_BIT_DIAG1|RAIL_BIT_LEFT|RAIL_BIT_UPPER, |
|
190 |
RAIL_BIT_DIAG1|RAIL_BIT_DIAG2|RAIL_BIT_UPPER|RAIL_BIT_LOWER|RAIL_BIT_LEFT|RAIL_BIT_RIGHT, |
|
191 |
RAIL_BIT_DIAG1|RAIL_BIT_DIAG2|RAIL_BIT_UPPER|RAIL_BIT_LOWER|RAIL_BIT_LEFT|RAIL_BIT_RIGHT, |
|
192 |
||
193 |
RAIL_BIT_DIAG2|RAIL_BIT_RIGHT|RAIL_BIT_UPPER, |
|
194 |
RAIL_BIT_DIAG1|RAIL_BIT_DIAG2|RAIL_BIT_UPPER|RAIL_BIT_LOWER|RAIL_BIT_LEFT|RAIL_BIT_RIGHT, |
|
195 |
RAIL_BIT_DIAG1|RAIL_BIT_DIAG2|RAIL_BIT_UPPER|RAIL_BIT_LOWER|RAIL_BIT_LEFT|RAIL_BIT_RIGHT, |
|
13
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
196 |
}, |
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
197 |
|
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
198 |
// valid railway crossings on slopes |
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
199 |
{ |
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
200 |
1, 0, 0, // 0, 1, 2 |
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
201 |
0, 0, 1, // 3, 4, 5 |
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
202 |
0, 1, 0, // 6, 7, 8 |
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
203 |
0, 1, 1, // 9, 10, 11 |
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
204 |
0, 1, 1, // 12, 13, 14 |
0 | 205 |
} |
206 |
}; |
|
207 |
||
84
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
59
diff
changeset
|
208 |
uint GetRailFoundation(uint tileh, uint bits) |
0 | 209 |
{ |
210 |
int i; |
|
211 |
||
212 |
if ((~_valid_tileh_slopes[0][tileh] & bits) == 0) |
|
213 |
return 0; |
|
214 |
||
215 |
if ((~_valid_tileh_slopes[1][tileh] & bits) == 0) |
|
216 |
return tileh; |
|
217 |
||
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
218 |
if ( ((i=0, tileh == 1) || (i+=2, tileh == 2) || (i+=2, tileh == 4) || (i+=2, tileh == 8)) && (bits == RAIL_BIT_DIAG1 || (i++, bits == RAIL_BIT_DIAG2))) |
0 | 219 |
return i + 15; |
220 |
||
221 |
return 0; |
|
222 |
} |
|
223 |
||
224 |
// |
|
225 |
static uint32 CheckRailSlope(int tileh, uint rail_bits, uint existing, uint tile) |
|
226 |
{ |
|
227 |
// never allow building on top of steep tiles |
|
228 |
if (!(tileh & 0x10)) { |
|
229 |
rail_bits |= existing; |
|
230 |
||
231 |
// don't allow building on the lower side of a coast |
|
232 |
if (IS_TILETYPE(tile, MP_WATER) && ~_valid_tileh_slopes[2][tileh] & rail_bits) { |
|
233 |
return_cmd_error(STR_3807_CAN_T_BUILD_ON_WATER); |
|
234 |
} |
|
235 |
||
236 |
// no special foundation |
|
237 |
if ((~_valid_tileh_slopes[0][tileh] & rail_bits) == 0) |
|
238 |
return 0; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
239 |
|
0 | 240 |
if (((~_valid_tileh_slopes[1][tileh] & rail_bits) == 0) || // whole tile is leveled up |
241 |
((rail_bits == RAIL_BIT_DIAG1 || rail_bits == RAIL_BIT_DIAG2) && (tileh == 1 || tileh == 2 || tileh == 4 || tileh == 8))) { // partly up |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
242 |
return existing ? 0 : _price.terraform; |
0 | 243 |
} |
244 |
} |
|
245 |
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); |
|
246 |
} |
|
247 |
||
248 |
/* Build a single track. |
|
249 |
* p1 - railroad type normal/maglev |
|
250 |
* p2 - tile direction |
|
251 |
*/ |
|
252 |
||
253 |
int32 CmdBuildSingleRail(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
254 |
{ |
|
255 |
TileInfo ti; |
|
256 |
int32 ret, cost = 0; |
|
257 |
byte rail_bit = 1 << p2; |
|
258 |
byte rail_type = (byte)(p1 & 0xF); |
|
259 |
uint tile; |
|
260 |
byte existing = 0; |
|
261 |
bool need_clear = false; |
|
262 |
||
263 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
264 |
||
265 |
_error_message = STR_1007_ALREADY_BUILT; |
|
266 |
||
267 |
FindLandscapeHeight(&ti, x, y); |
|
268 |
tile = ti.tile; |
|
269 |
||
270 |
// allow building rail under bridge |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
271 |
if (ti.type != MP_TUNNELBRIDGE && !EnsureNoVehicle(tile)) |
0 | 272 |
return CMD_ERROR; |
273 |
||
274 |
if (ti.type == MP_TUNNELBRIDGE) { |
|
275 |
/* BUILD ON BRIDGE CODE */ |
|
276 |
if (!EnsureNoVehicleZ(tile, GET_TILEHEIGHT(tile))) |
|
277 |
return CMD_ERROR; |
|
278 |
||
279 |
if ((ti.map5 & 0xF8) == 0xC0) { |
|
280 |
if (ti.tileh & 0x10 || rail_bit != (byte)((ti.map5 & 1) ? 1 : 2)) goto need_clear; |
|
281 |
||
282 |
if (!(flags & DC_EXEC)) |
|
283 |
return _price.build_rail; |
|
284 |
||
285 |
_map5[tile] = (ti.map5 & 0xC7) | 0x20; |
|
286 |
goto set_ownership; |
|
287 |
} else if ((ti.map5 & 0xF8) == 0xE0) { |
|
288 |
if ((_map3_lo[tile] & 0xF) != (int)p1) goto need_clear; |
|
289 |
if (rail_bit != (byte)((ti.map5 & 1) ? 1 : 2)) goto need_clear; |
|
290 |
return CMD_ERROR; |
|
291 |
} else |
|
292 |
goto need_clear; |
|
293 |
} else if (ti.type == MP_STREET) { |
|
294 |
byte m5; |
|
295 |
/* BUILD ON STREET CODE */ |
|
13
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
296 |
if (ti.tileh & 0x10) // very steep tile |
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
297 |
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); |
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
298 |
|
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
299 |
if (!_valid_tileh_slopes[3][ti.tileh]) // prevent certain slopes |
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
300 |
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); |
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
301 |
|
0 | 302 |
if (!(ti.map5 & 0xF0)) { |
303 |
if ((ti.map5 & 0x0F) == 0xA) { |
|
304 |
if (rail_bit != 2) goto need_clear; |
|
305 |
m5 = 0x10; |
|
306 |
} else if ((ti.map5 & 0x0F) == 0x5) { |
|
307 |
if (rail_bit != 1) goto need_clear; |
|
308 |
m5 = 0x18; |
|
309 |
} else |
|
310 |
goto need_clear; |
|
311 |
||
312 |
if (!(flags & DC_EXEC)) |
|
313 |
return _price.build_rail; |
|
314 |
||
315 |
ModifyTile(tile, |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
316 |
MP_SETTYPE(MP_STREET) | |
0 | 317 |
MP_MAP3LO | MP_MAP3HI | MP_MAPOWNER_CURRENT | MP_MAP5, |
318 |
_map_owner[tile], /* map3_lo */ |
|
319 |
p1, /* map3_hi */ |
|
320 |
m5 /* map5 */ |
|
321 |
); |
|
322 |
goto fix_signals; |
|
323 |
} else if (!(ti.map5 & 0xE0)) { |
|
324 |
if (rail_bit != (byte)((ti.map5 & 8) ? 1 : 2)) goto need_clear; |
|
325 |
return CMD_ERROR; |
|
326 |
} else |
|
327 |
goto need_clear; |
|
328 |
} else if (ti.type == MP_RAILWAY) { |
|
329 |
||
330 |
/* BUILD ON RAILWAY CODE */ |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
331 |
if (_map_owner[tile] != _current_player || (byte)(_map3_lo[tile]&0xF) != rail_type) |
0 | 332 |
goto need_clear; |
333 |
if (!CheckTrackCombination(ti.map5, rail_bit, (byte)flags)) |
|
334 |
return CMD_ERROR; |
|
335 |
||
336 |
existing = ti.map5 & 0x3F; |
|
337 |
} else { |
|
338 |
||
339 |
/* DEFAULT BUILD ON CODE */ |
|
340 |
need_clear:; |
|
341 |
/* isnot_railway */ |
|
342 |
if (!(flags & DC_EXEC)) { |
|
343 |
ret = DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
|
344 |
if (ret == CMD_ERROR) return CMD_ERROR; |
|
345 |
cost += ret; |
|
346 |
} |
|
347 |
need_clear = true; |
|
348 |
} |
|
349 |
||
350 |
ret = CheckRailSlope(ti.tileh, rail_bit, existing, tile); |
|
351 |
if (ret & 0x80000000) |
|
352 |
return ret; |
|
353 |
cost += ret; |
|
354 |
||
355 |
// the AI is not allowed to used foundationed tiles. |
|
84
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
59
diff
changeset
|
356 |
if (ret && (!_patches.build_on_slopes || (!_patches.ainew_active && _is_ai_player))) |
0 | 357 |
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); |
358 |
||
359 |
if (flags & DC_EXEC && need_clear) { |
|
360 |
ret = DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
|
361 |
if (ret == CMD_ERROR) return CMD_ERROR; |
|
362 |
cost += ret; |
|
363 |
} |
|
364 |
||
365 |
if (flags & DC_EXEC) { |
|
366 |
_map_type_and_height[tile] &= 0xF; |
|
367 |
_map_type_and_height[tile] |= MP_RAILWAY << 4; |
|
368 |
_map5[tile] |= rail_bit; |
|
369 |
_map2[tile] &= ~RAIL_MAP2LO_GROUND_MASK; |
|
370 |
||
371 |
// In case it's a tile without signals, clear the signal bits. Why? |
|
372 |
if ((_map5[tile] & RAIL_TYPE_MASK) != RAIL_TYPE_SIGNALS) |
|
373 |
_map2[tile] &= ~0xF0; |
|
374 |
||
375 |
set_ownership: |
|
376 |
_map_owner[tile] = _current_player; |
|
377 |
||
378 |
_map3_lo[tile] &= ~0xF; |
|
379 |
_map3_lo[tile] |= rail_type; |
|
380 |
||
381 |
MarkTileDirtyByTile(tile); |
|
382 |
||
383 |
fix_signals: |
|
384 |
SetSignalsOnBothDir(tile, (byte)p2); |
|
385 |
} |
|
386 |
||
387 |
return cost + _price.build_rail; |
|
388 |
} |
|
389 |
||
390 |
static const byte _signals_table[] = { |
|
391 |
0x40, 0x40, 0x40, 0x10, 0x80, 0x20, 0, 0, // direction 1 |
|
392 |
0x80, 0x80, 0x80, 0x20, 0x40, 0x10, 0, 0 // direction 2 |
|
393 |
}; |
|
394 |
||
395 |
static const byte _signals_table_other[] = { |
|
396 |
0x80, 0x80, 0x80, 0x20, 0x40, 0x10, 0, 0, // direction 1 |
|
397 |
0x40, 0x40, 0x40, 0x10, 0x80, 0x20, 0, 0 // direction 2 |
|
398 |
}; |
|
399 |
||
400 |
static const byte _signals_table_both[] = { |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
401 |
0xC0, 0xC0, 0xC0, 0x30, 0xC0, 0x30, 0, 0, // both directions combined |
0 | 402 |
0xC0, 0xC0, 0xC0, 0x30, 0xC0, 0x30, 0, 0 |
403 |
}; |
|
404 |
||
405 |
||
406 |
/* Remove a single track. |
|
407 |
* p1 - unused |
|
408 |
* p2 - tile direction |
|
409 |
*/ |
|
410 |
||
411 |
int32 CmdRemoveSingleRail(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
412 |
{ |
|
413 |
TileInfo ti; |
|
414 |
byte rail_bit = 1 << p2; |
|
415 |
byte m5; |
|
416 |
uint tile; |
|
417 |
||
418 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
419 |
||
420 |
FindLandscapeHeight(&ti, x, y); |
|
421 |
||
422 |
tile = ti.tile; |
|
423 |
||
424 |
if (!((1<<ti.type) & ((1<<MP_TUNNELBRIDGE)|(1<<MP_STREET)|(1<<MP_RAILWAY)))) |
|
425 |
return CMD_ERROR; |
|
426 |
||
427 |
if (_current_player != OWNER_WATER && !CheckTileOwnership(tile)) |
|
428 |
return CMD_ERROR; |
|
429 |
||
430 |
// allow building rail under bridge |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
431 |
if (ti.type != MP_TUNNELBRIDGE && !EnsureNoVehicle(tile)) |
0 | 432 |
return CMD_ERROR; |
433 |
||
434 |
if (ti.type == MP_TUNNELBRIDGE) { |
|
435 |
if (!EnsureNoVehicleZ(tile, GET_TILEHEIGHT(tile))) |
|
436 |
return CMD_ERROR; |
|
437 |
||
438 |
if ((ti.map5 & 0xF8) != 0xE0) |
|
439 |
return CMD_ERROR; |
|
440 |
||
441 |
if ( ((ti.map5 & 1) ? 1 : 2) != rail_bit ) |
|
442 |
return CMD_ERROR; |
|
443 |
||
444 |
if (!(flags & DC_EXEC)) |
|
445 |
return _price.remove_rail; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
446 |
|
0 | 447 |
_map_owner[tile] = OWNER_NONE; |
448 |
_map5[tile] = ti.map5 & 0xC7; |
|
449 |
} else if (ti.type == MP_STREET) { |
|
450 |
if (!(ti.map5 & 0xF0)) |
|
451 |
return CMD_ERROR; |
|
452 |
||
453 |
if (ti.map5 & 0xE0) |
|
454 |
return CMD_ERROR; |
|
455 |
||
456 |
if (ti.map5 & 8) { |
|
457 |
m5 = 5; |
|
458 |
if (rail_bit != 1) |
|
459 |
return CMD_ERROR; |
|
460 |
} else { |
|
461 |
m5 = 10; |
|
462 |
if (rail_bit != 2) |
|
463 |
return CMD_ERROR; |
|
464 |
} |
|
465 |
||
466 |
if (!(flags & DC_EXEC)) |
|
467 |
return _price.remove_rail; |
|
468 |
||
469 |
_map5[tile] = m5; |
|
470 |
_map_owner[tile] = _map3_lo[tile]; |
|
471 |
_map2[tile] = 0; |
|
472 |
} else { |
|
473 |
assert(ti.type == MP_RAILWAY); |
|
474 |
||
475 |
if (ti.map5 & RAIL_TYPE_SPECIAL) |
|
476 |
return CMD_ERROR; |
|
477 |
||
478 |
if (!(ti.map5 & rail_bit)) |
|
479 |
return CMD_ERROR; |
|
480 |
||
481 |
// don't allow remove if there are signals on the track |
|
482 |
if (ti.map5 & RAIL_TYPE_SIGNALS) { |
|
483 |
if (_map3_lo[tile] & _signals_table_both[p2]) |
|
484 |
return CMD_ERROR; |
|
485 |
} |
|
486 |
||
487 |
if (!(flags & DC_EXEC)) |
|
488 |
return _price.remove_rail; |
|
489 |
||
490 |
if ( (_map5[tile] ^= rail_bit) == 0) { |
|
491 |
DoClearSquare(tile); |
|
492 |
goto skip_mark_dirty; |
|
493 |
} |
|
494 |
} |
|
495 |
||
496 |
/* mark_dirty */ |
|
497 |
MarkTileDirtyByTile(tile); |
|
498 |
||
499 |
skip_mark_dirty:; |
|
500 |
||
501 |
SetSignalsOnBothDir(tile, (byte)p2); |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
502 |
|
0 | 503 |
return _price.remove_rail; |
504 |
} |
|
505 |
||
506 |
static const struct { |
|
507 |
int8 xinc[16]; |
|
508 |
int8 yinc[16]; |
|
509 |
byte initial[16]; |
|
510 |
} _railbit = {{ |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
511 |
// 0 1 2 3 4 5 |
0 | 512 |
16, 0,-16, 0, 16, 0, 0, 0, |
513 |
-16, 0, 0, 16, 0,-16, 0, 0, |
|
514 |
},{ |
|
515 |
0, 16, 0, 16, 0, 16, 0, 0, |
|
516 |
0, -16, -16, 0,-16, 0, 0, 0, |
|
517 |
},{ |
|
518 |
5, 1, 0,4, // normal |
|
519 |
2, 1, 8,3, // x > sx |
|
520 |
10, 9, 0,11, // y > sy |
|
521 |
13, 9, 8,12, // x > sx && y > sy |
|
522 |
}}; |
|
523 |
||
524 |
||
525 |
/* Build either NE or NW sequence of tracks. |
|
58
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
526 |
* p1 0:15 - end pt X |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
527 |
* p1 16:31 - end pt y |
0 | 528 |
* |
529 |
* p2 0:3 - rail type |
|
530 |
* p2 4:7 - rail direction |
|
531 |
*/ |
|
532 |
||
533 |
||
534 |
int32 CmdBuildRailroadTrack(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
535 |
{ |
|
536 |
int sx, sy; |
|
537 |
int32 ret, total_cost = 0; |
|
538 |
int railbit; |
|
539 |
||
540 |
if (flags & DC_EXEC) |
|
541 |
SndPlayTileFx(0x1E, TILE_FROM_XY(x,y)); |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
542 |
|
58
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
543 |
/* unpack end point */ |
0 | 544 |
sx = (p1 & 0xFFFF) & ~0xF; |
545 |
sy = (p1 >> 16) & ~0xF; |
|
546 |
||
547 |
railbit = _railbit.initial[(p2 >> 4) + (x > sx ? 4 : 0) + (y > sy ? 8 : 0)]; |
|
548 |
||
549 |
for(;;) { |
|
550 |
ret = DoCommand(x, y, p2&0xF, railbit&7, flags, CMD_BUILD_SINGLE_RAIL); |
|
551 |
||
552 |
if (ret == CMD_ERROR) { |
|
553 |
if (_error_message != STR_1007_ALREADY_BUILT) |
|
554 |
break; |
|
555 |
} else |
|
556 |
total_cost += ret; |
|
557 |
||
558 |
if (x == sx && y == sy) |
|
559 |
break; |
|
560 |
||
561 |
x += _railbit.xinc[railbit]; |
|
562 |
y += _railbit.yinc[railbit]; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
563 |
|
0 | 564 |
// toggle railbit for the diagonal tiles |
565 |
if (railbit & 0x6) railbit ^= 1; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
566 |
} |
0 | 567 |
|
568 |
if (total_cost == 0) |
|
569 |
return CMD_ERROR; |
|
570 |
||
571 |
return total_cost; |
|
572 |
} |
|
573 |
||
574 |
||
575 |
/* Remove either NE or NW sequence of tracks. |
|
576 |
* p1 0:15 - start pt X |
|
577 |
* p1 16:31 - start pt y |
|
578 |
* |
|
579 |
* p2 0:3 - rail type |
|
580 |
* p2 4:7 - rail direction |
|
581 |
*/ |
|
582 |
||
583 |
||
584 |
int32 CmdRemoveRailroadTrack(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
585 |
{ |
|
586 |
int sx, sy; |
|
587 |
int32 ret, total_cost = 0; |
|
588 |
int railbit; |
|
589 |
||
590 |
if (flags & DC_EXEC) |
|
591 |
SndPlayTileFx(0x1E, TILE_FROM_XY(x,y)); |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
592 |
|
0 | 593 |
/* unpack start point */ |
594 |
sx = (p1 & 0xFFFF) & ~0xF; |
|
595 |
sy = (p1 >> 16) & ~0xF; |
|
596 |
||
597 |
railbit = _railbit.initial[(p2 >> 4) + (x > sx ? 4 : 0) + (y > sy ? 8 : 0)]; |
|
598 |
||
599 |
for(;;) { |
|
600 |
ret = DoCommand(x, y, p2&0xF, railbit&7, flags, CMD_REMOVE_SINGLE_RAIL); |
|
601 |
if (ret != CMD_ERROR) total_cost += ret; |
|
602 |
if (x == sx && y == sy) |
|
603 |
break; |
|
604 |
x += _railbit.xinc[railbit]; |
|
605 |
y += _railbit.yinc[railbit]; |
|
606 |
// toggle railbit for the diagonal tiles |
|
607 |
if (railbit & 0x6) railbit ^= 1; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
608 |
} |
0 | 609 |
|
610 |
if (total_cost == 0) |
|
611 |
return CMD_ERROR; |
|
612 |
||
613 |
return total_cost; |
|
614 |
} |
|
615 |
||
616 |
/* Build a train depot |
|
617 |
* p1 = rail type |
|
618 |
* p2 = depot direction |
|
619 |
*/ |
|
620 |
int32 CmdBuildTrainDepot(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
621 |
{ |
|
622 |
uint tile = TILE_FROM_XY(x,y); |
|
623 |
int32 cost, ret; |
|
624 |
Depot *dep; |
|
625 |
uint tileh; |
|
626 |
||
627 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
628 |
||
629 |
if (!EnsureNoVehicle(tile)) return CMD_ERROR; |
|
630 |
||
631 |
tileh = GetTileSlope(tile, NULL); |
|
632 |
if (tileh != 0) { |
|
84
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
59
diff
changeset
|
633 |
if ((!_patches.ainew_active && _is_ai_player) || !_patches.build_on_slopes || (tileh & 0x10 || !((0x4C >> p2) & tileh) )) |
0 | 634 |
return_cmd_error(STR_0007_FLAT_LAND_REQUIRED); |
635 |
} |
|
636 |
||
637 |
ret = DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
|
638 |
if (ret == CMD_ERROR) return CMD_ERROR; |
|
639 |
cost = ret; |
|
640 |
||
641 |
dep = AllocateDepot(); |
|
642 |
if (dep == NULL) |
|
643 |
return CMD_ERROR; |
|
644 |
||
645 |
if (flags & DC_EXEC) { |
|
646 |
if (_current_player == _local_player) |
|
647 |
_last_built_train_depot_tile = (TileIndex)tile; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
648 |
|
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
649 |
ModifyTile(tile, |
0 | 650 |
MP_SETTYPE(MP_RAILWAY) | |
651 |
MP_MAP3LO | MP_MAPOWNER_CURRENT | MP_MAP5, |
|
652 |
p1, /* map3_lo */ |
|
653 |
p2 | RAIL_TYPE_DEPOT /* map5 */ |
|
654 |
); |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
655 |
|
0 | 656 |
dep->xy = tile; |
657 |
dep->town_index = ClosestTownFromTile(tile, (uint)-1)->index; |
|
658 |
||
659 |
SetSignalsOnBothDir(tile, (p2&1) ? 2 : 1); |
|
660 |
||
661 |
} |
|
662 |
||
663 |
return cost + _price.build_train_depot; |
|
664 |
} |
|
665 |
||
395
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
393
diff
changeset
|
666 |
static void MakeDefaultWaypointName(Waypoint *cp) |
0 | 667 |
{ |
668 |
int townidx = ClosestTownFromTile(cp->xy, (uint)-1)->index; |
|
395
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
393
diff
changeset
|
669 |
Waypoint *cc; |
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
393
diff
changeset
|
670 |
bool used_waypoint[64]; |
0 | 671 |
int i; |
672 |
||
395
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
393
diff
changeset
|
673 |
memset(used_waypoint, 0, sizeof(used_waypoint)); |
0 | 674 |
|
395
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
393
diff
changeset
|
675 |
// find an unused waypoint number belonging to this town |
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
393
diff
changeset
|
676 |
for(cc = _waypoints; cc != endof(_waypoints); cc++) { |
0 | 677 |
if (cc->xy && cc->town_or_string & 0xC000 && (cc->town_or_string & 0xFF) == townidx) |
395
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
393
diff
changeset
|
678 |
used_waypoint[(cc->town_or_string >> 8) & 0x3F] = true; |
0 | 679 |
} |
680 |
||
395
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
393
diff
changeset
|
681 |
for(i=0; used_waypoint[i] && i!=lengthof(used_waypoint)-1; i++) {} |
0 | 682 |
cp->town_or_string = 0xC000 + (i << 8) + townidx; |
683 |
} |
|
684 |
||
395
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
393
diff
changeset
|
685 |
// find a deleted waypoint close to a tile. |
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
393
diff
changeset
|
686 |
static Waypoint *FindDeletedWaypointCloseTo(uint tile) |
0 | 687 |
{ |
395
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
393
diff
changeset
|
688 |
Waypoint *cp,*best = NULL; |
0 | 689 |
uint thres = 8, cur_dist; |
690 |
||
395
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
393
diff
changeset
|
691 |
for(cp = _waypoints; cp != endof(_waypoints); cp++) { |
0 | 692 |
if (cp->deleted && cp->xy) { |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
693 |
cur_dist = GetTileDist(tile, cp->xy); |
0 | 694 |
if (cur_dist < thres) { |
695 |
thres = cur_dist; |
|
696 |
best = cp; |
|
697 |
} |
|
698 |
} |
|
699 |
} |
|
700 |
return best; |
|
701 |
} |
|
702 |
||
395
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
393
diff
changeset
|
703 |
/* Convert existing rail to waypoint */ |
0 | 704 |
|
395
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
393
diff
changeset
|
705 |
int32 CmdBuildTrainWaypoint(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
0 | 706 |
{ |
707 |
uint tile = TILE_FROM_XY(x,y); |
|
395
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
393
diff
changeset
|
708 |
Waypoint *cp; |
0 | 709 |
uint tileh; |
710 |
uint dir; |
|
711 |
||
712 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
713 |
||
714 |
if (!IS_TILETYPE(tile, MP_RAILWAY) || ((dir=0, _map5[tile] != 1) && (dir=1, _map5[tile] != 2))) |
|
715 |
return_cmd_error(STR_1005_NO_SUITABLE_RAILROAD_TRACK); |
|
716 |
||
717 |
if (!CheckTileOwnership(tile)) |
|
718 |
return CMD_ERROR; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
719 |
|
0 | 720 |
if (!EnsureNoVehicle(tile)) return CMD_ERROR; |
721 |
||
722 |
tileh = GetTileSlope(tile, NULL); |
|
723 |
if (tileh != 0) { |
|
724 |
if (!_patches.build_on_slopes || tileh & 0x10 || !(tileh & (0x3 << dir)) || !(tileh & ~(0x3 << dir))) |
|
725 |
return_cmd_error(STR_0007_FLAT_LAND_REQUIRED); |
|
726 |
} |
|
727 |
||
395
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
393
diff
changeset
|
728 |
// check if there is an already existing, deleted, waypoint close to us that we can reuse. |
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
393
diff
changeset
|
729 |
cp = FindDeletedWaypointCloseTo(tile); |
0 | 730 |
if (cp == NULL) { |
395
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
393
diff
changeset
|
731 |
cp = AllocateWaypoint(); |
0 | 732 |
if (cp == NULL) return CMD_ERROR; |
733 |
cp->town_or_string = 0; |
|
734 |
} |
|
735 |
||
736 |
if (flags & DC_EXEC) { |
|
395
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
393
diff
changeset
|
737 |
ModifyTile(tile, MP_MAP5, RAIL_TYPE_WAYPOINT | dir); |
389
2d394eeba5e5
(svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents:
337
diff
changeset
|
738 |
if (p1 & 0x100) { |
2d394eeba5e5
(svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents:
337
diff
changeset
|
739 |
// custom graphics |
2d394eeba5e5
(svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents:
337
diff
changeset
|
740 |
_map3_lo[tile] |= 16; |
2d394eeba5e5
(svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents:
337
diff
changeset
|
741 |
_map3_hi[tile] = p1 & 0xff; |
2d394eeba5e5
(svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents:
337
diff
changeset
|
742 |
} |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
743 |
|
0 | 744 |
cp->deleted = 0; |
745 |
cp->xy = tile; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
746 |
|
395
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
393
diff
changeset
|
747 |
if (cp->town_or_string == 0) MakeDefaultWaypointName(cp); else RedrawWaypointSign(cp); |
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
393
diff
changeset
|
748 |
UpdateWaypointSign(cp); |
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
393
diff
changeset
|
749 |
RedrawWaypointSign(cp); |
0 | 750 |
SetSignalsOnBothDir(tile, dir ? 2 : 1); |
751 |
} |
|
752 |
||
753 |
return _price.build_train_depot; |
|
754 |
} |
|
755 |
||
395
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
393
diff
changeset
|
756 |
static void DoDeleteWaypoint(Waypoint *cp) |
0 | 757 |
{ |
758 |
cp->xy = 0; |
|
395
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
393
diff
changeset
|
759 |
DeleteCommandFromVehicleSchedule(((cp-_waypoints) << 8) + OT_GOTO_WAYPOINT); |
0 | 760 |
if (~cp->town_or_string & 0xC000) DeleteName(cp->town_or_string); |
395
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
393
diff
changeset
|
761 |
RedrawWaypointSign(cp); |
0 | 762 |
} |
763 |
||
395
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
393
diff
changeset
|
764 |
// delete waypoints after a while |
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
393
diff
changeset
|
765 |
void WaypointsDailyLoop() |
0 | 766 |
{ |
395
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
393
diff
changeset
|
767 |
Waypoint *cp; |
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
393
diff
changeset
|
768 |
for(cp = _waypoints; cp != endof(_waypoints); cp++) { |
0 | 769 |
if (cp->deleted && !--cp->deleted) { |
395
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
393
diff
changeset
|
770 |
DoDeleteWaypoint(cp); |
0 | 771 |
} |
772 |
} |
|
773 |
} |
|
774 |
||
395
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
393
diff
changeset
|
775 |
static int32 RemoveTrainWaypoint(uint tile, uint32 flags, bool justremove) |
0 | 776 |
{ |
395
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
393
diff
changeset
|
777 |
Waypoint *cp; |
0 | 778 |
|
395
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
393
diff
changeset
|
779 |
// make sure it's a waypoint |
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
393
diff
changeset
|
780 |
if (!IS_TILETYPE(tile, MP_RAILWAY) || !IS_RAIL_WAYPOINT(_map5[tile])) |
0 | 781 |
return CMD_ERROR; |
782 |
||
783 |
if (!CheckTileOwnership(tile) && !(_current_player==17)) |
|
784 |
return CMD_ERROR; |
|
785 |
||
786 |
if (!EnsureNoVehicle(tile)) |
|
787 |
return CMD_ERROR; |
|
788 |
||
789 |
if (flags & DC_EXEC) { |
|
395
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
393
diff
changeset
|
790 |
int direction = _map5[tile] & RAIL_WAYPOINT_TRACK_MASK; |
0 | 791 |
|
395
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
393
diff
changeset
|
792 |
// mark the waypoint deleted |
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
393
diff
changeset
|
793 |
for(cp=_waypoints; cp->xy != (TileIndex)tile; cp++) {} |
0 | 794 |
cp->deleted = 30; // let it live for this many days before we do the actual deletion. |
395
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
393
diff
changeset
|
795 |
RedrawWaypointSign(cp); |
0 | 796 |
|
797 |
if (justremove) { |
|
798 |
ModifyTile(tile, MP_MAP5, 1<<direction); |
|
389
2d394eeba5e5
(svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents:
337
diff
changeset
|
799 |
_map3_lo[tile] &= ~16; |
2d394eeba5e5
(svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents:
337
diff
changeset
|
800 |
_map3_hi[tile] = 0; |
0 | 801 |
} else { |
802 |
DoClearSquare(tile); |
|
803 |
SetSignalsOnBothDir(tile, direction); |
|
804 |
} |
|
805 |
} |
|
806 |
||
807 |
return _price.remove_train_depot; |
|
808 |
} |
|
809 |
||
395
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
393
diff
changeset
|
810 |
int32 CmdRemoveTrainWaypoint(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
0 | 811 |
{ |
812 |
uint tile = TILE_FROM_XY(x,y); |
|
395
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
393
diff
changeset
|
813 |
return RemoveTrainWaypoint(tile, flags, true); |
0 | 814 |
} |
815 |
||
816 |
||
395
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
393
diff
changeset
|
817 |
// p1 = id of waypoint |
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
393
diff
changeset
|
818 |
int32 CmdRenameWaypoint(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
0 | 819 |
{ |
395
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
393
diff
changeset
|
820 |
Waypoint *cp; |
0 | 821 |
StringID str; |
822 |
||
823 |
if (_decode_parameters[0] != 0) { |
|
824 |
str = AllocateName((byte*)_decode_parameters, 0); |
|
825 |
if (str == 0) return CMD_ERROR; |
|
826 |
||
827 |
if (flags & DC_EXEC) { |
|
395
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
393
diff
changeset
|
828 |
cp = &_waypoints[p1]; |
0 | 829 |
if (~cp->town_or_string & 0xC000) DeleteName(cp->town_or_string); |
830 |
cp->town_or_string = str; |
|
395
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
393
diff
changeset
|
831 |
UpdateWaypointSign(cp); |
0 | 832 |
MarkWholeScreenDirty(); |
833 |
} else { |
|
834 |
DeleteName(str); |
|
835 |
} |
|
836 |
} else { |
|
837 |
if (flags & DC_EXEC) { |
|
395
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
393
diff
changeset
|
838 |
cp = &_waypoints[p1]; |
0 | 839 |
if (~cp->town_or_string & 0xC000) DeleteName(cp->town_or_string); |
395
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
393
diff
changeset
|
840 |
MakeDefaultWaypointName(cp); |
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
393
diff
changeset
|
841 |
UpdateWaypointSign(cp); |
0 | 842 |
MarkWholeScreenDirty(); |
843 |
} |
|
844 |
} |
|
845 |
return 0; |
|
846 |
} |
|
847 |
||
848 |
||
58
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
849 |
/* build signals, alternate between double/single, signal/semaphore, pre/exit/combo -signals |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
850 |
p1 = (lower 3 bytes) - track-orientation |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
851 |
p1 = (byte 4) - semaphores/signals |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
852 |
p2 = used for CmdBuildManySignals() to copy style first signal |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
853 |
*/ |
0 | 854 |
int32 CmdBuildSignals(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
855 |
{ |
|
856 |
uint tile; |
|
857 |
byte m5; |
|
858 |
int32 cost; |
|
859 |
int track = p1 & 0x7; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
860 |
|
58
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
861 |
assert(track >= 0 && track < 6); // only 6 possible track-combinations |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
862 |
|
0 | 863 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
864 |
||
865 |
tile = TILE_FROM_XY(x,y); |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
866 |
|
0 | 867 |
if (!EnsureNoVehicle(tile)) |
868 |
return CMD_ERROR; |
|
869 |
||
870 |
// must be railway, and not a depot, and it must have a track in the suggested position. |
|
871 |
if (!IS_TILETYPE(tile, MP_RAILWAY) || (m5=_map5[tile], m5&0x80) || !HASBIT(m5, track)) |
|
872 |
return CMD_ERROR; |
|
873 |
||
58
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
874 |
_error_message = STR_1005_NO_SUITABLE_RAILROAD_TRACK; |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
875 |
|
0 | 876 |
// check rail combination |
877 |
{ |
|
878 |
byte m = m5 & RAIL_BIT_MASK; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
879 |
if (m != RAIL_BIT_DIAG1 && m != RAIL_BIT_DIAG2 && m != RAIL_BIT_UPPER && m != RAIL_BIT_LOWER && |
0 | 880 |
m != RAIL_BIT_LEFT && m != RAIL_BIT_RIGHT && m != (RAIL_BIT_UPPER|RAIL_BIT_LOWER) && m != (RAIL_BIT_LEFT|RAIL_BIT_RIGHT)) |
881 |
return CMD_ERROR; |
|
882 |
} |
|
883 |
||
884 |
// check ownership |
|
885 |
if (!CheckTileOwnership(tile)) |
|
886 |
return CMD_ERROR; |
|
887 |
||
58
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
888 |
// If it had signals previously it is free to change orientation/pre-exit-combo signals |
0 | 889 |
cost = 0; |
890 |
if (!(m5 & RAIL_TYPE_SIGNALS)) { |
|
891 |
cost = _price.build_signals; |
|
58
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
892 |
// if converting signals<->semaphores, charge the player for it |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
893 |
} else if (p2 && ((HASBIT(p1, 3) && !HASBIT(_map3_hi[tile], 2)) || (!HASBIT(p1, 3) && HASBIT(_map3_hi[tile], 2)) ) ) { |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
894 |
cost += _price.build_signals + _price.remove_signals; |
0 | 895 |
} |
896 |
||
897 |
if (flags & DC_EXEC) { |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
898 |
|
0 | 899 |
|
58
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
900 |
if (!(m5 & RAIL_TYPE_SIGNALS)) { // if there are no signals yet present on the track |
0 | 901 |
_map5[tile] |= RAIL_TYPE_SIGNALS; // change into signals |
902 |
_map2[tile] |= 0xF0; // all signals are on |
|
903 |
_map3_lo[tile] &= ~0xF0; // no signals built by default |
|
904 |
_map3_hi[tile] = (p1 & 8) ? 4 : 0;// initial presignal state, semaphores depend on ctrl key |
|
58
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
905 |
if (!p2) |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
906 |
goto ignore_presig; |
0 | 907 |
} |
908 |
||
58
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
909 |
if (!p2) { // not called from CmdBuildManySignals |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
910 |
if (!HASBIT(p1, 3)) { // not CTRL pressed |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
911 |
byte a,b,c,d; |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
912 |
ignore_presig: |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
913 |
a = _signals_table[track]; // signal for this track in one direction |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
914 |
b = _signals_table[track + 8]; // signal for this track in the other direction |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
915 |
c = a | b; |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
916 |
d = _map3_lo[tile] & c; // mask of built signals. it only affects &0xF0 |
0 | 917 |
|
58
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
918 |
// Alternate between a|b, b, a |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
919 |
if ( d != 0 && d != a) { |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
920 |
c = (d==c)?b:a; |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
921 |
} |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
922 |
|
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
923 |
_map3_lo[tile] = (_map3_lo[tile]&~(a|b)) | c; |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
924 |
} else // CTRL pressed |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
925 |
_map3_hi[tile] = (_map3_hi[tile] & ~3) | ((_map3_hi[tile] + 1) & 3); |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
926 |
} else { |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
927 |
/* If CmdBuildManySignals is called with copying signals, just copy the style of the first signal |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
928 |
* given as parameter by CmdBuildManySignals */ |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
929 |
switch (track) { |
59
fb1a20aefeae
(svn r60) -Fix: signal_density is given as a parameter to autosignal. This means all players can define it for themselves.
darkvater
parents:
58
diff
changeset
|
930 |
case 2: case 4: _map3_lo[tile] = (p2&0xC0) | (_map3_lo[tile]&~0xC0); break; |
fb1a20aefeae
(svn r60) -Fix: signal_density is given as a parameter to autosignal. This means all players can define it for themselves.
darkvater
parents:
58
diff
changeset
|
931 |
case 3: case 5: _map3_lo[tile] = (p2&0x30) | (_map3_lo[tile]&~0x30); break; |
fb1a20aefeae
(svn r60) -Fix: signal_density is given as a parameter to autosignal. This means all players can define it for themselves.
darkvater
parents:
58
diff
changeset
|
932 |
default : _map3_lo[tile] = (p2&0xF0) | (_map3_lo[tile]&0xF); |
0 | 933 |
} |
58
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
934 |
// convert between signal<->semaphores when dragging |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
935 |
HASBIT(p1, 3) ? SETBIT(_map3_hi[tile], 2) : CLRBIT(_map3_hi[tile], 2); |
0 | 936 |
} |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
937 |
|
0 | 938 |
MarkTileDirtyByTile(tile); |
939 |
SetSignalsOnBothDir(tile, track); |
|
940 |
} |
|
941 |
||
942 |
return cost; |
|
943 |
} |
|
944 |
||
58
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
945 |
/* Build many signals by dragging: AutoSignals |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
946 |
x,y= start tile |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
947 |
p1 = end tile |
59
fb1a20aefeae
(svn r60) -Fix: signal_density is given as a parameter to autosignal. This means all players can define it for themselves.
darkvater
parents:
58
diff
changeset
|
948 |
p2 = (byte 0) - 0 = build, 1 = remove signals |
fb1a20aefeae
(svn r60) -Fix: signal_density is given as a parameter to autosignal. This means all players can define it for themselves.
darkvater
parents:
58
diff
changeset
|
949 |
p2 = (byte 3) - 0 = signals, 1 = semaphores |
fb1a20aefeae
(svn r60) -Fix: signal_density is given as a parameter to autosignal. This means all players can define it for themselves.
darkvater
parents:
58
diff
changeset
|
950 |
p2 = (byte 7-4) - track-orientation |
fb1a20aefeae
(svn r60) -Fix: signal_density is given as a parameter to autosignal. This means all players can define it for themselves.
darkvater
parents:
58
diff
changeset
|
951 |
p2 = (byte 8-) - track style |
fb1a20aefeae
(svn r60) -Fix: signal_density is given as a parameter to autosignal. This means all players can define it for themselves.
darkvater
parents:
58
diff
changeset
|
952 |
p2 = (byte 24-31) - user defined signals_density |
58
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
953 |
*/ |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
954 |
int32 CmdBuildManySignals(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
955 |
{ |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
956 |
int ex, ey, railbit; |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
957 |
bool error = true; |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
958 |
TileIndex tile = TILE_FROM_XY(x, y); |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
959 |
int32 ret, total_cost, signal_ctr; |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
960 |
byte m5, semaphores = (HASBIT(p2, 3)) ? 8 : 0; |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
961 |
int mode = (p2 >> 4)&0xF; |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
962 |
// for vertical/horizontal tracks, double the given signals density |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
963 |
// since the original amount will be too dense (shorter tracks) |
59
fb1a20aefeae
(svn r60) -Fix: signal_density is given as a parameter to autosignal. This means all players can define it for themselves.
darkvater
parents:
58
diff
changeset
|
964 |
byte signal_density = (mode == 1 || mode == 2) ? (p2 >> 24) : (p2 >> 24) * 2; |
fb1a20aefeae
(svn r60) -Fix: signal_density is given as a parameter to autosignal. This means all players can define it for themselves.
darkvater
parents:
58
diff
changeset
|
965 |
byte signals = (p2 >> 8)&0xFF; |
58
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
966 |
mode = p2 & 0x1; // build/remove signals |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
967 |
|
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
968 |
/* unpack end tile */ |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
969 |
ex = GET_TILE_X(p1)*16; |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
970 |
ey = GET_TILE_Y(p1)*16; |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
971 |
|
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
972 |
railbit = _railbit.initial[((p2 >> 4)&0xF) + (x > ex ? 4 : 0) + (y > ey ? 8 : 0)]; |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
973 |
|
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
974 |
// copy the signal-style of the first rail-piece if existing |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
975 |
m5 = _map5[tile]; |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
976 |
if (!(m5 & RAIL_TYPE_SPECIAL) && (m5 & RAIL_BIT_MASK) && (m5 & RAIL_TYPE_SIGNALS)) { |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
977 |
if (m5 & 0x3) // X,Y direction tracks |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
978 |
signals = _map3_lo[tile]&0xC0; |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
979 |
else { |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
980 |
/* W-E or N-S direction, only copy the side which was chosen, leave |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
981 |
* the other side alone */ |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
982 |
switch (signals) { |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
983 |
case 0x20: case 8: /* east corner (N-S), south corner (W-E) */ |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
984 |
if (_map3_lo[tile]&0x30) |
58
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
985 |
signals = _map3_lo[tile]&0x30; |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
986 |
else |
59
fb1a20aefeae
(svn r60) -Fix: signal_density is given as a parameter to autosignal. This means all players can define it for themselves.
darkvater
parents:
58
diff
changeset
|
987 |
signals = 0x30 | (_map3_lo[tile]&0xC0); |
58
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
988 |
break; |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
989 |
case 0x10: case 4: /* west corner (N-S), north corner (W-E) */ |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
990 |
if (_map3_lo[tile]&0xC0) |
58
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
991 |
signals = _map3_lo[tile]&0xC0; |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
992 |
else |
59
fb1a20aefeae
(svn r60) -Fix: signal_density is given as a parameter to autosignal. This means all players can define it for themselves.
darkvater
parents:
58
diff
changeset
|
993 |
signals = 0xC0 | (_map3_lo[tile]&0x30); |
58
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
994 |
break; |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
995 |
} |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
996 |
} |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
997 |
|
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
998 |
semaphores = (_map3_hi[tile] & ~3) ? 8 : 0; // copy signal/semaphores style (independent of CTRL) |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
999 |
} else { // no signals exist, drag a two-way signal stretch |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
1000 |
switch (signals) { |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
1001 |
case 0x20: case 8: /* east corner (N-S), south corner (W-E) */ |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
1002 |
signals = 0x30; break; |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
1003 |
case 0x10: case 4: /* west corner (N-S), north corner (W-E) */ |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
1004 |
signals = 0xC0; |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
1005 |
} |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
1006 |
} |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
1007 |
|
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
1008 |
/* signal_density_ctr - amount of tiles already processed |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
1009 |
* signals_density - patch setting to put signal on every Nth tile (double space on |, -- tracks) |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
1010 |
********** |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
1011 |
* railbit - direction of autorail |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
1012 |
* semaphores - semaphores or signals |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1013 |
* signals - is there a signal/semaphore on the first tile, copy its style (two-way/single-way) |
58
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
1014 |
and convert all others to semaphore/signal |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
1015 |
* mode - 1 remove signals, 0 build signals */ |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
1016 |
signal_ctr = total_cost = 0; |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
1017 |
for(;;) { |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
1018 |
// only build/remove signals with the specified density |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
1019 |
if ((signal_ctr % signal_density) == 0 ) { |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
1020 |
ret = DoCommand(x, y, (railbit & 7) | semaphores, signals, flags, (mode == 1) ? CMD_REMOVE_SIGNALS : CMD_BUILD_SIGNALS); |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
1021 |
|
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
1022 |
/* Abort placement for any other error then NOT_SUITEABLE_TRACK |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
1023 |
* This includes vehicles on track, competitor's tracks, etc. */ |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
1024 |
if (ret == CMD_ERROR) { |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
1025 |
if (_error_message != STR_1005_NO_SUITABLE_RAILROAD_TRACK && mode != 1) { |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
1026 |
return CMD_ERROR; |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
1027 |
} |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
1028 |
} else { |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
1029 |
error = false; |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
1030 |
total_cost += ret; |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
1031 |
} |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
1032 |
} |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
1033 |
|
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
1034 |
if (ex == x && ey == y) // reached end of drag |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
1035 |
break; |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
1036 |
|
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
1037 |
x += _railbit.xinc[railbit]; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1038 |
y += _railbit.yinc[railbit]; |
58
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
1039 |
signal_ctr++; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1040 |
|
58
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
1041 |
// toggle railbit for the diagonal tiles (|, -- tracks) |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
1042 |
if (railbit & 0x6) railbit ^= 1; |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
1043 |
} |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
1044 |
|
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
1045 |
return (error) ? CMD_ERROR : total_cost; |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
1046 |
} |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
1047 |
|
0 | 1048 |
/* Remove signals |
1049 |
* p1 = unused |
|
1050 |
* p2 = unused |
|
1051 |
*/ |
|
1052 |
||
1053 |
int32 CmdRemoveSignals(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
1054 |
{ |
|
1055 |
TileInfo ti; |
|
1056 |
uint tile; |
|
1057 |
||
1058 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
1059 |
||
1060 |
FindLandscapeHeight(&ti, x, y); |
|
1061 |
tile = ti.tile; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1062 |
|
0 | 1063 |
/* No vehicle behind. */ |
1064 |
if (!EnsureNoVehicle(tile)) |
|
1065 |
return CMD_ERROR; |
|
1066 |
||
1067 |
/* Signals can only exist on railways */ |
|
1068 |
if (ti.type != MP_RAILWAY) |
|
1069 |
return CMD_ERROR; |
|
1070 |
||
1071 |
/* Map5 mode is 0x40 when there's signals */ |
|
1072 |
if ((ti.map5 & RAIL_TYPE_MASK) != RAIL_TYPE_SIGNALS) |
|
1073 |
return CMD_ERROR; |
|
1074 |
||
1075 |
/* Who owns the tile? */ |
|
1076 |
if (_current_player != OWNER_WATER && !CheckTileOwnership(tile)) |
|
1077 |
return CMD_ERROR; |
|
1078 |
||
1079 |
/* Do it? */ |
|
1080 |
if (flags & DC_EXEC) { |
|
1081 |
byte bits = _map5[tile]; |
|
1082 |
_map5[tile] &= ~RAIL_TYPE_SIGNALS; |
|
1083 |
_map2[tile] &= ~0xF0; |
|
58
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
1084 |
CLRBIT(_map3_hi[tile], 2); // remove any possible semaphores |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1085 |
|
0 | 1086 |
/* TTDBUG: this code contains a bug, if a tile contains 2 signals |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1087 |
* on separate tracks, it won't work properly for the 2nd track */ |
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1088 |
SetSignalsOnBothDir(tile, FIND_FIRST_BIT(bits & RAIL_BIT_MASK)); |
0 | 1089 |
|
1090 |
MarkTileDirtyByTile(tile); |
|
1091 |
} |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1092 |
|
0 | 1093 |
return _price.remove_signals; |
1094 |
} |
|
1095 |
||
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1096 |
typedef int32 DoConvertRailProc(uint tile, uint totype, bool exec); |
0 | 1097 |
|
1098 |
static int32 DoConvertRail(uint tile, uint totype, bool exec) |
|
1099 |
{ |
|
1100 |
if (!CheckTileOwnership(tile) || !EnsureNoVehicle(tile)) |
|
1101 |
return CMD_ERROR; |
|
1102 |
||
1103 |
// tile is already of requested type? |
|
1104 |
if ( (uint)(_map3_lo[tile] & 0xF) == totype) |
|
1105 |
return CMD_ERROR; |
|
1106 |
||
1107 |
// change type. |
|
1108 |
if (exec) { |
|
1109 |
_map3_lo[tile] = (_map3_lo[tile] & 0xF0) + totype; |
|
1110 |
MarkTileDirtyByTile(tile); |
|
1111 |
} |
|
1112 |
||
1113 |
return _price.build_rail >> 1; |
|
1114 |
} |
|
1115 |
||
1116 |
extern int32 DoConvertStationRail(uint tile, uint totype, bool exec); |
|
1117 |
extern int32 DoConvertStreetRail(uint tile, uint totype, bool exec); |
|
1118 |
extern int32 DoConvertTunnelBridgeRail(uint tile, uint totype, bool exec); |
|
1119 |
||
1120 |
// p1 = start tile |
|
1121 |
// p2 = new railtype |
|
1122 |
int32 CmdConvertRail(int ex, int ey, uint32 flags, uint32 p1, uint32 p2) |
|
1123 |
{ |
|
1124 |
int32 ret, cost, money; |
|
1125 |
int sx,sy,x,y; |
|
1126 |
||
1127 |
// make sure sx,sy are smaller than ex,ey |
|
1128 |
sx = GET_TILE_X(p1)*16; |
|
1129 |
sy = GET_TILE_Y(p1)*16; |
|
1130 |
if (ex < sx) intswap(ex, sx); |
|
1131 |
if (ey < sy) intswap(ey, sy); |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1132 |
|
0 | 1133 |
money = GetAvailableMoneyForCommand(); |
1134 |
ret = false; |
|
1135 |
cost = 0; |
|
1136 |
for(x=sx; x<=ex; x+=16) { |
|
1137 |
for(y=sy; y<=ey; y+=16) { |
|
1138 |
uint tile = TILE_FROM_XY(x,y); |
|
1139 |
DoConvertRailProc *p; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1140 |
|
0 | 1141 |
if (IS_TILETYPE(tile, MP_RAILWAY)) p = DoConvertRail; |
1142 |
else if (IS_TILETYPE(tile, MP_STATION)) p = DoConvertStationRail; |
|
1143 |
else if (IS_TILETYPE(tile, MP_STREET)) p = DoConvertStreetRail; |
|
1144 |
else if (IS_TILETYPE(tile, MP_TUNNELBRIDGE)) p = DoConvertTunnelBridgeRail; |
|
1145 |
else continue; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1146 |
|
0 | 1147 |
ret = p(tile, p2, false); |
1148 |
if (ret == CMD_ERROR) continue; |
|
1149 |
cost += ret; |
|
1150 |
||
1151 |
if (flags & DC_EXEC) { |
|
1152 |
if ( (money -= ret) < 0) { _additional_cash_required = ret; return cost - ret; } |
|
1153 |
p(tile, p2, true); |
|
1154 |
} |
|
1155 |
} |
|
1156 |
} |
|
1157 |
if (cost == 0) cost = CMD_ERROR; |
|
1158 |
return cost; |
|
1159 |
} |
|
1160 |
||
1161 |
static int32 RemoveTrainDepot(uint tile, uint32 flags) |
|
1162 |
{ |
|
149
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
84
diff
changeset
|
1163 |
if (!CheckTileOwnership(tile) && _current_player != OWNER_WATER) |
0 | 1164 |
return CMD_ERROR; |
1165 |
||
1166 |
if (!EnsureNoVehicle(tile)) |
|
1167 |
return CMD_ERROR; |
|
1168 |
||
1169 |
if (flags & DC_EXEC) { |
|
1170 |
int track = _map5[tile] & RAIL_DEPOT_TRACK_MASK; |
|
1171 |
||
1172 |
DoDeleteDepot(tile); |
|
1173 |
SetSignalsOnBothDir(tile, track); |
|
1174 |
} |
|
1175 |
||
1176 |
return _price.remove_train_depot; |
|
1177 |
} |
|
1178 |
||
1179 |
static int32 ClearTile_Track(uint tile, byte flags) { |
|
1180 |
int32 cost,ret; |
|
1181 |
int i; |
|
1182 |
byte m5; |
|
1183 |
||
1184 |
m5 = _map5[tile]; |
|
1185 |
||
1186 |
if (flags & DC_AUTO) { |
|
1187 |
if (m5 & RAIL_TYPE_SPECIAL) |
|
1188 |
return_cmd_error(STR_2004_BUILDING_MUST_BE_DEMOLISHED); |
|
1189 |
||
1190 |
if (_map_owner[tile] != _current_player) |
|
1191 |
return_cmd_error(STR_1024_AREA_IS_OWNED_BY_ANOTHER); |
|
1192 |
||
1193 |
return_cmd_error(STR_1008_MUST_REMOVE_RAILROAD_TRACK); |
|
1194 |
} |
|
1195 |
||
1196 |
cost = 0; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1197 |
|
0 | 1198 |
|
1199 |
if ( (m5 & RAIL_TYPE_MASK) == RAIL_TYPE_NORMAL) { |
|
1200 |
regular_track:; |
|
1201 |
for(i=0; m5; i++, m5>>=1) { |
|
1202 |
if (m5 & 1) { |
|
1203 |
ret = DoCommandByTile(tile, 0, i, flags, CMD_REMOVE_SINGLE_RAIL); |
|
1204 |
if (ret == CMD_ERROR) |
|
1205 |
return CMD_ERROR; |
|
1206 |
cost += ret; |
|
1207 |
} |
|
1208 |
} |
|
1209 |
return cost; |
|
1210 |
||
1211 |
} else if ((m5 & RAIL_TYPE_MASK)==RAIL_TYPE_SIGNALS) { |
|
1212 |
cost = DoCommandByTile(tile, 0, 0, flags, CMD_REMOVE_SIGNALS); |
|
1213 |
if (cost == CMD_ERROR) |
|
1214 |
return CMD_ERROR; |
|
1215 |
m5 &= RAIL_BIT_MASK; |
|
1216 |
if (flags & DC_EXEC) |
|
1217 |
goto regular_track; |
|
1218 |
return cost + _price.remove_rail; |
|
1219 |
} else if ( (m5 & (RAIL_TYPE_MASK|RAIL_DEPOT_UNUSED_BITS)) == RAIL_TYPE_DEPOT) { |
|
1220 |
return RemoveTrainDepot(tile, flags); |
|
395
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
393
diff
changeset
|
1221 |
} else if ( (m5 & (RAIL_TYPE_MASK|RAIL_WAYPOINT_UNUSED_BITS)) == RAIL_TYPE_WAYPOINT) { |
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
393
diff
changeset
|
1222 |
return RemoveTrainWaypoint(tile, flags, false); |
0 | 1223 |
} else |
1224 |
return CMD_ERROR; |
|
1225 |
} |
|
1226 |
||
1227 |
||
1228 |
||
1229 |
typedef struct DrawTrackSeqStruct { |
|
1230 |
uint16 image; |
|
1231 |
byte subcoord_x; |
|
1232 |
byte subcoord_y; |
|
1233 |
byte width; |
|
1234 |
byte height; |
|
1235 |
} DrawTrackSeqStruct; |
|
1236 |
||
1237 |
#include "table/track_land.h" |
|
1238 |
||
1239 |
// used for presignals |
|
1240 |
static const SpriteID _signal_base_sprites[16] = { |
|
1241 |
0x4FB, |
|
1242 |
0x1323, |
|
1243 |
0x1333, |
|
1244 |
0x1343, |
|
1245 |
||
1246 |
// use semaphores instead of signals? |
|
1247 |
0x1353, |
|
1248 |
0x1363, |
|
1249 |
0x1373, |
|
1250 |
0x1383, |
|
1251 |
||
1252 |
// mirrored versions |
|
1253 |
0x4FB, |
|
1254 |
0x1323, |
|
1255 |
0x1333, |
|
1256 |
0x1343, |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1257 |
|
0 | 1258 |
0x13C6, |
1259 |
0x13D6, |
|
1260 |
0x13E6, |
|
1261 |
0x13F6, |
|
1262 |
}; |
|
1263 |
||
1264 |
// used to determine the side of the road for the signal |
|
1265 |
static const byte _signal_position[24] = { |
|
1266 |
/* original: left side position */ |
|
1267 |
0x58,0x1E,0xE1,0xB9,0x01,0xA3,0x4B,0xEE,0x3B,0xD4,0x43,0xBD, |
|
1268 |
/* patch: ride side position */ |
|
1269 |
0x1E,0xAC,0x64,0xE1,0x4A,0x10,0xEE,0xC5,0xDB,0x34,0x4D,0xB3 |
|
1270 |
}; |
|
1271 |
||
1272 |
static void DrawSignalHelper(TileInfo *ti, byte condition, uint32 image_and_pos) |
|
1273 |
{ |
|
1274 |
bool otherside = _opt.road_side & _patches.signal_side; |
|
1275 |
||
1276 |
uint v = _signal_position[(image_and_pos & 0xF) + (otherside ? 12 : 0)]; |
|
1277 |
uint x = ti->x | (v&0xF); |
|
1278 |
uint y = ti->y | (v>>4); |
|
1279 |
uint sprite = _signal_base_sprites[(_map3_hi[ti->tile] & 7) + (otherside ? 8 : 0)] + (image_and_pos>>4) + ((condition != 0) ? 1 : 0); |
|
1280 |
AddSortableSpriteToDraw(sprite, x, y, 1, 1, 10, GetSlopeZ(x,y)); |
|
1281 |
} |
|
1282 |
||
1283 |
static uint32 _drawtile_track_palette; |
|
1284 |
||
1285 |
||
1286 |
static void DrawTrackFence_NW(TileInfo *ti) |
|
1287 |
{ |
|
1288 |
uint32 image = 0x515; |
|
1289 |
if (ti->tileh != 0) { |
|
1290 |
image = 0x519; |
|
1291 |
if (!(ti->tileh & 2)) { |
|
1292 |
image = 0x51B; |
|
1293 |
} |
|
1294 |
} |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1295 |
AddSortableSpriteToDraw(image | _drawtile_track_palette, |
0 | 1296 |
ti->x, ti->y+1, 16, 1, 4, ti->z); |
1297 |
} |
|
1298 |
||
1299 |
static void DrawTrackFence_SE(TileInfo *ti) |
|
1300 |
{ |
|
1301 |
uint32 image = 0x515; |
|
1302 |
if (ti->tileh != 0) { |
|
1303 |
image = 0x519; |
|
1304 |
if (!(ti->tileh & 2)) { |
|
1305 |
image = 0x51B; |
|
1306 |
} |
|
1307 |
} |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1308 |
AddSortableSpriteToDraw(image | _drawtile_track_palette, |
0 | 1309 |
ti->x, ti->y+15, 16, 1, 4, ti->z); |
1310 |
} |
|
1311 |
||
1312 |
static void DrawTrackFence_NW_SE(TileInfo *ti) |
|
1313 |
{ |
|
1314 |
DrawTrackFence_NW(ti); |
|
1315 |
DrawTrackFence_SE(ti); |
|
1316 |
} |
|
1317 |
||
1318 |
static void DrawTrackFence_NE(TileInfo *ti) |
|
1319 |
{ |
|
1320 |
uint32 image = 0x516; |
|
1321 |
if (ti->tileh != 0) { |
|
1322 |
image = 0x51A; |
|
1323 |
if (!(ti->tileh & 2)) { |
|
1324 |
image = 0x51C; |
|
1325 |
} |
|
1326 |
} |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1327 |
AddSortableSpriteToDraw(image | _drawtile_track_palette, |
0 | 1328 |
ti->x+1, ti->y, 1, 16, 4, ti->z); |
1329 |
} |
|
1330 |
||
1331 |
static void DrawTrackFence_SW(TileInfo *ti) |
|
1332 |
{ |
|
1333 |
uint32 image = 0x516; |
|
1334 |
if (ti->tileh != 0) { |
|
1335 |
image = 0x51A; |
|
1336 |
if (!(ti->tileh & 2)) { |
|
1337 |
image = 0x51C; |
|
1338 |
} |
|
1339 |
} |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1340 |
AddSortableSpriteToDraw(image | _drawtile_track_palette, |
0 | 1341 |
ti->x+15, ti->y, 1, 16, 4, ti->z); |
1342 |
} |
|
1343 |
||
1344 |
static void DrawTrackFence_NE_SW(TileInfo *ti) |
|
1345 |
{ |
|
1346 |
DrawTrackFence_NE(ti); |
|
1347 |
DrawTrackFence_SW(ti); |
|
1348 |
} |
|
1349 |
||
1350 |
static void DrawTrackFence_NS_1(TileInfo *ti) |
|
1351 |
{ |
|
1352 |
int z = ti->z; |
|
1353 |
if (ti->tileh & 1) |
|
1354 |
z += 8; |
|
1355 |
AddSortableSpriteToDraw(0x517 | _drawtile_track_palette, |
|
1356 |
ti->x + 8, ti->y + 8, 1, 1, 4, z); |
|
1357 |
} |
|
1358 |
||
1359 |
static void DrawTrackFence_NS_2(TileInfo *ti) |
|
1360 |
{ |
|
1361 |
int z = ti->z; |
|
1362 |
if (ti->tileh & 4) |
|
1363 |
z += 8; |
|
1364 |
AddSortableSpriteToDraw(0x517 | _drawtile_track_palette, |
|
1365 |
ti->x + 8, ti->y + 8, 1, 1, 4, z); |
|
1366 |
} |
|
1367 |
||
1368 |
static void DrawTrackFence_WE_1(TileInfo *ti) |
|
1369 |
{ |
|
1370 |
int z = ti->z; |
|
1371 |
if (ti->tileh & 8) |
|
1372 |
z += 8; |
|
1373 |
AddSortableSpriteToDraw(0x518 | _drawtile_track_palette, |
|
1374 |
ti->x + 8, ti->y + 8, 1, 1, 4, z); |
|
1375 |
} |
|
1376 |
||
1377 |
static void DrawTrackFence_WE_2(TileInfo *ti) |
|
1378 |
{ |
|
1379 |
int z = ti->z; |
|
1380 |
if (ti->tileh & 2) |
|
1381 |
z += 8; |
|
1382 |
AddSortableSpriteToDraw(0x518 | _drawtile_track_palette, |
|
1383 |
ti->x + 8, ti->y + 8, 1, 1, 4, z); |
|
1384 |
} |
|
1385 |
||
1386 |
static void DetTrackDrawProc_Null(TileInfo *ti) |
|
1387 |
{ |
|
1388 |
/* nothing should be here */ |
|
1389 |
} |
|
1390 |
||
1391 |
typedef void DetailedTrackProc(TileInfo *ti); |
|
1392 |
DetailedTrackProc * const _detailed_track_proc[16] = { |
|
1393 |
DetTrackDrawProc_Null, |
|
1394 |
DetTrackDrawProc_Null, |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1395 |
|
0 | 1396 |
DrawTrackFence_NW, |
1397 |
DrawTrackFence_SE, |
|
1398 |
DrawTrackFence_NW_SE, |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1399 |
|
0 | 1400 |
DrawTrackFence_NE, |
1401 |
DrawTrackFence_SW, |
|
1402 |
DrawTrackFence_NE_SW, |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1403 |
|
0 | 1404 |
DrawTrackFence_NS_1, |
1405 |
DrawTrackFence_NS_2, |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1406 |
|
0 | 1407 |
DrawTrackFence_WE_1, |
1408 |
DrawTrackFence_WE_2, |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1409 |
|
0 | 1410 |
DetTrackDrawProc_Null, |
1411 |
DetTrackDrawProc_Null, |
|
1412 |
DetTrackDrawProc_Null, |
|
1413 |
DetTrackDrawProc_Null, |
|
1414 |
}; |
|
1415 |
||
389
2d394eeba5e5
(svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents:
337
diff
changeset
|
1416 |
static void DrawSpecialBuilding(uint32 image, uint32 tracktype_offs, |
2d394eeba5e5
(svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents:
337
diff
changeset
|
1417 |
TileInfo *ti, |
2d394eeba5e5
(svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents:
337
diff
changeset
|
1418 |
byte x, byte y, byte z, |
2d394eeba5e5
(svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents:
337
diff
changeset
|
1419 |
byte xsize, byte ysize, byte zsize) |
2d394eeba5e5
(svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents:
337
diff
changeset
|
1420 |
{ |
2d394eeba5e5
(svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents:
337
diff
changeset
|
1421 |
if (image & 0x8000) |
2d394eeba5e5
(svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents:
337
diff
changeset
|
1422 |
image |= _drawtile_track_palette; |
2d394eeba5e5
(svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents:
337
diff
changeset
|
1423 |
image += tracktype_offs; |
2d394eeba5e5
(svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents:
337
diff
changeset
|
1424 |
if (!(_display_opt & DO_TRANS_BUILDINGS)) // show transparent depots |
2d394eeba5e5
(svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents:
337
diff
changeset
|
1425 |
image = (image & 0x3FFF) | 0x3224000; |
2d394eeba5e5
(svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents:
337
diff
changeset
|
1426 |
AddSortableSpriteToDraw(image, ti->x + x, ti->y + y, xsize, ysize, zsize, ti->z + z); |
2d394eeba5e5
(svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents:
337
diff
changeset
|
1427 |
} |
2d394eeba5e5
(svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents:
337
diff
changeset
|
1428 |
|
0 | 1429 |
static void DrawTile_Track(TileInfo *ti) |
1430 |
{ |
|
1431 |
uint32 tracktype_offs, image; |
|
1432 |
byte m5; |
|
1433 |
||
1434 |
_drawtile_track_palette = SPRITE_PALETTE(PLAYER_SPRITE_COLOR(_map_owner[ti->tile])); |
|
1435 |
||
1436 |
tracktype_offs = (_map3_lo[ti->tile] & 0xF) * TRACKTYPE_SPRITE_PITCH; |
|
1437 |
||
1438 |
m5 = (byte)ti->map5; |
|
1439 |
if (!(m5 & RAIL_TYPE_SPECIAL)) { |
|
1440 |
bool special; |
|
1441 |
||
1442 |
m5 &= RAIL_BIT_MASK; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1443 |
|
0 | 1444 |
special = false; |
1445 |
||
1446 |
// select the sprite to use based on the map5 byte. |
|
1447 |
(image = 0x3F3, m5 == RAIL_BIT_DIAG2) || |
|
1448 |
(image++, m5 == RAIL_BIT_DIAG1) || |
|
1449 |
(image++, m5 == RAIL_BIT_UPPER) || |
|
1450 |
(image++, m5 == RAIL_BIT_LOWER) || |
|
1451 |
(image++, m5 == RAIL_BIT_RIGHT) || |
|
1452 |
(image++, m5 == RAIL_BIT_LEFT) || |
|
1453 |
(image++, m5 == (RAIL_BIT_DIAG1|RAIL_BIT_DIAG2)) || |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1454 |
|
0 | 1455 |
(image = 0x40B, m5 == (RAIL_BIT_UPPER|RAIL_BIT_LOWER)) || |
1456 |
(image++, m5 == (RAIL_BIT_LEFT|RAIL_BIT_RIGHT)) || |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1457 |
|
0 | 1458 |
(special=true, false) || |
1459 |
||
1460 |
(image = 0x3FA, !(m5 & (RAIL_BIT_RIGHT|RAIL_BIT_UPPER|RAIL_BIT_DIAG1))) || |
|
1461 |
(image++, !(m5 & (RAIL_BIT_LEFT|RAIL_BIT_LOWER|RAIL_BIT_DIAG1))) || |
|
1462 |
(image++, !(m5 & (RAIL_BIT_LEFT|RAIL_BIT_UPPER|RAIL_BIT_DIAG2))) || |
|
1463 |
(image++, !(m5 & (RAIL_BIT_RIGHT|RAIL_BIT_LOWER|RAIL_BIT_DIAG2))) || |
|
1464 |
(image++, true); |
|
1465 |
||
1466 |
if (ti->tileh != 0) { |
|
1467 |
int f = GetRailFoundation(ti->tileh, ti->map5 & 0x3F); |
|
1468 |
if (f) DrawFoundation(ti, f); |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1469 |
|
0 | 1470 |
// default sloped sprites.. |
1471 |
if (ti->tileh != 0) image = _track_sloped_sprites[ti->tileh - 1] + 0x3F3; |
|
1472 |
} |
|
1473 |
||
1474 |
if ((_map2[ti->tile] & RAIL_MAP2LO_GROUND_MASK)==RAIL_GROUND_BROWN) |
|
1475 |
image = (image & 0xFFFF) | 0x3178000; // use a brown palette |
|
1476 |
else if ((_map2[ti->tile] & RAIL_MAP2LO_GROUND_MASK)==RAIL_GROUND_ICE_DESERT) |
|
1477 |
image += 26; |
|
1478 |
||
1479 |
DrawGroundSprite(image + tracktype_offs); |
|
1480 |
||
1481 |
if (special) { |
|
1482 |
if (m5 & RAIL_BIT_DIAG1) DrawGroundSprite(0x3ED + tracktype_offs); |
|
1483 |
if (m5 & RAIL_BIT_DIAG2) DrawGroundSprite(0x3EE + tracktype_offs); |
|
1484 |
if (m5 & RAIL_BIT_UPPER) DrawGroundSprite(0x3EF + tracktype_offs); |
|
1485 |
if (m5 & RAIL_BIT_LOWER) DrawGroundSprite(0x3F0 + tracktype_offs); |
|
1486 |
if (m5 & RAIL_BIT_LEFT) DrawGroundSprite(0x3F2 + tracktype_offs); |
|
1487 |
if (m5 & RAIL_BIT_RIGHT) DrawGroundSprite(0x3F1 + tracktype_offs); |
|
1488 |
} |
|
1489 |
||
1490 |
if (_display_opt & DO_FULL_DETAIL) { |
|
1491 |
_detailed_track_proc[_map2[ti->tile] & RAIL_MAP2LO_GROUND_MASK](ti); |
|
1492 |
} |
|
1493 |
||
1494 |
/* draw signals also? */ |
|
1495 |
if (!(ti->map5 & RAIL_TYPE_SIGNALS)) |
|
1496 |
return; |
|
1497 |
||
1498 |
{ |
|
1499 |
byte m23; |
|
1500 |
||
1501 |
m23 = (_map3_lo[ti->tile] >> 4) | (_map2[ti->tile] & 0xF0); |
|
1502 |
||
1503 |
#define HAS_SIGNAL(x) (m23 & (byte)(0x1 << (x))) |
|
1504 |
#define ISON_SIGNAL(x) (m23 & (byte)(0x10 << (x))) |
|
1505 |
#define MAYBE_DRAW_SIGNAL(x,y,z) if (HAS_SIGNAL(x)) DrawSignalHelper(ti, ISON_SIGNAL(x), ((y-0x4FB) << 4)|(z)) |
|
1506 |
||
1507 |
if (!(m5 & RAIL_BIT_DIAG2)) { |
|
1508 |
if (!(m5 & RAIL_BIT_DIAG1)) { |
|
1509 |
if (m5 & RAIL_BIT_LEFT) { |
|
1510 |
MAYBE_DRAW_SIGNAL(2, 0x509, 0); |
|
1511 |
MAYBE_DRAW_SIGNAL(3, 0x507, 1); |
|
1512 |
} |
|
1513 |
if (m5 & RAIL_BIT_RIGHT) { |
|
1514 |
MAYBE_DRAW_SIGNAL(0, 0x509, 2); |
|
1515 |
MAYBE_DRAW_SIGNAL(1, 0x507, 3); |
|
1516 |
} |
|
1517 |
if (m5 & RAIL_BIT_UPPER) { |
|
1518 |
MAYBE_DRAW_SIGNAL(3, 0x505, 4); |
|
1519 |
MAYBE_DRAW_SIGNAL(2, 0x503, 5); |
|
1520 |
} |
|
1521 |
if (m5 & RAIL_BIT_LOWER) { |
|
1522 |
MAYBE_DRAW_SIGNAL(1, 0x505, 6); |
|
1523 |
MAYBE_DRAW_SIGNAL(0, 0x503, 7); |
|
1524 |
} |
|
1525 |
} else { |
|
1526 |
MAYBE_DRAW_SIGNAL(3, 0x4FB, 8); |
|
1527 |
MAYBE_DRAW_SIGNAL(2, 0x4FD, 9); |
|
1528 |
} |
|
1529 |
} else { |
|
1530 |
MAYBE_DRAW_SIGNAL(3, 0x4FF, 10); |
|
1531 |
MAYBE_DRAW_SIGNAL(2, 0x501, 11); |
|
1532 |
} |
|
1533 |
} |
|
1534 |
} else { |
|
395
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
393
diff
changeset
|
1535 |
/* draw depots / waypoints */ |
0 | 1536 |
const byte *s; |
1537 |
const DrawTrackSeqStruct *drss; |
|
395
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
393
diff
changeset
|
1538 |
byte type = m5 & 0x3F; // 0-3: depots, 4-5: waypoints |
0 | 1539 |
|
1540 |
if (!(m5 & (RAIL_TYPE_MASK&~RAIL_TYPE_SPECIAL))) |
|
1541 |
return; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1542 |
|
0 | 1543 |
if (ti->tileh != 0) { DrawFoundation(ti, ti->tileh); } |
1544 |
||
395
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
393
diff
changeset
|
1545 |
if (!IS_RAIL_DEPOT(m5) && IS_RAIL_WAYPOINT(m5) && _map3_lo[ti->tile]&16) { |
389
2d394eeba5e5
(svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents:
337
diff
changeset
|
1546 |
// look for customization |
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:
395
diff
changeset
|
1547 |
DrawTileSprites *cust = GetCustomStationRenderdata('WAYP', _map3_hi[ti->tile]); |
389
2d394eeba5e5
(svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents:
337
diff
changeset
|
1548 |
|
2d394eeba5e5
(svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents:
337
diff
changeset
|
1549 |
if (cust) { |
2d394eeba5e5
(svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents:
337
diff
changeset
|
1550 |
DrawTileSeqStruct const *seq; |
2d394eeba5e5
(svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents:
337
diff
changeset
|
1551 |
|
2d394eeba5e5
(svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents:
337
diff
changeset
|
1552 |
cust = &cust[2 + (m5 & 0x1)]; // emulate station tile - open with building |
2d394eeba5e5
(svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents:
337
diff
changeset
|
1553 |
|
2d394eeba5e5
(svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents:
337
diff
changeset
|
1554 |
image = cust->ground_sprite; |
2d394eeba5e5
(svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents:
337
diff
changeset
|
1555 |
if (image & 0x8000) image = (image & 0x7FFF) + tracktype_offs; |
2d394eeba5e5
(svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents:
337
diff
changeset
|
1556 |
DrawGroundSprite(image); |
2d394eeba5e5
(svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents:
337
diff
changeset
|
1557 |
|
2d394eeba5e5
(svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents:
337
diff
changeset
|
1558 |
foreach_draw_tile_seq(seq, cust->seq) { |
2d394eeba5e5
(svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents:
337
diff
changeset
|
1559 |
DrawSpecialBuilding(seq->image|0x8000, 0, ti, |
2d394eeba5e5
(svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents:
337
diff
changeset
|
1560 |
seq->delta_x, seq->delta_y, seq->delta_z, |
2d394eeba5e5
(svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents:
337
diff
changeset
|
1561 |
seq->width, seq->height, seq->unk); |
2d394eeba5e5
(svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents:
337
diff
changeset
|
1562 |
} |
2d394eeba5e5
(svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents:
337
diff
changeset
|
1563 |
return; |
2d394eeba5e5
(svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents:
337
diff
changeset
|
1564 |
} |
2d394eeba5e5
(svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents:
337
diff
changeset
|
1565 |
} |
2d394eeba5e5
(svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents:
337
diff
changeset
|
1566 |
|
282
08af1e5feb66
(svn r288) Fix: new checkpoint graphics now also work for monorail/maglev
dominik
parents:
222
diff
changeset
|
1567 |
s = _track_depot_layout_table[type]; |
0 | 1568 |
|
222
b88456001397
(svn r223) -Fix: Const correctness and miscellaneous fixes. Thank you Tron for your diligent fixing of warnings (and some possibly bugs) (Tron)
darkvater
parents:
204
diff
changeset
|
1569 |
image = *(const uint16*)s; |
0 | 1570 |
if (image & 0x8000) image = (image & 0x7FFF) + tracktype_offs; |
1571 |
||
1572 |
// adjust ground tile for desert |
|
283
c1a99d78e5a3
(svn r289) Fix: Checkpoints on snow have correct ground now
dominik
parents:
282
diff
changeset
|
1573 |
// (don't adjust for arctic depots, because snow in depots looks weird) |
c1a99d78e5a3
(svn r289) Fix: Checkpoints on snow have correct ground now
dominik
parents:
282
diff
changeset
|
1574 |
if ((_map2[ti->tile] & RAIL_MAP2LO_GROUND_MASK)==RAIL_GROUND_ICE_DESERT && (_opt.landscape == LT_DESERT || type>=4)) |
0 | 1575 |
{ |
1576 |
if(image!=3981) |
|
1577 |
image += 26; // tile with tracks |
|
1578 |
else |
|
1579 |
image = 4550; // flat ground |
|
1580 |
} |
|
1581 |
||
1582 |
DrawGroundSprite(image); |
|
1583 |
||
1584 |
drss = (const DrawTrackSeqStruct*)(s + sizeof(uint16)); |
|
1585 |
||
1586 |
while ((image=drss->image) != 0) { |
|
389
2d394eeba5e5
(svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents:
337
diff
changeset
|
1587 |
DrawSpecialBuilding(image, type < 4 ? tracktype_offs : 0, ti, |
2d394eeba5e5
(svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents:
337
diff
changeset
|
1588 |
drss->subcoord_x, drss->subcoord_y, 0, |
2d394eeba5e5
(svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents:
337
diff
changeset
|
1589 |
drss->width, drss->height, 0x17); |
0 | 1590 |
drss++; |
1591 |
} |
|
1592 |
} |
|
1593 |
} |
|
1594 |
||
1595 |
void DrawTrainDepotSprite(int x, int y, int image, int railtype) |
|
1596 |
{ |
|
1597 |
uint32 ormod, img; |
|
1598 |
const DrawTrackSeqStruct *dtss; |
|
1599 |
const byte *t; |
|
1600 |
||
1601 |
/* baseimage */ |
|
1602 |
railtype *= TRACKTYPE_SPRITE_PITCH; |
|
1603 |
||
1604 |
ormod = PLAYER_SPRITE_COLOR(_local_player); |
|
1605 |
||
1606 |
t = _track_depot_layout_table[image]; |
|
1607 |
||
1608 |
x+=33; |
|
1609 |
y+=17; |
|
1610 |
||
222
b88456001397
(svn r223) -Fix: Const correctness and miscellaneous fixes. Thank you Tron for your diligent fixing of warnings (and some possibly bugs) (Tron)
darkvater
parents:
204
diff
changeset
|
1611 |
img = *(const uint16*)t; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1612 |
if (img & 0x8000) img = (img & 0x7FFF) + railtype; |
0 | 1613 |
DrawSprite(img, x, y); |
1614 |
||
222
b88456001397
(svn r223) -Fix: Const correctness and miscellaneous fixes. Thank you Tron for your diligent fixing of warnings (and some possibly bugs) (Tron)
darkvater
parents:
204
diff
changeset
|
1615 |
for(dtss = (const DrawTrackSeqStruct *)(t + sizeof(uint16)); dtss->image != 0; dtss++) { |
0 | 1616 |
Point pt = RemapCoords(dtss->subcoord_x, dtss->subcoord_y, 0); |
1617 |
image = dtss->image; |
|
1618 |
if (image & 0x8000) image |= ormod; |
|
1619 |
DrawSprite(image + railtype, x + pt.x, y + pt.y); |
|
1620 |
} |
|
1621 |
} |
|
1622 |
||
395
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
393
diff
changeset
|
1623 |
void DrawWaypointSprite(int x, int y, int stat_id) |
393
82c2bf635cd9
(svn r585) -newgrf: GUI for selecting custom waypoint graphics to use. Patch by dominik81 and pasky.
darkvater
parents:
389
diff
changeset
|
1624 |
{ |
82c2bf635cd9
(svn r585) -newgrf: GUI for selecting custom waypoint graphics to use. Patch by dominik81 and pasky.
darkvater
parents:
389
diff
changeset
|
1625 |
// TODO: We should use supersets with cargo-id FF, if available. --pasky |
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:
395
diff
changeset
|
1626 |
DrawTileSprites *cust = GetCustomStationRenderdata('WAYP', stat_id); |
393
82c2bf635cd9
(svn r585) -newgrf: GUI for selecting custom waypoint graphics to use. Patch by dominik81 and pasky.
darkvater
parents:
389
diff
changeset
|
1627 |
DrawTileSeqStruct const *seq; |
82c2bf635cd9
(svn r585) -newgrf: GUI for selecting custom waypoint graphics to use. Patch by dominik81 and pasky.
darkvater
parents:
389
diff
changeset
|
1628 |
uint32 ormod, img; |
82c2bf635cd9
(svn r585) -newgrf: GUI for selecting custom waypoint graphics to use. Patch by dominik81 and pasky.
darkvater
parents:
389
diff
changeset
|
1629 |
|
82c2bf635cd9
(svn r585) -newgrf: GUI for selecting custom waypoint graphics to use. Patch by dominik81 and pasky.
darkvater
parents:
389
diff
changeset
|
1630 |
assert(cust); |
82c2bf635cd9
(svn r585) -newgrf: GUI for selecting custom waypoint graphics to use. Patch by dominik81 and pasky.
darkvater
parents:
389
diff
changeset
|
1631 |
|
82c2bf635cd9
(svn r585) -newgrf: GUI for selecting custom waypoint graphics to use. Patch by dominik81 and pasky.
darkvater
parents:
389
diff
changeset
|
1632 |
// emulate station tile - open with building |
82c2bf635cd9
(svn r585) -newgrf: GUI for selecting custom waypoint graphics to use. Patch by dominik81 and pasky.
darkvater
parents:
389
diff
changeset
|
1633 |
// add 1 to get the other direction |
82c2bf635cd9
(svn r585) -newgrf: GUI for selecting custom waypoint graphics to use. Patch by dominik81 and pasky.
darkvater
parents:
389
diff
changeset
|
1634 |
cust = &cust[2]; |
82c2bf635cd9
(svn r585) -newgrf: GUI for selecting custom waypoint graphics to use. Patch by dominik81 and pasky.
darkvater
parents:
389
diff
changeset
|
1635 |
|
82c2bf635cd9
(svn r585) -newgrf: GUI for selecting custom waypoint graphics to use. Patch by dominik81 and pasky.
darkvater
parents:
389
diff
changeset
|
1636 |
ormod = SPRITE_PALETTE(PLAYER_SPRITE_COLOR(_local_player)); |
82c2bf635cd9
(svn r585) -newgrf: GUI for selecting custom waypoint graphics to use. Patch by dominik81 and pasky.
darkvater
parents:
389
diff
changeset
|
1637 |
|
82c2bf635cd9
(svn r585) -newgrf: GUI for selecting custom waypoint graphics to use. Patch by dominik81 and pasky.
darkvater
parents:
389
diff
changeset
|
1638 |
x += 33; |
82c2bf635cd9
(svn r585) -newgrf: GUI for selecting custom waypoint graphics to use. Patch by dominik81 and pasky.
darkvater
parents:
389
diff
changeset
|
1639 |
y += 17; |
82c2bf635cd9
(svn r585) -newgrf: GUI for selecting custom waypoint graphics to use. Patch by dominik81 and pasky.
darkvater
parents:
389
diff
changeset
|
1640 |
|
82c2bf635cd9
(svn r585) -newgrf: GUI for selecting custom waypoint graphics to use. Patch by dominik81 and pasky.
darkvater
parents:
389
diff
changeset
|
1641 |
img = cust->ground_sprite; |
82c2bf635cd9
(svn r585) -newgrf: GUI for selecting custom waypoint graphics to use. Patch by dominik81 and pasky.
darkvater
parents:
389
diff
changeset
|
1642 |
if (img & 0x8000) img = (img & 0x7FFF); |
82c2bf635cd9
(svn r585) -newgrf: GUI for selecting custom waypoint graphics to use. Patch by dominik81 and pasky.
darkvater
parents:
389
diff
changeset
|
1643 |
DrawSprite(img, x, y); |
82c2bf635cd9
(svn r585) -newgrf: GUI for selecting custom waypoint graphics to use. Patch by dominik81 and pasky.
darkvater
parents:
389
diff
changeset
|
1644 |
|
82c2bf635cd9
(svn r585) -newgrf: GUI for selecting custom waypoint graphics to use. Patch by dominik81 and pasky.
darkvater
parents:
389
diff
changeset
|
1645 |
foreach_draw_tile_seq(seq, cust->seq) { |
82c2bf635cd9
(svn r585) -newgrf: GUI for selecting custom waypoint graphics to use. Patch by dominik81 and pasky.
darkvater
parents:
389
diff
changeset
|
1646 |
Point pt = RemapCoords(seq->delta_x, seq->delta_y, seq->delta_z); |
82c2bf635cd9
(svn r585) -newgrf: GUI for selecting custom waypoint graphics to use. Patch by dominik81 and pasky.
darkvater
parents:
389
diff
changeset
|
1647 |
DrawSprite((seq->image&0x3FFF) | ormod, x + pt.x, y + pt.y); |
82c2bf635cd9
(svn r585) -newgrf: GUI for selecting custom waypoint graphics to use. Patch by dominik81 and pasky.
darkvater
parents:
389
diff
changeset
|
1648 |
} |
82c2bf635cd9
(svn r585) -newgrf: GUI for selecting custom waypoint graphics to use. Patch by dominik81 and pasky.
darkvater
parents:
389
diff
changeset
|
1649 |
} |
82c2bf635cd9
(svn r585) -newgrf: GUI for selecting custom waypoint graphics to use. Patch by dominik81 and pasky.
darkvater
parents:
389
diff
changeset
|
1650 |
|
82c2bf635cd9
(svn r585) -newgrf: GUI for selecting custom waypoint graphics to use. Patch by dominik81 and pasky.
darkvater
parents:
389
diff
changeset
|
1651 |
|
0 | 1652 |
#define NUM_SSD_ENTRY 256 |
1653 |
#define NUM_SSD_STACK 32 |
|
1654 |
||
1655 |
typedef struct SetSignalsData { |
|
1656 |
int cur; |
|
1657 |
int cur_stack; |
|
1658 |
bool stop; |
|
1659 |
bool has_presignal; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1660 |
|
0 | 1661 |
// presignal info |
1662 |
int presignal_exits; |
|
1663 |
int presignal_exits_free; |
|
1664 |
||
1665 |
// these are used to keep track of the signals that change. |
|
1666 |
byte bit[NUM_SSD_ENTRY]; |
|
1667 |
TileIndex tile[NUM_SSD_ENTRY]; |
|
1668 |
||
1669 |
// these are used to keep track of the stack that modifies presignals recursively |
|
1670 |
TileIndex next_tile[NUM_SSD_STACK]; |
|
1671 |
byte next_dir[NUM_SSD_STACK]; |
|
1672 |
||
1673 |
} SetSignalsData; |
|
1674 |
||
1675 |
static bool SetSignalsEnumProc(uint tile, SetSignalsData *ssd, int track, uint length, byte *state) |
|
1676 |
{ |
|
1677 |
// the tile has signals? |
|
1678 |
if (IS_TILETYPE(tile, MP_RAILWAY)) { |
|
1679 |
if ((_map5[tile]&RAIL_TYPE_MASK) == RAIL_TYPE_SIGNALS) { |
|
1680 |
if ((_map3_lo[tile] & _signals_table_both[track]) != 0) { |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1681 |
|
0 | 1682 |
// is the signal pointing in to the segment existing? |
1683 |
if ((_map3_lo[tile] & _signals_table[track]) != 0) { |
|
1684 |
// yes, add the signal to the list of signals |
|
1685 |
if (ssd->cur != NUM_SSD_ENTRY) { |
|
1686 |
ssd->tile[ssd->cur] = tile; // remember the tile index |
|
1687 |
ssd->bit[ssd->cur] = track; // and the controlling bit number |
|
1688 |
ssd->cur++; |
|
1689 |
} |
|
1690 |
||
1691 |
// remember if this block has a presignal. |
|
1692 |
ssd->has_presignal |= (_map3_hi[tile]&1); |
|
1693 |
} |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1694 |
|
0 | 1695 |
// is this an exit signal that points out from the segment? |
1696 |
if ((_map3_hi[tile]&2) && _map3_lo[tile]&_signals_table_other[track]) { |
|
1697 |
ssd->presignal_exits++; |
|
1698 |
if ((_map2[tile]&_signals_table_other[track]) != 0) |
|
1699 |
ssd->presignal_exits_free++; |
|
1700 |
} |
|
1701 |
||
1702 |
return true; |
|
1703 |
} |
|
1704 |
} else if (IS_RAIL_DEPOT(_map5[tile])) |
|
1705 |
return true; // don't look further if the tile is a depot |
|
1706 |
} |
|
1707 |
return false; |
|
1708 |
} |
|
1709 |
||
1710 |
static void SetSignalsAfterProc(TrackPathFinder *tpf) |
|
1711 |
{ |
|
1712 |
SetSignalsData *ssd = tpf->userdata; |
|
1713 |
Vehicle *v; |
|
1714 |
uint tile, hash, val, offs; |
|
1715 |
TrackPathFinderLink *link; |
|
1716 |
||
1717 |
ssd->stop = false; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1718 |
|
0 | 1719 |
// for each train, check if it is in the segment. |
1720 |
// then we know that the signal should be red. |
|
1721 |
FOR_ALL_VEHICLES(v) { |
|
1722 |
if (v->type != VEH_Train) |
|
1723 |
continue; |
|
1724 |
||
1725 |
tile = v->tile; |
|
1726 |
if (v->u.rail.track == 0x40) { tile = GetVehicleOutOfTunnelTile(v); } |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1727 |
|
0 | 1728 |
hash = PATHFIND_HASH_TILE(tile); |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1729 |
|
0 | 1730 |
val = tpf->hash_head[hash]; |
1731 |
if (val == 0) |
|
1732 |
continue; |
|
1733 |
||
1734 |
if (!(val & 0x8000)) { |
|
1735 |
if ((TileIndex)tile == tpf->hash_tile[hash]) |
|
1736 |
goto check_val; |
|
1737 |
} else { |
|
1738 |
offs = tpf->hash_tile[hash]; |
|
1739 |
do { |
|
1740 |
link = PATHFIND_GET_LINK_PTR(tpf, offs); |
|
1741 |
if ( (TileIndex)tile == link->tile) { |
|
1742 |
val = link->flags; |
|
1743 |
check_val:; |
|
1744 |
// the train is on the track, in either direction? |
|
1745 |
if (val & (v->u.rail.track + (v->u.rail.track<<8))) { |
|
1746 |
ssd->stop = true; |
|
1747 |
return; |
|
1748 |
} |
|
1749 |
break; |
|
1750 |
} |
|
1751 |
} while ((offs=link->next) != 0xFFFF); |
|
1752 |
} |
|
1753 |
} |
|
1754 |
} |
|
1755 |
||
1756 |
static const byte _dir_from_track[14] = { |
|
1757 |
0,1,0,1,2,1, 0,0, |
|
1758 |
2,3,3,2,3,0, |
|
1759 |
}; |
|
1760 |
||
1761 |
||
1762 |
static void ChangeSignalStates(SetSignalsData *ssd) |
|
1763 |
{ |
|
1764 |
int i; |
|
1765 |
||
1766 |
// thinking about presignals... |
|
1767 |
// the presignal is green if, |
|
1768 |
// if no train is in the segment AND |
|
1769 |
// there is at least one green exit signal OR |
|
1770 |
// there are no exit signals in the segment |
|
1771 |
||
1772 |
// then mark the signals in the segment accordingly |
|
1773 |
for(i=0; i!=ssd->cur; i++) { |
|
1774 |
uint tile = ssd->tile[i]; |
|
1775 |
byte bit = _signals_table[ssd->bit[i]]; |
|
1776 |
byte m2 = _map2[tile]; |
|
1777 |
||
1778 |
// presignals don't turn green if there is at least one presignal exit and none are free |
|
1779 |
if (_map3_hi[tile] & 1) { |
|
1780 |
int ex = ssd->presignal_exits, exfree = ssd->presignal_exits_free; |
|
1781 |
||
1782 |
// subtract for dual combo signals so they don't count themselves |
|
1783 |
if (_map3_hi[tile]&2 && _map3_lo[tile]&_signals_table_other[ssd->bit[i]]) { |
|
1784 |
ex--; |
|
1785 |
if ((_map2[tile]&_signals_table_other[ssd->bit[i]]) != 0) exfree--; |
|
1786 |
} |
|
1787 |
||
1788 |
// if we have exits and none are free, make red. |
|
1789 |
if (ex && !exfree) goto make_red; |
|
1790 |
} |
|
1791 |
||
1792 |
// check if the signal is unaffected. |
|
1793 |
if (ssd->stop) { |
|
1794 |
make_red: |
|
1795 |
// turn red |
|
1796 |
if ( (bit&m2) == 0 ) |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1797 |
continue; |
0 | 1798 |
} else { |
1799 |
// turn green |
|
1800 |
if ( (bit&m2) != 0 ) |
|
1801 |
continue; |
|
1802 |
} |
|
1803 |
||
1804 |
// Update signals on the other side of this exit signal, it changed. |
|
1805 |
// If this segment has presignals, then we treat exit signals going into the segment as normal signals. |
|
1806 |
if (_map3_hi[tile]&2 && (_map3_hi[tile]&1 || !ssd->has_presignal)) { |
|
1807 |
if (ssd->cur_stack != NUM_SSD_STACK) { |
|
1808 |
ssd->next_tile[ssd->cur_stack] = tile; |
|
1809 |
ssd->next_dir[ssd->cur_stack] = _dir_from_track[ssd->bit[i]]; |
|
1810 |
ssd->cur_stack++; |
|
1811 |
} else { |
|
1812 |
printf("NUM_SSD_STACK too small\n"); |
|
1813 |
} |
|
1814 |
} |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1815 |
|
0 | 1816 |
// it changed, so toggle it |
1817 |
_map2[tile] = m2 ^ bit; |
|
1818 |
MarkTileDirtyByTile(tile); |
|
1819 |
} |
|
1820 |
} |
|
1821 |
||
1822 |
||
1823 |
bool UpdateSignalsOnSegment(uint tile, byte direction) |
|
1824 |
{ |
|
1825 |
SetSignalsData ssd; |
|
1826 |
int result = -1; |
|
1827 |
||
1828 |
ssd.cur_stack = 0; |
|
1829 |
direction>>=1; |
|
1830 |
||
1831 |
for(;;) { |
|
1832 |
// go through one segment and update all signals pointing into that segment. |
|
1833 |
ssd.cur = ssd.presignal_exits = ssd.presignal_exits_free = 0; |
|
1834 |
ssd.has_presignal = false; |
|
1835 |
||
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
149
diff
changeset
|
1836 |
FollowTrack(tile, 0xC000 | TRANSPORT_RAIL, direction, (TPFEnumProc*)SetSignalsEnumProc, SetSignalsAfterProc, &ssd); |
0 | 1837 |
ChangeSignalStates(&ssd); |
1838 |
||
1839 |
// remember the result only for the first iteration. |
|
1840 |
if (result < 0) result = ssd.stop; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1841 |
|
0 | 1842 |
// if any exit signals were changed, we need to keep going to modify the stuff behind those. |
1843 |
if(!ssd.cur_stack) |
|
1844 |
break; |
|
1845 |
||
1846 |
// one or more exit signals were changed, so we need to update another segment too. |
|
1847 |
tile = ssd.next_tile[--ssd.cur_stack]; |
|
1848 |
direction = ssd.next_dir[ssd.cur_stack]; |
|
1849 |
} |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1850 |
|
0 | 1851 |
return (bool)result; |
1852 |
} |
|
1853 |
||
1854 |
void SetSignalsOnBothDir(uint tile, byte track) |
|
1855 |
{ |
|
1856 |
static const byte _search_dir_1[6] = {1, 3, 1, 3, 5, 3}; |
|
1857 |
static const byte _search_dir_2[6] = {5, 7, 7, 5, 7, 1}; |
|
1858 |
||
1859 |
UpdateSignalsOnSegment(tile, _search_dir_1[track]); |
|
1860 |
UpdateSignalsOnSegment(tile, _search_dir_2[track]); |
|
1861 |
} |
|
1862 |
||
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1863 |
uint GetSlopeZ_Track(TileInfo *ti) |
0 | 1864 |
{ |
1865 |
uint z = ti->z; |
|
1866 |
int th = ti->tileh; |
|
13
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
1867 |
|
0 | 1868 |
// check if it's a foundation |
1869 |
if (ti->tileh != 0) { |
|
1870 |
if ((ti->map5 & 0x80) == 0) { |
|
1871 |
uint f = GetRailFoundation(ti->tileh, ti->map5 & 0x3F); |
|
1872 |
if (f != 0) { |
|
1873 |
if (f < 15) { |
|
1874 |
// leveled foundation |
|
1875 |
return z + 8; |
|
1876 |
} |
|
1877 |
// inclined foundation |
|
1878 |
th = _inclined_tileh[f - 15]; |
|
1879 |
} |
|
1880 |
} else if ((ti->map5 & 0xC0) == 0xC0) { |
|
395
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
393
diff
changeset
|
1881 |
// depot or waypoint |
0 | 1882 |
return z + 8; |
1883 |
} |
|
1884 |
return GetPartialZ(ti->x&0xF, ti->y&0xF, th) + z; |
|
1885 |
} |
|
1886 |
return z; |
|
1887 |
} |
|
1888 |
||
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1889 |
uint GetSlopeTileh_Track(TileInfo *ti) |
39 | 1890 |
{ |
1891 |
// check if it's a foundation |
|
1892 |
if (ti->tileh != 0) { |
|
1893 |
if ((ti->map5 & 0x80) == 0) { |
|
1894 |
uint f = GetRailFoundation(ti->tileh, ti->map5 & 0x3F); |
|
1895 |
if (f != 0) { |
|
1896 |
if (f < 15) { |
|
1897 |
// leveled foundation |
|
1898 |
return 0; |
|
1899 |
} |
|
1900 |
// inclined foundation |
|
1901 |
return _inclined_tileh[f - 15]; |
|
1902 |
} |
|
1903 |
} else if ((ti->map5 & 0xC0) == 0xC0) { |
|
395
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
393
diff
changeset
|
1904 |
// depot or waypoint |
39 | 1905 |
return 0; |
1906 |
} |
|
1907 |
} |
|
1908 |
return ti->tileh; |
|
1909 |
} |
|
1910 |
||
0 | 1911 |
static void GetAcceptedCargo_Track(uint tile, AcceptedCargo *ac) |
1912 |
{ |
|
1913 |
/* not used */ |
|
1914 |
} |
|
1915 |
||
1916 |
static void AnimateTile_Track(uint tile) |
|
1917 |
{ |
|
1918 |
/* not used */ |
|
1919 |
} |
|
1920 |
||
1921 |
static void TileLoop_Track(uint tile) |
|
1922 |
{ |
|
1923 |
byte a2; |
|
1924 |
byte rail; |
|
1925 |
byte m2; |
|
1926 |
byte owner; |
|
1927 |
||
1928 |
m2 = _map2[tile] & 0xF; |
|
1929 |
||
1930 |
/* special code for alps landscape */ |
|
1931 |
if (_opt.landscape == LT_HILLY) { |
|
1932 |
/* convert into snow? */ |
|
1933 |
if (GetTileZ(tile) > _opt.snow_line) { |
|
1934 |
a2 = RAIL_GROUND_ICE_DESERT; |
|
1935 |
goto modify_me; |
|
1936 |
} |
|
1937 |
||
1938 |
/* special code for desert landscape */ |
|
1939 |
} else if (_opt.landscape == LT_DESERT) { |
|
1940 |
/* convert into desert? */ |
|
1941 |
if (GetMapExtraBits(tile) == 1) { |
|
1942 |
a2 = RAIL_GROUND_ICE_DESERT; |
|
1943 |
goto modify_me; |
|
1944 |
} |
|
1945 |
} |
|
1946 |
||
1947 |
// Don't continue tile loop for depots |
|
1948 |
if (_map5[tile] & RAIL_TYPE_SPECIAL) |
|
1949 |
return; |
|
1950 |
||
1951 |
a2 = RAIL_GROUND_GREEN; |
|
1952 |
||
1953 |
if (m2 != RAIL_GROUND_BROWN) { /* wait until bottom is green */ |
|
1954 |
/* determine direction of fence */ |
|
1955 |
rail = _map5[tile] & RAIL_BIT_MASK; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1956 |
|
0 | 1957 |
if (rail == RAIL_BIT_UPPER) { |
1958 |
a2 = RAIL_GROUND_FENCE_HORIZ1; |
|
1959 |
} else if (rail == RAIL_BIT_LOWER) { |
|
1960 |
a2 = RAIL_GROUND_FENCE_HORIZ2; |
|
1961 |
} else if (rail == RAIL_BIT_LEFT) { |
|
1962 |
a2 = RAIL_GROUND_FENCE_VERT1; |
|
1963 |
} else if (rail == RAIL_BIT_RIGHT) { |
|
1964 |
a2 = RAIL_GROUND_FENCE_VERT2; |
|
1965 |
} else { |
|
1966 |
owner = _map_owner[tile]; |
|
1967 |
||
1968 |
if ( (!(rail&(RAIL_BIT_DIAG2|RAIL_BIT_UPPER|RAIL_BIT_LEFT)) && (rail&RAIL_BIT_DIAG1)) || rail==(RAIL_BIT_LOWER|RAIL_BIT_RIGHT)) { |
|
1969 |
if (!IS_TILETYPE(tile + TILE_XY(0,-1), MP_RAILWAY) || |
|
1970 |
owner != _map_owner[tile + TILE_XY(0,-1)] || |
|
1971 |
(_map5[tile + TILE_XY(0,-1)]==RAIL_BIT_UPPER || _map5[tile + TILE_XY(0,-1)]==RAIL_BIT_LEFT)) |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1972 |
a2 = RAIL_GROUND_FENCE_NW; |
0 | 1973 |
} |
1974 |
||
1975 |
if ( (!(rail&(RAIL_BIT_DIAG2|RAIL_BIT_LOWER|RAIL_BIT_RIGHT)) && (rail&RAIL_BIT_DIAG1)) || rail==(RAIL_BIT_UPPER|RAIL_BIT_LEFT)) { |
|
1976 |
if (!IS_TILETYPE(tile + TILE_XY(0,1), MP_RAILWAY) || |
|
1977 |
owner != _map_owner[tile + TILE_XY(0,1)] || |
|
1978 |
(_map5[tile + TILE_XY(0,1)]==RAIL_BIT_LOWER || _map5[tile + TILE_XY(0,1)]==RAIL_BIT_RIGHT)) |
|
1979 |
a2 = (a2 == RAIL_GROUND_FENCE_NW) ? RAIL_GROUND_FENCE_SENW : RAIL_GROUND_FENCE_SE; |
|
1980 |
} |
|
1981 |
||
1982 |
if ( (!(rail&(RAIL_BIT_DIAG1|RAIL_BIT_UPPER|RAIL_BIT_RIGHT)) && (rail&RAIL_BIT_DIAG2)) || rail==(RAIL_BIT_LOWER|RAIL_BIT_LEFT)) { |
|
1983 |
if (!IS_TILETYPE(tile + TILE_XY(-1,0), MP_RAILWAY) || |
|
1984 |
owner != _map_owner[tile + TILE_XY(-1,0)] || |
|
1985 |
(_map5[tile + TILE_XY(-1,0)]==RAIL_BIT_UPPER || _map5[tile + TILE_XY(-1,0)]==RAIL_BIT_RIGHT)) |
|
1986 |
a2 = RAIL_GROUND_FENCE_NE; |
|
1987 |
} |
|
1988 |
||
1989 |
if ( (!(rail&(RAIL_BIT_DIAG1|RAIL_BIT_LOWER|RAIL_BIT_LEFT)) && (rail&RAIL_BIT_DIAG2)) || rail==(RAIL_BIT_UPPER|RAIL_BIT_RIGHT)) { |
|
1990 |
if (!IS_TILETYPE(tile + TILE_XY(1,0), MP_RAILWAY) || |
|
1991 |
owner != _map_owner[tile + TILE_XY(1,0)] || |
|
1992 |
(_map5[tile + TILE_XY(1,0)]==RAIL_BIT_LOWER || _map5[tile + TILE_XY(1,0)]==RAIL_BIT_LEFT)) |
|
1993 |
a2 = (a2 == RAIL_GROUND_FENCE_NE) ? RAIL_GROUND_FENCE_NESW : RAIL_GROUND_FENCE_SW; |
|
1994 |
} |
|
1995 |
} |
|
1996 |
} |
|
1997 |
||
1998 |
modify_me:; |
|
1999 |
/* tile changed? */ |
|
2000 |
if ( m2 != a2) { |
|
2001 |
_map2[tile] = (_map2[tile] & ~RAIL_MAP2LO_GROUND_MASK) | a2; |
|
2002 |
MarkTileDirtyByTile(tile); |
|
2003 |
} |
|
2004 |
} |
|
2005 |
||
2006 |
||
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
149
diff
changeset
|
2007 |
static uint32 GetTileTrackStatus_Track(uint tile, TransportType mode) { |
0 | 2008 |
byte m5, a, b; |
2009 |
uint32 ret; |
|
2010 |
||
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
149
diff
changeset
|
2011 |
if (mode != TRANSPORT_RAIL) |
0 | 2012 |
return 0; |
2013 |
||
2014 |
m5 = _map5[tile]; |
|
2015 |
||
2016 |
if (!(m5 & RAIL_TYPE_SPECIAL)) { |
|
2017 |
ret = (m5 | (m5 << 8)) & 0x3F3F; |
|
2018 |
if (!(m5 & RAIL_TYPE_SIGNALS)) { |
|
2019 |
if ( (ret & 0xFF) == 3) |
|
22 | 2020 |
/* Diagonal crossing? */ |
0 | 2021 |
ret |= 0x40; |
2022 |
} else { |
|
2023 |
/* has_signals */ |
|
2024 |
||
2025 |
a = _map3_lo[tile]; |
|
2026 |
b = _map2[tile]; |
|
2027 |
||
2028 |
b &= a; |
|
2029 |
||
22 | 2030 |
/* When signals are not present (in neither |
2031 |
* direction), we pretend them to be green. (So if |
|
2032 |
* signals are only one way, the other way will |
|
2033 |
* implicitely become `red' */ |
|
0 | 2034 |
if ((a & 0xC0) == 0) { b |= 0xC0; } |
2035 |
if ((a & 0x30) == 0) { b |= 0x30; } |
|
2036 |
||
2037 |
if ( (b & 0x80) == 0) ret |= 0x10070000; |
|
2038 |
if ( (b & 0x40) == 0) ret |= 0x7100000; |
|
2039 |
if ( (b & 0x20) == 0) ret |= 0x20080000; |
|
2040 |
if ( (b & 0x10) == 0) ret |= 0x8200000; |
|
2041 |
} |
|
2042 |
} else if (m5 & 0x40) { |
|
2043 |
static const byte _train_spec_tracks[6] = {1,2,1,2,1,2}; |
|
2044 |
m5 = _train_spec_tracks[m5 & 0x3F]; |
|
2045 |
ret = (m5 << 8) + m5; |
|
2046 |
} else |
|
2047 |
return 0; |
|
2048 |
||
2049 |
return ret; |
|
2050 |
} |
|
2051 |
||
2052 |
static void ClickTile_Track(uint tile) |
|
2053 |
{ |
|
2054 |
if (IS_RAIL_DEPOT(_map5[tile])) |
|
2055 |
ShowTrainDepotWindow(tile); |
|
395
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
393
diff
changeset
|
2056 |
else if (IS_RAIL_WAYPOINT(_map5[tile])) |
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
393
diff
changeset
|
2057 |
ShowRenameWaypointWindow(&_waypoints[GetWaypointByTile(tile)]); |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
2058 |
|
0 | 2059 |
} |
2060 |
||
2061 |
static void GetTileDesc_Track(uint tile, TileDesc *td) |
|
2062 |
{ |
|
2063 |
byte m5 = _map5[tile]; |
|
2064 |
if (!(m5 & 0x80)) { |
|
2065 |
if(!(m5 & 0x40)) // no signals |
|
2066 |
td->str = STR_1021_RAILROAD_TRACK; |
|
2067 |
else |
|
2068 |
{ |
|
2069 |
switch(_map3_hi[tile] & 0x03) |
|
2070 |
{ |
|
2071 |
case 0: td->str = STR_RAILROAD_TRACK_WITH_NORMAL_SIGNALS; |
|
2072 |
break; |
|
2073 |
case 1: td->str = STR_RAILROAD_TRACK_WITH_PRESIGNALS; |
|
2074 |
break; |
|
2075 |
case 2: td->str = STR_RAILROAD_TRACK_WITH_EXITSIGNALS; |
|
2076 |
break; |
|
2077 |
case 3: td->str = STR_RAILROAD_TRACK_WITH_COMBOSIGNALS; |
|
2078 |
break; |
|
2079 |
} |
|
2080 |
} |
|
2081 |
} else { |
|
395
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
393
diff
changeset
|
2082 |
td->str = m5 < 0xC4 ? STR_1023_RAILROAD_TRAIN_DEPOT : STR_LANDINFO_WAYPOINT; |
0 | 2083 |
} |
2084 |
td->owner = _map_owner[tile]; |
|
2085 |
} |
|
2086 |
||
2087 |
static void ChangeTileOwner_Track(uint tile, byte old_player, byte new_player) |
|
2088 |
{ |
|
2089 |
if (_map_owner[tile] != old_player) |
|
2090 |
return; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
2091 |
|
0 | 2092 |
if (new_player != 255) { |
2093 |
_map_owner[tile] = new_player; |
|
2094 |
} else { |
|
2095 |
DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); |
|
2096 |
} |
|
2097 |
} |
|
2098 |
||
2099 |
static const byte _fractcoords_behind[4] = { 0x8F, 0x8, 0x80, 0xF8 }; |
|
2100 |
static const byte _fractcoords_enter[4] = { 0x8A, 0x48, 0x84, 0xA8 }; |
|
2101 |
static const byte _fractcoords_leave[4] = { 0x81, 0xD8, 0x8D, 0x18 }; |
|
2102 |
static const byte _enter_directions[4] = {5, 7, 1, 3}; |
|
2103 |
static const byte _leave_directions[4] = {1, 3, 5, 7}; |
|
2104 |
static const byte _depot_track_mask[4] = {1, 2, 1, 2}; |
|
2105 |
||
2106 |
uint32 VehicleEnter_Track(Vehicle *v, uint tile, int x, int y) |
|
2107 |
{ |
|
2108 |
byte fract_coord; |
|
2109 |
int dir; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
2110 |
|
0 | 2111 |
// this routine applies only to trains in depot tiles |
2112 |
if (v->type != VEH_Train || !IS_RAIL_DEPOT(_map5[tile])) |
|
2113 |
return 0; |
|
2114 |
||
2115 |
/* depot direction */ |
|
2116 |
dir = _map5[tile] & RAIL_DEPOT_DIR; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
2117 |
|
0 | 2118 |
fract_coord = (x & 0xF) + ((y & 0xF) << 4); |
2119 |
if (_fractcoords_behind[dir] == fract_coord) { |
|
2120 |
/* make sure a train is not entering the tile from behind */ |
|
2121 |
return 8; |
|
2122 |
} else if (_fractcoords_enter[dir] == fract_coord) { |
|
2123 |
if (_enter_directions[dir] == v->direction) { |
|
2124 |
/* enter the depot */ |
|
2125 |
v->u.rail.track = 0x80, |
|
2126 |
v->vehstatus |= VS_HIDDEN; /* hide it */ |
|
2127 |
v->direction ^= 4; |
|
2128 |
if (v->next == NULL) |
|
2129 |
TrainEnterDepot(v, tile); |
|
2130 |
v->tile = tile; |
|
2131 |
InvalidateWindow(WC_VEHICLE_DEPOT, tile); |
|
2132 |
return 4; |
|
2133 |
} |
|
2134 |
} else if (_fractcoords_leave[dir] == fract_coord) { |
|
2135 |
if (_leave_directions[dir] == v->direction) { |
|
2136 |
/* leave the depot? */ |
|
2137 |
if ((v=v->next) != NULL) { |
|
2138 |
v->vehstatus &= ~VS_HIDDEN; |
|
2139 |
v->u.rail.track = _depot_track_mask[dir]; |
|
2140 |
} |
|
2141 |
} |
|
2142 |
} |
|
2143 |
||
2144 |
return 0; |
|
2145 |
} |
|
2146 |
||
2147 |
void InitializeRail() |
|
2148 |
{ |
|
2149 |
_last_built_train_depot_tile = 0; |
|
2150 |
} |
|
2151 |
||
2152 |
const TileTypeProcs _tile_type_rail_procs = { |
|
2153 |
DrawTile_Track, /* draw_tile_proc */ |
|
2154 |
GetSlopeZ_Track, /* get_slope_z_proc */ |
|
2155 |
ClearTile_Track, /* clear_tile_proc */ |
|
2156 |
GetAcceptedCargo_Track, /* get_accepted_cargo_proc */ |
|
2157 |
GetTileDesc_Track, /* get_tile_desc_proc */ |
|
2158 |
GetTileTrackStatus_Track, /* get_tile_track_status_proc */ |
|
2159 |
ClickTile_Track, /* click_tile_proc */ |
|
2160 |
AnimateTile_Track, /* animate_tile_proc */ |
|
2161 |
TileLoop_Track, /* tile_loop_clear */ |
|
2162 |
ChangeTileOwner_Track, /* change_tile_owner_clear */ |
|
2163 |
NULL, /* get_produced_cargo_proc */ |
|
2164 |
VehicleEnter_Track, /* vehicle_enter_tile_proc */ |
|
2165 |
NULL, /* vehicle_leave_tile_proc */ |
|
39 | 2166 |
GetSlopeTileh_Track, /* get_slope_tileh_proc */ |
0 | 2167 |
}; |