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