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