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