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