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