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