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