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