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