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