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