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