author | Darkvater |
Sun, 26 Mar 2006 22:41:56 +0000 | |
changeset 3346 | a0d4def7d934 |
parent 3333 | 5feb21487332 |
child 3355 | e414a0b104a6 |
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" |
3189
bf047128dee7
(svn r3846) Add functions to set the type of stuff (clear, water, rail, road) under bridges
tron
parents:
3185
diff
changeset
|
5 |
#include "bridge_map.h" |
1922
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1903
diff
changeset
|
6 |
#include "debug.h" |
2163
b17b313113a0
(svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents:
2148
diff
changeset
|
7 |
#include "functions.h" |
3101
a44fdf9faef1
(svn r3696) Add functions to turn a tile into a normal rail tile/depot/waypoint. This is just a tiny step, the rail code needs way more love and caring
tron
parents:
3099
diff
changeset
|
8 |
#include "rail_map.h" |
3144
33e42feae531
(svn r3763) Adapt to the new 'map accessors go in foo_map.h'-scheme
tron
parents:
3142
diff
changeset
|
9 |
#include "road_map.h" |
1363
775a7ee52369
(svn r1867) Include tables/sprites.h only in files which need it
tron
parents:
1330
diff
changeset
|
10 |
#include "table/sprites.h" |
507
04b5403aaf6b
(svn r815) Include strings.h only in the files which need it.
tron
parents:
497
diff
changeset
|
11 |
#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
|
12 |
#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
|
13 |
#include "tile.h" |
3319
16c0f06829a5
(svn r4085) Add GetTown{Index,ByTile}() to get the town index resp. the town from a tile
tron
parents:
3286
diff
changeset
|
14 |
#include "town_map.h" |
3154 | 15 |
#include "tunnel_map.h" |
0 | 16 |
#include "vehicle.h" |
17 |
#include "viewport.h" |
|
18 |
#include "command.h" |
|
19 |
#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
|
20 |
#include "engine.h" |
0 | 21 |
#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
|
22 |
#include "sound.h" |
389
16ee9854091e
(svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents:
337
diff
changeset
|
23 |
#include "station.h" |
405
415546028e8d
(svn r602) -newgrf: Move DrawTileSeqStruct & co and struct SpriteGroup to sprite.h (pasky)
darkvater
parents:
403
diff
changeset
|
24 |
#include "sprite.h" |
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1247
diff
changeset
|
25 |
#include "depot.h" |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1536
diff
changeset
|
26 |
#include "waypoint.h" |
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
27 |
#include "rail.h" |
2236 | 28 |
#include "railtypes.h" // include table for railtypes |
0 | 29 |
|
415
20f981988266
(svn r612) [newgrf] Fix: custom waypoints on monorail/maglev are displayed correctly
dominik
parents:
413
diff
changeset
|
30 |
extern uint16 _custom_sprites_base; |
20f981988266
(svn r612) [newgrf] Fix: custom waypoints on monorail/maglev are displayed correctly
dominik
parents:
413
diff
changeset
|
31 |
|
2261
d3554e5d3e86
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2254
diff
changeset
|
32 |
const byte _track_sloped_sprites[14] = { |
d3554e5d3e86
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2254
diff
changeset
|
33 |
14, 15, 22, 13, |
d3554e5d3e86
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2254
diff
changeset
|
34 |
0, 21, 17, 12, |
d3554e5d3e86
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2254
diff
changeset
|
35 |
23, 0, 18, 20, |
d3554e5d3e86
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2254
diff
changeset
|
36 |
19, 16 |
d3554e5d3e86
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2254
diff
changeset
|
37 |
}; |
d3554e5d3e86
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2254
diff
changeset
|
38 |
|
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1963
diff
changeset
|
39 |
void ShowTrainDepotWindow(TileIndex tile); |
0 | 40 |
|
41 |
/* 4 |
|
42 |
* --------- |
|
43 |
* |\ /| |
|
44 |
* | \ 1/ | |
|
45 |
* | \ / | |
|
46 |
* | \ / | |
|
47 |
* 16| \ |32 |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
48 |
* | / \2 | |
0 | 49 |
* | / \ | |
50 |
* | / \ | |
|
51 |
* |/ \| |
|
52 |
* --------- |
|
53 |
* 8 |
|
54 |
*/ |
|
55 |
||
56 |
||
57 |
// 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
|
58 |
enum RailMap2Lower4 { |
0 | 59 |
RAIL_MAP2LO_GROUND_MASK = 0xF, |
60 |
RAIL_GROUND_BROWN = 0, |
|
61 |
RAIL_GROUND_GREEN = 1, |
|
62 |
RAIL_GROUND_FENCE_NW = 2, |
|
63 |
RAIL_GROUND_FENCE_SE = 3, |
|
64 |
RAIL_GROUND_FENCE_SENW = 4, |
|
65 |
RAIL_GROUND_FENCE_NE = 5, |
|
66 |
RAIL_GROUND_FENCE_SW = 6, |
|
67 |
RAIL_GROUND_FENCE_NESW = 7, |
|
68 |
RAIL_GROUND_FENCE_VERT1 = 8, |
|
69 |
RAIL_GROUND_FENCE_VERT2 = 9, |
|
70 |
RAIL_GROUND_FENCE_HORIZ1 = 10, |
|
71 |
RAIL_GROUND_FENCE_HORIZ2 = 11, |
|
72 |
RAIL_GROUND_ICE_DESERT = 12, |
|
73 |
}; |
|
74 |
||
75 |
||
22 | 76 |
/* 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
|
77 |
* MAP3LO byte: abcd???? => Signal Exists? |
22 | 78 |
* a and b are for diagonals, upper and left, |
79 |
* one for each direction. (ie a == NE->SW, b == |
|
80 |
* SW->NE, or v.v., I don't know. b and c are |
|
81 |
* similar for lower and right. |
|
0 | 82 |
* MAP2 byte: ????abcd => Type of ground. |
83 |
* MAP3LO byte: ????abcd => Type of rail. |
|
84 |
* MAP5: 00abcdef => rail |
|
85 |
* 01abcdef => rail w/ signals |
|
86 |
* 10uuuuuu => unused |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
87 |
* 11uuuudd => rail depot |
0 | 88 |
*/ |
89 |
||
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
90 |
static bool CheckTrackCombination(TileIndex tile, TrackBits to_build, uint flags) |
0 | 91 |
{ |
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
92 |
RailTileType type = GetRailTileType(tile); |
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
93 |
TrackBits current; /* The current track layout */ |
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
94 |
TrackBits future; /* The track layout we want to build */ |
0 | 95 |
_error_message = STR_1001_IMPOSSIBLE_TRACK_COMBINATION; |
96 |
||
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
97 |
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
|
98 |
return false; /* Cannot build anything on depots and checkpoints */ |
0 | 99 |
|
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
100 |
/* 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
|
101 |
* what tracks first */ |
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
102 |
current = GetTrackBits(tile); |
1946
f197fb0d840f
(svn r2452) Fix defect in r2448 which caused building tracks unexpectedly fail or succeed
tron
parents:
1942
diff
changeset
|
103 |
future = current | to_build; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
104 |
|
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
105 |
/* Are we really building something new? */ |
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
106 |
if (current == future) { |
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
107 |
/* Nothing new is being built */ |
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
108 |
_error_message = STR_1007_ALREADY_BUILT; |
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
109 |
return false; |
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
110 |
} |
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 |
/* 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
|
113 |
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
|
114 |
/* 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
|
115 |
* signals on the tile), check that */ |
3258
1c079364726d
(svn r3946) Add short hand names for common track combinations
tron
parents:
3254
diff
changeset
|
116 |
return future == TRACK_BIT_HORZ || future == TRACK_BIT_VERT; |
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
117 |
} else { |
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
118 |
/* 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
|
119 |
return true; |
0 | 120 |
} |
121 |
} |
|
122 |
||
123 |
||
3279
3f3b6ce1f427
(svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents:
3276
diff
changeset
|
124 |
const TrackBits _valid_tileh_slopes[2][15] = { |
0 | 125 |
|
126 |
// set of normal ones |
|
127 |
{ |
|
3258
1c079364726d
(svn r3946) Add short hand names for common track combinations
tron
parents:
3254
diff
changeset
|
128 |
TRACK_BIT_ALL, |
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
129 |
TRACK_BIT_RIGHT, |
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
130 |
TRACK_BIT_UPPER, |
3102
f9ca4379db9d
(svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron
parents:
3101
diff
changeset
|
131 |
TRACK_BIT_X, |
0 | 132 |
|
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
133 |
TRACK_BIT_LEFT, |
0 | 134 |
0, |
3102
f9ca4379db9d
(svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron
parents:
3101
diff
changeset
|
135 |
TRACK_BIT_Y, |
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
136 |
TRACK_BIT_LOWER, |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
137 |
|
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
138 |
TRACK_BIT_LOWER, |
3102
f9ca4379db9d
(svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron
parents:
3101
diff
changeset
|
139 |
TRACK_BIT_Y, |
0 | 140 |
0, |
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
141 |
TRACK_BIT_LEFT, |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
142 |
|
3102
f9ca4379db9d
(svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron
parents:
3101
diff
changeset
|
143 |
TRACK_BIT_X, |
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
144 |
TRACK_BIT_UPPER, |
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
145 |
TRACK_BIT_RIGHT, |
0 | 146 |
}, |
147 |
||
148 |
// allowed rail for an evenly raised platform |
|
149 |
{ |
|
150 |
0, |
|
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
151 |
TRACK_BIT_LEFT, |
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
152 |
TRACK_BIT_LOWER, |
3102
f9ca4379db9d
(svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron
parents:
3101
diff
changeset
|
153 |
TRACK_BIT_Y | TRACK_BIT_LOWER | TRACK_BIT_LEFT, |
0 | 154 |
|
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
155 |
TRACK_BIT_RIGHT, |
3258
1c079364726d
(svn r3946) Add short hand names for common track combinations
tron
parents:
3254
diff
changeset
|
156 |
TRACK_BIT_ALL, |
3102
f9ca4379db9d
(svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron
parents:
3101
diff
changeset
|
157 |
TRACK_BIT_X | TRACK_BIT_LOWER | TRACK_BIT_RIGHT, |
3258
1c079364726d
(svn r3946) Add short hand names for common track combinations
tron
parents:
3254
diff
changeset
|
158 |
TRACK_BIT_ALL, |
0 | 159 |
|
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
160 |
TRACK_BIT_UPPER, |
3102
f9ca4379db9d
(svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron
parents:
3101
diff
changeset
|
161 |
TRACK_BIT_X | TRACK_BIT_UPPER | TRACK_BIT_LEFT, |
3258
1c079364726d
(svn r3946) Add short hand names for common track combinations
tron
parents:
3254
diff
changeset
|
162 |
TRACK_BIT_ALL, |
1c079364726d
(svn r3946) Add short hand names for common track combinations
tron
parents:
3254
diff
changeset
|
163 |
TRACK_BIT_ALL, |
0 | 164 |
|
3102
f9ca4379db9d
(svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron
parents:
3101
diff
changeset
|
165 |
TRACK_BIT_Y | TRACK_BIT_UPPER | TRACK_BIT_RIGHT, |
3258
1c079364726d
(svn r3946) Add short hand names for common track combinations
tron
parents:
3254
diff
changeset
|
166 |
TRACK_BIT_ALL, |
1c079364726d
(svn r3946) Add short hand names for common track combinations
tron
parents:
3254
diff
changeset
|
167 |
TRACK_BIT_ALL |
3276
97da497e3a29
(svn r3988) Remove the info about valid rails on shore tiles. It's the same as for any other sloped tile
tron
parents:
3274
diff
changeset
|
168 |
} |
0 | 169 |
}; |
170 |
||
3267
feff95208a9f
(svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents:
3265
diff
changeset
|
171 |
uint GetRailFoundation(uint tileh, TrackBits bits) |
0 | 172 |
{ |
173 |
int i; |
|
174 |
||
175 |
if ((~_valid_tileh_slopes[0][tileh] & bits) == 0) |
|
176 |
return 0; |
|
177 |
||
178 |
if ((~_valid_tileh_slopes[1][tileh] & bits) == 0) |
|
179 |
return tileh; |
|
180 |
||
2951 | 181 |
if (( |
182 |
(i = 0, tileh == 1) || |
|
183 |
(i += 2, tileh == 2) || |
|
184 |
(i += 2, tileh == 4) || |
|
185 |
(i += 2, tileh == 8) |
|
186 |
) && ( |
|
3102
f9ca4379db9d
(svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron
parents:
3101
diff
changeset
|
187 |
bits == TRACK_BIT_X || |
f9ca4379db9d
(svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron
parents:
3101
diff
changeset
|
188 |
(i++, bits == TRACK_BIT_Y) |
2951 | 189 |
)) { |
0 | 190 |
return i + 15; |
2951 | 191 |
} else { |
192 |
return 0; |
|
193 |
} |
|
0 | 194 |
} |
195 |
||
2639 | 196 |
|
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
197 |
static uint32 CheckRailSlope(uint tileh, TrackBits rail_bits, TrackBits existing, TileIndex tile) |
0 | 198 |
{ |
199 |
// 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
|
200 |
if (!IsSteepTileh(tileh)) { |
0 | 201 |
rail_bits |= existing; |
202 |
||
203 |
// 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
|
204 |
if (IsTileType(tile, MP_WATER) && |
3276
97da497e3a29
(svn r3988) Remove the info about valid rails on shore tiles. It's the same as for any other sloped tile
tron
parents:
3274
diff
changeset
|
205 |
~_valid_tileh_slopes[1][tileh] & rail_bits) { |
0 | 206 |
return_cmd_error(STR_3807_CAN_T_BUILD_ON_WATER); |
207 |
} |
|
208 |
||
209 |
// no special foundation |
|
210 |
if ((~_valid_tileh_slopes[0][tileh] & rail_bits) == 0) |
|
211 |
return 0; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
212 |
|
1627
f365c96e74a4
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
213 |
if ((~_valid_tileh_slopes[1][tileh] & rail_bits) == 0 || ( // whole tile is leveled up |
3102
f9ca4379db9d
(svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron
parents:
3101
diff
changeset
|
214 |
(rail_bits == TRACK_BIT_X || rail_bits == TRACK_BIT_Y) && |
1627
f365c96e74a4
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
215 |
(tileh == 1 || tileh == 2 || tileh == 4 || tileh == 8) |
f365c96e74a4
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
216 |
)) { // partly up |
f365c96e74a4
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
217 |
if (existing != 0) { |
f365c96e74a4
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
218 |
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
|
219 |
} 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
|
220 |
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
|
221 |
} else { |
f365c96e74a4
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
222 |
return _price.terraform; |
f365c96e74a4
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
223 |
} |
0 | 224 |
} |
225 |
} |
|
226 |
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); |
|
227 |
} |
|
228 |
||
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
|
229 |
/* Validate functions for rail building */ |
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
230 |
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
|
231 |
|
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
|
232 |
/** 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
|
233 |
* @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
|
234 |
* @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
|
235 |
* @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
|
236 |
*/ |
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
|
237 |
int32 CmdBuildSingleRail(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
0 | 238 |
{ |
1627
f365c96e74a4
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
239 |
TileIndex tile; |
f365c96e74a4
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
240 |
uint tileh; |
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
241 |
Track track = (Track)p2; |
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
242 |
TrackBits trackbit; |
1627
f365c96e74a4
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
243 |
int32 cost = 0; |
f365c96e74a4
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
244 |
int32 ret; |
f365c96e74a4
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
245 |
|
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
246 |
if (!ValParamRailtype(p1) || !ValParamTrackOrientation(track)) return CMD_ERROR; |
1627
f365c96e74a4
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
247 |
|
1980
6c5917cfcb78
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1977
diff
changeset
|
248 |
tile = TileVirtXY(x, y); |
1627
f365c96e74a4
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
249 |
tileh = GetTileSlope(tile, NULL); |
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
250 |
trackbit = TrackToTrackBits(track); |
0 | 251 |
|
252 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
253 |
||
1627
f365c96e74a4
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
254 |
switch (GetTileType(tile)) { |
f365c96e74a4
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
255 |
case MP_TUNNELBRIDGE: |
3234
a2791a480b71
(svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents:
3220
diff
changeset
|
256 |
if (!IsBridge(tile) || |
a2791a480b71
(svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents:
3220
diff
changeset
|
257 |
!IsBridgeMiddle(tile) || |
a2791a480b71
(svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents:
3220
diff
changeset
|
258 |
(GetBridgeAxis(tile) == AXIS_X ? TRACK_BIT_Y : TRACK_BIT_X) != trackbit) { |
1627
f365c96e74a4
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
259 |
// Get detailed error message |
f365c96e74a4
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
260 |
return DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
f365c96e74a4
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
261 |
} |
0 | 262 |
|
3234
a2791a480b71
(svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents:
3220
diff
changeset
|
263 |
if (IsClearUnderBridge(tile)) { |
a2791a480b71
(svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents:
3220
diff
changeset
|
264 |
ret = CheckRailSlope(tileh, trackbit, 0, tile); |
a2791a480b71
(svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents:
3220
diff
changeset
|
265 |
if (CmdFailed(ret)) return ret; |
a2791a480b71
(svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents:
3220
diff
changeset
|
266 |
cost += ret; |
0 | 267 |
|
3234
a2791a480b71
(svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents:
3220
diff
changeset
|
268 |
if (flags & DC_EXEC) SetRailUnderBridge(tile, _current_player, p1); |
a2791a480b71
(svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents:
3220
diff
changeset
|
269 |
} else if (IsTransportUnderBridge(tile) && |
a2791a480b71
(svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents:
3220
diff
changeset
|
270 |
GetTransportTypeUnderBridge(tile) == TRANSPORT_RAIL) { |
a2791a480b71
(svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents:
3220
diff
changeset
|
271 |
return_cmd_error(STR_1007_ALREADY_BUILT); |
a2791a480b71
(svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents:
3220
diff
changeset
|
272 |
} else { |
a2791a480b71
(svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents:
3220
diff
changeset
|
273 |
// Get detailed error message |
a2791a480b71
(svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents:
3220
diff
changeset
|
274 |
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
|
275 |
} |
f365c96e74a4
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
276 |
break; |
0 | 277 |
|
1627
f365c96e74a4
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
278 |
case MP_RAILWAY: |
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
279 |
if (!CheckTrackCombination(tile, trackbit, flags) || |
1627
f365c96e74a4
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
280 |
!EnsureNoVehicle(tile)) { |
f365c96e74a4
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
281 |
return CMD_ERROR; |
f365c96e74a4
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
282 |
} |
3253 | 283 |
if (GetRailTileType(tile) == RAIL_TYPE_DEPOT_WAYPOINT || |
1903 | 284 |
!IsTileOwner(tile, _current_player) || |
3242
4c32bf21153b
(svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents:
3238
diff
changeset
|
285 |
GetRailType(tile) != p1) { |
1627
f365c96e74a4
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
286 |
// Get detailed error message |
f365c96e74a4
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
287 |
return DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
f365c96e74a4
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
288 |
} |
f365c96e74a4
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
289 |
|
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
290 |
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
|
291 |
if (CmdFailed(ret)) return ret; |
0 | 292 |
cost += ret; |
293 |
||
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
|
294 |
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
|
295 |
_m[tile].m2 &= ~RAIL_MAP2LO_GROUND_MASK; // Bare land |
3271
114243e3465f
(svn r3983) Use existing functions to access tree and road info
tron
parents:
3270
diff
changeset
|
296 |
_m[tile].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
|
297 |
} |
1627
f365c96e74a4
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
298 |
break; |
0 | 299 |
|
1627
f365c96e74a4
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
300 |
case MP_STREET: |
3142
ef213f02d4bf
(svn r3760) Replace some magic numbers for checking for a suitable slope for a level crossing by some less magic numbers. Quite similar to r3699, though this time for placing the rails
tron
parents:
3103
diff
changeset
|
301 |
#define M(x) (1 << (x)) |
ef213f02d4bf
(svn r3760) Replace some magic numbers for checking for a suitable slope for a level crossing by some less magic numbers. Quite similar to r3699, though this time for placing the rails
tron
parents:
3103
diff
changeset
|
302 |
/* Level crossings may only be built on these slopes */ |
ef213f02d4bf
(svn r3760) Replace some magic numbers for checking for a suitable slope for a level crossing by some less magic numbers. Quite similar to r3699, though this time for placing the rails
tron
parents:
3103
diff
changeset
|
303 |
if (!HASBIT(M(14) | M(13) | M(11) | M(10) | M(7) | M(5) | M(0), tileh)) { |
1627
f365c96e74a4
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
304 |
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); |
3142
ef213f02d4bf
(svn r3760) Replace some magic numbers for checking for a suitable slope for a level crossing by some less magic numbers. Quite similar to r3699, though this time for placing the rails
tron
parents:
3103
diff
changeset
|
305 |
} |
ef213f02d4bf
(svn r3760) Replace some magic numbers for checking for a suitable slope for a level crossing by some less magic numbers. Quite similar to r3699, though this time for placing the rails
tron
parents:
3103
diff
changeset
|
306 |
#undef M |
ef213f02d4bf
(svn r3760) Replace some magic numbers for checking for a suitable slope for a level crossing by some less magic numbers. Quite similar to r3699, though this time for placing the rails
tron
parents:
3103
diff
changeset
|
307 |
|
1627
f365c96e74a4
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
308 |
if (!EnsureNoVehicle(tile)) return CMD_ERROR; |
0 | 309 |
|
3069
9a1fd047b595
(svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents:
3017
diff
changeset
|
310 |
if (GetRoadType(tile) == ROAD_NORMAL && ( |
3271
114243e3465f
(svn r3983) Use existing functions to access tree and road info
tron
parents:
3270
diff
changeset
|
311 |
(track == TRACK_X && GetRoadBits(tile) == ROAD_Y) || |
114243e3465f
(svn r3983) Use existing functions to access tree and road info
tron
parents:
3270
diff
changeset
|
312 |
(track == TRACK_Y && GetRoadBits(tile) == ROAD_X) |
1627
f365c96e74a4
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
313 |
)) { |
f365c96e74a4
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
314 |
if (flags & DC_EXEC) { |
3319
16c0f06829a5
(svn r4085) Add GetTown{Index,ByTile}() to get the town index resp. the town from a tile
tron
parents:
3286
diff
changeset
|
315 |
MakeRoadCrossing(tile, GetTileOwner(tile), _current_player, (track == TRACK_X ? AXIS_Y : AXIS_X), p1, GetTownIndex(tile)); |
1627
f365c96e74a4
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
316 |
} |
f365c96e74a4
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
317 |
break; |
f365c96e74a4
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
318 |
} |
f365c96e74a4
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
319 |
|
3267
feff95208a9f
(svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents:
3265
diff
changeset
|
320 |
if (IsLevelCrossing(tile) && GetCrossingRailBits(tile) == trackbit) { |
1627
f365c96e74a4
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
321 |
return_cmd_error(STR_1007_ALREADY_BUILT); |
3267
feff95208a9f
(svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents:
3265
diff
changeset
|
322 |
} |
1627
f365c96e74a4
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
323 |
/* FALLTHROUGH */ |
f365c96e74a4
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
324 |
|
f365c96e74a4
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
325 |
default: |
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
326 |
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
|
327 |
if (CmdFailed(ret)) return ret; |
1627
f365c96e74a4
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
328 |
cost += ret; |
f365c96e74a4
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
329 |
|
f365c96e74a4
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
330 |
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
|
331 |
if (CmdFailed(ret)) return ret; |
1627
f365c96e74a4
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
332 |
cost += ret; |
f365c96e74a4
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
333 |
|
3101
a44fdf9faef1
(svn r3696) Add functions to turn a tile into a normal rail tile/depot/waypoint. This is just a tiny step, the rail code needs way more love and caring
tron
parents:
3099
diff
changeset
|
334 |
if (flags & DC_EXEC) MakeRailNormal(tile, _current_player, trackbit, p1); |
1627
f365c96e74a4
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
335 |
break; |
0 | 336 |
} |
337 |
||
338 |
if (flags & DC_EXEC) { |
|
339 |
MarkTileDirtyByTile(tile); |
|
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
340 |
SetSignalsOnBothDir(tile, track); |
0 | 341 |
} |
342 |
||
343 |
return cost + _price.build_rail; |
|
344 |
} |
|
345 |
||
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
|
346 |
/** 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
|
347 |
* @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
|
348 |
* @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
|
349 |
* @param p2 rail orientation |
0 | 350 |
*/ |
351 |
int32 CmdRemoveSingleRail(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
352 |
{ |
|
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
353 |
Track track = (Track)p2; |
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
354 |
TrackBits trackbit; |
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
|
355 |
TileIndex tile; |
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
|
356 |
int32 cost = _price.remove_rail; |
3284
84eda61a0167
(svn r3998) - Fix: When removing rail track from a while where only X and Y (/ and \) pieces exist, explicitly update signals in both directions.
peter1138
parents:
3279
diff
changeset
|
357 |
bool crossing = false; |
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
|
358 |
|
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
|
359 |
if (!ValParamTrackOrientation(p2)) return CMD_ERROR; |
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
360 |
trackbit = TrackToTrackBits(track); |
0 | 361 |
|
362 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
363 |
||
1980
6c5917cfcb78
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1977
diff
changeset
|
364 |
tile = TileVirtXY(x, y); |
0 | 365 |
|
3273
3089ecca8e21
(svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents:
3271
diff
changeset
|
366 |
switch (GetTileType(tile)) { |
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
367 |
case MP_TUNNELBRIDGE: |
3234
a2791a480b71
(svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents:
3220
diff
changeset
|
368 |
if (!IsBridge(tile) || |
a2791a480b71
(svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents:
3220
diff
changeset
|
369 |
!IsBridgeMiddle(tile) || |
a2791a480b71
(svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents:
3220
diff
changeset
|
370 |
!IsTransportUnderBridge(tile) || |
a2791a480b71
(svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents:
3220
diff
changeset
|
371 |
GetTransportTypeUnderBridge(tile) != TRANSPORT_RAIL || |
a2791a480b71
(svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents:
3220
diff
changeset
|
372 |
GetRailBitsUnderBridge(tile) != trackbit || |
3273
3089ecca8e21
(svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents:
3271
diff
changeset
|
373 |
(_current_player != OWNER_WATER && !CheckTileOwnership(tile)) || |
3234
a2791a480b71
(svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents:
3220
diff
changeset
|
374 |
!EnsureNoVehicleZ(tile, TilePixelHeight(tile))) { |
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
375 |
return CMD_ERROR; |
3234
a2791a480b71
(svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents:
3220
diff
changeset
|
376 |
} |
0 | 377 |
|
3273
3089ecca8e21
(svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents:
3271
diff
changeset
|
378 |
if (flags & DC_EXEC) SetClearUnderBridge(tile); |
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
379 |
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
|
380 |
|
3071
6f3417a859d4
(svn r3660) Convert further road bits and type references to the functions/enums
tron
parents:
3069
diff
changeset
|
381 |
case MP_STREET: { |
3273
3089ecca8e21
(svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents:
3271
diff
changeset
|
382 |
if (!IsLevelCrossing(tile) || |
3089ecca8e21
(svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents:
3271
diff
changeset
|
383 |
GetCrossingRailBits(tile) != trackbit || |
3089ecca8e21
(svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents:
3271
diff
changeset
|
384 |
(_current_player != OWNER_WATER && !CheckTileOwnership(tile)) || |
3089ecca8e21
(svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents:
3271
diff
changeset
|
385 |
!EnsureNoVehicle(tile)) { |
3089ecca8e21
(svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents:
3271
diff
changeset
|
386 |
return CMD_ERROR; |
3089ecca8e21
(svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents:
3271
diff
changeset
|
387 |
} |
0 | 388 |
|
3273
3089ecca8e21
(svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents:
3271
diff
changeset
|
389 |
if (flags & DC_EXEC) { |
3319
16c0f06829a5
(svn r4085) Add GetTown{Index,ByTile}() to get the town index resp. the town from a tile
tron
parents:
3286
diff
changeset
|
390 |
MakeRoadNormal(tile, GetCrossingRoadOwner(tile), GetCrossingRoadBits(tile), GetTownIndex(tile)); |
3273
3089ecca8e21
(svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents:
3271
diff
changeset
|
391 |
} |
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
392 |
break; |
3071
6f3417a859d4
(svn r3660) Convert further road bits and type references to the functions/enums
tron
parents:
3069
diff
changeset
|
393 |
} |
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
|
394 |
|
3273
3089ecca8e21
(svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents:
3271
diff
changeset
|
395 |
case MP_RAILWAY: { |
3089ecca8e21
(svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents:
3271
diff
changeset
|
396 |
TrackBits present; |
3089ecca8e21
(svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents:
3271
diff
changeset
|
397 |
|
3089ecca8e21
(svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents:
3271
diff
changeset
|
398 |
if (!IsPlainRailTile(tile) || |
3089ecca8e21
(svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents:
3271
diff
changeset
|
399 |
(_current_player != OWNER_WATER && !CheckTileOwnership(tile)) || |
3089ecca8e21
(svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents:
3271
diff
changeset
|
400 |
!EnsureNoVehicle(tile)) { |
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
401 |
return CMD_ERROR; |
3273
3089ecca8e21
(svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents:
3271
diff
changeset
|
402 |
} |
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
403 |
|
3273
3089ecca8e21
(svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents:
3271
diff
changeset
|
404 |
present = GetTrackBits(tile); |
3089ecca8e21
(svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents:
3271
diff
changeset
|
405 |
if ((present & trackbit) == 0) return CMD_ERROR; |
3284
84eda61a0167
(svn r3998) - Fix: When removing rail track from a while where only X and Y (/ and \) pieces exist, explicitly update signals in both directions.
peter1138
parents:
3279
diff
changeset
|
406 |
if (present == (TRACK_BIT_X | TRACK_BIT_Y)) crossing = true; |
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
407 |
|
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
|
408 |
/* 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
|
409 |
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
|
410 |
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
|
411 |
|
3273
3089ecca8e21
(svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents:
3271
diff
changeset
|
412 |
if (flags & DC_EXEC) { |
3089ecca8e21
(svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents:
3271
diff
changeset
|
413 |
present ^= trackbit; |
3089ecca8e21
(svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents:
3271
diff
changeset
|
414 |
if (present == 0) { |
3089ecca8e21
(svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents:
3271
diff
changeset
|
415 |
DoClearSquare(tile); |
3089ecca8e21
(svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents:
3271
diff
changeset
|
416 |
} else { |
3089ecca8e21
(svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents:
3271
diff
changeset
|
417 |
SetTrackBits(tile, present); |
3089ecca8e21
(svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents:
3271
diff
changeset
|
418 |
} |
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
419 |
} |
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
420 |
break; |
3273
3089ecca8e21
(svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents:
3271
diff
changeset
|
421 |
} |
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
|
422 |
|
3273
3089ecca8e21
(svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents:
3271
diff
changeset
|
423 |
default: return CMD_ERROR; |
0 | 424 |
} |
425 |
||
3273
3089ecca8e21
(svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents:
3271
diff
changeset
|
426 |
if (flags & DC_EXEC) { |
3089ecca8e21
(svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents:
3271
diff
changeset
|
427 |
MarkTileDirtyByTile(tile); |
3284
84eda61a0167
(svn r3998) - Fix: When removing rail track from a while where only X and Y (/ and \) pieces exist, explicitly update signals in both directions.
peter1138
parents:
3279
diff
changeset
|
428 |
if (crossing) { |
84eda61a0167
(svn r3998) - Fix: When removing rail track from a while where only X and Y (/ and \) pieces exist, explicitly update signals in both directions.
peter1138
parents:
3279
diff
changeset
|
429 |
/* crossing is set when only TRACK_BIT_X and TRACK_BIT_Y are set. As we |
84eda61a0167
(svn r3998) - Fix: When removing rail track from a while where only X and Y (/ and \) pieces exist, explicitly update signals in both directions.
peter1138
parents:
3279
diff
changeset
|
430 |
* are removing one of these pieces, we'll need to update signals for |
84eda61a0167
(svn r3998) - Fix: When removing rail track from a while where only X and Y (/ and \) pieces exist, explicitly update signals in both directions.
peter1138
parents:
3279
diff
changeset
|
431 |
* both directions explicitly, as after the track is removed it won't |
84eda61a0167
(svn r3998) - Fix: When removing rail track from a while where only X and Y (/ and \) pieces exist, explicitly update signals in both directions.
peter1138
parents:
3279
diff
changeset
|
432 |
* 'connect' with the other piece. */ |
84eda61a0167
(svn r3998) - Fix: When removing rail track from a while where only X and Y (/ and \) pieces exist, explicitly update signals in both directions.
peter1138
parents:
3279
diff
changeset
|
433 |
SetSignalsOnBothDir(tile, TRACK_X); |
84eda61a0167
(svn r3998) - Fix: When removing rail track from a while where only X and Y (/ and \) pieces exist, explicitly update signals in both directions.
peter1138
parents:
3279
diff
changeset
|
434 |
SetSignalsOnBothDir(tile, TRACK_Y); |
84eda61a0167
(svn r3998) - Fix: When removing rail track from a while where only X and Y (/ and \) pieces exist, explicitly update signals in both directions.
peter1138
parents:
3279
diff
changeset
|
435 |
} else { |
84eda61a0167
(svn r3998) - Fix: When removing rail track from a while where only X and Y (/ and \) pieces exist, explicitly update signals in both directions.
peter1138
parents:
3279
diff
changeset
|
436 |
SetSignalsOnBothDir(tile, track); |
84eda61a0167
(svn r3998) - Fix: When removing rail track from a while where only X and Y (/ and \) pieces exist, explicitly update signals in both directions.
peter1138
parents:
3279
diff
changeset
|
437 |
} |
3273
3089ecca8e21
(svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents:
3271
diff
changeset
|
438 |
} |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
439 |
|
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
|
440 |
return cost; |
0 | 441 |
} |
442 |
||
443 |
static const struct { |
|
444 |
int8 xinc[16]; |
|
445 |
int8 yinc[16]; |
|
446 |
} _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
|
447 |
// 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
|
448 |
-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
|
449 |
16, 0, 0, 16, 0,-16, 0, 0, |
0 | 450 |
},{ |
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
|
451 |
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
|
452 |
0,-16,-16, 0,-16, 0, 0, 0, |
0 | 453 |
}}; |
454 |
||
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
455 |
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
|
456 |
{ |
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
|
457 |
int dx, dy, trdx, trdy; |
0 | 458 |
|
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
459 |
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
|
460 |
|
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
|
461 |
// 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
|
462 |
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
|
463 |
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
|
464 |
|
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
|
465 |
// 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
|
466 |
trdx = _railbit.xinc[*trackdir]; |
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
467 |
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
|
468 |
|
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
469 |
if (!IsDiagonalTrackdir(*trackdir)) { |
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
470 |
trdx += _railbit.xinc[*trackdir ^ 1]; |
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
471 |
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
|
472 |
} |
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
|
473 |
|
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
|
474 |
// validate the direction |
2951 | 475 |
while ( |
476 |
(trdx <= 0 && dx > 0) || |
|
477 |
(trdx >= 0 && dx < 0) || |
|
478 |
(trdy <= 0 && dy > 0) || |
|
479 |
(trdy >= 0 && dy < 0) |
|
480 |
) { |
|
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
481 |
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
|
482 |
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
|
483 |
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
|
484 |
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
|
485 |
} 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
|
486 |
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
|
487 |
} |
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
|
488 |
|
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
|
489 |
// (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
|
490 |
// 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
|
491 |
if (!IsDiagonalTrackdir(*trackdir)) { |
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
492 |
trdx = _railbit.xinc[*trackdir]; |
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
493 |
trdy = _railbit.yinc[*trackdir]; |
2951 | 494 |
if (abs(dx) != abs(dy) && abs(dx) + abs(trdy) != abs(dy) + abs(trdx)) |
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
|
495 |
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
|
496 |
} |
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
|
497 |
|
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
|
498 |
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
|
499 |
} |
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
|
500 |
|
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
|
501 |
/** 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
|
502 |
* @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
|
503 |
* @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
|
504 |
* @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
|
505 |
* - 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
|
506 |
* - 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
|
507 |
* - p2 = (bit 7) - 0 = build, 1 = remove tracks |
0 | 508 |
*/ |
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
|
509 |
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
|
510 |
{ |
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
|
511 |
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
|
512 |
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
|
513 |
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
|
514 |
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
|
515 |
byte mode = HASBIT(p2, 7); |
2604
e3e60351c067
(svn r3141) Replace incorrect railtype bitmask in CmdRailTrackHelper with appropriate GB()
peter1138
parents:
2549
diff
changeset
|
516 |
RailType railtype = (RailType)GB(p2, 0, 4); |
0 | 517 |
|
2604
e3e60351c067
(svn r3141) Replace incorrect railtype bitmask in CmdRailTrackHelper with appropriate GB()
peter1138
parents:
2549
diff
changeset
|
518 |
if (!ValParamRailtype(railtype) || !ValParamTrackOrientation(track)) return CMD_ERROR; |
2934
3f29a7212713
(svn r3490) -Fix: A bunch (10) of off-by-one errors when checking if a TileIndex points to a tile on the map
tron
parents:
2916
diff
changeset
|
519 |
if (p1 >= MapSize()) return CMD_ERROR; |
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
520 |
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
|
521 |
|
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
|
522 |
/* unpack end point */ |
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
523 |
ex = TileX(p1) * TILE_SIZE; |
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
524 |
ey = TileY(p1) * TILE_SIZE; |
0 | 525 |
|
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
|
526 |
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
|
527 |
|
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
528 |
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
|
529 |
|
1980
6c5917cfcb78
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1977
diff
changeset
|
530 |
if (flags & DC_EXEC) SndPlayTileFx(SND_20_SPLAT_2, TileVirtXY(x, y)); |
0 | 531 |
|
2952 | 532 |
for (;;) { |
2604
e3e60351c067
(svn r3141) Replace incorrect railtype bitmask in CmdRailTrackHelper with appropriate GB()
peter1138
parents:
2549
diff
changeset
|
533 |
ret = DoCommand(x, y, railtype, TrackdirToTrack(trackdir), flags, (mode == 0) ? CMD_BUILD_SINGLE_RAIL : CMD_REMOVE_SINGLE_RAIL); |
0 | 534 |
|
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
|
535 |
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
|
536 |
if ((_error_message != STR_1007_ALREADY_BUILT) && (mode == 0)) |
0 | 537 |
break; |
538 |
} else |
|
539 |
total_cost += ret; |
|
540 |
||
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
|
541 |
if (x == ex && y == ey) |
0 | 542 |
break; |
543 |
||
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
544 |
x += _railbit.xinc[trackdir]; |
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
545 |
y += _railbit.yinc[trackdir]; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
546 |
|
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
|
547 |
// 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
|
548 |
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
|
549 |
} |
0 | 550 |
|
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
|
551 |
return (total_cost == 0) ? CMD_ERROR : total_cost; |
0 | 552 |
} |
553 |
||
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
|
554 |
/** 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
|
555 |
* 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
|
556 |
* @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
|
557 |
*/ |
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
|
558 |
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
|
559 |
{ |
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
|
560 |
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
|
561 |
} |
0 | 562 |
|
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
|
563 |
/** 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
|
564 |
* 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
|
565 |
* @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
|
566 |
*/ |
0 | 567 |
int32 CmdRemoveRailroadTrack(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
568 |
{ |
|
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
|
569 |
return CmdRailTrackHelper(x, y, flags, p1, SETBIT(p2, 7)); |
0 | 570 |
} |
571 |
||
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
|
572 |
/** 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
|
573 |
* @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
|
574 |
* @param p1 rail type |
3333 | 575 |
* @param p2 entrance direction (DiagDirection) |
2085
876f20a0e843
(svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents:
2049
diff
changeset
|
576 |
* |
876f20a0e843
(svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents:
2049
diff
changeset
|
577 |
* @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
|
578 |
* distingush between "Flat land required" and "land sloped in wrong direction" |
0 | 579 |
*/ |
580 |
int32 CmdBuildTrainDepot(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
581 |
{ |
|
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
|
582 |
Depot *d; |
1980
6c5917cfcb78
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1977
diff
changeset
|
583 |
TileIndex tile = TileVirtXY(x, y); |
0 | 584 |
int32 cost, ret; |
585 |
uint tileh; |
|
586 |
||
587 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
588 |
||
589 |
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
|
590 |
/* 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
|
591 |
if (!ValParamRailtype(p1) || p2 > 3) return CMD_ERROR; |
0 | 592 |
|
593 |
tileh = GetTileSlope(tile, NULL); |
|
2085
876f20a0e843
(svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents:
2049
diff
changeset
|
594 |
|
876f20a0e843
(svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents:
2049
diff
changeset
|
595 |
/* Prohibit construction if |
876f20a0e843
(svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents:
2049
diff
changeset
|
596 |
The tile is non-flat AND |
876f20a0e843
(svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents:
2049
diff
changeset
|
597 |
1) The AI is "old-school" |
876f20a0e843
(svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents:
2049
diff
changeset
|
598 |
2) build-on-slopes is disabled |
876f20a0e843
(svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents:
2049
diff
changeset
|
599 |
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
|
600 |
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
|
601 |
|
876f20a0e843
(svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents:
2049
diff
changeset
|
602 |
*/ |
876f20a0e843
(svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents:
2049
diff
changeset
|
603 |
|
876f20a0e843
(svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents:
2049
diff
changeset
|
604 |
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
|
605 |
_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
|
606 |
!_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
|
607 |
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
|
608 |
!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
|
609 |
)) { |
49c8a096033f
(svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents:
2544
diff
changeset
|
610 |
return_cmd_error(STR_0007_FLAT_LAND_REQUIRED); |
0 | 611 |
} |
612 |
||
613 |
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
|
614 |
if (CmdFailed(ret)) return CMD_ERROR; |
0 | 615 |
cost = ret; |
616 |
||
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
|
617 |
d = AllocateDepot(); |
2639 | 618 |
if (d == NULL) return CMD_ERROR; |
0 | 619 |
|
620 |
if (flags & DC_EXEC) { |
|
2425
e755ee29133a
(svn r2951) - Fix: [ 1259345 ] Changing engine in netgame opens train window for everyone
Darkvater
parents:
2422
diff
changeset
|
621 |
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
|
622 |
|
3101
a44fdf9faef1
(svn r3696) Add functions to turn a tile into a normal rail tile/depot/waypoint. This is just a tiny step, the rail code needs way more love and caring
tron
parents:
3099
diff
changeset
|
623 |
MakeRailDepot(tile, _current_player, p2, p1); |
a44fdf9faef1
(svn r3696) Add functions to turn a tile into a normal rail tile/depot/waypoint. This is just a tiny step, the rail code needs way more love and caring
tron
parents:
3099
diff
changeset
|
624 |
MarkTileDirtyByTile(tile); |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
625 |
|
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
|
626 |
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
|
627 |
d->town_index = ClosestTownFromTile(tile, (uint)-1)->index; |
0 | 628 |
|
3191
b2bebf380cd7
(svn r3851) Rail depots only have an entrance at one side, therefore use UpdateSignalsOnSegment() instead of SetSignalsOnBothDir()
tron
parents:
3189
diff
changeset
|
629 |
UpdateSignalsOnSegment(tile, p2); |
0 | 630 |
} |
631 |
||
632 |
return cost + _price.build_train_depot; |
|
633 |
} |
|
634 |
||
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
|
635 |
/** 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
|
636 |
* 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
|
637 |
* @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
|
638 |
* @param p1 various bitstuffed elements |
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
639 |
* - 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
|
640 |
* - 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
|
641 |
* @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
|
642 |
* 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
|
643 |
*/ |
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
|
644 |
int32 CmdBuildSingleSignal(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
0 | 645 |
{ |
1980
6c5917cfcb78
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1977
diff
changeset
|
646 |
TileIndex tile = TileVirtXY(x, y); |
3237
2cf19f9603b2
(svn r3911) Add functions to retrieve/set the signal variant (electric/semaphore)
tron
parents:
3234
diff
changeset
|
647 |
SignalVariant sigvar; |
1084 | 648 |
bool pre_signal; |
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
649 |
Track track = (Track)(p1 & 0x7); |
0 | 650 |
int32 cost; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
651 |
|
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
652 |
// Same bit, used in different contexts |
3237
2cf19f9603b2
(svn r3911) Add functions to retrieve/set the signal variant (electric/semaphore)
tron
parents:
3234
diff
changeset
|
653 |
sigvar = HASBIT(p1, 3) ? SIG_SEMAPHORE : SIG_ELECTRIC; |
2cf19f9603b2
(svn r3911) Add functions to retrieve/set the signal variant (electric/semaphore)
tron
parents:
3234
diff
changeset
|
654 |
pre_signal = HASBIT(p1, 3); |
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
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 |
if (!ValParamTrackOrientation(track) || !IsTileType(tile, MP_RAILWAY) || !EnsureNoVehicle(tile)) |
0 | 657 |
return CMD_ERROR; |
658 |
||
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
|
659 |
/* Protect against invalid signal copying */ |
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
660 |
if (p2 != 0 && (p2 & SignalOnTrack(track)) == 0) return CMD_ERROR; |
0 | 661 |
|
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
662 |
/* 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
|
663 |
if (!IsPlainRailTile(tile) || !HasTrack(tile, track)) return CMD_ERROR; |
1084 | 664 |
|
665 |
if (!CheckTileOwnership(tile)) return CMD_ERROR; |
|
666 |
||
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
|
667 |
_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
|
668 |
|
0 | 669 |
{ |
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
670 |
/* 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
|
671 |
TrackBits trackbits = GetTrackBits(tile); |
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
672 |
if (KILL_FIRST_BIT(trackbits) != 0 && /* More than one track present */ |
3258
1c079364726d
(svn r3946) Add short hand names for common track combinations
tron
parents:
3254
diff
changeset
|
673 |
trackbits != TRACK_BIT_HORZ && |
1c079364726d
(svn r3946) Add short hand names for common track combinations
tron
parents:
3254
diff
changeset
|
674 |
trackbits != TRACK_BIT_VERT |
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
675 |
) |
0 | 676 |
return CMD_ERROR; |
677 |
} |
|
678 |
||
1084 | 679 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
0 | 680 |
|
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
681 |
if (!HasSignalOnTrack(tile, track)) { |
1084 | 682 |
// build new signals |
0 | 683 |
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
|
684 |
} else { |
3237
2cf19f9603b2
(svn r3911) Add functions to retrieve/set the signal variant (electric/semaphore)
tron
parents:
3234
diff
changeset
|
685 |
if (p2 != 0 && sigvar != GetSignalVariant(tile)) { |
1084 | 686 |
// convert signals <-> semaphores |
687 |
cost = _price.build_signals + _price.remove_signals; |
|
688 |
} else { |
|
689 |
// it is free to change orientation/pre-exit-combo signals |
|
690 |
cost = 0; |
|
691 |
} |
|
0 | 692 |
} |
693 |
||
694 |
if (flags & DC_EXEC) { |
|
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
695 |
if (GetRailTileType(tile) != RAIL_TYPE_SIGNALS) { |
1084 | 696 |
// 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
|
697 |
_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
|
698 |
_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
|
699 |
_m[tile].m3 &= ~0xF0; // no signals built by default |
3237
2cf19f9603b2
(svn r3911) Add functions to retrieve/set the signal variant (electric/semaphore)
tron
parents:
3234
diff
changeset
|
700 |
_m[tile].m4 = 0; |
2cf19f9603b2
(svn r3911) Add functions to retrieve/set the signal variant (electric/semaphore)
tron
parents:
3234
diff
changeset
|
701 |
SetSignalVariant(tile, sigvar); |
0 | 702 |
} |
703 |
||
1084 | 704 |
if (p2 == 0) { |
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
705 |
if (!HasSignalOnTrack(tile, track)) { |
1084 | 706 |
// 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
|
707 |
_m[tile].m3 |= SignalOnTrack(track); |
1084 | 708 |
} else { |
709 |
if (pre_signal) { |
|
2916
b687477adcba
(svn r3472) - [PBS] Remove from trunk. Anyone interested can still find it in branch/pbs. This reverts revisions r3158, r3140, r3075, r2977, r2674, r2625, r2621, r2529, r2528, r2525, r2524, r2519, r2517, r2516, r2507, r2499. (in conjunction with Tron)
Darkvater
parents:
2911
diff
changeset
|
710 |
// cycle between normal -> pre -> exit -> combo -> ... |
3238
9ebec0a611ee
(svn r3912) Move the signal type enum and GetSignalType() to rail_map.h; also add SetSignalType() and use the functions
tron
parents:
3237
diff
changeset
|
711 |
SignalType type = GetSignalType(tile); |
9ebec0a611ee
(svn r3912) Move the signal type enum and GetSignalType() to rail_map.h; also add SetSignalType() and use the functions
tron
parents:
3237
diff
changeset
|
712 |
|
9ebec0a611ee
(svn r3912) Move the signal type enum and GetSignalType() to rail_map.h; also add SetSignalType() and use the functions
tron
parents:
3237
diff
changeset
|
713 |
SetSignalType(tile, type == SIGTYPE_COMBO ? SIGTYPE_NORMAL : type + 1); |
1084 | 714 |
} else { |
715 |
// 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
|
716 |
/* TODO: Rewrite switch into something more general */ |
1084 | 717 |
switch (track) { |
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
718 |
case TRACK_LOWER: |
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
719 |
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
|
720 |
byte signal = (_m[tile].m3 - 0x10) & 0x30; |
1084 | 721 |
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
|
722 |
_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
|
723 |
_m[tile].m3 |= signal; |
1084 | 724 |
break; |
725 |
} |
|
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
|
726 |
|
1084 | 727 |
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
|
728 |
byte signal = (_m[tile].m3 - 0x40) & 0xC0; |
1084 | 729 |
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
|
730 |
_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
|
731 |
_m[tile].m3 |= signal; |
1084 | 732 |
break; |
733 |
} |
|
734 |
} |
|
735 |
} |
|
736 |
} |
|
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
|
737 |
} else { |
1084 | 738 |
/* 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
|
739 |
* 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
|
740 |
_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
|
741 |
_m[tile].m3 |= p2 & SignalOnTrack(track); |
3237
2cf19f9603b2
(svn r3911) Add functions to retrieve/set the signal variant (electric/semaphore)
tron
parents:
3234
diff
changeset
|
742 |
SetSignalVariant(tile, sigvar); |
0 | 743 |
} |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
744 |
|
0 | 745 |
MarkTileDirtyByTile(tile); |
746 |
SetSignalsOnBothDir(tile, track); |
|
747 |
} |
|
748 |
||
749 |
return cost; |
|
750 |
} |
|
751 |
||
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
|
752 |
/** 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
|
753 |
* @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
|
754 |
* @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
|
755 |
* @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
|
756 |
* - 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
|
757 |
* - 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
|
758 |
* - 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
|
759 |
* - 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
|
760 |
*/ |
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
|
761 |
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
|
762 |
{ |
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
|
763 |
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
|
764 |
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
|
765 |
byte signals; |
1980
6c5917cfcb78
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1977
diff
changeset
|
766 |
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
|
767 |
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
|
768 |
|
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
|
769 |
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
|
770 |
Track track = GB(p2, 4, 3); |
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
771 |
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
|
772 |
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
|
773 |
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
|
774 |
|
2934
3f29a7212713
(svn r3490) -Fix: A bunch (10) of off-by-one errors when checking if a TileIndex points to a tile on the map
tron
parents:
2916
diff
changeset
|
775 |
if (p1 >= MapSize()) return CMD_ERROR; |
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
|
776 |
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
|
777 |
|
2639 | 778 |
if (!IsTileType(tile, MP_RAILWAY)) return CMD_ERROR; |
1954
2beb56cfddbb
(svn r2460) - Fix: Prevent assertion failure when trying to drag signals starting from a non-rail tile.
hackykid
parents:
1946
diff
changeset
|
779 |
|
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
|
780 |
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
|
781 |
|
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
|
782 |
/* 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
|
783 |
* 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
|
784 |
if (!IsDiagonalTrack(track)) |
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
785 |
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
|
786 |
|
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
|
787 |
// unpack end tile |
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
788 |
ex = TileX(p1) * TILE_SIZE; |
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
789 |
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
|
790 |
|
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
791 |
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
|
792 |
|
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
793 |
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
|
794 |
|
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
|
795 |
// 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
|
796 |
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
|
797 |
signals = _m[tile].m3 & SignalOnTrack(track); |
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
798 |
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
|
799 |
|
3237
2cf19f9603b2
(svn r3911) Add functions to retrieve/set the signal variant (electric/semaphore)
tron
parents:
3234
diff
changeset
|
800 |
// copy signal/semaphores style (independent of CTRL) |
2cf19f9603b2
(svn r3911) Add functions to retrieve/set the signal variant (electric/semaphore)
tron
parents:
3234
diff
changeset
|
801 |
semaphores = (GetSignalVariant(tile) == SIG_ELECTRIC ? 0 : 8); |
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
|
802 |
} 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
|
803 |
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
|
804 |
|
1954
2beb56cfddbb
(svn r2460) - Fix: Prevent assertion failure when trying to drag signals starting from a non-rail tile.
hackykid
parents:
1946
diff
changeset
|
805 |
/* 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
|
806 |
* 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
|
807 |
********** |
1954
2beb56cfddbb
(svn r2460) - Fix: Prevent assertion failure when trying to drag signals starting from a non-rail tile.
hackykid
parents:
1946
diff
changeset
|
808 |
* 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
|
809 |
* semaphores - semaphores or signals |
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
810 |
* 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
|
811 |
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
|
812 |
* 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
|
813 |
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
|
814 |
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
|
815 |
// 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
|
816 |
if ((signal_ctr % signal_density) == 0 ) { |
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
817 |
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
|
818 |
|
826 | 819 |
/* 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
|
820 |
* 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
|
821 |
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
|
822 |
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
|
823 |
} 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
|
824 |
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
|
825 |
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
|
826 |
} |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
827 |
} |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
828 |
|
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
|
829 |
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
|
830 |
|
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
831 |
x += _railbit.xinc[trackdir]; |
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
832 |
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
|
833 |
signal_ctr++; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
834 |
|
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
|
835 |
// 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
|
836 |
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
|
837 |
} |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
838 |
|
2951 | 839 |
return error ? CMD_ERROR : total_cost; |
58
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
840 |
} |
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
39
diff
changeset
|
841 |
|
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
|
842 |
/** 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
|
843 |
* 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
|
844 |
* @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
|
845 |
*/ |
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
|
846 |
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
|
847 |
{ |
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
|
848 |
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
|
849 |
} |
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
|
850 |
|
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
|
851 |
/** 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
|
852 |
* @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
|
853 |
* @param p1 track to remove signal from (Track enum) |
0 | 854 |
*/ |
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
|
855 |
int32 CmdRemoveSingleSignal(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
0 | 856 |
{ |
1980
6c5917cfcb78
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1977
diff
changeset
|
857 |
TileIndex tile = TileVirtXY(x, y); |
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
858 |
Track track = (Track)(p1 & 0x7); |
1518
9a876c45238b
(svn r2022) Revise CmdRemoveSingleSignal: Check parameters for validity and simplify the function
tron
parents:
1477
diff
changeset
|
859 |
|
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
|
860 |
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
|
861 |
return CMD_ERROR; |
9a876c45238b
(svn r2022) Revise CmdRemoveSingleSignal: Check parameters for validity and simplify the function
tron
parents:
1477
diff
changeset
|
862 |
|
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
863 |
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
|
864 |
return CMD_ERROR; |
9a876c45238b
(svn r2022) Revise CmdRemoveSingleSignal: Check parameters for validity and simplify the function
tron
parents:
1477
diff
changeset
|
865 |
|
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
|
866 |
/* 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
|
867 |
if (_current_player != OWNER_WATER && !CheckTileOwnership(tile)) return CMD_ERROR; |
0 | 868 |
|
869 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
870 |
||
871 |
/* Do it? */ |
|
872 |
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
|
873 |
_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
|
874 |
|
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
|
875 |
/* removed last signal from tile? */ |
2493
f6b4300cc2b0
(svn r3019) -Codechange: Replace explicit shifting/anding/oring with GB and SB
tron
parents:
2472
diff
changeset
|
876 |
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
|
877 |
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
|
878 |
SB(_m[tile].m5, 6, 2, RAIL_TYPE_NORMAL >> 6); // XXX >> because the constant is meant for direct application, not use with SB |
3237
2cf19f9603b2
(svn r3911) Add functions to retrieve/set the signal variant (electric/semaphore)
tron
parents:
3234
diff
changeset
|
879 |
SetSignalVariant(tile, SIG_ELECTRIC); // 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
|
880 |
} |
1109
ecb98f43ba2c
(svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents:
1095
diff
changeset
|
881 |
|
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
|
882 |
SetSignalsOnBothDir(tile, track); |
0 | 883 |
|
884 |
MarkTileDirtyByTile(tile); |
|
885 |
} |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
886 |
|
0 | 887 |
return _price.remove_signals; |
888 |
} |
|
889 |
||
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
|
890 |
/** 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
|
891 |
* 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
|
892 |
* @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
|
893 |
*/ |
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
|
894 |
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
|
895 |
{ |
1229
f698e29a6908
(svn r1733) - Fix: oops "| 1" is SETBIT(x, 0), not 1 :(. Now you can remove signals again
darkvater
parents:
1227
diff
changeset
|
896 |
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
|
897 |
} |
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
|
898 |
|
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1963
diff
changeset
|
899 |
typedef int32 DoConvertRailProc(TileIndex tile, uint totype, bool exec); |
0 | 900 |
|
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1963
diff
changeset
|
901 |
static int32 DoConvertRail(TileIndex tile, uint totype, bool exec) |
0 | 902 |
{ |
2549 | 903 |
if (!CheckTileOwnership(tile) || !EnsureNoVehicle(tile)) return CMD_ERROR; |
0 | 904 |
|
905 |
// tile is already of requested type? |
|
2549 | 906 |
if (GetRailType(tile) == totype) return CMD_ERROR; |
0 | 907 |
|
908 |
// change type. |
|
909 |
if (exec) { |
|
3242
4c32bf21153b
(svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents:
3238
diff
changeset
|
910 |
SetRailType(tile, totype); |
0 | 911 |
MarkTileDirtyByTile(tile); |
912 |
} |
|
913 |
||
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
914 |
return _price.build_rail / 2; |
0 | 915 |
} |
916 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1963
diff
changeset
|
917 |
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
|
918 |
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
|
919 |
extern int32 DoConvertTunnelBridgeRail(TileIndex tile, uint totype, bool exec); |
0 | 920 |
|
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
921 |
/** 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
|
922 |
* monorail/maglev easily or vice-versa. |
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
923 |
* @param ex,ey end tile of rail conversion drag |
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
924 |
* @param p1 start tile of drag |
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
925 |
* @param p2 new railtype to convert to |
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
926 |
*/ |
0 | 927 |
int32 CmdConvertRail(int ex, int ey, uint32 flags, uint32 p1, uint32 p2) |
928 |
{ |
|
929 |
int32 ret, cost, money; |
|
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
930 |
int sx, sy, x, y; |
0 | 931 |
|
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
|
932 |
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
|
933 |
|
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
934 |
if (!ValParamRailtype(p2)) return CMD_ERROR; |
2934
3f29a7212713
(svn r3490) -Fix: A bunch (10) of off-by-one errors when checking if a TileIndex points to a tile on the map
tron
parents:
2916
diff
changeset
|
935 |
if (p1 >= MapSize()) return CMD_ERROR; |
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
936 |
|
0 | 937 |
// 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
|
938 |
sx = TileX(p1) * TILE_SIZE; |
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
939 |
sy = TileY(p1) * TILE_SIZE; |
0 | 940 |
if (ex < sx) intswap(ex, sx); |
941 |
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
|
942 |
|
0 | 943 |
money = GetAvailableMoneyForCommand(); |
944 |
cost = 0; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
945 |
|
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
946 |
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
|
947 |
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
|
948 |
TileIndex tile = TileVirtXY(x, y); |
2549 | 949 |
DoConvertRailProc* proc; |
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
950 |
|
2549 | 951 |
switch (GetTileType(tile)) { |
952 |
case MP_RAILWAY: proc = DoConvertRail; break; |
|
953 |
case MP_STATION: proc = DoConvertStationRail; break; |
|
954 |
case MP_STREET: proc = DoConvertStreetRail; break; |
|
955 |
case MP_TUNNELBRIDGE: proc = DoConvertTunnelBridgeRail; break; |
|
956 |
default: continue; |
|
957 |
} |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
958 |
|
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
959 |
ret = proc(tile, p2, false); |
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
960 |
if (CmdFailed(ret)) continue; |
0 | 961 |
cost += ret; |
962 |
||
963 |
if (flags & DC_EXEC) { |
|
2549 | 964 |
money -= ret; |
965 |
if (money < 0) { |
|
966 |
_additional_cash_required = ret; |
|
967 |
return cost - ret; |
|
968 |
} |
|
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
969 |
proc(tile, p2, true); |
0 | 970 |
} |
971 |
} |
|
972 |
} |
|
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
973 |
|
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
974 |
return (cost == 0) ? CMD_ERROR : cost; |
0 | 975 |
} |
976 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1963
diff
changeset
|
977 |
static int32 RemoveTrainDepot(TileIndex tile, uint32 flags) |
0 | 978 |
{ |
149
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
84
diff
changeset
|
979 |
if (!CheckTileOwnership(tile) && _current_player != OWNER_WATER) |
0 | 980 |
return CMD_ERROR; |
981 |
||
982 |
if (!EnsureNoVehicle(tile)) |
|
983 |
return CMD_ERROR; |
|
984 |
||
985 |
if (flags & DC_EXEC) { |
|
3191
b2bebf380cd7
(svn r3851) Rail depots only have an entrance at one side, therefore use UpdateSignalsOnSegment() instead of SetSignalsOnBothDir()
tron
parents:
3189
diff
changeset
|
986 |
DiagDirection dir = GetRailDepotDirection(tile); |
0 | 987 |
|
988 |
DoDeleteDepot(tile); |
|
3191
b2bebf380cd7
(svn r3851) Rail depots only have an entrance at one side, therefore use UpdateSignalsOnSegment() instead of SetSignalsOnBothDir()
tron
parents:
3189
diff
changeset
|
989 |
UpdateSignalsOnSegment(tile, dir); |
0 | 990 |
} |
991 |
||
992 |
return _price.remove_train_depot; |
|
993 |
} |
|
994 |
||
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
|
995 |
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
|
996 |
{ |
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
|
997 |
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
|
998 |
int32 ret; |
0 | 999 |
byte m5; |
1000 |
||
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
|
1001 |
m5 = _m[tile].m5; |
0 | 1002 |
|
1003 |
if (flags & DC_AUTO) { |
|
3253 | 1004 |
if (GetRailTileType(tile) == RAIL_TYPE_DEPOT_WAYPOINT) { |
0 | 1005 |
return_cmd_error(STR_2004_BUILDING_MUST_BE_DEMOLISHED); |
3253 | 1006 |
} |
0 | 1007 |
|
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
|
1008 |
if (!IsTileOwner(tile, _current_player)) |
0 | 1009 |
return_cmd_error(STR_1024_AREA_IS_OWNED_BY_ANOTHER); |
1010 |
||
1011 |
return_cmd_error(STR_1008_MUST_REMOVE_RAILROAD_TRACK); |
|
1012 |
} |
|
1013 |
||
1014 |
cost = 0; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1015 |
|
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
1016 |
switch (GetRailTileType(tile)) { |
2821
cb5abbcc0f0c
(svn r3369) - Codechange: Replace tables _signals_table, _signals_table_other and _signals_table_both by the equivalent calls to rail.h functions.
matthijs
parents:
2817
diff
changeset
|
1017 |
/* XXX: Why the fuck do we remove these thow signals first? */ |
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
|
1018 |
case RAIL_TYPE_SIGNALS: |
3102
f9ca4379db9d
(svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron
parents:
3101
diff
changeset
|
1019 |
if (HasSignalOnTrack(tile, TRACK_X)) { |
f9ca4379db9d
(svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron
parents:
3101
diff
changeset
|
1020 |
ret = DoCommandByTile(tile, TRACK_X, 0, flags, CMD_REMOVE_SIGNALS); |
2737
fb1556b8f5e0
(svn r3282) - Codechange: Replace tests against CMD_ERROR with CmdFailed()
peter1138
parents:
2670
diff
changeset
|
1021 |
if (CmdFailed(ret)) return CMD_ERROR; |
0 | 1022 |
cost += ret; |
1023 |
} |
|
2951 | 1024 |
if (HasSignalOnTrack(tile, TRACK_LOWER)) { |
2821
cb5abbcc0f0c
(svn r3369) - Codechange: Replace tables _signals_table, _signals_table_other and _signals_table_both by the equivalent calls to rail.h functions.
matthijs
parents:
2817
diff
changeset
|
1025 |
ret = DoCommandByTile(tile, TRACK_LOWER, 0, flags, CMD_REMOVE_SIGNALS); |
2737
fb1556b8f5e0
(svn r3282) - Codechange: Replace tests against CMD_ERROR with CmdFailed()
peter1138
parents:
2670
diff
changeset
|
1026 |
if (CmdFailed(ret)) 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
|
1027 |
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
|
1028 |
} |
0 | 1029 |
|
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
1030 |
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
|
1031 |
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
|
1032 |
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
|
1033 |
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
|
1034 |
} |
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
|
1035 |
/* FALLTHROUGH */ |
1109
ecb98f43ba2c
(svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents:
1095
diff
changeset
|
1036 |
|
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
|
1037 |
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
|
1038 |
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
|
1039 |
|
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
|
1040 |
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
|
1041 |
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
|
1042 |
ret = DoCommandByTile(tile, 0, i, flags, CMD_REMOVE_SINGLE_RAIL); |
2737
fb1556b8f5e0
(svn r3282) - Codechange: Replace tests against CMD_ERROR with CmdFailed()
peter1138
parents:
2670
diff
changeset
|
1043 |
if (CmdFailed(ret)) 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
|
1044 |
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
|
1045 |
} |
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
|
1046 |
} |
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
|
1047 |
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
|
1048 |
} |
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
|
1049 |
|
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
1050 |
case RAIL_TYPE_DEPOT_WAYPOINT: |
3269
62fb247bf94b
(svn r3981) More work for the rail accessing functions and enums
tron
parents:
3267
diff
changeset
|
1051 |
if (GetRailTileSubtype(tile) == RAIL_SUBTYPE_DEPOT) { |
62fb247bf94b
(svn r3981) More work for the rail accessing functions and enums
tron
parents:
3267
diff
changeset
|
1052 |
return RemoveTrainDepot(tile, flags); |
62fb247bf94b
(svn r3981) More work for the rail accessing functions and enums
tron
parents:
3267
diff
changeset
|
1053 |
} else { |
62fb247bf94b
(svn r3981) More work for the rail accessing functions and enums
tron
parents:
3267
diff
changeset
|
1054 |
return RemoveTrainWaypoint(tile, flags, false); |
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
|
1055 |
} |
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
|
1056 |
|
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
|
1057 |
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
|
1058 |
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
|
1059 |
} |
0 | 1060 |
} |
1061 |
||
1062 |
||
1063 |
||
1064 |
#include "table/track_land.h" |
|
1065 |
||
1066 |
// used for presignals |
|
2916
b687477adcba
(svn r3472) - [PBS] Remove from trunk. Anyone interested can still find it in branch/pbs. This reverts revisions r3158, r3140, r3075, r2977, r2674, r2625, r2621, r2529, r2528, r2525, r2524, r2519, r2517, r2516, r2507, r2499. (in conjunction with Tron)
Darkvater
parents:
2911
diff
changeset
|
1067 |
static const SpriteID _signal_base_sprites[16] = { |
0 | 1068 |
0x4FB, |
1069 |
0x1323, |
|
1070 |
0x1333, |
|
1071 |
0x1343, |
|
1072 |
||
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
|
1073 |
// semaphores |
0 | 1074 |
0x1353, |
1075 |
0x1363, |
|
1076 |
0x1373, |
|
1077 |
0x1383, |
|
1078 |
||
1079 |
// mirrored versions |
|
1080 |
0x4FB, |
|
1081 |
0x1323, |
|
1082 |
0x1333, |
|
1083 |
0x1343, |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1084 |
|
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
|
1085 |
// 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
|
1086 |
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
|
1087 |
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
|
1088 |
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
|
1089 |
0x1476, |
0 | 1090 |
}; |
1091 |
||
1092 |
// used to determine the side of the road for the signal |
|
1093 |
static const byte _signal_position[24] = { |
|
1094 |
/* original: left side position */ |
|
2951 | 1095 |
0x58, 0x1E, 0xE1, 0xB9, 0x01, 0xA3, 0x4B, 0xEE, 0x3B, 0xD4, 0x43, 0xBD, |
0 | 1096 |
/* patch: ride side position */ |
2951 | 1097 |
0x1E, 0xAC, 0x64, 0xE1, 0x4A, 0x10, 0xEE, 0xC5, 0xDB, 0x34, 0x4D, 0xB3 |
0 | 1098 |
}; |
1099 |
||
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
|
1100 |
static void DrawSignalHelper(const TileInfo *ti, byte condition, uint32 image_and_pos) |
0 | 1101 |
{ |
1102 |
bool otherside = _opt.road_side & _patches.signal_side; |
|
1103 |
||
1104 |
uint v = _signal_position[(image_and_pos & 0xF) + (otherside ? 12 : 0)]; |
|
1105 |
uint x = ti->x | (v&0xF); |
|
1106 |
uint y = ti->y | (v>>4); |
|
2916
b687477adcba
(svn r3472) - [PBS] Remove from trunk. Anyone interested can still find it in branch/pbs. This reverts revisions r3158, r3140, r3075, r2977, r2674, r2625, r2621, r2529, r2528, r2525, r2524, r2519, r2517, r2516, r2507, r2499. (in conjunction with Tron)
Darkvater
parents:
2911
diff
changeset
|
1107 |
uint sprite = _signal_base_sprites[(_m[ti->tile].m4 & 0x7) + (otherside ? 8 : 0)] + (image_and_pos>>4) + ((condition != 0) ? 1 : 0); |
0 | 1108 |
AddSortableSpriteToDraw(sprite, x, y, 1, 1, 10, GetSlopeZ(x,y)); |
1109 |
} |
|
1110 |
||
1111 |
static uint32 _drawtile_track_palette; |
|
1112 |
||
1113 |
||
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
|
1114 |
static void DrawTrackFence_NW(const TileInfo *ti) |
0 | 1115 |
{ |
1116 |
uint32 image = 0x515; |
|
2645
841087328e0e
(svn r3187) Simplify overly complicated ifs, especially if (foo) return false; else return true; is confusing
tron
parents:
2642
diff
changeset
|
1117 |
if (ti->tileh != 0) image = (ti->tileh & 2) ? 0x519 : 0x51B; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1118 |
AddSortableSpriteToDraw(image | _drawtile_track_palette, |
2951 | 1119 |
ti->x, ti->y + 1, 16, 1, 4, ti->z); |
0 | 1120 |
} |
1121 |
||
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
|
1122 |
static void DrawTrackFence_SE(const TileInfo *ti) |
0 | 1123 |
{ |
1124 |
uint32 image = 0x515; |
|
2645
841087328e0e
(svn r3187) Simplify overly complicated ifs, especially if (foo) return false; else return true; is confusing
tron
parents:
2642
diff
changeset
|
1125 |
if (ti->tileh != 0) image = (ti->tileh & 2) ? 0x519 : 0x51B; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1126 |
AddSortableSpriteToDraw(image | _drawtile_track_palette, |
2951 | 1127 |
ti->x, ti->y + 15, 16, 1, 4, ti->z); |
0 | 1128 |
} |
1129 |
||
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
|
1130 |
static void DrawTrackFence_NW_SE(const TileInfo *ti) |
0 | 1131 |
{ |
1132 |
DrawTrackFence_NW(ti); |
|
1133 |
DrawTrackFence_SE(ti); |
|
1134 |
} |
|
1135 |
||
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
|
1136 |
static void DrawTrackFence_NE(const TileInfo *ti) |
0 | 1137 |
{ |
1138 |
uint32 image = 0x516; |
|
2645
841087328e0e
(svn r3187) Simplify overly complicated ifs, especially if (foo) return false; else return true; is confusing
tron
parents:
2642
diff
changeset
|
1139 |
if (ti->tileh != 0) image = (ti->tileh & 2) ? 0x51A : 0x51C; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1140 |
AddSortableSpriteToDraw(image | _drawtile_track_palette, |
2951 | 1141 |
ti->x + 1, ti->y, 1, 16, 4, ti->z); |
0 | 1142 |
} |
1143 |
||
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
|
1144 |
static void DrawTrackFence_SW(const TileInfo *ti) |
0 | 1145 |
{ |
1146 |
uint32 image = 0x516; |
|
2645
841087328e0e
(svn r3187) Simplify overly complicated ifs, especially if (foo) return false; else return true; is confusing
tron
parents:
2642
diff
changeset
|
1147 |
if (ti->tileh != 0) image = (ti->tileh & 2) ? 0x51A : 0x51C; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1148 |
AddSortableSpriteToDraw(image | _drawtile_track_palette, |
2951 | 1149 |
ti->x + 15, ti->y, 1, 16, 4, ti->z); |
0 | 1150 |
} |
1151 |
||
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
|
1152 |
static void DrawTrackFence_NE_SW(const TileInfo *ti) |
0 | 1153 |
{ |
1154 |
DrawTrackFence_NE(ti); |
|
1155 |
DrawTrackFence_SW(ti); |
|
1156 |
} |
|
1157 |
||
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
|
1158 |
static void DrawTrackFence_NS_1(const TileInfo *ti) |
0 | 1159 |
{ |
1160 |
int z = ti->z; |
|
2639 | 1161 |
if (ti->tileh & 1) z += 8; |
0 | 1162 |
AddSortableSpriteToDraw(0x517 | _drawtile_track_palette, |
1163 |
ti->x + 8, ti->y + 8, 1, 1, 4, z); |
|
1164 |
} |
|
1165 |
||
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
|
1166 |
static void DrawTrackFence_NS_2(const TileInfo *ti) |
0 | 1167 |
{ |
1168 |
int z = ti->z; |
|
2639 | 1169 |
if (ti->tileh & 4) z += 8; |
0 | 1170 |
AddSortableSpriteToDraw(0x517 | _drawtile_track_palette, |
1171 |
ti->x + 8, ti->y + 8, 1, 1, 4, z); |
|
1172 |
} |
|
1173 |
||
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
|
1174 |
static void DrawTrackFence_WE_1(const TileInfo *ti) |
0 | 1175 |
{ |
1176 |
int z = ti->z; |
|
2639 | 1177 |
if (ti->tileh & 8) z += 8; |
0 | 1178 |
AddSortableSpriteToDraw(0x518 | _drawtile_track_palette, |
1179 |
ti->x + 8, ti->y + 8, 1, 1, 4, z); |
|
1180 |
} |
|
1181 |
||
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
|
1182 |
static void DrawTrackFence_WE_2(const TileInfo *ti) |
0 | 1183 |
{ |
1184 |
int z = ti->z; |
|
2639 | 1185 |
if (ti->tileh & 2) z += 8; |
0 | 1186 |
AddSortableSpriteToDraw(0x518 | _drawtile_track_palette, |
1187 |
ti->x + 8, ti->y + 8, 1, 1, 4, z); |
|
1188 |
} |
|
1189 |
||
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
|
1190 |
static void DetTrackDrawProc_Null(const TileInfo *ti) |
0 | 1191 |
{ |
1192 |
/* nothing should be here */ |
|
1193 |
} |
|
1194 |
||
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
|
1195 |
typedef void DetailedTrackProc(const TileInfo *ti); |
2752 | 1196 |
static DetailedTrackProc* const _detailed_track_proc[] = { |
0 | 1197 |
DetTrackDrawProc_Null, |
1198 |
DetTrackDrawProc_Null, |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1199 |
|
0 | 1200 |
DrawTrackFence_NW, |
1201 |
DrawTrackFence_SE, |
|
1202 |
DrawTrackFence_NW_SE, |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1203 |
|
0 | 1204 |
DrawTrackFence_NE, |
1205 |
DrawTrackFence_SW, |
|
1206 |
DrawTrackFence_NE_SW, |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1207 |
|
0 | 1208 |
DrawTrackFence_NS_1, |
1209 |
DrawTrackFence_NS_2, |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1210 |
|
0 | 1211 |
DrawTrackFence_WE_1, |
1212 |
DrawTrackFence_WE_2, |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1213 |
|
0 | 1214 |
DetTrackDrawProc_Null, |
1215 |
DetTrackDrawProc_Null, |
|
1216 |
DetTrackDrawProc_Null, |
|
1217 |
DetTrackDrawProc_Null, |
|
1218 |
}; |
|
1219 |
||
2951 | 1220 |
static void DrawSpecialBuilding( |
1221 |
uint32 image, uint32 offset, |
|
1222 |
const TileInfo* ti, |
|
1223 |
byte x, byte y, byte z, |
|
1224 |
byte xsize, byte ysize, byte zsize) |
|
389
16ee9854091e
(svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents:
337
diff
changeset
|
1225 |
{ |
2549 | 1226 |
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
|
1227 |
image += offset; |
2549 | 1228 |
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
|
1229 |
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
|
1230 |
} |
16ee9854091e
(svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents:
337
diff
changeset
|
1231 |
|
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
|
1232 |
/** |
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
|
1233 |
* 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
|
1234 |
* @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
|
1235 |
* @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
|
1236 |
* @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
|
1237 |
* @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
|
1238 |
* @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
|
1239 |
*/ |
2817 | 1240 |
static void DrawTrackBits(TileInfo* ti, TrackBits track, bool earth, bool snow, bool flat) |
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
|
1241 |
{ |
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
|
1242 |
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
|
1243 |
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
|
1244 |
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
|
1245 |
|
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
|
1246 |
// Select the sprite to use. |
3102
f9ca4379db9d
(svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron
parents:
3101
diff
changeset
|
1247 |
(image = rti->base_sprites.track_y, track == TRACK_BIT_Y) || |
f9ca4379db9d
(svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron
parents:
3101
diff
changeset
|
1248 |
(image++, track == TRACK_BIT_X) || |
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
|
1249 |
(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
|
1250 |
(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
|
1251 |
(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
|
1252 |
(image++, track == TRACK_BIT_LEFT) || |
3258
1c079364726d
(svn r3946) Add short hand names for common track combinations
tron
parents:
3254
diff
changeset
|
1253 |
(image++, track == TRACK_BIT_CROSS) || |
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
|
1254 |
|
3258
1c079364726d
(svn r3946) Add short hand names for common track combinations
tron
parents:
3254
diff
changeset
|
1255 |
(image = rti->base_sprites.track_ns, track == TRACK_BIT_HORZ) || |
1c079364726d
(svn r3946) Add short hand names for common track combinations
tron
parents:
3254
diff
changeset
|
1256 |
(image++, track == TRACK_BIT_VERT) || |
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
|
1257 |
|
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
|
1258 |
(junction = true, false) || |
3258
1c079364726d
(svn r3946) Add short hand names for common track combinations
tron
parents:
3254
diff
changeset
|
1259 |
(image = rti->base_sprites.ground, (track & TRACK_BIT_3WAY_NE) == 0) || |
1c079364726d
(svn r3946) Add short hand names for common track combinations
tron
parents:
3254
diff
changeset
|
1260 |
(image++, (track & TRACK_BIT_3WAY_SW) == 0) || |
1c079364726d
(svn r3946) Add short hand names for common track combinations
tron
parents:
3254
diff
changeset
|
1261 |
(image++, (track & TRACK_BIT_3WAY_NW) == 0) || |
1c079364726d
(svn r3946) Add short hand names for common track combinations
tron
parents:
3254
diff
changeset
|
1262 |
(image++, (track & TRACK_BIT_3WAY_SE) == 0) || |
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
|
1263 |
(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
|
1264 |
|
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
|
1265 |
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
|
1266 |
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
|
1267 |
|
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
|
1268 |
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
|
1269 |
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
|
1270 |
} 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
|
1271 |
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
|
1272 |
} |
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
|
1273 |
|
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
|
1274 |
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
|
1275 |
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
|
1276 |
|
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
|
1277 |
// 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
|
1278 |
// 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
|
1279 |
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
|
1280 |
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
|
1281 |
} |
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
|
1282 |
|
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
|
1283 |
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
|
1284 |
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
|
1285 |
} 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
|
1286 |
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
|
1287 |
} |
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
|
1288 |
|
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
|
1289 |
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
|
1290 |
|
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
|
1291 |
// 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
|
1292 |
if (junction) { |
3102
f9ca4379db9d
(svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron
parents:
3101
diff
changeset
|
1293 |
if (track & TRACK_BIT_X) DrawGroundSprite(rti->base_sprites.single_y); |
f9ca4379db9d
(svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron
parents:
3101
diff
changeset
|
1294 |
if (track & TRACK_BIT_Y) DrawGroundSprite(rti->base_sprites.single_x); |
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
|
1295 |
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
|
1296 |
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
|
1297 |
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
|
1298 |
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
|
1299 |
} |
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
|
1300 |
} |
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
|
1301 |
|
0 | 1302 |
static void DrawTile_Track(TileInfo *ti) |
1303 |
{ |
|
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
|
1304 |
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
|
1305 |
PalSpriteID image; |
0 | 1306 |
|
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
|
1307 |
_drawtile_track_palette = SPRITE_PALETTE(PLAYER_SPRITE_COLOR(GetTileOwner(ti->tile))); |
0 | 1308 |
|
3253 | 1309 |
if (GetRailTileType(ti->tile) != RAIL_TYPE_DEPOT_WAYPOINT) { |
3267
feff95208a9f
(svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents:
3265
diff
changeset
|
1310 |
TrackBits rails = GetTrackBits(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
|
1311 |
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
|
1312 |
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
|
1313 |
|
3267
feff95208a9f
(svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents:
3265
diff
changeset
|
1314 |
DrawTrackBits(ti, rails, 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
|
1315 |
|
0 | 1316 |
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
|
1317 |
_detailed_track_proc[_m[ti->tile].m2 & RAIL_MAP2LO_GROUND_MASK](ti); |
0 | 1318 |
} |
1319 |
||
1320 |
/* draw signals also? */ |
|
3253 | 1321 |
if (GetRailTileType(ti->tile) != RAIL_TYPE_SIGNALS) return; |
0 | 1322 |
|
1323 |
{ |
|
1324 |
byte m23; |
|
1325 |
||
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
|
1326 |
m23 = (_m[ti->tile].m3 >> 4) | (_m[ti->tile].m2 & 0xF0); |
0 | 1327 |
|
1328 |
#define HAS_SIGNAL(x) (m23 & (byte)(0x1 << (x))) |
|
1329 |
#define ISON_SIGNAL(x) (m23 & (byte)(0x10 << (x))) |
|
1330 |
#define MAYBE_DRAW_SIGNAL(x,y,z) if (HAS_SIGNAL(x)) DrawSignalHelper(ti, ISON_SIGNAL(x), ((y-0x4FB) << 4)|(z)) |
|
1331 |
||
3267
feff95208a9f
(svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents:
3265
diff
changeset
|
1332 |
if (!(rails & TRACK_BIT_Y)) { |
feff95208a9f
(svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents:
3265
diff
changeset
|
1333 |
if (!(rails & TRACK_BIT_X)) { |
feff95208a9f
(svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents:
3265
diff
changeset
|
1334 |
if (rails & TRACK_BIT_LEFT) { |
0 | 1335 |
MAYBE_DRAW_SIGNAL(2, 0x509, 0); |
1336 |
MAYBE_DRAW_SIGNAL(3, 0x507, 1); |
|
1337 |
} |
|
3267
feff95208a9f
(svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents:
3265
diff
changeset
|
1338 |
if (rails & TRACK_BIT_RIGHT) { |
0 | 1339 |
MAYBE_DRAW_SIGNAL(0, 0x509, 2); |
1340 |
MAYBE_DRAW_SIGNAL(1, 0x507, 3); |
|
1341 |
} |
|
3267
feff95208a9f
(svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents:
3265
diff
changeset
|
1342 |
if (rails & TRACK_BIT_UPPER) { |
0 | 1343 |
MAYBE_DRAW_SIGNAL(3, 0x505, 4); |
1344 |
MAYBE_DRAW_SIGNAL(2, 0x503, 5); |
|
1345 |
} |
|
3267
feff95208a9f
(svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents:
3265
diff
changeset
|
1346 |
if (rails & TRACK_BIT_LOWER) { |
0 | 1347 |
MAYBE_DRAW_SIGNAL(1, 0x505, 6); |
1348 |
MAYBE_DRAW_SIGNAL(0, 0x503, 7); |
|
1349 |
} |
|
1350 |
} else { |
|
1351 |
MAYBE_DRAW_SIGNAL(3, 0x4FB, 8); |
|
1352 |
MAYBE_DRAW_SIGNAL(2, 0x4FD, 9); |
|
1353 |
} |
|
1354 |
} else { |
|
1355 |
MAYBE_DRAW_SIGNAL(3, 0x4FF, 10); |
|
1356 |
MAYBE_DRAW_SIGNAL(2, 0x501, 11); |
|
1357 |
} |
|
1358 |
} |
|
1359 |
} 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
|
1360 |
/* draw depots / waypoints */ |
0 | 1361 |
const DrawTrackSeqStruct *drss; |
3267
feff95208a9f
(svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents:
3265
diff
changeset
|
1362 |
byte type = ti->map5 & 0x3F; // 0-3: depots, 4-5: waypoints |
0 | 1363 |
|
2549 | 1364 |
if (ti->tileh != 0) DrawFoundation(ti, ti->tileh); |
0 | 1365 |
|
2668
c0f1828b89e4
(svn r3210) -Codechange: use IsRailWaypoint where possible (instead of magicnumbers)
truelight
parents:
2667
diff
changeset
|
1366 |
if (IsRailWaypoint(ti->tile) && 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
|
1367 |
// look for customization |
2670
f2d6a8424e3e
(svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents:
2668
diff
changeset
|
1368 |
byte stat_id = GetWaypointByTile(ti->tile)->stat_id; |
f2d6a8424e3e
(svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents:
2668
diff
changeset
|
1369 |
const StationSpec *stat = GetCustomStation(STAT_CLASS_WAYP, stat_id); |
389
16ee9854091e
(svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents:
337
diff
changeset
|
1370 |
|
2624
9e8bbcb41835
(svn r3166) Constify read-only accesses of custom stations
peter1138
parents:
2604
diff
changeset
|
1371 |
if (stat != NULL) { |
389
16ee9854091e
(svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents:
337
diff
changeset
|
1372 |
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
|
1373 |
// emulate station tile - open with building |
3267
feff95208a9f
(svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents:
3265
diff
changeset
|
1374 |
const DrawTileSprites *cust = &stat->renderdata[2 + (ti->map5 & 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
|
1375 |
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
|
1376 |
|
447
7e4bb71b8752
(svn r657) Do not touch 0x8000 bit in sprite index for custom waypoints. (pasky)
celestar
parents:
438
diff
changeset
|
1377 |
/* 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
|
1378 |
* 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
|
1379 |
* 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
|
1380 |
* 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
|
1381 |
* 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
|
1382 |
* 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
|
1383 |
* 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
|
1384 |
* 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
|
1385 |
|
417 | 1386 |
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
|
1387 |
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
|
1388 |
|
389
16ee9854091e
(svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents:
337
diff
changeset
|
1389 |
DrawGroundSprite(image); |
16ee9854091e
(svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents:
337
diff
changeset
|
1390 |
|
16ee9854091e
(svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents:
337
diff
changeset
|
1391 |
foreach_draw_tile_seq(seq, cust->seq) { |
2989 | 1392 |
DrawSpecialBuilding( |
1393 |
seq->image + relocation, 0, ti, |
|
1394 |
seq->delta_x, seq->delta_y, seq->delta_z, |
|
1395 |
seq->width, seq->height, seq->unk |
|
1396 |
); |
|
389
16ee9854091e
(svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents:
337
diff
changeset
|
1397 |
} |
16ee9854091e
(svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents:
337
diff
changeset
|
1398 |
return; |
16ee9854091e
(svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents:
337
diff
changeset
|
1399 |
} |
16ee9854091e
(svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents:
337
diff
changeset
|
1400 |
} |
16ee9854091e
(svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents:
337
diff
changeset
|
1401 |
|
1399
61e7c68e9da6
(svn r1903) Replace some casts and macro magic with proper typing, similar to r1902
tron
parents:
1363
diff
changeset
|
1402 |
drss = _track_depot_layout_table[type]; |
0 | 1403 |
|
1399
61e7c68e9da6
(svn r1903) Replace some casts and macro magic with proper typing, similar to r1902
tron
parents:
1363
diff
changeset
|
1404 |
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
|
1405 |
/* @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
|
1406 |
* 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
|
1407 |
if (image & PALETTE_MODIFIER_COLOR) image = (image & SPRITE_MASK) + rti->total_offset; |
0 | 1408 |
|
1409 |
// adjust ground tile for desert |
|
283
1ab67e2e4907
(svn r289) Fix: Checkpoints on snow have correct ground now
dominik
parents:
282
diff
changeset
|
1410 |
// (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
|
1411 |
// type >= 4 means waypoints |
2951 | 1412 |
if ((_m[ti->tile].m4 & RAIL_MAP2LO_GROUND_MASK) == RAIL_GROUND_ICE_DESERT && |
1413 |
(_opt.landscape == LT_DESERT || type >= 4)) { |
|
2549 | 1414 |
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
|
1415 |
image += rti->snow_offset; // tile with tracks |
2549 | 1416 |
} else { |
2254
99de94953104
(svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents:
2236
diff
changeset
|
1417 |
image = SPR_FLAT_SNOWY_TILE; // flat ground |
2549 | 1418 |
} |
0 | 1419 |
} |
1420 |
||
1421 |
DrawGroundSprite(image); |
|
1422 |
||
2549 | 1423 |
for (; drss->image != 0; drss++) { |
2951 | 1424 |
DrawSpecialBuilding( |
1425 |
drss->image, type < 4 ? rti->total_offset : 0, ti, |
|
1426 |
drss->subcoord_x, drss->subcoord_y, 0, |
|
1427 |
drss->width, drss->height, 0x17 |
|
1428 |
); |
|
0 | 1429 |
} |
1430 |
} |
|
1431 |
} |
|
1432 |
||
2520
8a52362c4ada
(svn r3049) Replace byte/int/uint by RailType where appropriate
tron
parents:
2502
diff
changeset
|
1433 |
void DrawTrainDepotSprite(int x, int y, int image, RailType railtype) |
0 | 1434 |
{ |
1435 |
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
|
1436 |
const RailtypeInfo *rti = GetRailTypeInfo(railtype); |
0 | 1437 |
const DrawTrackSeqStruct *dtss; |
1438 |
||
1439 |
ormod = PLAYER_SPRITE_COLOR(_local_player); |
|
1440 |
||
1399
61e7c68e9da6
(svn r1903) Replace some casts and macro magic with proper typing, similar to r1902
tron
parents:
1363
diff
changeset
|
1441 |
dtss = _track_depot_layout_table[image]; |
0 | 1442 |
|
2549 | 1443 |
x += 33; |
1444 |
y += 17; |
|
0 | 1445 |
|
1399
61e7c68e9da6
(svn r1903) Replace some casts and macro magic with proper typing, similar to r1902
tron
parents:
1363
diff
changeset
|
1446 |
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
|
1447 |
/* @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
|
1448 |
* 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
|
1449 |
if (img & PALETTE_MODIFIER_COLOR) img = (img & SPRITE_MASK) + rti->total_offset; |
0 | 1450 |
DrawSprite(img, x, y); |
1451 |
||
1399
61e7c68e9da6
(svn r1903) Replace some casts and macro magic with proper typing, similar to r1902
tron
parents:
1363
diff
changeset
|
1452 |
for (; dtss->image != 0; dtss++) { |
0 | 1453 |
Point pt = RemapCoords(dtss->subcoord_x, dtss->subcoord_y, 0); |
1454 |
image = dtss->image; |
|
2187
a0e206ce9fbf
(svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents:
2186
diff
changeset
|
1455 |
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
|
1456 |
DrawSprite(image + rti->total_offset, x + pt.x, y + pt.y); |
0 | 1457 |
} |
1458 |
} |
|
1459 |
||
2520
8a52362c4ada
(svn r3049) Replace byte/int/uint by RailType where appropriate
tron
parents:
2502
diff
changeset
|
1460 |
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
|
1461 |
{ |
d3554e5d3e86
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2254
diff
changeset
|
1462 |
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
|
1463 |
const RailtypeInfo *rti = GetRailTypeInfo(railtype); |
d3554e5d3e86
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2254
diff
changeset
|
1464 |
uint32 img; |
d3554e5d3e86
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2254
diff
changeset
|
1465 |
|
d3554e5d3e86
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2254
diff
changeset
|
1466 |
img = dtss++->image; |
d3554e5d3e86
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2254
diff
changeset
|
1467 |
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
|
1468 |
DrawSprite(img, x, y); |
d3554e5d3e86
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2254
diff
changeset
|
1469 |
|
d3554e5d3e86
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2254
diff
changeset
|
1470 |
for (; dtss->image != 0; dtss++) { |
d3554e5d3e86
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2254
diff
changeset
|
1471 |
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
|
1472 |
img = dtss->image; |
d3554e5d3e86
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2254
diff
changeset
|
1473 |
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
|
1474 |
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
|
1475 |
} |
d3554e5d3e86
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2254
diff
changeset
|
1476 |
} |
d3554e5d3e86
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2254
diff
changeset
|
1477 |
|
0 | 1478 |
typedef struct SetSignalsData { |
1479 |
int cur; |
|
1480 |
int cur_stack; |
|
1481 |
bool stop; |
|
1482 |
bool has_presignal; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1483 |
|
0 | 1484 |
// presignal info |
1485 |
int presignal_exits; |
|
1486 |
int presignal_exits_free; |
|
1487 |
||
1488 |
// these are used to keep track of the signals that change. |
|
1489 |
byte bit[NUM_SSD_ENTRY]; |
|
1490 |
TileIndex tile[NUM_SSD_ENTRY]; |
|
1491 |
||
1492 |
// these are used to keep track of the stack that modifies presignals recursively |
|
1493 |
TileIndex next_tile[NUM_SSD_STACK]; |
|
1494 |
byte next_dir[NUM_SSD_STACK]; |
|
1495 |
||
1496 |
} SetSignalsData; |
|
1497 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1963
diff
changeset
|
1498 |
static bool SetSignalsEnumProc(TileIndex tile, SetSignalsData *ssd, int track, uint length, byte *state) |
0 | 1499 |
{ |
3017
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
1500 |
if (!IsTileType(tile, MP_RAILWAY)) return false; |
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
1501 |
|
0 | 1502 |
// the tile has signals? |
3017
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
1503 |
if (HasSignalOnTrack(tile, TrackdirToTrack(track))) { |
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
1504 |
if (HasSignalOnTrackdir(tile, ReverseTrackdir(track))) { |
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
1505 |
// yes, add the signal to the list of signals |
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
1506 |
if (ssd->cur != NUM_SSD_ENTRY) { |
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
1507 |
ssd->tile[ssd->cur] = tile; // remember the tile index |
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
1508 |
ssd->bit[ssd->cur] = track; // and the controlling bit number |
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
1509 |
ssd->cur++; |
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
1510 |
} |
0 | 1511 |
|
3017
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
1512 |
// remember if this block has a presignal. |
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
1513 |
ssd->has_presignal |= (_m[tile].m4&1); |
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
1514 |
} |
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
1515 |
|
3017
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
1516 |
if (HasSignalOnTrackdir(tile, track) && _m[tile].m4 & 2) { |
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
1517 |
// this is an exit signal that points out from the segment |
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
1518 |
ssd->presignal_exits++; |
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
1519 |
if (GetSignalState(tile, track) != SIGNAL_STATE_RED) |
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
1520 |
ssd->presignal_exits_free++; |
2549 | 1521 |
} |
3017
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
1522 |
|
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
1523 |
return true; |
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
1524 |
} else if (IsTileDepotType(tile, TRANSPORT_RAIL)) { |
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
1525 |
return true; // don't look further if the tile is a depot |
0 | 1526 |
} |
3017
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
1527 |
|
0 | 1528 |
return false; |
1529 |
} |
|
1530 |
||
1555
7259e8f70267
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1531 |
/* 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
|
1532 |
typedef struct SignalVehicleCheckStruct { |
7259e8f70267
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1533 |
TileIndex tile; |
7259e8f70267
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1534 |
uint track; |
7259e8f70267
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1535 |
} SignalVehicleCheckStruct; |
7259e8f70267
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1536 |
|
7259e8f70267
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1537 |
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
|
1538 |
{ |
2549 | 1539 |
const SignalVehicleCheckStruct* dest = data; |
1555
7259e8f70267
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1540 |
TileIndex tile; |
7259e8f70267
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1541 |
|
2549 | 1542 |
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
|
1543 |
|
1555
7259e8f70267
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1544 |
/* Find the tile outside the tunnel, for signalling */ |
2549 | 1545 |
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
|
1546 |
tile = GetVehicleOutOfTunnelTile(v); |
2549 | 1547 |
} else { |
1555
7259e8f70267
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1548 |
tile = v->tile; |
2549 | 1549 |
} |
1555
7259e8f70267
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1550 |
|
7259e8f70267
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1551 |
/* Wrong tile, or no train? Not a match */ |
2549 | 1552 |
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
|
1553 |
|
7259e8f70267
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1554 |
/* Are we on the same piece of track? */ |
2549 | 1555 |
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
|
1556 |
|
7259e8f70267
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1557 |
return NULL; |
7259e8f70267
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1558 |
} |
7259e8f70267
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1559 |
|
7259e8f70267
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1560 |
/* Special check for SetSignalsAfterProc, to see if there is a vehicle on this tile */ |
2752 | 1561 |
static bool SignalVehicleCheck(TileIndex tile, uint track) |
1555
7259e8f70267
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1562 |
{ |
7259e8f70267
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1563 |
SignalVehicleCheckStruct dest; |
7259e8f70267
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1564 |
|
7259e8f70267
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1565 |
dest.tile = tile; |
7259e8f70267
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1566 |
dest.track = track; |
7259e8f70267
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1567 |
|
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
|
1568 |
/** @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
|
1569 |
* 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
|
1570 |
* 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
|
1571 |
*/ |
3184
118a520164e4
(svn r3830) Move IsTunnelTile() from tile.h to tunnel_map.h and add IsTunnel(), which just checks for a tunnel, but not the tile type as IsTunnelTile() does
tron
parents:
3172
diff
changeset
|
1572 |
if (IsTunnelTile(tile)) { |
1816
732d82acc97e
(svn r2320) - Fix: [ 1185176 ] Train in tunnel is not properly detected by signal code (Hackykid)
matthijs
parents:
1813
diff
changeset
|
1573 |
// 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
|
1574 |
// because VehicleFromPos will not find the vihicle otherwise |
3154 | 1575 |
TileIndex end = GetOtherTunnelEnd(tile); |
1576 |
DiagDirection direction = GetTunnelDirection(tile); |
|
1577 |
||
1816
732d82acc97e
(svn r2320) - Fix: [ 1185176 ] Train in tunnel is not properly detected by signal code (Hackykid)
matthijs
parents:
1813
diff
changeset
|
1578 |
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
|
1579 |
|
732d82acc97e
(svn r2320) - Fix: [ 1185176 ] Train in tunnel is not properly detected by signal code (Hackykid)
matthijs
parents:
1813
diff
changeset
|
1580 |
// 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
|
1581 |
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
|
1582 |
|
732d82acc97e
(svn r2320) - Fix: [ 1185176 ] Train in tunnel is not properly detected by signal code (Hackykid)
matthijs
parents:
1813
diff
changeset
|
1583 |
// check for a vehicle with that trackdir on the end tile of the tunnel |
3154 | 1584 |
if (VehicleFromPos(end, &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
|
1585 |
|
732d82acc97e
(svn r2320) - Fix: [ 1185176 ] Train in tunnel is not properly detected by signal code (Hackykid)
matthijs
parents:
1813
diff
changeset
|
1586 |
// 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
|
1587 |
// 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
|
1588 |
dest.track = 0x40; // trackbit for vehicles "hidden" inside a tunnel |
3154 | 1589 |
for (; tile != end; tile += TileOffsByDir(direction)) { |
1816
732d82acc97e
(svn r2320) - Fix: [ 1185176 ] Train in tunnel is not properly detected by signal code (Hackykid)
matthijs
parents:
1813
diff
changeset
|
1590 |
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
|
1591 |
return true; |
732d82acc97e
(svn r2320) - Fix: [ 1185176 ] Train in tunnel is not properly detected by signal code (Hackykid)
matthijs
parents:
1813
diff
changeset
|
1592 |
} |
732d82acc97e
(svn r2320) - Fix: [ 1185176 ] Train in tunnel is not properly detected by signal code (Hackykid)
matthijs
parents:
1813
diff
changeset
|
1593 |
|
732d82acc97e
(svn r2320) - Fix: [ 1185176 ] Train in tunnel is not properly detected by signal code (Hackykid)
matthijs
parents:
1813
diff
changeset
|
1594 |
// no vehicle found |
732d82acc97e
(svn r2320) - Fix: [ 1185176 ] Train in tunnel is not properly detected by signal code (Hackykid)
matthijs
parents:
1813
diff
changeset
|
1595 |
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
|
1596 |
} |
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
|
1597 |
|
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
|
1598 |
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
|
1599 |
} |
7259e8f70267
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1600 |
|
0 | 1601 |
static void SetSignalsAfterProc(TrackPathFinder *tpf) |
1602 |
{ |
|
1603 |
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
|
1604 |
const TrackPathFinderLink* link; |
1555
7259e8f70267
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1605 |
uint offs; |
7259e8f70267
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1606 |
uint i; |
0 | 1607 |
|
1608 |
ssd->stop = false; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1609 |
|
1555
7259e8f70267
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1610 |
/* Go through all the PF tiles */ |
7259e8f70267
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1611 |
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
|
1612 |
/* Empty hash item */ |
2639 | 1613 |
if (tpf->hash_head[i] == 0) continue; |
0 | 1614 |
|
1555
7259e8f70267
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1615 |
/* 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
|
1616 |
if (!(tpf->hash_head[i] & 0x8000)) { |
7259e8f70267
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1617 |
/* 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
|
1618 |
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
|
1619 |
ssd->stop = true; |
7259e8f70267
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1620 |
return; |
7259e8f70267
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1621 |
} |
0 | 1622 |
} else { |
1555
7259e8f70267
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1623 |
/* 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
|
1624 |
offs = tpf->hash_tile[i]; |
0 | 1625 |
do { |
1555
7259e8f70267
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1626 |
/* Find the next item */ |
0 | 1627 |
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
|
1628 |
/* 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
|
1629 |
if (SignalVehicleCheck(link->tile, link->flags)) { |
7259e8f70267
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1630 |
ssd->stop = true; |
7259e8f70267
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1631 |
return; |
0 | 1632 |
} |
1555
7259e8f70267
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1633 |
/* Goto the next item */ |
2951 | 1634 |
} while ((offs = link->next) != 0xFFFF); |
0 | 1635 |
} |
1636 |
} |
|
1637 |
} |
|
1638 |
||
1639 |
static const byte _dir_from_track[14] = { |
|
1640 |
0,1,0,1,2,1, 0,0, |
|
1641 |
2,3,3,2,3,0, |
|
1642 |
}; |
|
1643 |
||
1644 |
||
1645 |
static void ChangeSignalStates(SetSignalsData *ssd) |
|
1646 |
{ |
|
1647 |
int i; |
|
1648 |
||
1649 |
// thinking about presignals... |
|
1650 |
// the presignal is green if, |
|
1651 |
// if no train is in the segment AND |
|
1652 |
// there is at least one green exit signal OR |
|
1653 |
// there are no exit signals in the segment |
|
1654 |
||
1655 |
// then mark the signals in the segment accordingly |
|
2549 | 1656 |
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
|
1657 |
TileIndex tile = ssd->tile[i]; |
2821
cb5abbcc0f0c
(svn r3369) - Codechange: Replace tables _signals_table, _signals_table_other and _signals_table_both by the equivalent calls to rail.h functions.
matthijs
parents:
2817
diff
changeset
|
1658 |
byte bit = SignalAgainstTrackdir(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
|
1659 |
uint16 m2 = _m[tile].m2; |
0 | 1660 |
|
1661 |
// 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
|
1662 |
if (_m[tile].m4 & 1) { |
0 | 1663 |
int ex = ssd->presignal_exits, exfree = ssd->presignal_exits_free; |
1664 |
||
1665 |
// subtract for dual combo signals so they don't count themselves |
|
2951 | 1666 |
if (_m[tile].m4 & 2 && HasSignalOnTrackdir(tile, ssd->bit[i])) { |
0 | 1667 |
ex--; |
2821
cb5abbcc0f0c
(svn r3369) - Codechange: Replace tables _signals_table, _signals_table_other and _signals_table_both by the equivalent calls to rail.h functions.
matthijs
parents:
2817
diff
changeset
|
1668 |
if (GetSignalState(tile, ssd->bit[i]) != SIGNAL_STATE_RED) exfree--; |
0 | 1669 |
} |
1670 |
||
1671 |
// if we have exits and none are free, make red. |
|
1672 |
if (ex && !exfree) goto make_red; |
|
1673 |
} |
|
1674 |
||
1675 |
// check if the signal is unaffected. |
|
1676 |
if (ssd->stop) { |
|
1677 |
make_red: |
|
1678 |
// turn red |
|
2951 | 1679 |
if ((bit & m2) == 0) continue; |
0 | 1680 |
} else { |
1681 |
// turn green |
|
2951 | 1682 |
if ((bit & m2) != 0) continue; |
0 | 1683 |
} |
1684 |
||
1813
f41543d443b0
(svn r2317) - Fix: [ 1193048 ] Pre-signal stays red when there is only a single exit signal (dinno)
Darkvater
parents:
1796
diff
changeset
|
1685 |
/* Update signals on the other side of this exit-combo signal; it changed. */ |
2951 | 1686 |
if (_m[tile].m4 & 2) { |
0 | 1687 |
if (ssd->cur_stack != NUM_SSD_STACK) { |
1688 |
ssd->next_tile[ssd->cur_stack] = tile; |
|
1689 |
ssd->next_dir[ssd->cur_stack] = _dir_from_track[ssd->bit[i]]; |
|
1690 |
ssd->cur_stack++; |
|
1691 |
} 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
|
1692 |
printf("NUM_SSD_STACK too small\n"); /// @todo WTF is this??? |
0 | 1693 |
} |
1694 |
} |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1695 |
|
0 | 1696 |
// 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
|
1697 |
_m[tile].m2 = m2 ^ bit; |
0 | 1698 |
MarkTileDirtyByTile(tile); |
1699 |
} |
|
1700 |
} |
|
1701 |
||
1702 |
||
3172
ade284ef48ed
(svn r3803) Change the second parameter of UpdateSignalsOnSegment() from Direction to DiagDirection as that's what it really operates on
tron
parents:
3157
diff
changeset
|
1703 |
bool UpdateSignalsOnSegment(TileIndex tile, DiagDirection direction) |
0 | 1704 |
{ |
1705 |
SetSignalsData ssd; |
|
1706 |
int result = -1; |
|
1707 |
||
1708 |
ssd.cur_stack = 0; |
|
1709 |
||
2951 | 1710 |
for (;;) { |
0 | 1711 |
// go through one segment and update all signals pointing into that segment. |
2916
b687477adcba
(svn r3472) - [PBS] Remove from trunk. Anyone interested can still find it in branch/pbs. This reverts revisions r3158, r3140, r3075, r2977, r2674, r2625, r2621, r2529, r2528, r2525, r2524, r2519, r2517, r2516, r2507, r2499. (in conjunction with Tron)
Darkvater
parents:
2911
diff
changeset
|
1712 |
ssd.cur = ssd.presignal_exits = ssd.presignal_exits_free = 0; |
0 | 1713 |
ssd.has_presignal = false; |
1714 |
||
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
149
diff
changeset
|
1715 |
FollowTrack(tile, 0xC000 | TRANSPORT_RAIL, direction, (TPFEnumProc*)SetSignalsEnumProc, SetSignalsAfterProc, &ssd); |
0 | 1716 |
ChangeSignalStates(&ssd); |
1717 |
||
1718 |
// remember the result only for the first iteration. |
|
1719 |
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
|
1720 |
|
0 | 1721 |
// if any exit signals were changed, we need to keep going to modify the stuff behind those. |
2639 | 1722 |
if (ssd.cur_stack == 0) break; |
0 | 1723 |
|
1724 |
// one or more exit signals were changed, so we need to update another segment too. |
|
1725 |
tile = ssd.next_tile[--ssd.cur_stack]; |
|
1726 |
direction = ssd.next_dir[ssd.cur_stack]; |
|
1727 |
} |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1728 |
|
3017
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
1729 |
return result != 0; |
0 | 1730 |
} |
1731 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1963
diff
changeset
|
1732 |
void SetSignalsOnBothDir(TileIndex tile, byte track) |
0 | 1733 |
{ |
3172
ade284ef48ed
(svn r3803) Change the second parameter of UpdateSignalsOnSegment() from Direction to DiagDirection as that's what it really operates on
tron
parents:
3157
diff
changeset
|
1734 |
static const DiagDirection _search_dir_1[] = { |
ade284ef48ed
(svn r3803) Change the second parameter of UpdateSignalsOnSegment() from Direction to DiagDirection as that's what it really operates on
tron
parents:
3157
diff
changeset
|
1735 |
DIAGDIR_NE, DIAGDIR_SE, DIAGDIR_NE, DIAGDIR_SE, DIAGDIR_SW, DIAGDIR_SE |
ade284ef48ed
(svn r3803) Change the second parameter of UpdateSignalsOnSegment() from Direction to DiagDirection as that's what it really operates on
tron
parents:
3157
diff
changeset
|
1736 |
}; |
ade284ef48ed
(svn r3803) Change the second parameter of UpdateSignalsOnSegment() from Direction to DiagDirection as that's what it really operates on
tron
parents:
3157
diff
changeset
|
1737 |
static const DiagDirection _search_dir_2[] = { |
ade284ef48ed
(svn r3803) Change the second parameter of UpdateSignalsOnSegment() from Direction to DiagDirection as that's what it really operates on
tron
parents:
3157
diff
changeset
|
1738 |
DIAGDIR_SW, DIAGDIR_NW, DIAGDIR_NW, DIAGDIR_SW, DIAGDIR_NW, DIAGDIR_NE |
ade284ef48ed
(svn r3803) Change the second parameter of UpdateSignalsOnSegment() from Direction to DiagDirection as that's what it really operates on
tron
parents:
3157
diff
changeset
|
1739 |
}; |
0 | 1740 |
|
1741 |
UpdateSignalsOnSegment(tile, _search_dir_1[track]); |
|
1742 |
UpdateSignalsOnSegment(tile, _search_dir_2[track]); |
|
1743 |
} |
|
1744 |
||
2537 | 1745 |
static uint GetSlopeZ_Track(const TileInfo* ti) |
0 | 1746 |
{ |
3286
5177aab0ec21
(svn r4000) Rewrite GetSlope{Tileh,Z}_{Road,Track} in a less confusing way
tron
parents:
3284
diff
changeset
|
1747 |
uint tileh = ti->tileh; |
0 | 1748 |
uint z = ti->z; |
2951 | 1749 |
|
3286
5177aab0ec21
(svn r4000) Rewrite GetSlope{Tileh,Z}_{Road,Track} in a less confusing way
tron
parents:
3284
diff
changeset
|
1750 |
if (tileh == 0) return z; |
5177aab0ec21
(svn r4000) Rewrite GetSlope{Tileh,Z}_{Road,Track} in a less confusing way
tron
parents:
3284
diff
changeset
|
1751 |
if (GetRailTileType(ti->tile) == RAIL_TYPE_DEPOT_WAYPOINT) { |
5177aab0ec21
(svn r4000) Rewrite GetSlope{Tileh,Z}_{Road,Track} in a less confusing way
tron
parents:
3284
diff
changeset
|
1752 |
return z + 8; |
5177aab0ec21
(svn r4000) Rewrite GetSlope{Tileh,Z}_{Road,Track} in a less confusing way
tron
parents:
3284
diff
changeset
|
1753 |
} else { |
5177aab0ec21
(svn r4000) Rewrite GetSlope{Tileh,Z}_{Road,Track} in a less confusing way
tron
parents:
3284
diff
changeset
|
1754 |
uint f = GetRailFoundation(ti->tileh, GetTrackBits(ti->tile)); |
5177aab0ec21
(svn r4000) Rewrite GetSlope{Tileh,Z}_{Road,Track} in a less confusing way
tron
parents:
3284
diff
changeset
|
1755 |
|
5177aab0ec21
(svn r4000) Rewrite GetSlope{Tileh,Z}_{Road,Track} in a less confusing way
tron
parents:
3284
diff
changeset
|
1756 |
if (f != 0) { |
5177aab0ec21
(svn r4000) Rewrite GetSlope{Tileh,Z}_{Road,Track} in a less confusing way
tron
parents:
3284
diff
changeset
|
1757 |
if (f < 15) return z + 8; // leveled foundation |
5177aab0ec21
(svn r4000) Rewrite GetSlope{Tileh,Z}_{Road,Track} in a less confusing way
tron
parents:
3284
diff
changeset
|
1758 |
tileh = _inclined_tileh[f - 15]; // inclined foundation |
0 | 1759 |
} |
3286
5177aab0ec21
(svn r4000) Rewrite GetSlope{Tileh,Z}_{Road,Track} in a less confusing way
tron
parents:
3284
diff
changeset
|
1760 |
return z + GetPartialZ(ti->x & 0xF, ti->y & 0xF, tileh); |
0 | 1761 |
} |
1762 |
} |
|
1763 |
||
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
|
1764 |
static uint GetSlopeTileh_Track(const TileInfo *ti) |
39 | 1765 |
{ |
3286
5177aab0ec21
(svn r4000) Rewrite GetSlope{Tileh,Z}_{Road,Track} in a less confusing way
tron
parents:
3284
diff
changeset
|
1766 |
if (ti->tileh == 0) return ti->tileh; |
5177aab0ec21
(svn r4000) Rewrite GetSlope{Tileh,Z}_{Road,Track} in a less confusing way
tron
parents:
3284
diff
changeset
|
1767 |
if (GetRailTileType(ti->tile) == RAIL_TYPE_DEPOT_WAYPOINT) { |
5177aab0ec21
(svn r4000) Rewrite GetSlope{Tileh,Z}_{Road,Track} in a less confusing way
tron
parents:
3284
diff
changeset
|
1768 |
return 0; |
5177aab0ec21
(svn r4000) Rewrite GetSlope{Tileh,Z}_{Road,Track} in a less confusing way
tron
parents:
3284
diff
changeset
|
1769 |
} else { |
5177aab0ec21
(svn r4000) Rewrite GetSlope{Tileh,Z}_{Road,Track} in a less confusing way
tron
parents:
3284
diff
changeset
|
1770 |
uint f = GetRailFoundation(ti->tileh, GetTrackBits(ti->tile)); |
5177aab0ec21
(svn r4000) Rewrite GetSlope{Tileh,Z}_{Road,Track} in a less confusing way
tron
parents:
3284
diff
changeset
|
1771 |
|
5177aab0ec21
(svn r4000) Rewrite GetSlope{Tileh,Z}_{Road,Track} in a less confusing way
tron
parents:
3284
diff
changeset
|
1772 |
if (f == 0) return ti->tileh; |
5177aab0ec21
(svn r4000) Rewrite GetSlope{Tileh,Z}_{Road,Track} in a less confusing way
tron
parents:
3284
diff
changeset
|
1773 |
if (f < 15) return 0; // leveled foundation |
5177aab0ec21
(svn r4000) Rewrite GetSlope{Tileh,Z}_{Road,Track} in a less confusing way
tron
parents:
3284
diff
changeset
|
1774 |
return _inclined_tileh[f - 15]; // inclined foundation |
39 | 1775 |
} |
1776 |
} |
|
1777 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1963
diff
changeset
|
1778 |
static void GetAcceptedCargo_Track(TileIndex tile, AcceptedCargo ac) |
0 | 1779 |
{ |
1780 |
/* not used */ |
|
1781 |
} |
|
1782 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1963
diff
changeset
|
1783 |
static void AnimateTile_Track(TileIndex tile) |
0 | 1784 |
{ |
1785 |
/* not used */ |
|
1786 |
} |
|
1787 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1963
diff
changeset
|
1788 |
static void TileLoop_Track(TileIndex tile) |
0 | 1789 |
{ |
2667
f3ffefc784c5
(svn r3209) In TileLoop_Track(), use names based on function rather than their place in the map array.
peter1138
parents:
2645
diff
changeset
|
1790 |
byte old_ground; |
f3ffefc784c5
(svn r3209) In TileLoop_Track(), use names based on function rather than their place in the map array.
peter1138
parents:
2645
diff
changeset
|
1791 |
byte new_ground; |
0 | 1792 |
|
3253 | 1793 |
if (GetRailType(tile) == RAIL_TYPE_DEPOT_WAYPOINT) { |
1794 |
old_ground = GB(_m[tile].m4, 0, 4); |
|
1795 |
} else { |
|
1796 |
old_ground = GB(_m[tile].m2, 0, 4); |
|
1797 |
} |
|
0 | 1798 |
|
2631
2ed0eb408229
(svn r3173) Use the trinary operator and switch to improve readability
tron
parents:
2626
diff
changeset
|
1799 |
switch (_opt.landscape) { |
2ed0eb408229
(svn r3173) Use the trinary operator and switch to improve readability
tron
parents:
2626
diff
changeset
|
1800 |
case LT_HILLY: |
2ed0eb408229
(svn r3173) Use the trinary operator and switch to improve readability
tron
parents:
2626
diff
changeset
|
1801 |
if (GetTileZ(tile) > _opt.snow_line) { /* convert into snow? */ |
2667
f3ffefc784c5
(svn r3209) In TileLoop_Track(), use names based on function rather than their place in the map array.
peter1138
parents:
2645
diff
changeset
|
1802 |
new_ground = RAIL_GROUND_ICE_DESERT; |
2631
2ed0eb408229
(svn r3173) Use the trinary operator and switch to improve readability
tron
parents:
2626
diff
changeset
|
1803 |
goto modify_me; |
2ed0eb408229
(svn r3173) Use the trinary operator and switch to improve readability
tron
parents:
2626
diff
changeset
|
1804 |
} |
2ed0eb408229
(svn r3173) Use the trinary operator and switch to improve readability
tron
parents:
2626
diff
changeset
|
1805 |
break; |
0 | 1806 |
|
2631
2ed0eb408229
(svn r3173) Use the trinary operator and switch to improve readability
tron
parents:
2626
diff
changeset
|
1807 |
case LT_DESERT: |
2ed0eb408229
(svn r3173) Use the trinary operator and switch to improve readability
tron
parents:
2626
diff
changeset
|
1808 |
if (GetMapExtraBits(tile) == 1) { /* convert into desert? */ |
2667
f3ffefc784c5
(svn r3209) In TileLoop_Track(), use names based on function rather than their place in the map array.
peter1138
parents:
2645
diff
changeset
|
1809 |
new_ground = RAIL_GROUND_ICE_DESERT; |
2631
2ed0eb408229
(svn r3173) Use the trinary operator and switch to improve readability
tron
parents:
2626
diff
changeset
|
1810 |
goto modify_me; |
2ed0eb408229
(svn r3173) Use the trinary operator and switch to improve readability
tron
parents:
2626
diff
changeset
|
1811 |
} |
2ed0eb408229
(svn r3173) Use the trinary operator and switch to improve readability
tron
parents:
2626
diff
changeset
|
1812 |
break; |
0 | 1813 |
} |
1814 |
||
1815 |
// Don't continue tile loop for depots |
|
3253 | 1816 |
if (GetRailType(tile) == RAIL_TYPE_DEPOT_WAYPOINT) return; |
0 | 1817 |
|
2667
f3ffefc784c5
(svn r3209) In TileLoop_Track(), use names based on function rather than their place in the map array.
peter1138
parents:
2645
diff
changeset
|
1818 |
new_ground = RAIL_GROUND_GREEN; |
0 | 1819 |
|
2667
f3ffefc784c5
(svn r3209) In TileLoop_Track(), use names based on function rather than their place in the map array.
peter1138
parents:
2645
diff
changeset
|
1820 |
if (old_ground != RAIL_GROUND_BROWN) { /* wait until bottom is green */ |
0 | 1821 |
/* determine direction of fence */ |
3267
feff95208a9f
(svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents:
3265
diff
changeset
|
1822 |
TrackBits rail = GetTrackBits(tile); |
0 | 1823 |
|
2839
a466d41923d8
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1824 |
switch (rail) { |
a466d41923d8
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1825 |
case TRACK_BIT_UPPER: new_ground = RAIL_GROUND_FENCE_HORIZ1; break; |
a466d41923d8
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1826 |
case TRACK_BIT_LOWER: new_ground = RAIL_GROUND_FENCE_HORIZ2; break; |
a466d41923d8
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1827 |
case TRACK_BIT_LEFT: new_ground = RAIL_GROUND_FENCE_VERT1; break; |
a466d41923d8
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1828 |
case TRACK_BIT_RIGHT: new_ground = RAIL_GROUND_FENCE_VERT2; break; |
0 | 1829 |
|
2839
a466d41923d8
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1830 |
default: { |
a466d41923d8
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1831 |
PlayerID owner = GetTileOwner(tile); |
0 | 1832 |
|
2839
a466d41923d8
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1833 |
if (rail == (TRACK_BIT_LOWER | TRACK_BIT_RIGHT) || ( |
3258
1c079364726d
(svn r3946) Add short hand names for common track combinations
tron
parents:
3254
diff
changeset
|
1834 |
(rail & TRACK_BIT_3WAY_NW) == 0 && |
3102
f9ca4379db9d
(svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron
parents:
3101
diff
changeset
|
1835 |
(rail & TRACK_BIT_X) |
2839
a466d41923d8
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1836 |
)) { |
a466d41923d8
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1837 |
TileIndex n = tile + TileDiffXY(0, -1); |
0 | 1838 |
|
2839
a466d41923d8
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1839 |
if (!IsTileType(n, MP_RAILWAY) || |
a466d41923d8
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1840 |
!IsTileOwner(n, owner) || |
2841
321a4e85a5fe
(svn r3389) -Fix: No fence was placed when placing fences and the neighbouring tile is a rail configuration which permits a fence but has a signal
tron
parents:
2839
diff
changeset
|
1841 |
(_m[n].m5 & TRACK_BIT_MASK) == TRACK_BIT_UPPER || |
321a4e85a5fe
(svn r3389) -Fix: No fence was placed when placing fences and the neighbouring tile is a rail configuration which permits a fence but has a signal
tron
parents:
2839
diff
changeset
|
1842 |
(_m[n].m5 & TRACK_BIT_MASK) == TRACK_BIT_LEFT) { |
2839
a466d41923d8
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1843 |
new_ground = RAIL_GROUND_FENCE_NW; |
a466d41923d8
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1844 |
} |
a466d41923d8
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1845 |
} |
a466d41923d8
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1846 |
|
a466d41923d8
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1847 |
if (rail == (TRACK_BIT_UPPER | TRACK_BIT_LEFT) || ( |
3258
1c079364726d
(svn r3946) Add short hand names for common track combinations
tron
parents:
3254
diff
changeset
|
1848 |
(rail & TRACK_BIT_3WAY_SE) == 0 && |
3102
f9ca4379db9d
(svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron
parents:
3101
diff
changeset
|
1849 |
(rail & TRACK_BIT_X) |
2839
a466d41923d8
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1850 |
)) { |
a466d41923d8
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1851 |
TileIndex n = tile + TileDiffXY(0, 1); |
a466d41923d8
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1852 |
|
a466d41923d8
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1853 |
if (!IsTileType(n, MP_RAILWAY) || |
a466d41923d8
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1854 |
!IsTileOwner(n, owner) || |
2841
321a4e85a5fe
(svn r3389) -Fix: No fence was placed when placing fences and the neighbouring tile is a rail configuration which permits a fence but has a signal
tron
parents:
2839
diff
changeset
|
1855 |
(_m[n].m5 & TRACK_BIT_MASK) == TRACK_BIT_LOWER || |
321a4e85a5fe
(svn r3389) -Fix: No fence was placed when placing fences and the neighbouring tile is a rail configuration which permits a fence but has a signal
tron
parents:
2839
diff
changeset
|
1856 |
(_m[n].m5 & TRACK_BIT_MASK) == TRACK_BIT_RIGHT) { |
2839
a466d41923d8
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1857 |
new_ground = (new_ground == RAIL_GROUND_FENCE_NW) ? |
a466d41923d8
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1858 |
RAIL_GROUND_FENCE_SENW : RAIL_GROUND_FENCE_SE; |
a466d41923d8
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1859 |
} |
a466d41923d8
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1860 |
} |
a466d41923d8
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1861 |
|
a466d41923d8
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1862 |
if (rail == (TRACK_BIT_LOWER | TRACK_BIT_LEFT) || ( |
3258
1c079364726d
(svn r3946) Add short hand names for common track combinations
tron
parents:
3254
diff
changeset
|
1863 |
(rail & TRACK_BIT_3WAY_NE) == 0 && |
3102
f9ca4379db9d
(svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron
parents:
3101
diff
changeset
|
1864 |
(rail & TRACK_BIT_Y) |
2839
a466d41923d8
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1865 |
)) { |
a466d41923d8
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1866 |
TileIndex n = tile + TileDiffXY(-1, 0); |
a466d41923d8
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1867 |
|
a466d41923d8
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1868 |
if (!IsTileType(n, MP_RAILWAY) || |
a466d41923d8
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1869 |
!IsTileOwner(n, owner) || |
2841
321a4e85a5fe
(svn r3389) -Fix: No fence was placed when placing fences and the neighbouring tile is a rail configuration which permits a fence but has a signal
tron
parents:
2839
diff
changeset
|
1870 |
(_m[n].m5 & TRACK_BIT_MASK) == TRACK_BIT_UPPER || |
321a4e85a5fe
(svn r3389) -Fix: No fence was placed when placing fences and the neighbouring tile is a rail configuration which permits a fence but has a signal
tron
parents:
2839
diff
changeset
|
1871 |
(_m[n].m5 & TRACK_BIT_MASK) == TRACK_BIT_RIGHT) { |
2839
a466d41923d8
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1872 |
new_ground = RAIL_GROUND_FENCE_NE; |
a466d41923d8
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1873 |
} |
a466d41923d8
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1874 |
} |
a466d41923d8
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1875 |
|
a466d41923d8
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1876 |
if (rail == (TRACK_BIT_UPPER | TRACK_BIT_RIGHT) || ( |
3265 | 1877 |
(rail & TRACK_BIT_3WAY_SW) == 0 && |
3102
f9ca4379db9d
(svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron
parents:
3101
diff
changeset
|
1878 |
(rail & TRACK_BIT_Y) |
2839
a466d41923d8
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1879 |
)) { |
a466d41923d8
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1880 |
TileIndex n = tile + TileDiffXY(1, 0); |
a466d41923d8
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1881 |
|
a466d41923d8
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1882 |
if (!IsTileType(n, MP_RAILWAY) || |
a466d41923d8
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1883 |
!IsTileOwner(n, owner) || |
2841
321a4e85a5fe
(svn r3389) -Fix: No fence was placed when placing fences and the neighbouring tile is a rail configuration which permits a fence but has a signal
tron
parents:
2839
diff
changeset
|
1884 |
(_m[n].m5 & TRACK_BIT_MASK) == TRACK_BIT_LOWER || |
321a4e85a5fe
(svn r3389) -Fix: No fence was placed when placing fences and the neighbouring tile is a rail configuration which permits a fence but has a signal
tron
parents:
2839
diff
changeset
|
1885 |
(_m[n].m5 & TRACK_BIT_MASK) == TRACK_BIT_LEFT) { |
2839
a466d41923d8
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1886 |
new_ground = (new_ground == RAIL_GROUND_FENCE_NE) ? |
a466d41923d8
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1887 |
RAIL_GROUND_FENCE_NESW : RAIL_GROUND_FENCE_SW; |
a466d41923d8
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1888 |
} |
a466d41923d8
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1889 |
} |
a466d41923d8
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1890 |
break; |
0 | 1891 |
} |
1892 |
} |
|
1893 |
} |
|
1894 |
||
1895 |
modify_me:; |
|
1896 |
/* tile changed? */ |
|
2667
f3ffefc784c5
(svn r3209) In TileLoop_Track(), use names based on function rather than their place in the map array.
peter1138
parents:
2645
diff
changeset
|
1897 |
if (old_ground != new_ground) { |
3253 | 1898 |
if (GetRailTileType(tile) == RAIL_TYPE_DEPOT_WAYPOINT) { |
2670
f2d6a8424e3e
(svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents:
2668
diff
changeset
|
1899 |
SB(_m[tile].m4, 0, 4, new_ground); |
f2d6a8424e3e
(svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents:
2668
diff
changeset
|
1900 |
} else { |
f2d6a8424e3e
(svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents:
2668
diff
changeset
|
1901 |
SB(_m[tile].m2, 0, 4, new_ground); |
f2d6a8424e3e
(svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents:
2668
diff
changeset
|
1902 |
} |
0 | 1903 |
MarkTileDirtyByTile(tile); |
1904 |
} |
|
1905 |
} |
|
1906 |
||
1907 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1963
diff
changeset
|
1908 |
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
|
1909 |
{ |
3267
feff95208a9f
(svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents:
3265
diff
changeset
|
1910 |
byte a; |
817
238bbdaa228b
(svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents:
679
diff
changeset
|
1911 |
uint16 b; |
0 | 1912 |
|
2639 | 1913 |
if (mode != TRANSPORT_RAIL) return 0; |
0 | 1914 |
|
3254
4a9863a19922
(svn r3942) GetRailType() != GetRailTileType(), fix r3941
tron
parents:
3253
diff
changeset
|
1915 |
if (GetRailTileType(tile) != RAIL_TYPE_DEPOT_WAYPOINT) { |
3267
feff95208a9f
(svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents:
3265
diff
changeset
|
1916 |
TrackBits rails = GetTrackBits(tile); |
feff95208a9f
(svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents:
3265
diff
changeset
|
1917 |
uint32 ret = rails * 0x101; |
feff95208a9f
(svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents:
3265
diff
changeset
|
1918 |
|
3254
4a9863a19922
(svn r3942) GetRailType() != GetRailTileType(), fix r3941
tron
parents:
3253
diff
changeset
|
1919 |
if (GetRailTileType(tile) != RAIL_TYPE_SIGNALS) { |
3267
feff95208a9f
(svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents:
3265
diff
changeset
|
1920 |
if (rails == TRACK_BIT_CROSS) ret |= 0x40; |
0 | 1921 |
} else { |
1922 |
/* has_signals */ |
|
1923 |
||
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
|
1924 |
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
|
1925 |
b = _m[tile].m2; |
0 | 1926 |
|
1927 |
b &= a; |
|
1928 |
||
22 | 1929 |
/* When signals are not present (in neither |
1930 |
* direction), we pretend them to be green. (So if |
|
1931 |
* signals are only one way, the other way will |
|
1932 |
* implicitely become `red' */ |
|
2549 | 1933 |
if ((a & 0xC0) == 0) b |= 0xC0; |
1934 |
if ((a & 0x30) == 0) b |= 0x30; |
|
0 | 1935 |
|
2639 | 1936 |
if ((b & 0x80) == 0) ret |= 0x10070000; |
1937 |
if ((b & 0x40) == 0) ret |= 0x07100000; |
|
1938 |
if ((b & 0x20) == 0) ret |= 0x20080000; |
|
1939 |
if ((b & 0x10) == 0) ret |= 0x08200000; |
|
0 | 1940 |
} |
3267
feff95208a9f
(svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents:
3265
diff
changeset
|
1941 |
return ret; |
feff95208a9f
(svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents:
3265
diff
changeset
|
1942 |
} else { |
3269
62fb247bf94b
(svn r3981) More work for the rail accessing functions and enums
tron
parents:
3267
diff
changeset
|
1943 |
if (GetRailTileSubtype(tile) == RAIL_SUBTYPE_DEPOT) { |
3270
a9bed87794a2
(svn r3982) Fix last commit. I got confused by some strange test, which did nothing
tron
parents:
3269
diff
changeset
|
1944 |
return (DiagDirToAxis(GetRailDepotDirection(tile)) == AXIS_X ? TRACK_BIT_X : TRACK_BIT_Y) * 0x101; |
3269
62fb247bf94b
(svn r3981) More work for the rail accessing functions and enums
tron
parents:
3267
diff
changeset
|
1945 |
} else { |
3267
feff95208a9f
(svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents:
3265
diff
changeset
|
1946 |
return GetRailWaypointBits(tile) * 0x101; |
feff95208a9f
(svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents:
3265
diff
changeset
|
1947 |
} |
feff95208a9f
(svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents:
3265
diff
changeset
|
1948 |
} |
0 | 1949 |
} |
1950 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1963
diff
changeset
|
1951 |
static void ClickTile_Track(TileIndex tile) |
0 | 1952 |
{ |
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
|
1953 |
if (IsTileDepotType(tile, TRANSPORT_RAIL)) { |
0 | 1954 |
ShowTrainDepotWindow(tile); |
2668
c0f1828b89e4
(svn r3210) -Codechange: use IsRailWaypoint where possible (instead of magicnumbers)
truelight
parents:
2667
diff
changeset
|
1955 |
} else if (IsRailWaypoint(tile)) { |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1536
diff
changeset
|
1956 |
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
|
1957 |
} |
0 | 1958 |
} |
1959 |
||
1590
3351993cb1da
(svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron
parents:
1555
diff
changeset
|
1960 |
static void GetTileDesc_Track(TileIndex tile, TileDesc *td) |
0 | 1961 |
{ |
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
|
1962 |
td->owner = GetTileOwner(tile); |
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
1963 |
switch (GetRailTileType(tile)) { |
1590
3351993cb1da
(svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron
parents:
1555
diff
changeset
|
1964 |
case RAIL_TYPE_NORMAL: |
0 | 1965 |
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
|
1966 |
break; |
3351993cb1da
(svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron
parents:
1555
diff
changeset
|
1967 |
|
3351993cb1da
(svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron
parents:
1555
diff
changeset
|
1968 |
case RAIL_TYPE_SIGNALS: { |
2916
b687477adcba
(svn r3472) - [PBS] Remove from trunk. Anyone interested can still find it in branch/pbs. This reverts revisions r3158, r3140, r3075, r2977, r2674, r2625, r2621, r2529, r2528, r2525, r2524, r2519, r2517, r2516, r2507, r2499. (in conjunction with Tron)
Darkvater
parents:
2911
diff
changeset
|
1969 |
const StringID signal_type[] = { |
1590
3351993cb1da
(svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron
parents:
1555
diff
changeset
|
1970 |
STR_RAILROAD_TRACK_WITH_NORMAL_SIGNALS, |
3351993cb1da
(svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron
parents:
1555
diff
changeset
|
1971 |
STR_RAILROAD_TRACK_WITH_PRESIGNALS, |
3351993cb1da
(svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron
parents:
1555
diff
changeset
|
1972 |
STR_RAILROAD_TRACK_WITH_EXITSIGNALS, |
2916
b687477adcba
(svn r3472) - [PBS] Remove from trunk. Anyone interested can still find it in branch/pbs. This reverts revisions r3158, r3140, r3075, r2977, r2674, r2625, r2621, r2529, r2528, r2525, r2524, r2519, r2517, r2516, r2507, r2499. (in conjunction with Tron)
Darkvater
parents:
2911
diff
changeset
|
1973 |
STR_RAILROAD_TRACK_WITH_COMBOSIGNALS |
1590
3351993cb1da
(svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron
parents:
1555
diff
changeset
|
1974 |
}; |
3351993cb1da
(svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron
parents:
1555
diff
changeset
|
1975 |
|
3238
9ebec0a611ee
(svn r3912) Move the signal type enum and GetSignalType() to rail_map.h; also add SetSignalType() and use the functions
tron
parents:
3237
diff
changeset
|
1976 |
td->str = signal_type[GetSignalType(tile)]; |
1590
3351993cb1da
(svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron
parents:
1555
diff
changeset
|
1977 |
break; |
0 | 1978 |
} |
1590
3351993cb1da
(svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron
parents:
1555
diff
changeset
|
1979 |
|
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
1980 |
case RAIL_TYPE_DEPOT_WAYPOINT: |
1590
3351993cb1da
(svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron
parents:
1555
diff
changeset
|
1981 |
default: |
3269
62fb247bf94b
(svn r3981) More work for the rail accessing functions and enums
tron
parents:
3267
diff
changeset
|
1982 |
td->str = (GetRailTileSubtype(tile) == RAIL_SUBTYPE_DEPOT) ? |
1590
3351993cb1da
(svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron
parents:
1555
diff
changeset
|
1983 |
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
|
1984 |
break; |
0 | 1985 |
} |
1986 |
} |
|
1987 |
||
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
|
1988 |
static void ChangeTileOwner_Track(TileIndex tile, PlayerID old_player, PlayerID new_player) |
0 | 1989 |
{ |
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
|
1990 |
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
|
1991 |
|
2502 | 1992 |
if (new_player != OWNER_SPECTATOR) { |
1902 | 1993 |
SetTileOwner(tile, new_player); |
0 | 1994 |
} else { |
1995 |
DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); |
|
1996 |
} |
|
1997 |
} |
|
1998 |
||
1999 |
static const byte _fractcoords_behind[4] = { 0x8F, 0x8, 0x80, 0xF8 }; |
|
2000 |
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
|
2001 |
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
|
2002 |
-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
|
2003 |
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
|
2004 |
}; |
0 | 2005 |
static const byte _depot_track_mask[4] = {1, 2, 1, 2}; |
2006 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1963
diff
changeset
|
2007 |
static uint32 VehicleEnter_Track(Vehicle *v, TileIndex tile, int x, int y) |
0 | 2008 |
{ |
2009 |
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
|
2010 |
byte fract_coord_leave; |
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3154
diff
changeset
|
2011 |
DiagDirection dir; |
1922
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1903
diff
changeset
|
2012 |
int length; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
2013 |
|
0 | 2014 |
// this routine applies only to trains in depot tiles |
2639 | 2015 |
if (v->type != VEH_Train || !IsTileDepotType(tile, TRANSPORT_RAIL)) return 0; |
0 | 2016 |
|
2017 |
/* depot direction */ |
|
3185 | 2018 |
dir = GetRailDepotDirection(tile); |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
2019 |
|
1922
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1903
diff
changeset
|
2020 |
/* 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
|
2021 |
/* 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
|
2022 |
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
|
2023 |
|
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1903
diff
changeset
|
2024 |
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
|
2025 |
((_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
|
2026 |
(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
|
2027 |
(((_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
|
2028 |
((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
|
2029 |
|
0 | 2030 |
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
|
2031 |
|
0 | 2032 |
if (_fractcoords_behind[dir] == fract_coord) { |
2033 |
/* make sure a train is not entering the tile from behind */ |
|
2034 |
return 8; |
|
2035 |
} else if (_fractcoords_enter[dir] == fract_coord) { |
|
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3154
diff
changeset
|
2036 |
if (DiagDirToDir(ReverseDiagDir(dir)) == v->direction) { |
0 | 2037 |
/* enter the depot */ |
2038 |
v->u.rail.track = 0x80, |
|
2039 |
v->vehstatus |= VS_HIDDEN; /* hide it */ |
|
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3154
diff
changeset
|
2040 |
v->direction = ReverseDir(v->direction); |
0 | 2041 |
if (v->next == NULL) |
2042 |
TrainEnterDepot(v, tile); |
|
2043 |
v->tile = tile; |
|
2044 |
InvalidateWindow(WC_VEHICLE_DEPOT, tile); |
|
2045 |
return 4; |
|
2046 |
} |
|
1922
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1903
diff
changeset
|
2047 |
} else if (fract_coord_leave == fract_coord) { |
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3154
diff
changeset
|
2048 |
if (DiagDirToDir(dir) == v->direction) { |
0 | 2049 |
/* leave the depot? */ |
2951 | 2050 |
if ((v = v->next) != NULL) { |
0 | 2051 |
v->vehstatus &= ~VS_HIDDEN; |
2052 |
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
|
2053 |
assert(v->u.rail.track); |
0 | 2054 |
} |
2055 |
} |
|
2056 |
} |
|
2057 |
||
2058 |
return 0; |
|
2059 |
} |
|
2060 |
||
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
|
2061 |
void InitializeRail(void) |
0 | 2062 |
{ |
2063 |
_last_built_train_depot_tile = 0; |
|
2064 |
} |
|
2065 |
||
2066 |
const TileTypeProcs _tile_type_rail_procs = { |
|
2067 |
DrawTile_Track, /* draw_tile_proc */ |
|
2068 |
GetSlopeZ_Track, /* get_slope_z_proc */ |
|
2069 |
ClearTile_Track, /* clear_tile_proc */ |
|
2070 |
GetAcceptedCargo_Track, /* get_accepted_cargo_proc */ |
|
2071 |
GetTileDesc_Track, /* get_tile_desc_proc */ |
|
2072 |
GetTileTrackStatus_Track, /* get_tile_track_status_proc */ |
|
2073 |
ClickTile_Track, /* click_tile_proc */ |
|
2074 |
AnimateTile_Track, /* animate_tile_proc */ |
|
2075 |
TileLoop_Track, /* tile_loop_clear */ |
|
2076 |
ChangeTileOwner_Track, /* change_tile_owner_clear */ |
|
2077 |
NULL, /* get_produced_cargo_proc */ |
|
2078 |
VehicleEnter_Track, /* vehicle_enter_tile_proc */ |
|
2079 |
NULL, /* vehicle_leave_tile_proc */ |
|
39 | 2080 |
GetSlopeTileh_Track, /* get_slope_tileh_proc */ |
0 | 2081 |
}; |