author | tron |
Tue, 27 Jun 2006 21:25:53 +0000 | |
changeset 4077 | d3022f976946 |
parent 4067 | ab047dec0733 |
child 4081 | 8d4111a68f72 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
0 | 3 |
#include "stdafx.h" |
1891
92a3b0aa0946
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1818
diff
changeset
|
4 |
#include "openttd.h" |
3189
1af302c5abd0
(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
797081e56d13
(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
637ec3c361f5
(svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents:
2148
diff
changeset
|
7 |
#include "functions.h" |
3101
e2fdb8802c2f
(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
426b825578f9
(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
01d3de5d8039
(svn r1867) Include tables/sprites.h only in files which need it
tron
parents:
1330
diff
changeset
|
10 |
#include "table/sprites.h" |
507
8aa8100b0b22
(svn r815) Include strings.h only in the files which need it.
tron
parents:
497
diff
changeset
|
11 |
#include "table/strings.h" |
679
e959706a3e4d
(svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
555
diff
changeset
|
12 |
#include "map.h" |
1209
a1ac96655b79
(svn r1713) Split off several functions which query/set information about a single tile from map.h and put them into a seperate file tile.h
tron
parents:
1123
diff
changeset
|
13 |
#include "tile.h" |
3319
7d04847e4689
(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
797081e56d13
(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
66647f97e7c0
(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
2d394eeba5e5
(svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents:
337
diff
changeset
|
23 |
#include "station.h" |
405
6830ae7a0d5d
(svn r602) -newgrf: Move DrawTileSeqStruct & co and struct SpriteGroup to sprite.h (pasky)
darkvater
parents:
403
diff
changeset
|
24 |
#include "sprite.h" |
1313
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1247
diff
changeset
|
25 |
#include "depot.h" |
1542
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1536
diff
changeset
|
26 |
#include "waypoint.h" |
1942
634961366cdc
(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 |
3638
6e0b43d905d4
(svn r4546) - NewGRF: add support for Action 0x05, type 0x04: replacement signal graphics. Thanks to Purno for supplying data to test
peter1138
parents:
3636
diff
changeset
|
29 |
#include "newgrf.h" |
3900
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3884
diff
changeset
|
30 |
#include "yapf/yapf.h" |
3757
a0bba34a94ba
(svn r4748) - Newstations: use custom sprite layout callback for waypoints as well as stations. Supports merging of adjacent waypoints if the GRF supports it (newstatsw.grf)
peter1138
parents:
3751
diff
changeset
|
31 |
#include "newgrf_callbacks.h" |
a0bba34a94ba
(svn r4748) - Newstations: use custom sprite layout callback for waypoints as well as stations. Supports merging of adjacent waypoints if the GRF supports it (newstatsw.grf)
peter1138
parents:
3751
diff
changeset
|
32 |
#include "newgrf_station.h" |
0 | 33 |
|
2261
3f78323707bb
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2254
diff
changeset
|
34 |
const byte _track_sloped_sprites[14] = { |
3f78323707bb
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2254
diff
changeset
|
35 |
14, 15, 22, 13, |
3f78323707bb
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2254
diff
changeset
|
36 |
0, 21, 17, 12, |
3f78323707bb
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2254
diff
changeset
|
37 |
23, 0, 18, 20, |
3f78323707bb
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2254
diff
changeset
|
38 |
19, 16 |
3f78323707bb
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2254
diff
changeset
|
39 |
}; |
3f78323707bb
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2254
diff
changeset
|
40 |
|
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1963
diff
changeset
|
41 |
void ShowTrainDepotWindow(TileIndex tile); |
0 | 42 |
|
43 |
/* 4 |
|
44 |
* --------- |
|
45 |
* |\ /| |
|
46 |
* | \ 1/ | |
|
47 |
* | \ / | |
|
48 |
* | \ / | |
|
49 |
* 16| \ |32 |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
50 |
* | / \2 | |
0 | 51 |
* | / \ | |
52 |
* | / \ | |
|
53 |
* |/ \| |
|
54 |
* --------- |
|
55 |
* 8 |
|
56 |
*/ |
|
57 |
||
58 |
||
59 |
||
22 | 60 |
/* 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
|
61 |
* MAP3LO byte: abcd???? => Signal Exists? |
22 | 62 |
* a and b are for diagonals, upper and left, |
63 |
* one for each direction. (ie a == NE->SW, b == |
|
64 |
* SW->NE, or v.v., I don't know. b and c are |
|
65 |
* similar for lower and right. |
|
0 | 66 |
* MAP2 byte: ????abcd => Type of ground. |
67 |
* MAP3LO byte: ????abcd => Type of rail. |
|
68 |
* MAP5: 00abcdef => rail |
|
69 |
* 01abcdef => rail w/ signals |
|
70 |
* 10uuuuuu => unused |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
71 |
* 11uuuudd => rail depot |
0 | 72 |
*/ |
73 |
||
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
74 |
static bool CheckTrackCombination(TileIndex tile, TrackBits to_build, uint flags) |
0 | 75 |
{ |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
76 |
RailTileType type = GetRailTileType(tile); |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
77 |
TrackBits current; /* The current track layout */ |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
78 |
TrackBits future; /* The track layout we want to build */ |
0 | 79 |
_error_message = STR_1001_IMPOSSIBLE_TRACK_COMBINATION; |
80 |
||
3792
2eb8388731bf
(svn r4788) - Codechange: RAILTYPE_{NORMAL,ELECTRIC,...} and RAIL_TYPE_{NORMAL,SIGNAL,...} have nearly the same name, rename RAIL_TYPE_* to RAIL_TILE_* of extra clarity
rubidium
parents:
3778
diff
changeset
|
81 |
if (type != RAIL_TILE_NORMAL && type != RAIL_TILE_SIGNALS) |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
82 |
return false; /* Cannot build anything on depots and checkpoints */ |
0 | 83 |
|
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
84 |
/* So, we have a tile with tracks on it (and possibly signals). Let's see |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
85 |
* what tracks first */ |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
86 |
current = GetTrackBits(tile); |
1946
68e7ee03016a
(svn r2452) Fix defect in r2448 which caused building tracks unexpectedly fail or succeed
tron
parents:
1942
diff
changeset
|
87 |
future = current | to_build; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
88 |
|
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
89 |
/* Are we really building something new? */ |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
90 |
if (current == future) { |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
91 |
/* Nothing new is being built */ |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
92 |
_error_message = STR_1007_ALREADY_BUILT; |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
93 |
return false; |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
94 |
} |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
95 |
|
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
96 |
/* Let's see if we may build this */ |
3792
2eb8388731bf
(svn r4788) - Codechange: RAILTYPE_{NORMAL,ELECTRIC,...} and RAIL_TYPE_{NORMAL,SIGNAL,...} have nearly the same name, rename RAIL_TYPE_* to RAIL_TILE_* of extra clarity
rubidium
parents:
3778
diff
changeset
|
97 |
if ((flags & DC_NO_RAIL_OVERLAP) || type == RAIL_TILE_SIGNALS) { |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
98 |
/* If we are not allowed to overlap (flag is on for ai players or we have |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
99 |
* signals on the tile), check that */ |
3258
94a915e7485f
(svn r3946) Add short hand names for common track combinations
tron
parents:
3254
diff
changeset
|
100 |
return future == TRACK_BIT_HORZ || future == TRACK_BIT_VERT; |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
101 |
} else { |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
102 |
/* Normally, we may overlap and any combination is valid */ |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
103 |
return true; |
0 | 104 |
} |
105 |
} |
|
106 |
||
107 |
||
4067
ab047dec0733
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
4052
diff
changeset
|
108 |
static const TrackBits _valid_tileh_slopes[][15] = { |
0 | 109 |
|
110 |
// set of normal ones |
|
111 |
{ |
|
3258
94a915e7485f
(svn r3946) Add short hand names for common track combinations
tron
parents:
3254
diff
changeset
|
112 |
TRACK_BIT_ALL, |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
113 |
TRACK_BIT_RIGHT, |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
114 |
TRACK_BIT_UPPER, |
3102
fde95020fc8e
(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
|
115 |
TRACK_BIT_X, |
0 | 116 |
|
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
117 |
TRACK_BIT_LEFT, |
0 | 118 |
0, |
3102
fde95020fc8e
(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
|
119 |
TRACK_BIT_Y, |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
120 |
TRACK_BIT_LOWER, |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
121 |
|
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
122 |
TRACK_BIT_LOWER, |
3102
fde95020fc8e
(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
|
123 |
TRACK_BIT_Y, |
0 | 124 |
0, |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
125 |
TRACK_BIT_LEFT, |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
126 |
|
3102
fde95020fc8e
(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
|
127 |
TRACK_BIT_X, |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
128 |
TRACK_BIT_UPPER, |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
129 |
TRACK_BIT_RIGHT, |
0 | 130 |
}, |
131 |
||
132 |
// allowed rail for an evenly raised platform |
|
133 |
{ |
|
134 |
0, |
|
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
135 |
TRACK_BIT_LEFT, |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
136 |
TRACK_BIT_LOWER, |
3102
fde95020fc8e
(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
|
137 |
TRACK_BIT_Y | TRACK_BIT_LOWER | TRACK_BIT_LEFT, |
0 | 138 |
|
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
139 |
TRACK_BIT_RIGHT, |
3258
94a915e7485f
(svn r3946) Add short hand names for common track combinations
tron
parents:
3254
diff
changeset
|
140 |
TRACK_BIT_ALL, |
3102
fde95020fc8e
(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
|
141 |
TRACK_BIT_X | TRACK_BIT_LOWER | TRACK_BIT_RIGHT, |
3258
94a915e7485f
(svn r3946) Add short hand names for common track combinations
tron
parents:
3254
diff
changeset
|
142 |
TRACK_BIT_ALL, |
0 | 143 |
|
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
144 |
TRACK_BIT_UPPER, |
3102
fde95020fc8e
(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
|
145 |
TRACK_BIT_X | TRACK_BIT_UPPER | TRACK_BIT_LEFT, |
3258
94a915e7485f
(svn r3946) Add short hand names for common track combinations
tron
parents:
3254
diff
changeset
|
146 |
TRACK_BIT_ALL, |
94a915e7485f
(svn r3946) Add short hand names for common track combinations
tron
parents:
3254
diff
changeset
|
147 |
TRACK_BIT_ALL, |
0 | 148 |
|
3102
fde95020fc8e
(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
|
149 |
TRACK_BIT_Y | TRACK_BIT_UPPER | TRACK_BIT_RIGHT, |
3258
94a915e7485f
(svn r3946) Add short hand names for common track combinations
tron
parents:
3254
diff
changeset
|
150 |
TRACK_BIT_ALL, |
94a915e7485f
(svn r3946) Add short hand names for common track combinations
tron
parents:
3254
diff
changeset
|
151 |
TRACK_BIT_ALL |
3276
fa7cc2225ca4
(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
|
152 |
} |
0 | 153 |
}; |
154 |
||
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3575
diff
changeset
|
155 |
uint GetRailFoundation(Slope tileh, TrackBits bits) |
0 | 156 |
{ |
3878
91a8b87f641e
(svn r4927) Replace 3 big ifs (which regard foundations) by a bit less confusing code
tron
parents:
3869
diff
changeset
|
157 |
uint i; |
0 | 158 |
|
3878
91a8b87f641e
(svn r4927) Replace 3 big ifs (which regard foundations) by a bit less confusing code
tron
parents:
3869
diff
changeset
|
159 |
if ((~_valid_tileh_slopes[0][tileh] & bits) == 0) return 0; |
91a8b87f641e
(svn r4927) Replace 3 big ifs (which regard foundations) by a bit less confusing code
tron
parents:
3869
diff
changeset
|
160 |
if ((~_valid_tileh_slopes[1][tileh] & bits) == 0) return tileh; |
91a8b87f641e
(svn r4927) Replace 3 big ifs (which regard foundations) by a bit less confusing code
tron
parents:
3869
diff
changeset
|
161 |
|
91a8b87f641e
(svn r4927) Replace 3 big ifs (which regard foundations) by a bit less confusing code
tron
parents:
3869
diff
changeset
|
162 |
switch (bits) { |
91a8b87f641e
(svn r4927) Replace 3 big ifs (which regard foundations) by a bit less confusing code
tron
parents:
3869
diff
changeset
|
163 |
case TRACK_BIT_X: i = 0; break; |
91a8b87f641e
(svn r4927) Replace 3 big ifs (which regard foundations) by a bit less confusing code
tron
parents:
3869
diff
changeset
|
164 |
case TRACK_BIT_Y: i = 1; break; |
91a8b87f641e
(svn r4927) Replace 3 big ifs (which regard foundations) by a bit less confusing code
tron
parents:
3869
diff
changeset
|
165 |
default: return 0; |
2951 | 166 |
} |
3878
91a8b87f641e
(svn r4927) Replace 3 big ifs (which regard foundations) by a bit less confusing code
tron
parents:
3869
diff
changeset
|
167 |
switch (tileh) { |
91a8b87f641e
(svn r4927) Replace 3 big ifs (which regard foundations) by a bit less confusing code
tron
parents:
3869
diff
changeset
|
168 |
case SLOPE_W: i += 0; break; |
91a8b87f641e
(svn r4927) Replace 3 big ifs (which regard foundations) by a bit less confusing code
tron
parents:
3869
diff
changeset
|
169 |
case SLOPE_S: i += 2; break; |
91a8b87f641e
(svn r4927) Replace 3 big ifs (which regard foundations) by a bit less confusing code
tron
parents:
3869
diff
changeset
|
170 |
case SLOPE_E: i += 4; break; |
91a8b87f641e
(svn r4927) Replace 3 big ifs (which regard foundations) by a bit less confusing code
tron
parents:
3869
diff
changeset
|
171 |
case SLOPE_N: i += 6; break; |
91a8b87f641e
(svn r4927) Replace 3 big ifs (which regard foundations) by a bit less confusing code
tron
parents:
3869
diff
changeset
|
172 |
default: return 0; |
91a8b87f641e
(svn r4927) Replace 3 big ifs (which regard foundations) by a bit less confusing code
tron
parents:
3869
diff
changeset
|
173 |
} |
91a8b87f641e
(svn r4927) Replace 3 big ifs (which regard foundations) by a bit less confusing code
tron
parents:
3869
diff
changeset
|
174 |
return i + 15; |
0 | 175 |
} |
176 |
||
2639 | 177 |
|
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3575
diff
changeset
|
178 |
static uint32 CheckRailSlope(Slope tileh, TrackBits rail_bits, TrackBits existing, TileIndex tile) |
0 | 179 |
{ |
180 |
// never allow building on top of steep tiles |
|
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3575
diff
changeset
|
181 |
if (!IsSteepSlope(tileh)) { |
0 | 182 |
rail_bits |= existing; |
183 |
||
184 |
// don't allow building on the lower side of a coast |
|
1627
d88508d9ced0
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
185 |
if (IsTileType(tile, MP_WATER) && |
3276
fa7cc2225ca4
(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
|
186 |
~_valid_tileh_slopes[1][tileh] & rail_bits) { |
0 | 187 |
return_cmd_error(STR_3807_CAN_T_BUILD_ON_WATER); |
188 |
} |
|
189 |
||
190 |
// no special foundation |
|
191 |
if ((~_valid_tileh_slopes[0][tileh] & rail_bits) == 0) |
|
192 |
return 0; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
193 |
|
1627
d88508d9ced0
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
194 |
if ((~_valid_tileh_slopes[1][tileh] & rail_bits) == 0 || ( // whole tile is leveled up |
3102
fde95020fc8e
(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
|
195 |
(rail_bits == TRACK_BIT_X || rail_bits == TRACK_BIT_Y) && |
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3575
diff
changeset
|
196 |
(tileh == SLOPE_W || tileh == SLOPE_S || tileh == SLOPE_E || tileh == SLOPE_N) |
1627
d88508d9ced0
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
197 |
)) { // partly up |
d88508d9ced0
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
198 |
if (existing != 0) { |
d88508d9ced0
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
199 |
return 0; |
2422
914a12dee832
(svn r2948) -Fix: the old AI needs a special flag that triggers all kind of special
truelight
parents:
2364
diff
changeset
|
200 |
} else if (!_patches.build_on_slopes || _is_old_ai_player) { |
1627
d88508d9ced0
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
201 |
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); |
d88508d9ced0
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
202 |
} else { |
d88508d9ced0
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
203 |
return _price.terraform; |
d88508d9ced0
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
204 |
} |
0 | 205 |
} |
206 |
} |
|
207 |
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); |
|
208 |
} |
|
209 |
||
1775
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1719
diff
changeset
|
210 |
/* Validate functions for rail building */ |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
211 |
static inline bool ValParamTrackOrientation(Track track) {return IsValidTrack(track);} |
1775
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1719
diff
changeset
|
212 |
|
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1719
diff
changeset
|
213 |
/** Build a single piece of rail |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3486
diff
changeset
|
214 |
* @param tile tile to build on |
1775
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1719
diff
changeset
|
215 |
* @param p1 railtype of being built piece (normal, mono, maglev) |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
216 |
* @param p2 rail track to build |
1775
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1719
diff
changeset
|
217 |
*/ |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3486
diff
changeset
|
218 |
int32 CmdBuildSingleRail(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 219 |
{ |
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3575
diff
changeset
|
220 |
Slope tileh; |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
221 |
Track track = (Track)p2; |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
222 |
TrackBits trackbit; |
1627
d88508d9ced0
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
223 |
int32 cost = 0; |
d88508d9ced0
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
224 |
int32 ret; |
d88508d9ced0
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
225 |
|
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
226 |
if (!ValParamRailtype(p1) || !ValParamTrackOrientation(track)) return CMD_ERROR; |
1627
d88508d9ced0
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
227 |
|
d88508d9ced0
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
228 |
tileh = GetTileSlope(tile, NULL); |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
229 |
trackbit = TrackToTrackBits(track); |
0 | 230 |
|
231 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
232 |
||
1627
d88508d9ced0
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
233 |
switch (GetTileType(tile)) { |
3977
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
234 |
case MP_TUNNELBRIDGE: |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
235 |
if (!IsBridge(tile) || |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
236 |
!IsBridgeMiddle(tile) || |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
237 |
(GetBridgeAxis(tile) == AXIS_X ? TRACK_BIT_Y : TRACK_BIT_X) != trackbit) { |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
238 |
// Get detailed error message |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
239 |
return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
240 |
} |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
241 |
|
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
242 |
if (IsClearUnderBridge(tile)) { |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
243 |
ret = CheckRailSlope(tileh, trackbit, 0, tile); |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
244 |
if (CmdFailed(ret)) return ret; |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
245 |
cost += ret; |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
246 |
|
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
247 |
if (flags & DC_EXEC) SetRailUnderBridge(tile, _current_player, p1); |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
248 |
} else if (IsTransportUnderBridge(tile) && |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
249 |
GetTransportTypeUnderBridge(tile) == TRANSPORT_RAIL) { |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
250 |
return_cmd_error(STR_1007_ALREADY_BUILT); |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
251 |
} else { |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
252 |
// Get detailed error message |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
253 |
return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
254 |
} |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
255 |
break; |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
256 |
|
1627
d88508d9ced0
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
257 |
case MP_RAILWAY: |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
258 |
if (!CheckTrackCombination(tile, trackbit, flags) || |
1627
d88508d9ced0
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
259 |
!EnsureNoVehicle(tile)) { |
d88508d9ced0
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
260 |
return CMD_ERROR; |
d88508d9ced0
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
261 |
} |
3792
2eb8388731bf
(svn r4788) - Codechange: RAILTYPE_{NORMAL,ELECTRIC,...} and RAIL_TYPE_{NORMAL,SIGNAL,...} have nearly the same name, rename RAIL_TYPE_* to RAIL_TILE_* of extra clarity
rubidium
parents:
3778
diff
changeset
|
262 |
if (GetRailTileType(tile) == RAIL_TILE_DEPOT_WAYPOINT || |
1903 | 263 |
!IsTileOwner(tile, _current_player) || |
3242
1cefa03f0d5e
(svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents:
3238
diff
changeset
|
264 |
GetRailType(tile) != p1) { |
1627
d88508d9ced0
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
265 |
// Get detailed error message |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3486
diff
changeset
|
266 |
return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
1627
d88508d9ced0
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
267 |
} |
d88508d9ced0
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
268 |
|
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
269 |
ret = CheckRailSlope(tileh, trackbit, GetTrackBits(tile), tile); |
1691
fcd9fefaed02
(svn r2195) Add CmdFailed() as the One True Way(tm) to check if a command failed.
tron
parents:
1669
diff
changeset
|
270 |
if (CmdFailed(ret)) return ret; |
0 | 271 |
cost += ret; |
272 |
||
1719
b428568cec03
(svn r2223) When adding tracks to a railway tile reset the ground to bare land, fix for a glitch in r2131
tron
parents:
1691
diff
changeset
|
273 |
if (flags & DC_EXEC) { |
3523
168ee460418b
(svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents:
3522
diff
changeset
|
274 |
SetRailGroundType(tile, RAIL_GROUND_BARREN); |
3271
0e796a2b7c9e
(svn r3983) Use existing functions to access tree and road info
tron
parents:
3270
diff
changeset
|
275 |
_m[tile].m5 |= trackbit; |
1719
b428568cec03
(svn r2223) When adding tracks to a railway tile reset the ground to bare land, fix for a glitch in r2131
tron
parents:
1691
diff
changeset
|
276 |
} |
1627
d88508d9ced0
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
277 |
break; |
0 | 278 |
|
1627
d88508d9ced0
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
279 |
case MP_STREET: |
3142
00b67636048f
(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
|
280 |
#define M(x) (1 << (x)) |
00b67636048f
(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
|
281 |
/* Level crossings may only be built on these slopes */ |
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3575
diff
changeset
|
282 |
if (!HASBIT(M(SLOPE_SEN) | M(SLOPE_ENW) | M(SLOPE_NWS) | M(SLOPE_NS) | M(SLOPE_WSE) | M(SLOPE_EW) | M(SLOPE_FLAT), tileh)) { |
1627
d88508d9ced0
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
283 |
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); |
3142
00b67636048f
(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
|
284 |
} |
00b67636048f
(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
|
285 |
#undef M |
00b67636048f
(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
|
286 |
|
1627
d88508d9ced0
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
287 |
if (!EnsureNoVehicle(tile)) return CMD_ERROR; |
0 | 288 |
|
4046
566de0b02064
(svn r5315) -Fix: Prohibit altering a road tile while road works are in progress
tron
parents:
4040
diff
changeset
|
289 |
if (GetRoadTileType(tile) == ROAD_TILE_NORMAL) { |
566de0b02064
(svn r5315) -Fix: Prohibit altering a road tile while road works are in progress
tron
parents:
4040
diff
changeset
|
290 |
if (HasRoadWorks(tile)) return_cmd_error(STR_ROAD_WORKS_IN_PROGRESS); |
566de0b02064
(svn r5315) -Fix: Prohibit altering a road tile while road works are in progress
tron
parents:
4040
diff
changeset
|
291 |
|
566de0b02064
(svn r5315) -Fix: Prohibit altering a road tile while road works are in progress
tron
parents:
4040
diff
changeset
|
292 |
if ((track == TRACK_X && GetRoadBits(tile) == ROAD_Y) || |
566de0b02064
(svn r5315) -Fix: Prohibit altering a road tile while road works are in progress
tron
parents:
4040
diff
changeset
|
293 |
(track == TRACK_Y && GetRoadBits(tile) == ROAD_X)) { |
566de0b02064
(svn r5315) -Fix: Prohibit altering a road tile while road works are in progress
tron
parents:
4040
diff
changeset
|
294 |
if (flags & DC_EXEC) { |
566de0b02064
(svn r5315) -Fix: Prohibit altering a road tile while road works are in progress
tron
parents:
4040
diff
changeset
|
295 |
MakeRoadCrossing(tile, GetTileOwner(tile), _current_player, (track == TRACK_X ? AXIS_Y : AXIS_X), p1, GetTownIndex(tile)); |
566de0b02064
(svn r5315) -Fix: Prohibit altering a road tile while road works are in progress
tron
parents:
4040
diff
changeset
|
296 |
} |
1627
d88508d9ced0
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
297 |
} |
d88508d9ced0
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
298 |
break; |
d88508d9ced0
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
299 |
} |
d88508d9ced0
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
300 |
|
3267
591027d10884
(svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents:
3265
diff
changeset
|
301 |
if (IsLevelCrossing(tile) && GetCrossingRailBits(tile) == trackbit) { |
1627
d88508d9ced0
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
302 |
return_cmd_error(STR_1007_ALREADY_BUILT); |
3267
591027d10884
(svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents:
3265
diff
changeset
|
303 |
} |
1627
d88508d9ced0
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
304 |
/* FALLTHROUGH */ |
d88508d9ced0
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
305 |
|
d88508d9ced0
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
306 |
default: |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
307 |
ret = CheckRailSlope(tileh, trackbit, 0, tile); |
1691
fcd9fefaed02
(svn r2195) Add CmdFailed() as the One True Way(tm) to check if a command failed.
tron
parents:
1669
diff
changeset
|
308 |
if (CmdFailed(ret)) return ret; |
1627
d88508d9ced0
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
309 |
cost += ret; |
d88508d9ced0
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
310 |
|
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3486
diff
changeset
|
311 |
ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
1691
fcd9fefaed02
(svn r2195) Add CmdFailed() as the One True Way(tm) to check if a command failed.
tron
parents:
1669
diff
changeset
|
312 |
if (CmdFailed(ret)) return ret; |
1627
d88508d9ced0
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
313 |
cost += ret; |
d88508d9ced0
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
314 |
|
3101
e2fdb8802c2f
(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
|
315 |
if (flags & DC_EXEC) MakeRailNormal(tile, _current_player, trackbit, p1); |
1627
d88508d9ced0
(svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents:
1609
diff
changeset
|
316 |
break; |
0 | 317 |
} |
318 |
||
319 |
if (flags & DC_EXEC) { |
|
320 |
MarkTileDirtyByTile(tile); |
|
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
321 |
SetSignalsOnBothDir(tile, track); |
3900
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3884
diff
changeset
|
322 |
YapfNotifyTrackLayoutChange(tile, track); |
0 | 323 |
} |
324 |
||
325 |
return cost + _price.build_rail; |
|
326 |
} |
|
327 |
||
1775
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1719
diff
changeset
|
328 |
/** Remove a single piece of track |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3486
diff
changeset
|
329 |
* @param tile tile to remove track from |
1775
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1719
diff
changeset
|
330 |
* @param p1 unused |
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1719
diff
changeset
|
331 |
* @param p2 rail orientation |
0 | 332 |
*/ |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3486
diff
changeset
|
333 |
int32 CmdRemoveSingleRail(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 334 |
{ |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
335 |
Track track = (Track)p2; |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
336 |
TrackBits trackbit; |
1963
8a398139fb87
(svn r2469) - Add: When removing tracks with the 'remove' tool, have it automatically remove signals on the tracks.
hackykid
parents:
1954
diff
changeset
|
337 |
int32 cost = _price.remove_rail; |
3284
fafe2ef7b809
(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
|
338 |
bool crossing = false; |
1775
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1719
diff
changeset
|
339 |
|
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1719
diff
changeset
|
340 |
if (!ValParamTrackOrientation(p2)) return CMD_ERROR; |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
341 |
trackbit = TrackToTrackBits(track); |
0 | 342 |
|
343 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
344 |
||
3273
7303df652359
(svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents:
3271
diff
changeset
|
345 |
switch (GetTileType(tile)) { |
3977
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
346 |
case MP_TUNNELBRIDGE: |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
347 |
if (!IsBridge(tile) || |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
348 |
!IsBridgeMiddle(tile) || |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
349 |
!IsTransportUnderBridge(tile) || |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
350 |
GetTransportTypeUnderBridge(tile) != TRANSPORT_RAIL || |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
351 |
GetRailBitsUnderBridge(tile) != trackbit || |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
352 |
(_current_player != OWNER_WATER && !CheckTileOwnership(tile)) || |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
353 |
!EnsureNoVehicleOnGround(tile)) { |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
354 |
return CMD_ERROR; |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
355 |
} |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
356 |
|
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
357 |
if (flags & DC_EXEC) SetClearUnderBridge(tile); |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
358 |
break; |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
359 |
|
3071
a6acfe74e0a7
(svn r3660) Convert further road bits and type references to the functions/enums
tron
parents:
3069
diff
changeset
|
360 |
case MP_STREET: { |
3273
7303df652359
(svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents:
3271
diff
changeset
|
361 |
if (!IsLevelCrossing(tile) || |
7303df652359
(svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents:
3271
diff
changeset
|
362 |
GetCrossingRailBits(tile) != trackbit || |
7303df652359
(svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents:
3271
diff
changeset
|
363 |
(_current_player != OWNER_WATER && !CheckTileOwnership(tile)) || |
7303df652359
(svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents:
3271
diff
changeset
|
364 |
!EnsureNoVehicle(tile)) { |
7303df652359
(svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents:
3271
diff
changeset
|
365 |
return CMD_ERROR; |
7303df652359
(svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents:
3271
diff
changeset
|
366 |
} |
0 | 367 |
|
3273
7303df652359
(svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents:
3271
diff
changeset
|
368 |
if (flags & DC_EXEC) { |
3319
7d04847e4689
(svn r4085) Add GetTown{Index,ByTile}() to get the town index resp. the town from a tile
tron
parents:
3286
diff
changeset
|
369 |
MakeRoadNormal(tile, GetCrossingRoadOwner(tile), GetCrossingRoadBits(tile), GetTownIndex(tile)); |
3273
7303df652359
(svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents:
3271
diff
changeset
|
370 |
} |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
371 |
break; |
3071
a6acfe74e0a7
(svn r3660) Convert further road bits and type references to the functions/enums
tron
parents:
3069
diff
changeset
|
372 |
} |
2548
97ada3bd2702
(svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents:
2544
diff
changeset
|
373 |
|
3273
7303df652359
(svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents:
3271
diff
changeset
|
374 |
case MP_RAILWAY: { |
7303df652359
(svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents:
3271
diff
changeset
|
375 |
TrackBits present; |
7303df652359
(svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents:
3271
diff
changeset
|
376 |
|
7303df652359
(svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents:
3271
diff
changeset
|
377 |
if (!IsPlainRailTile(tile) || |
7303df652359
(svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents:
3271
diff
changeset
|
378 |
(_current_player != OWNER_WATER && !CheckTileOwnership(tile)) || |
7303df652359
(svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents:
3271
diff
changeset
|
379 |
!EnsureNoVehicle(tile)) { |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
380 |
return CMD_ERROR; |
3273
7303df652359
(svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents:
3271
diff
changeset
|
381 |
} |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
382 |
|
3273
7303df652359
(svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents:
3271
diff
changeset
|
383 |
present = GetTrackBits(tile); |
7303df652359
(svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents:
3271
diff
changeset
|
384 |
if ((present & trackbit) == 0) return CMD_ERROR; |
3284
fafe2ef7b809
(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
|
385 |
if (present == (TRACK_BIT_X | TRACK_BIT_Y)) crossing = true; |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
386 |
|
1963
8a398139fb87
(svn r2469) - Add: When removing tracks with the 'remove' tool, have it automatically remove signals on the tracks.
hackykid
parents:
1954
diff
changeset
|
387 |
/* Charge extra to remove signals on the track, if they are there */ |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
388 |
if (HasSignalOnTrack(tile, track)) |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3486
diff
changeset
|
389 |
cost += DoCommand(tile, track, 0, flags, CMD_REMOVE_SIGNALS); |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
390 |
|
3273
7303df652359
(svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents:
3271
diff
changeset
|
391 |
if (flags & DC_EXEC) { |
7303df652359
(svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents:
3271
diff
changeset
|
392 |
present ^= trackbit; |
7303df652359
(svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents:
3271
diff
changeset
|
393 |
if (present == 0) { |
7303df652359
(svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents:
3271
diff
changeset
|
394 |
DoClearSquare(tile); |
7303df652359
(svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents:
3271
diff
changeset
|
395 |
} else { |
7303df652359
(svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents:
3271
diff
changeset
|
396 |
SetTrackBits(tile, present); |
7303df652359
(svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents:
3271
diff
changeset
|
397 |
} |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
398 |
} |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
399 |
break; |
3273
7303df652359
(svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents:
3271
diff
changeset
|
400 |
} |
2548
97ada3bd2702
(svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents:
2544
diff
changeset
|
401 |
|
3273
7303df652359
(svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents:
3271
diff
changeset
|
402 |
default: return CMD_ERROR; |
0 | 403 |
} |
404 |
||
3273
7303df652359
(svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents:
3271
diff
changeset
|
405 |
if (flags & DC_EXEC) { |
7303df652359
(svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents:
3271
diff
changeset
|
406 |
MarkTileDirtyByTile(tile); |
3284
fafe2ef7b809
(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
|
407 |
if (crossing) { |
fafe2ef7b809
(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
|
408 |
/* crossing is set when only TRACK_BIT_X and TRACK_BIT_Y are set. As we |
fafe2ef7b809
(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
|
409 |
* are removing one of these pieces, we'll need to update signals for |
fafe2ef7b809
(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
|
410 |
* both directions explicitly, as after the track is removed it won't |
fafe2ef7b809
(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
|
411 |
* 'connect' with the other piece. */ |
fafe2ef7b809
(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
|
412 |
SetSignalsOnBothDir(tile, TRACK_X); |
fafe2ef7b809
(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
|
413 |
SetSignalsOnBothDir(tile, TRACK_Y); |
3900
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3884
diff
changeset
|
414 |
YapfNotifyTrackLayoutChange(tile, TRACK_X); |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3884
diff
changeset
|
415 |
YapfNotifyTrackLayoutChange(tile, TRACK_Y); |
3284
fafe2ef7b809
(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
|
416 |
} else { |
fafe2ef7b809
(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
|
417 |
SetSignalsOnBothDir(tile, track); |
3900
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3884
diff
changeset
|
418 |
YapfNotifyTrackLayoutChange(tile, track); |
3284
fafe2ef7b809
(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
|
419 |
} |
3273
7303df652359
(svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents:
3271
diff
changeset
|
420 |
} |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
421 |
|
1963
8a398139fb87
(svn r2469) - Add: When removing tracks with the 'remove' tool, have it automatically remove signals on the tracks.
hackykid
parents:
1954
diff
changeset
|
422 |
return cost; |
0 | 423 |
} |
424 |
||
425 |
||
3493
4d5830846ec2
(svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents:
3491
diff
changeset
|
426 |
static const TileIndexDiffC _trackdelta[] = { |
4d5830846ec2
(svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents:
3491
diff
changeset
|
427 |
{ -1, 0 }, { 0, 1 }, { -1, 0 }, { 0, 1 }, { 1, 0 }, { 0, 1 }, |
4d5830846ec2
(svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents:
3491
diff
changeset
|
428 |
{ 0, 0 }, |
4d5830846ec2
(svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents:
3491
diff
changeset
|
429 |
{ 0, 0 }, |
4d5830846ec2
(svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents:
3491
diff
changeset
|
430 |
{ 1, 0 }, { 0, -1 }, { 0, -1 }, { 1, 0 }, { 0, -1 }, { -1, 0 }, |
4d5830846ec2
(svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents:
3491
diff
changeset
|
431 |
{ 0, 0 }, |
4d5830846ec2
(svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents:
3491
diff
changeset
|
432 |
{ 0, 0 } |
4d5830846ec2
(svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents:
3491
diff
changeset
|
433 |
}; |
4d5830846ec2
(svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents:
3491
diff
changeset
|
434 |
|
4d5830846ec2
(svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents:
3491
diff
changeset
|
435 |
|
4d5830846ec2
(svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents:
3491
diff
changeset
|
436 |
static int32 ValidateAutoDrag(Trackdir *trackdir, TileIndex start, TileIndex end) |
1227
3552f20fcfcb
(svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater
parents:
1209
diff
changeset
|
437 |
{ |
3493
4d5830846ec2
(svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents:
3491
diff
changeset
|
438 |
int x = TileX(start); |
4d5830846ec2
(svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents:
3491
diff
changeset
|
439 |
int y = TileY(start); |
4d5830846ec2
(svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents:
3491
diff
changeset
|
440 |
int ex = TileX(end); |
4d5830846ec2
(svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents:
3491
diff
changeset
|
441 |
int ey = TileY(end); |
1227
3552f20fcfcb
(svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater
parents:
1209
diff
changeset
|
442 |
int dx, dy, trdx, trdy; |
0 | 443 |
|
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
444 |
if (!ValParamTrackOrientation(*trackdir)) return CMD_ERROR; |
1227
3552f20fcfcb
(svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater
parents:
1209
diff
changeset
|
445 |
|
3552f20fcfcb
(svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater
parents:
1209
diff
changeset
|
446 |
// calculate delta x,y from start to end tile |
3552f20fcfcb
(svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater
parents:
1209
diff
changeset
|
447 |
dx = ex - x; |
3552f20fcfcb
(svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater
parents:
1209
diff
changeset
|
448 |
dy = ey - y; |
3552f20fcfcb
(svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater
parents:
1209
diff
changeset
|
449 |
|
3552f20fcfcb
(svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater
parents:
1209
diff
changeset
|
450 |
// calculate delta x,y for the first direction |
3493
4d5830846ec2
(svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents:
3491
diff
changeset
|
451 |
trdx = _trackdelta[*trackdir].x; |
4d5830846ec2
(svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents:
3491
diff
changeset
|
452 |
trdy = _trackdelta[*trackdir].y; |
1227
3552f20fcfcb
(svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater
parents:
1209
diff
changeset
|
453 |
|
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
454 |
if (!IsDiagonalTrackdir(*trackdir)) { |
3493
4d5830846ec2
(svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents:
3491
diff
changeset
|
455 |
trdx += _trackdelta[*trackdir ^ 1].x; |
4d5830846ec2
(svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents:
3491
diff
changeset
|
456 |
trdy += _trackdelta[*trackdir ^ 1].y; |
1227
3552f20fcfcb
(svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater
parents:
1209
diff
changeset
|
457 |
} |
3552f20fcfcb
(svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater
parents:
1209
diff
changeset
|
458 |
|
3552f20fcfcb
(svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater
parents:
1209
diff
changeset
|
459 |
// validate the direction |
2951 | 460 |
while ( |
461 |
(trdx <= 0 && dx > 0) || |
|
462 |
(trdx >= 0 && dx < 0) || |
|
463 |
(trdy <= 0 && dy > 0) || |
|
464 |
(trdy >= 0 && dy < 0) |
|
465 |
) { |
|
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
466 |
if (!HASBIT(*trackdir, 3)) { // first direction is invalid, try the other |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
467 |
SETBIT(*trackdir, 3); // reverse the direction |
1227
3552f20fcfcb
(svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater
parents:
1209
diff
changeset
|
468 |
trdx = -trdx; |
3552f20fcfcb
(svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater
parents:
1209
diff
changeset
|
469 |
trdy = -trdy; |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4067
diff
changeset
|
470 |
} else { // other direction is invalid too, invalid drag |
1227
3552f20fcfcb
(svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater
parents:
1209
diff
changeset
|
471 |
return CMD_ERROR; |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4067
diff
changeset
|
472 |
} |
1227
3552f20fcfcb
(svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater
parents:
1209
diff
changeset
|
473 |
} |
3552f20fcfcb
(svn r1731) - Fix: [ 1106930 ] BugFix: placing 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 |
|
3552f20fcfcb
(svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater
parents:
1209
diff
changeset
|
475 |
// (for diagonal tracks, this is already made sure of by above test), but: |
3552f20fcfcb
(svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater
parents:
1209
diff
changeset
|
476 |
// for non-diagonal tracks, check if the start and end tile are on 1 line |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
477 |
if (!IsDiagonalTrackdir(*trackdir)) { |
3493
4d5830846ec2
(svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents:
3491
diff
changeset
|
478 |
trdx = _trackdelta[*trackdir].x; |
4d5830846ec2
(svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents:
3491
diff
changeset
|
479 |
trdy = _trackdelta[*trackdir].y; |
2951 | 480 |
if (abs(dx) != abs(dy) && abs(dx) + abs(trdy) != abs(dy) + abs(trdx)) |
1227
3552f20fcfcb
(svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater
parents:
1209
diff
changeset
|
481 |
return CMD_ERROR; |
3552f20fcfcb
(svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater
parents:
1209
diff
changeset
|
482 |
} |
3552f20fcfcb
(svn r1731) - Fix: [ 1106930 ] BugFix: placing 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 |
|
3552f20fcfcb
(svn r1731) - Fix: [ 1106930 ] BugFix: placing 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 |
return 0; |
3552f20fcfcb
(svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater
parents:
1209
diff
changeset
|
485 |
} |
3552f20fcfcb
(svn r1731) - Fix: [ 1106930 ] BugFix: placing 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 |
|
1775
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1719
diff
changeset
|
487 |
/** Build a stretch of railroad tracks. |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3486
diff
changeset
|
488 |
* @param tile start tile of drag |
1775
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1719
diff
changeset
|
489 |
* @param p1 end tile of drag |
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1719
diff
changeset
|
490 |
* @param p2 various bitstuffed elements |
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1719
diff
changeset
|
491 |
* - p2 = (bit 0-3) - railroad type normal/maglev (0 = normal, 1 = mono, 2 = maglev) |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
492 |
* - p2 = (bit 4-6) - track-orientation, valid values: 0-5 (Track enum) |
1775
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1719
diff
changeset
|
493 |
* - p2 = (bit 7) - 0 = build, 1 = remove tracks |
0 | 494 |
*/ |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3486
diff
changeset
|
495 |
static int32 CmdRailTrackHelper(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
1227
3552f20fcfcb
(svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater
parents:
1209
diff
changeset
|
496 |
{ |
3552f20fcfcb
(svn r1731) - Fix: [ 1106930 ] BugFix: placing 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 |
int32 ret, total_cost = 0; |
2140
d708eb80ab8b
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2111
diff
changeset
|
498 |
Track track = (Track)GB(p2, 4, 3); |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
499 |
Trackdir trackdir; |
1227
3552f20fcfcb
(svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater
parents:
1209
diff
changeset
|
500 |
byte mode = HASBIT(p2, 7); |
2604
901508f52c3d
(svn r3141) Replace incorrect railtype bitmask in CmdRailTrackHelper with appropriate GB()
peter1138
parents:
2549
diff
changeset
|
501 |
RailType railtype = (RailType)GB(p2, 0, 4); |
3493
4d5830846ec2
(svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents:
3491
diff
changeset
|
502 |
TileIndex end_tile; |
0 | 503 |
|
2604
901508f52c3d
(svn r3141) Replace incorrect railtype bitmask in CmdRailTrackHelper with appropriate GB()
peter1138
parents:
2549
diff
changeset
|
504 |
if (!ValParamRailtype(railtype) || !ValParamTrackOrientation(track)) return CMD_ERROR; |
2934
3b7eef9871f8
(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
|
505 |
if (p1 >= MapSize()) return CMD_ERROR; |
3493
4d5830846ec2
(svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents:
3491
diff
changeset
|
506 |
end_tile = p1; |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
507 |
trackdir = TrackToTrackdir(track); |
1775
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1719
diff
changeset
|
508 |
|
889
7f8630bfea41
(svn r1375) -Fix: [1050990] Buying trains sometimes accounted for incorrectly. Was the result of the cost getting reset in a recursive call of docommand. That is fixed. In addition all cost-commands are typed explicitely. Please do not forget to do so or your costs will be credited to construction if you are unlucky.
darkvater
parents:
826
diff
changeset
|
509 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
7f8630bfea41
(svn r1375) -Fix: [1050990] Buying trains sometimes accounted for incorrectly. Was the result of the cost getting reset in a recursive call of docommand. That is fixed. In addition all cost-commands are typed explicitely. Please do not forget to do so or your costs will be credited to construction if you are unlucky.
darkvater
parents:
826
diff
changeset
|
510 |
|
3493
4d5830846ec2
(svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents:
3491
diff
changeset
|
511 |
if (CmdFailed(ValidateAutoDrag(&trackdir, tile, end_tile))) return CMD_ERROR; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
512 |
|
3493
4d5830846ec2
(svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents:
3491
diff
changeset
|
513 |
if (flags & DC_EXEC) SndPlayTileFx(SND_20_SPLAT_2, tile); |
0 | 514 |
|
2952 | 515 |
for (;;) { |
3493
4d5830846ec2
(svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents:
3491
diff
changeset
|
516 |
ret = DoCommand(tile, railtype, TrackdirToTrack(trackdir), flags, (mode == 0) ? CMD_BUILD_SINGLE_RAIL : CMD_REMOVE_SINGLE_RAIL); |
0 | 517 |
|
1775
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1719
diff
changeset
|
518 |
if (CmdFailed(ret)) { |
3671
6d3a34989d05
(svn r4586) - Codechange: Recursive commands that rely on _error_message to handle success/failure can fail if a recursive call fails but doesn't set the error message, thus resulting in an old, possibly erroneous being used (see FS#130 prior to r4585). Now properly reset the global variable _error_message in these cases.
Darkvater
parents:
3657
diff
changeset
|
519 |
if ((_error_message != STR_1007_ALREADY_BUILT) && (mode == 0)) break; |
6d3a34989d05
(svn r4586) - Codechange: Recursive commands that rely on _error_message to handle success/failure can fail if a recursive call fails but doesn't set the error message, thus resulting in an old, possibly erroneous being used (see FS#130 prior to r4585). Now properly reset the global variable _error_message in these cases.
Darkvater
parents:
3657
diff
changeset
|
520 |
_error_message = INVALID_STRING_ID; |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4067
diff
changeset
|
521 |
} else { |
0 | 522 |
total_cost += ret; |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4067
diff
changeset
|
523 |
} |
0 | 524 |
|
3493
4d5830846ec2
(svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents:
3491
diff
changeset
|
525 |
if (tile == end_tile) break; |
0 | 526 |
|
3493
4d5830846ec2
(svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents:
3491
diff
changeset
|
527 |
tile += ToTileIndexDiff(_trackdelta[trackdir]); |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
528 |
|
1227
3552f20fcfcb
(svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater
parents:
1209
diff
changeset
|
529 |
// toggle railbit for the non-diagonal tracks |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
530 |
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
|
531 |
} |
0 | 532 |
|
1775
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1719
diff
changeset
|
533 |
return (total_cost == 0) ? CMD_ERROR : total_cost; |
0 | 534 |
} |
535 |
||
1796
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1782
diff
changeset
|
536 |
/** Build rail on a stretch of track. |
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1782
diff
changeset
|
537 |
* Stub for the unified rail builder/remover |
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1782
diff
changeset
|
538 |
* @see CmdRailTrackHelper |
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1782
diff
changeset
|
539 |
*/ |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3486
diff
changeset
|
540 |
int32 CmdBuildRailroadTrack(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
1227
3552f20fcfcb
(svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater
parents:
1209
diff
changeset
|
541 |
{ |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3486
diff
changeset
|
542 |
return CmdRailTrackHelper(tile, flags, p1, CLRBIT(p2, 7)); |
1227
3552f20fcfcb
(svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater
parents:
1209
diff
changeset
|
543 |
} |
0 | 544 |
|
1796
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1782
diff
changeset
|
545 |
/** Build rail on a stretch of track. |
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1782
diff
changeset
|
546 |
* Stub for the unified rail builder/remover |
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1782
diff
changeset
|
547 |
* @see CmdRailTrackHelper |
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1782
diff
changeset
|
548 |
*/ |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3486
diff
changeset
|
549 |
int32 CmdRemoveRailroadTrack(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 550 |
{ |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3486
diff
changeset
|
551 |
return CmdRailTrackHelper(tile, flags, p1, SETBIT(p2, 7)); |
0 | 552 |
} |
553 |
||
1775
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1719
diff
changeset
|
554 |
/** Build a train depot |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3486
diff
changeset
|
555 |
* @param tile position of the train depot |
1775
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1719
diff
changeset
|
556 |
* @param p1 rail type |
3333 | 557 |
* @param p2 entrance direction (DiagDirection) |
2085
ae9e92ffe168
(svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents:
2049
diff
changeset
|
558 |
* |
ae9e92ffe168
(svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents:
2049
diff
changeset
|
559 |
* @todo When checking for the tile slope, |
ae9e92ffe168
(svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents:
2049
diff
changeset
|
560 |
* distingush between "Flat land required" and "land sloped in wrong direction" |
0 | 561 |
*/ |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3486
diff
changeset
|
562 |
int32 CmdBuildTrainDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 563 |
{ |
1775
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1719
diff
changeset
|
564 |
Depot *d; |
0 | 565 |
int32 cost, ret; |
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3575
diff
changeset
|
566 |
Slope tileh; |
0 | 567 |
|
568 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
569 |
||
570 |
if (!EnsureNoVehicle(tile)) return CMD_ERROR; |
|
1775
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1719
diff
changeset
|
571 |
/* check railtype and valid direction for depot (0 through 3), 4 in total */ |
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1719
diff
changeset
|
572 |
if (!ValParamRailtype(p1) || p2 > 3) return CMD_ERROR; |
0 | 573 |
|
574 |
tileh = GetTileSlope(tile, NULL); |
|
2085
ae9e92ffe168
(svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents:
2049
diff
changeset
|
575 |
|
ae9e92ffe168
(svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents:
2049
diff
changeset
|
576 |
/* Prohibit construction if |
ae9e92ffe168
(svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents:
2049
diff
changeset
|
577 |
The tile is non-flat AND |
ae9e92ffe168
(svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents:
2049
diff
changeset
|
578 |
1) The AI is "old-school" |
ae9e92ffe168
(svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents:
2049
diff
changeset
|
579 |
2) build-on-slopes is disabled |
ae9e92ffe168
(svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents:
2049
diff
changeset
|
580 |
3) the tile is steep i.e. spans two height levels |
ae9e92ffe168
(svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents:
2049
diff
changeset
|
581 |
4) the exit points in the wrong direction |
ae9e92ffe168
(svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents:
2049
diff
changeset
|
582 |
|
ae9e92ffe168
(svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents:
2049
diff
changeset
|
583 |
*/ |
ae9e92ffe168
(svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents:
2049
diff
changeset
|
584 |
|
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3575
diff
changeset
|
585 |
if (tileh != SLOPE_FLAT && ( |
2548
97ada3bd2702
(svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents:
2544
diff
changeset
|
586 |
_is_old_ai_player || |
97ada3bd2702
(svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents:
2544
diff
changeset
|
587 |
!_patches.build_on_slopes || |
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3575
diff
changeset
|
588 |
IsSteepSlope(tileh) || |
2548
97ada3bd2702
(svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents:
2544
diff
changeset
|
589 |
!CanBuildDepotByTileh(p2, tileh) |
97ada3bd2702
(svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents:
2544
diff
changeset
|
590 |
)) { |
97ada3bd2702
(svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents:
2544
diff
changeset
|
591 |
return_cmd_error(STR_0007_FLAT_LAND_REQUIRED); |
0 | 592 |
} |
593 |
||
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3486
diff
changeset
|
594 |
ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
1775
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1719
diff
changeset
|
595 |
if (CmdFailed(ret)) return CMD_ERROR; |
0 | 596 |
cost = ret; |
597 |
||
1775
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1719
diff
changeset
|
598 |
d = AllocateDepot(); |
2639 | 599 |
if (d == NULL) return CMD_ERROR; |
0 | 600 |
|
601 |
if (flags & DC_EXEC) { |
|
3101
e2fdb8802c2f
(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
|
602 |
MakeRailDepot(tile, _current_player, p2, p1); |
e2fdb8802c2f
(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
|
603 |
MarkTileDirtyByTile(tile); |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
604 |
|
1775
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1719
diff
changeset
|
605 |
d->xy = tile; |
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1719
diff
changeset
|
606 |
d->town_index = ClosestTownFromTile(tile, (uint)-1)->index; |
0 | 607 |
|
3191
d273bda0f5d4
(svn r3851) Rail depots only have an entrance at one side, therefore use UpdateSignalsOnSegment() instead of SetSignalsOnBothDir()
tron
parents:
3189
diff
changeset
|
608 |
UpdateSignalsOnSegment(tile, p2); |
3900
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3884
diff
changeset
|
609 |
YapfNotifyTrackLayoutChange(tile, TrackdirToTrack(DiagdirToDiagTrackdir(p2))); |
0 | 610 |
} |
611 |
||
612 |
return cost + _price.build_train_depot; |
|
613 |
} |
|
614 |
||
1775
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1719
diff
changeset
|
615 |
/** Build signals, alternate between double/single, signal/semaphore, |
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1719
diff
changeset
|
616 |
* pre/exit/combo-signals, and what-else not |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3486
diff
changeset
|
617 |
* @param tile tile where to build the signals |
1775
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1719
diff
changeset
|
618 |
* @param p1 various bitstuffed elements |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
619 |
* - p1 = (bit 0-2) - track-orientation, valid values: 0-5 (Track enum) |
1775
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1719
diff
changeset
|
620 |
* - p1 = (bit 3) - choose semaphores/signals or cycle normal/pre/exit/combo depending on context |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
621 |
* @param p2 used for CmdBuildManySignals() to copy direction of first signal |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
622 |
* 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
|
623 |
*/ |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3486
diff
changeset
|
624 |
int32 CmdBuildSingleSignal(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 625 |
{ |
3237
985399d4099d
(svn r3911) Add functions to retrieve/set the signal variant (electric/semaphore)
tron
parents:
3234
diff
changeset
|
626 |
SignalVariant sigvar; |
1084 | 627 |
bool pre_signal; |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
628 |
Track track = (Track)(p1 & 0x7); |
0 | 629 |
int32 cost; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
630 |
|
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
631 |
// Same bit, used in different contexts |
3237
985399d4099d
(svn r3911) Add functions to retrieve/set the signal variant (electric/semaphore)
tron
parents:
3234
diff
changeset
|
632 |
sigvar = HASBIT(p1, 3) ? SIG_SEMAPHORE : SIG_ELECTRIC; |
985399d4099d
(svn r3911) Add functions to retrieve/set the signal variant (electric/semaphore)
tron
parents:
3234
diff
changeset
|
633 |
pre_signal = HASBIT(p1, 3); |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
634 |
|
1775
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1719
diff
changeset
|
635 |
if (!ValParamTrackOrientation(track) || !IsTileType(tile, MP_RAILWAY) || !EnsureNoVehicle(tile)) |
0 | 636 |
return CMD_ERROR; |
637 |
||
1775
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1719
diff
changeset
|
638 |
/* Protect against invalid signal copying */ |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
639 |
if (p2 != 0 && (p2 & SignalOnTrack(track)) == 0) return CMD_ERROR; |
0 | 640 |
|
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
641 |
/* You can only build signals on plain rail tiles, and the selected track must exist */ |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
642 |
if (!IsPlainRailTile(tile) || !HasTrack(tile, track)) return CMD_ERROR; |
1084 | 643 |
|
644 |
if (!CheckTileOwnership(tile)) return CMD_ERROR; |
|
645 |
||
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
|
646 |
_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
|
647 |
|
0 | 648 |
{ |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4067
diff
changeset
|
649 |
/* See if this is a valid track combination for signals, (ie, no overlap) */ |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4067
diff
changeset
|
650 |
TrackBits trackbits = GetTrackBits(tile); |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
651 |
if (KILL_FIRST_BIT(trackbits) != 0 && /* More than one track present */ |
3258
94a915e7485f
(svn r3946) Add short hand names for common track combinations
tron
parents:
3254
diff
changeset
|
652 |
trackbits != TRACK_BIT_HORZ && |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4067
diff
changeset
|
653 |
trackbits != TRACK_BIT_VERT) { |
0 | 654 |
return CMD_ERROR; |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4067
diff
changeset
|
655 |
} |
0 | 656 |
} |
657 |
||
1084 | 658 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
0 | 659 |
|
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
660 |
if (!HasSignalOnTrack(tile, track)) { |
1084 | 661 |
// build new signals |
0 | 662 |
cost = _price.build_signals; |
1066
aad3c6ad147f
(svn r1567) -Fix: [110452] On horizontal/vertical tracks you are also charged for building/removing signals on the parallel track on the same tile. Signal updating is also correct. (Hackykid)
darkvater
parents:
1059
diff
changeset
|
663 |
} else { |
3237
985399d4099d
(svn r3911) Add functions to retrieve/set the signal variant (electric/semaphore)
tron
parents:
3234
diff
changeset
|
664 |
if (p2 != 0 && sigvar != GetSignalVariant(tile)) { |
1084 | 665 |
// convert signals <-> semaphores |
666 |
cost = _price.build_signals + _price.remove_signals; |
|
667 |
} else { |
|
668 |
// it is free to change orientation/pre-exit-combo signals |
|
669 |
cost = 0; |
|
670 |
} |
|
0 | 671 |
} |
672 |
||
673 |
if (flags & DC_EXEC) { |
|
3792
2eb8388731bf
(svn r4788) - Codechange: RAILTYPE_{NORMAL,ELECTRIC,...} and RAIL_TYPE_{NORMAL,SIGNAL,...} have nearly the same name, rename RAIL_TYPE_* to RAIL_TILE_* of extra clarity
rubidium
parents:
3778
diff
changeset
|
674 |
if (GetRailTileType(tile) != RAIL_TILE_SIGNALS) { |
1084 | 675 |
// there are no signals at all on this tile yet |
3792
2eb8388731bf
(svn r4788) - Codechange: RAILTYPE_{NORMAL,ELECTRIC,...} and RAIL_TYPE_{NORMAL,SIGNAL,...} have nearly the same name, rename RAIL_TYPE_* to RAIL_TILE_* of extra clarity
rubidium
parents:
3778
diff
changeset
|
676 |
_m[tile].m5 |= RAIL_TILE_SIGNALS; // change into signals |
2049
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2020
diff
changeset
|
677 |
_m[tile].m2 |= 0xF0; // all signals are on |
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2020
diff
changeset
|
678 |
_m[tile].m3 &= ~0xF0; // no signals built by default |
3526
3a0dddcfd33b
(svn r4382) -Codechange: Make use of SetSignalType where appropriate
celestar
parents:
3525
diff
changeset
|
679 |
SetSignalType(tile, SIGTYPE_NORMAL); |
3237
985399d4099d
(svn r3911) Add functions to retrieve/set the signal variant (electric/semaphore)
tron
parents:
3234
diff
changeset
|
680 |
SetSignalVariant(tile, sigvar); |
0 | 681 |
} |
682 |
||
1084 | 683 |
if (p2 == 0) { |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
684 |
if (!HasSignalOnTrack(tile, track)) { |
1084 | 685 |
// build new signals |
2049
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2020
diff
changeset
|
686 |
_m[tile].m3 |= SignalOnTrack(track); |
1084 | 687 |
} else { |
688 |
if (pre_signal) { |
|
2916
8f1aa489701f
(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
|
689 |
// cycle between normal -> pre -> exit -> combo -> ... |
3238
a100405fe221
(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
|
690 |
SignalType type = GetSignalType(tile); |
a100405fe221
(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
|
691 |
|
a100405fe221
(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
|
692 |
SetSignalType(tile, type == SIGTYPE_COMBO ? SIGTYPE_NORMAL : type + 1); |
1084 | 693 |
} else { |
3522
25ce619b9a19
(svn r4378) -Add and make use of an accessor function two-way => one-way => one-way => two-way signal cycling
celestar
parents:
3521
diff
changeset
|
694 |
CycleSignalSide(tile, track); |
1084 | 695 |
} |
696 |
} |
|
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
|
697 |
} else { |
1084 | 698 |
/* If CmdBuildManySignals is called with copying signals, just copy the |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
699 |
* direction of the first signal given as parameter by CmdBuildManySignals */ |
2049
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2020
diff
changeset
|
700 |
_m[tile].m3 &= ~SignalOnTrack(track); |
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2020
diff
changeset
|
701 |
_m[tile].m3 |= p2 & SignalOnTrack(track); |
3237
985399d4099d
(svn r3911) Add functions to retrieve/set the signal variant (electric/semaphore)
tron
parents:
3234
diff
changeset
|
702 |
SetSignalVariant(tile, sigvar); |
0 | 703 |
} |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
704 |
|
0 | 705 |
MarkTileDirtyByTile(tile); |
706 |
SetSignalsOnBothDir(tile, track); |
|
3900
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3884
diff
changeset
|
707 |
YapfNotifyTrackLayoutChange(tile, track); |
0 | 708 |
} |
709 |
||
710 |
return cost; |
|
711 |
} |
|
712 |
||
1796
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1782
diff
changeset
|
713 |
/** Build many signals by dragging; AutoSignals |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3486
diff
changeset
|
714 |
* @param tile start tile of drag |
1796
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1782
diff
changeset
|
715 |
* @param p1 end tile of drag |
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1782
diff
changeset
|
716 |
* @param p2 various bitstuffed elements |
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1782
diff
changeset
|
717 |
* - p2 = (bit 0) - 0 = build, 1 = remove signals |
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1782
diff
changeset
|
718 |
* - p2 = (bit 3) - 0 = signals, 1 = semaphores |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
719 |
* - p2 = (bit 4- 6) - track-orientation, valid values: 0-5 (Track enum) |
1796
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1782
diff
changeset
|
720 |
* - 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
|
721 |
*/ |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3486
diff
changeset
|
722 |
static int32 CmdSignalTrackHelper(TileIndex tile, 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
|
723 |
{ |
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
|
724 |
int32 ret, total_cost, signal_ctr; |
1954
58fee2f9eb81
(svn r2460) - Fix: Prevent assertion failure when trying to drag signals starting from a non-rail tile.
hackykid
parents:
1946
diff
changeset
|
725 |
byte signals; |
1796
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1782
diff
changeset
|
726 |
bool error = true; |
3493
4d5830846ec2
(svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents:
3491
diff
changeset
|
727 |
TileIndex end_tile; |
1796
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1782
diff
changeset
|
728 |
|
1227
3552f20fcfcb
(svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater
parents:
1209
diff
changeset
|
729 |
int mode = p2 & 0x1; |
2140
d708eb80ab8b
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2111
diff
changeset
|
730 |
Track track = GB(p2, 4, 3); |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
731 |
Trackdir trackdir = TrackToTrackdir(track); |
4000
bab1ebc37da0
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3977
diff
changeset
|
732 |
byte semaphores = (HASBIT(p2, 3) ? 8 : 0); |
1796
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1782
diff
changeset
|
733 |
byte signal_density = (p2 >> 24); |
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1782
diff
changeset
|
734 |
|
2934
3b7eef9871f8
(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
|
735 |
if (p1 >= MapSize()) return CMD_ERROR; |
3493
4d5830846ec2
(svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents:
3491
diff
changeset
|
736 |
end_tile = p1; |
1796
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1782
diff
changeset
|
737 |
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
|
738 |
|
2639 | 739 |
if (!IsTileType(tile, MP_RAILWAY)) return CMD_ERROR; |
1954
58fee2f9eb81
(svn r2460) - Fix: Prevent assertion failure when trying to drag signals starting from a non-rail tile.
hackykid
parents:
1946
diff
changeset
|
740 |
|
889
7f8630bfea41
(svn r1375) -Fix: [1050990] Buying trains sometimes accounted for incorrectly. Was the result of the cost getting reset in a recursive call of docommand. That is fixed. In addition all cost-commands are typed explicitely. Please do not forget to do so or your costs will be credited to construction if you are unlucky.
darkvater
parents:
826
diff
changeset
|
741 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
7f8630bfea41
(svn r1375) -Fix: [1050990] Buying trains sometimes accounted for incorrectly. Was the result of the cost getting reset in a recursive call of docommand. That is fixed. In addition all cost-commands are typed explicitely. Please do not forget to do so or your costs will be credited to construction if you are unlucky.
darkvater
parents:
826
diff
changeset
|
742 |
|
1796
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1782
diff
changeset
|
743 |
/* for vertical/horizontal tracks, double the given signals density |
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1782
diff
changeset
|
744 |
* since the original amount will be too dense (shorter tracks) */ |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4067
diff
changeset
|
745 |
if (!IsDiagonalTrack(track)) signal_density *= 2; |
1796
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1782
diff
changeset
|
746 |
|
3493
4d5830846ec2
(svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents:
3491
diff
changeset
|
747 |
if (CmdFailed(ValidateAutoDrag(&trackdir, tile, end_tile))) return CMD_ERROR; |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
748 |
|
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
749 |
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
|
750 |
|
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
|
751 |
// copy the signal-style of the first rail-piece if existing |
3792
2eb8388731bf
(svn r4788) - Codechange: RAILTYPE_{NORMAL,ELECTRIC,...} and RAIL_TYPE_{NORMAL,SIGNAL,...} have nearly the same name, rename RAIL_TYPE_* to RAIL_TILE_* of extra clarity
rubidium
parents:
3778
diff
changeset
|
752 |
if (GetRailTileType(tile) == RAIL_TILE_SIGNALS && GetTrackBits(tile) != 0) { /* XXX: GetTrackBits check useless? */ |
2049
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2020
diff
changeset
|
753 |
signals = _m[tile].m3 & SignalOnTrack(track); |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
754 |
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
|
755 |
|
3237
985399d4099d
(svn r3911) Add functions to retrieve/set the signal variant (electric/semaphore)
tron
parents:
3234
diff
changeset
|
756 |
// copy signal/semaphores style (independent of CTRL) |
985399d4099d
(svn r3911) Add functions to retrieve/set the signal variant (electric/semaphore)
tron
parents:
3234
diff
changeset
|
757 |
semaphores = (GetSignalVariant(tile) == SIG_ELECTRIC ? 0 : 8); |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4067
diff
changeset
|
758 |
} else { // no signals exist, drag a two-way signal stretch |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
759 |
signals = SignalOnTrack(track); |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4067
diff
changeset
|
760 |
} |
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
|
761 |
|
1954
58fee2f9eb81
(svn r2460) - Fix: Prevent assertion failure when trying to drag signals starting from a non-rail tile.
hackykid
parents:
1946
diff
changeset
|
762 |
/* signal_ctr - amount of tiles already processed |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
763 |
* 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
|
764 |
********** |
1954
58fee2f9eb81
(svn r2460) - Fix: Prevent assertion failure when trying to drag signals starting from a non-rail tile.
hackykid
parents:
1946
diff
changeset
|
765 |
* trackdir - trackdir to build with autorail |
58fee2f9eb81
(svn r2460) - Fix: Prevent assertion failure when trying to drag signals starting from a non-rail tile.
hackykid
parents:
1946
diff
changeset
|
766 |
* semaphores - semaphores or signals |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
767 |
* signals - is there a signal/semaphore on the first tile, copy its style (two-way/single-way) |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
768 |
and convert all others to semaphore/signal |
1954
58fee2f9eb81
(svn r2460) - Fix: Prevent assertion failure when trying to drag signals starting from a non-rail tile.
hackykid
parents:
1946
diff
changeset
|
769 |
* 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
|
770 |
signal_ctr = total_cost = 0; |
1796
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1782
diff
changeset
|
771 |
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
|
772 |
// only build/remove signals with the specified density |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4067
diff
changeset
|
773 |
if (signal_ctr % signal_density == 0) { |
3493
4d5830846ec2
(svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents:
3491
diff
changeset
|
774 |
ret = DoCommand(tile, 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
|
775 |
|
826 | 776 |
/* 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
|
777 |
* This includes vehicles on track, competitor's tracks, etc. */ |
1796
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1782
diff
changeset
|
778 |
if (CmdFailed(ret)) { |
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1782
diff
changeset
|
779 |
if (_error_message != STR_1005_NO_SUITABLE_RAILROAD_TRACK && mode != 1) return CMD_ERROR; |
3671
6d3a34989d05
(svn r4586) - Codechange: Recursive commands that rely on _error_message to handle success/failure can fail if a recursive call fails but doesn't set the error message, thus resulting in an old, possibly erroneous being used (see FS#130 prior to r4585). Now properly reset the global variable _error_message in these cases.
Darkvater
parents:
3657
diff
changeset
|
780 |
_error_message = INVALID_STRING_ID; |
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
|
781 |
} 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
|
782 |
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
|
783 |
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
|
784 |
} |
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
|
785 |
} |
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
|
786 |
|
3493
4d5830846ec2
(svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents:
3491
diff
changeset
|
787 |
if (tile == end_tile) break; |
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
|
788 |
|
3493
4d5830846ec2
(svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents:
3491
diff
changeset
|
789 |
tile += ToTileIndexDiff(_trackdelta[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
|
790 |
signal_ctr++; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
791 |
|
1227
3552f20fcfcb
(svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater
parents:
1209
diff
changeset
|
792 |
// toggle railbit for the non-diagonal tracks (|, -- tracks) |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
793 |
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
|
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 |
|
2951 | 796 |
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
|
797 |
} |
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
|
798 |
|
1796
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1782
diff
changeset
|
799 |
/** Build signals on a stretch of track. |
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1782
diff
changeset
|
800 |
* Stub for the unified signal builder/remover |
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1782
diff
changeset
|
801 |
* @see CmdSignalTrackHelper |
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1782
diff
changeset
|
802 |
*/ |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3486
diff
changeset
|
803 |
int32 CmdBuildSignalTrack(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
1227
3552f20fcfcb
(svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater
parents:
1209
diff
changeset
|
804 |
{ |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3486
diff
changeset
|
805 |
return CmdSignalTrackHelper(tile, flags, p1, p2); |
1227
3552f20fcfcb
(svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater
parents:
1209
diff
changeset
|
806 |
} |
3552f20fcfcb
(svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater
parents:
1209
diff
changeset
|
807 |
|
1775
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1719
diff
changeset
|
808 |
/** Remove signals |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3486
diff
changeset
|
809 |
* @param tile coordinates where signal is being deleted from |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
810 |
* @param p1 track to remove signal from (Track enum) |
0 | 811 |
*/ |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3486
diff
changeset
|
812 |
int32 CmdRemoveSingleSignal(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 813 |
{ |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
814 |
Track track = (Track)(p1 & 0x7); |
1518
ade7a74ac31a
(svn r2022) Revise CmdRemoveSingleSignal: Check parameters for validity and simplify the function
tron
parents:
1477
diff
changeset
|
815 |
|
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4067
diff
changeset
|
816 |
if (!ValParamTrackOrientation(track) || |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4067
diff
changeset
|
817 |
!IsTileType(tile, MP_RAILWAY) || |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4067
diff
changeset
|
818 |
!EnsureNoVehicle(tile) || |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4067
diff
changeset
|
819 |
!HasSignalOnTrack(tile, track)) { |
1518
ade7a74ac31a
(svn r2022) Revise CmdRemoveSingleSignal: Check parameters for validity and simplify the function
tron
parents:
1477
diff
changeset
|
820 |
return CMD_ERROR; |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4067
diff
changeset
|
821 |
} |
1518
ade7a74ac31a
(svn r2022) Revise CmdRemoveSingleSignal: Check parameters for validity and simplify the function
tron
parents:
1477
diff
changeset
|
822 |
|
1775
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1719
diff
changeset
|
823 |
/* Only water can remove signals from anyone */ |
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1719
diff
changeset
|
824 |
if (_current_player != OWNER_WATER && !CheckTileOwnership(tile)) return CMD_ERROR; |
0 | 825 |
|
826 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
827 |
||
828 |
/* Do it? */ |
|
829 |
if (flags & DC_EXEC) { |
|
2049
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2020
diff
changeset
|
830 |
_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
|
831 |
|
1066
aad3c6ad147f
(svn r1567) -Fix: [110452] On horizontal/vertical tracks you are also charged for building/removing signals on the parallel track on the same tile. Signal updating is also correct. (Hackykid)
darkvater
parents:
1059
diff
changeset
|
832 |
/* removed last signal from tile? */ |
2493
d834d0c1502a
(svn r3019) -Codechange: Replace explicit shifting/anding/oring with GB and SB
tron
parents:
2472
diff
changeset
|
833 |
if (GB(_m[tile].m3, 4, 4) == 0) { |
d834d0c1502a
(svn r3019) -Codechange: Replace explicit shifting/anding/oring with GB and SB
tron
parents:
2472
diff
changeset
|
834 |
SB(_m[tile].m2, 4, 4, 0); |
3792
2eb8388731bf
(svn r4788) - Codechange: RAILTYPE_{NORMAL,ELECTRIC,...} and RAIL_TYPE_{NORMAL,SIGNAL,...} have nearly the same name, rename RAIL_TYPE_* to RAIL_TILE_* of extra clarity
rubidium
parents:
3778
diff
changeset
|
835 |
SB(_m[tile].m5, 6, 2, RAIL_TILE_NORMAL >> 6); // XXX >> because the constant is meant for direct application, not use with SB |
3237
985399d4099d
(svn r3911) Add functions to retrieve/set the signal variant (electric/semaphore)
tron
parents:
3234
diff
changeset
|
836 |
SetSignalVariant(tile, SIG_ELECTRIC); // remove any possible semaphores |
1066
aad3c6ad147f
(svn r1567) -Fix: [110452] On horizontal/vertical tracks you are also charged for building/removing signals on the parallel track on the same tile. Signal updating is also correct. (Hackykid)
darkvater
parents:
1059
diff
changeset
|
837 |
} |
1109
1bab892228cd
(svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents:
1095
diff
changeset
|
838 |
|
1066
aad3c6ad147f
(svn r1567) -Fix: [110452] On horizontal/vertical tracks you are also charged for building/removing signals on the parallel track on the same tile. Signal updating is also correct. (Hackykid)
darkvater
parents:
1059
diff
changeset
|
839 |
SetSignalsOnBothDir(tile, track); |
3900
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3884
diff
changeset
|
840 |
YapfNotifyTrackLayoutChange(tile, track); |
0 | 841 |
|
842 |
MarkTileDirtyByTile(tile); |
|
843 |
} |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
844 |
|
0 | 845 |
return _price.remove_signals; |
846 |
} |
|
847 |
||
1796
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1782
diff
changeset
|
848 |
/** Remove signals on a stretch of track. |
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1782
diff
changeset
|
849 |
* Stub for the unified signal builder/remover |
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1782
diff
changeset
|
850 |
* @see CmdSignalTrackHelper |
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1782
diff
changeset
|
851 |
*/ |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3486
diff
changeset
|
852 |
int32 CmdRemoveSignalTrack(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
1227
3552f20fcfcb
(svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater
parents:
1209
diff
changeset
|
853 |
{ |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3486
diff
changeset
|
854 |
return CmdSignalTrackHelper(tile, flags, p1, SETBIT(p2, 0)); |
1227
3552f20fcfcb
(svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater
parents:
1209
diff
changeset
|
855 |
} |
3552f20fcfcb
(svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater
parents:
1209
diff
changeset
|
856 |
|
3355
a653b8e47f27
(svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
3333
diff
changeset
|
857 |
typedef int32 DoConvertRailProc(TileIndex tile, RailType totype, bool exec); |
0 | 858 |
|
3355
a653b8e47f27
(svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
3333
diff
changeset
|
859 |
static int32 DoConvertRail(TileIndex tile, RailType totype, bool exec) |
0 | 860 |
{ |
3355
a653b8e47f27
(svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
3333
diff
changeset
|
861 |
if (!CheckTileOwnership(tile)) return CMD_ERROR; |
a653b8e47f27
(svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
3333
diff
changeset
|
862 |
|
3778
1d32787783cf
(svn r4770) - Revert unindented change to rail_cmd.c in r4769.
peter1138
parents:
3777
diff
changeset
|
863 |
if (!EnsureNoVehicle(tile) && (!IsCompatibleRail(GetRailType(tile), totype) || IsPlainRailTile(tile))) return CMD_ERROR; |
0 | 864 |
|
865 |
// tile is already of requested type? |
|
2549 | 866 |
if (GetRailType(tile) == totype) return CMD_ERROR; |
0 | 867 |
|
868 |
// change type. |
|
869 |
if (exec) { |
|
3900
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3884
diff
changeset
|
870 |
TrackBits tracks; |
3242
1cefa03f0d5e
(svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents:
3238
diff
changeset
|
871 |
SetRailType(tile, totype); |
0 | 872 |
MarkTileDirtyByTile(tile); |
3869
446041505522
(svn r4906) - Fix: Refresh build vehicle window (if opened) when converting rail depot
glx
parents:
3794
diff
changeset
|
873 |
|
3900
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3884
diff
changeset
|
874 |
// notify YAPF about the track layout change |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3884
diff
changeset
|
875 |
for (tracks = GetTrackBits(tile); tracks != TRACK_BIT_NONE; tracks = KILL_FIRST_BIT(tracks)) |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3884
diff
changeset
|
876 |
YapfNotifyTrackLayoutChange(tile, FIND_FIRST_BIT(tracks)); |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3884
diff
changeset
|
877 |
|
3869
446041505522
(svn r4906) - Fix: Refresh build vehicle window (if opened) when converting rail depot
glx
parents:
3794
diff
changeset
|
878 |
/* Update build vehicle window related to this depot */ |
446041505522
(svn r4906) - Fix: Refresh build vehicle window (if opened) when converting rail depot
glx
parents:
3794
diff
changeset
|
879 |
if (IsTileDepotType(tile, TRANSPORT_RAIL)) { |
446041505522
(svn r4906) - Fix: Refresh build vehicle window (if opened) when converting rail depot
glx
parents:
3794
diff
changeset
|
880 |
Window *w = FindWindowById(WC_BUILD_VEHICLE, tile); |
446041505522
(svn r4906) - Fix: Refresh build vehicle window (if opened) when converting rail depot
glx
parents:
3794
diff
changeset
|
881 |
if (w != NULL) { |
446041505522
(svn r4906) - Fix: Refresh build vehicle window (if opened) when converting rail depot
glx
parents:
3794
diff
changeset
|
882 |
WP(w,buildtrain_d).railtype = totype; |
446041505522
(svn r4906) - Fix: Refresh build vehicle window (if opened) when converting rail depot
glx
parents:
3794
diff
changeset
|
883 |
SetWindowDirty(w); |
446041505522
(svn r4906) - Fix: Refresh build vehicle window (if opened) when converting rail depot
glx
parents:
3794
diff
changeset
|
884 |
} |
446041505522
(svn r4906) - Fix: Refresh build vehicle window (if opened) when converting rail depot
glx
parents:
3794
diff
changeset
|
885 |
} |
0 | 886 |
} |
887 |
||
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
888 |
return _price.build_rail / 2; |
0 | 889 |
} |
890 |
||
3435
f299c6f48763
(svn r4265) - Fix: compile warning on VS2005 (parameter 2 different from declaration)
Darkvater
parents:
3418
diff
changeset
|
891 |
extern int32 DoConvertStationRail(TileIndex tile, RailType totype, bool exec); |
f299c6f48763
(svn r4265) - Fix: compile warning on VS2005 (parameter 2 different from declaration)
Darkvater
parents:
3418
diff
changeset
|
892 |
extern int32 DoConvertStreetRail(TileIndex tile, RailType totype, bool exec); |
f299c6f48763
(svn r4265) - Fix: compile warning on VS2005 (parameter 2 different from declaration)
Darkvater
parents:
3418
diff
changeset
|
893 |
extern int32 DoConvertTunnelBridgeRail(TileIndex tile, RailType totype, bool exec); |
0 | 894 |
|
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
895 |
/** Convert one rail type to the other. You can convert normal rail to |
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
896 |
* monorail/maglev easily or vice-versa. |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3486
diff
changeset
|
897 |
* @param tile end tile of rail conversion drag |
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
898 |
* @param p1 start tile of drag |
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
899 |
* @param p2 new railtype to convert to |
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
900 |
*/ |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3486
diff
changeset
|
901 |
int32 CmdConvertRail(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 902 |
{ |
903 |
int32 ret, cost, money; |
|
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3486
diff
changeset
|
904 |
int ex; |
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3486
diff
changeset
|
905 |
int ey; |
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
906 |
int sx, sy, x, y; |
0 | 907 |
|
889
7f8630bfea41
(svn r1375) -Fix: [1050990] Buying trains sometimes accounted for incorrectly. Was the result of the cost getting reset in a recursive call of docommand. That is fixed. In addition all cost-commands are typed explicitely. Please do not forget to do so or your costs will be credited to construction if you are unlucky.
darkvater
parents:
826
diff
changeset
|
908 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
7f8630bfea41
(svn r1375) -Fix: [1050990] Buying trains sometimes accounted for incorrectly. Was the result of the cost getting reset in a recursive call of docommand. That is fixed. In addition all cost-commands are typed explicitely. Please do not forget to do so or your costs will be credited to construction if you are unlucky.
darkvater
parents:
826
diff
changeset
|
909 |
|
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
910 |
if (!ValParamRailtype(p2)) return CMD_ERROR; |
2934
3b7eef9871f8
(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
|
911 |
if (p1 >= MapSize()) return CMD_ERROR; |
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
912 |
|
0 | 913 |
// make sure sx,sy are smaller than ex,ey |
3493
4d5830846ec2
(svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents:
3491
diff
changeset
|
914 |
ex = TileX(tile); |
4d5830846ec2
(svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents:
3491
diff
changeset
|
915 |
ey = TileY(tile); |
4d5830846ec2
(svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents:
3491
diff
changeset
|
916 |
sx = TileX(p1); |
4d5830846ec2
(svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents:
3491
diff
changeset
|
917 |
sy = TileY(p1); |
0 | 918 |
if (ex < sx) intswap(ex, sx); |
919 |
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
|
920 |
|
0 | 921 |
money = GetAvailableMoneyForCommand(); |
922 |
cost = 0; |
|
3881 | 923 |
ret = 0; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
924 |
|
3493
4d5830846ec2
(svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents:
3491
diff
changeset
|
925 |
for (x = sx; x <= ex; ++x) { |
4d5830846ec2
(svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents:
3491
diff
changeset
|
926 |
for (y = sy; y <= ey; ++y) { |
4d5830846ec2
(svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents:
3491
diff
changeset
|
927 |
TileIndex tile = TileXY(x, y); |
2549 | 928 |
DoConvertRailProc* proc; |
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
929 |
|
2549 | 930 |
switch (GetTileType(tile)) { |
931 |
case MP_RAILWAY: proc = DoConvertRail; break; |
|
932 |
case MP_STATION: proc = DoConvertStationRail; break; |
|
933 |
case MP_STREET: proc = DoConvertStreetRail; break; |
|
934 |
case MP_TUNNELBRIDGE: proc = DoConvertTunnelBridgeRail; break; |
|
935 |
default: continue; |
|
936 |
} |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
937 |
|
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
938 |
ret = proc(tile, p2, false); |
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
939 |
if (CmdFailed(ret)) continue; |
0 | 940 |
cost += ret; |
941 |
||
942 |
if (flags & DC_EXEC) { |
|
2549 | 943 |
money -= ret; |
944 |
if (money < 0) { |
|
945 |
_additional_cash_required = ret; |
|
946 |
return cost - ret; |
|
947 |
} |
|
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
948 |
proc(tile, p2, true); |
0 | 949 |
} |
950 |
} |
|
951 |
} |
|
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
952 |
|
3881 | 953 |
return (cost == 0) ? ret : cost; |
0 | 954 |
} |
955 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1963
diff
changeset
|
956 |
static int32 RemoveTrainDepot(TileIndex tile, uint32 flags) |
0 | 957 |
{ |
149
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
84
diff
changeset
|
958 |
if (!CheckTileOwnership(tile) && _current_player != OWNER_WATER) |
0 | 959 |
return CMD_ERROR; |
960 |
||
961 |
if (!EnsureNoVehicle(tile)) |
|
962 |
return CMD_ERROR; |
|
963 |
||
964 |
if (flags & DC_EXEC) { |
|
3191
d273bda0f5d4
(svn r3851) Rail depots only have an entrance at one side, therefore use UpdateSignalsOnSegment() instead of SetSignalsOnBothDir()
tron
parents:
3189
diff
changeset
|
965 |
DiagDirection dir = GetRailDepotDirection(tile); |
0 | 966 |
|
967 |
DoDeleteDepot(tile); |
|
3191
d273bda0f5d4
(svn r3851) Rail depots only have an entrance at one side, therefore use UpdateSignalsOnSegment() instead of SetSignalsOnBothDir()
tron
parents:
3189
diff
changeset
|
968 |
UpdateSignalsOnSegment(tile, dir); |
3900
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3884
diff
changeset
|
969 |
YapfNotifyTrackLayoutChange(tile, TrackdirToTrack(DiagdirToDiagTrackdir(dir))); |
0 | 970 |
} |
971 |
||
972 |
return _price.remove_train_depot; |
|
973 |
} |
|
974 |
||
1534
2f7388d38291
(svn r2038) -Fix: A player only received the money for one rail when clearing a tile with 2 rails and signals
tron
parents:
1518
diff
changeset
|
975 |
static int32 ClearTile_Track(TileIndex tile, byte flags) |
2f7388d38291
(svn r2038) -Fix: A player only received the money for one rail when clearing a tile with 2 rails and signals
tron
parents:
1518
diff
changeset
|
976 |
{ |
2f7388d38291
(svn r2038) -Fix: A player only received the money for one rail when clearing a tile with 2 rails and signals
tron
parents:
1518
diff
changeset
|
977 |
int32 cost; |
2f7388d38291
(svn r2038) -Fix: A player only received the money for one rail when clearing a tile with 2 rails and signals
tron
parents:
1518
diff
changeset
|
978 |
int32 ret; |
0 | 979 |
byte m5; |
980 |
||
2049
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2020
diff
changeset
|
981 |
m5 = _m[tile].m5; |
0 | 982 |
|
983 |
if (flags & DC_AUTO) { |
|
3792
2eb8388731bf
(svn r4788) - Codechange: RAILTYPE_{NORMAL,ELECTRIC,...} and RAIL_TYPE_{NORMAL,SIGNAL,...} have nearly the same name, rename RAIL_TYPE_* to RAIL_TILE_* of extra clarity
rubidium
parents:
3778
diff
changeset
|
984 |
if (GetRailTileType(tile) == RAIL_TILE_DEPOT_WAYPOINT) { |
0 | 985 |
return_cmd_error(STR_2004_BUILDING_MUST_BE_DEMOLISHED); |
3253 | 986 |
} |
0 | 987 |
|
1901
fb05044cf5c3
(svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents:
1891
diff
changeset
|
988 |
if (!IsTileOwner(tile, _current_player)) |
0 | 989 |
return_cmd_error(STR_1024_AREA_IS_OWNED_BY_ANOTHER); |
990 |
||
991 |
return_cmd_error(STR_1008_MUST_REMOVE_RAILROAD_TRACK); |
|
992 |
} |
|
993 |
||
994 |
cost = 0; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
995 |
|
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
996 |
switch (GetRailTileType(tile)) { |
2821
ba75b5f98725
(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
|
997 |
/* XXX: Why the fuck do we remove these thow signals first? */ |
3792
2eb8388731bf
(svn r4788) - Codechange: RAILTYPE_{NORMAL,ELECTRIC,...} and RAIL_TYPE_{NORMAL,SIGNAL,...} have nearly the same name, rename RAIL_TYPE_* to RAIL_TILE_* of extra clarity
rubidium
parents:
3778
diff
changeset
|
998 |
case RAIL_TILE_SIGNALS: |
3102
fde95020fc8e
(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
|
999 |
if (HasSignalOnTrack(tile, TRACK_X)) { |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3486
diff
changeset
|
1000 |
ret = DoCommand(tile, TRACK_X, 0, flags, CMD_REMOVE_SIGNALS); |
2737
f16e0a808897
(svn r3282) - Codechange: Replace tests against CMD_ERROR with CmdFailed()
peter1138
parents:
2670
diff
changeset
|
1001 |
if (CmdFailed(ret)) return CMD_ERROR; |
0 | 1002 |
cost += ret; |
1003 |
} |
|
2951 | 1004 |
if (HasSignalOnTrack(tile, TRACK_LOWER)) { |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3486
diff
changeset
|
1005 |
ret = DoCommand(tile, TRACK_LOWER, 0, flags, CMD_REMOVE_SIGNALS); |
2737
f16e0a808897
(svn r3282) - Codechange: Replace tests against CMD_ERROR with CmdFailed()
peter1138
parents:
2670
diff
changeset
|
1006 |
if (CmdFailed(ret)) return CMD_ERROR; |
1534
2f7388d38291
(svn r2038) -Fix: A player only received the money for one rail when clearing a tile with 2 rails and signals
tron
parents:
1518
diff
changeset
|
1007 |
cost += ret; |
2f7388d38291
(svn r2038) -Fix: A player only received the money for one rail when clearing a tile with 2 rails and signals
tron
parents:
1518
diff
changeset
|
1008 |
} |
0 | 1009 |
|
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
1010 |
m5 &= TRACK_BIT_MASK; |
1598
4425f756c19b
(svn r2102) Fix bug introduced in r2038, which gave you money for clearing occupied railway tiles ([1171926])
tron
parents:
1591
diff
changeset
|
1011 |
if (!(flags & DC_EXEC)) { |
4425f756c19b
(svn r2102) Fix bug introduced in r2038, which gave you money for clearing occupied railway tiles ([1171926])
tron
parents:
1591
diff
changeset
|
1012 |
for (; m5 != 0; m5 >>= 1) if (m5 & 1) cost += _price.remove_rail; |
4425f756c19b
(svn r2102) Fix bug introduced in r2038, which gave you money for clearing occupied railway tiles ([1171926])
tron
parents:
1591
diff
changeset
|
1013 |
return cost; |
4425f756c19b
(svn r2102) Fix bug introduced in r2038, which gave you money for clearing occupied railway tiles ([1171926])
tron
parents:
1591
diff
changeset
|
1014 |
} |
1534
2f7388d38291
(svn r2038) -Fix: A player only received the money for one rail when clearing a tile with 2 rails and signals
tron
parents:
1518
diff
changeset
|
1015 |
/* FALLTHROUGH */ |
1109
1bab892228cd
(svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents:
1095
diff
changeset
|
1016 |
|
3792
2eb8388731bf
(svn r4788) - Codechange: RAILTYPE_{NORMAL,ELECTRIC,...} and RAIL_TYPE_{NORMAL,SIGNAL,...} have nearly the same name, rename RAIL_TYPE_* to RAIL_TILE_* of extra clarity
rubidium
parents:
3778
diff
changeset
|
1017 |
case RAIL_TILE_NORMAL: { |
1534
2f7388d38291
(svn r2038) -Fix: A player only received the money for one rail when clearing a tile with 2 rails and signals
tron
parents:
1518
diff
changeset
|
1018 |
uint i; |
2f7388d38291
(svn r2038) -Fix: A player only received the money for one rail when clearing a tile with 2 rails and signals
tron
parents:
1518
diff
changeset
|
1019 |
|
2f7388d38291
(svn r2038) -Fix: A player only received the money for one rail when clearing a tile with 2 rails and signals
tron
parents:
1518
diff
changeset
|
1020 |
for (i = 0; m5 != 0; i++, m5 >>= 1) { |
2f7388d38291
(svn r2038) -Fix: A player only received the money for one rail when clearing a tile with 2 rails and signals
tron
parents:
1518
diff
changeset
|
1021 |
if (m5 & 1) { |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3486
diff
changeset
|
1022 |
ret = DoCommand(tile, 0, i, flags, CMD_REMOVE_SINGLE_RAIL); |
2737
f16e0a808897
(svn r3282) - Codechange: Replace tests against CMD_ERROR with CmdFailed()
peter1138
parents:
2670
diff
changeset
|
1023 |
if (CmdFailed(ret)) return CMD_ERROR; |
1534
2f7388d38291
(svn r2038) -Fix: A player only received the money for one rail when clearing a tile with 2 rails and signals
tron
parents:
1518
diff
changeset
|
1024 |
cost += ret; |
2f7388d38291
(svn r2038) -Fix: A player only received the money for one rail when clearing a tile with 2 rails and signals
tron
parents:
1518
diff
changeset
|
1025 |
} |
2f7388d38291
(svn r2038) -Fix: A player only received the money for one rail when clearing a tile with 2 rails and signals
tron
parents:
1518
diff
changeset
|
1026 |
} |
2f7388d38291
(svn r2038) -Fix: A player only received the money for one rail when clearing a tile with 2 rails and signals
tron
parents:
1518
diff
changeset
|
1027 |
return cost; |
2f7388d38291
(svn r2038) -Fix: A player only received the money for one rail when clearing a tile with 2 rails and signals
tron
parents:
1518
diff
changeset
|
1028 |
} |
2f7388d38291
(svn r2038) -Fix: A player only received the money for one rail when clearing a tile with 2 rails and signals
tron
parents:
1518
diff
changeset
|
1029 |
|
3792
2eb8388731bf
(svn r4788) - Codechange: RAILTYPE_{NORMAL,ELECTRIC,...} and RAIL_TYPE_{NORMAL,SIGNAL,...} have nearly the same name, rename RAIL_TYPE_* to RAIL_TILE_* of extra clarity
rubidium
parents:
3778
diff
changeset
|
1030 |
case RAIL_TILE_DEPOT_WAYPOINT: |
3269
95e7bffcb3c5
(svn r3981) More work for the rail accessing functions and enums
tron
parents:
3267
diff
changeset
|
1031 |
if (GetRailTileSubtype(tile) == RAIL_SUBTYPE_DEPOT) { |
95e7bffcb3c5
(svn r3981) More work for the rail accessing functions and enums
tron
parents:
3267
diff
changeset
|
1032 |
return RemoveTrainDepot(tile, flags); |
95e7bffcb3c5
(svn r3981) More work for the rail accessing functions and enums
tron
parents:
3267
diff
changeset
|
1033 |
} else { |
95e7bffcb3c5
(svn r3981) More work for the rail accessing functions and enums
tron
parents:
3267
diff
changeset
|
1034 |
return RemoveTrainWaypoint(tile, flags, false); |
1534
2f7388d38291
(svn r2038) -Fix: A player only received the money for one rail when clearing a tile with 2 rails and signals
tron
parents:
1518
diff
changeset
|
1035 |
} |
2f7388d38291
(svn r2038) -Fix: A player only received the money for one rail when clearing a tile with 2 rails and signals
tron
parents:
1518
diff
changeset
|
1036 |
|
2f7388d38291
(svn r2038) -Fix: A player only received the money for one rail when clearing a tile with 2 rails and signals
tron
parents:
1518
diff
changeset
|
1037 |
default: |
2f7388d38291
(svn r2038) -Fix: A player only received the money for one rail when clearing a tile with 2 rails and signals
tron
parents:
1518
diff
changeset
|
1038 |
return CMD_ERROR; |
2f7388d38291
(svn r2038) -Fix: A player only received the money for one rail when clearing a tile with 2 rails and signals
tron
parents:
1518
diff
changeset
|
1039 |
} |
0 | 1040 |
} |
1041 |
||
1042 |
#include "table/track_land.h" |
|
1043 |
||
3575
867df1ec208a
(svn r4461) -Codechange: Add and make use of map accessor functions for signal drawing. Includes some basic cleanup of the drawing functions
celestar
parents:
3562
diff
changeset
|
1044 |
static void DrawSingleSignal(TileIndex tile, byte condition, uint image, uint pos) |
0 | 1045 |
{ |
3575
867df1ec208a
(svn r4461) -Codechange: Add and make use of map accessor functions for signal drawing. Includes some basic cleanup of the drawing functions
celestar
parents:
3562
diff
changeset
|
1046 |
bool side = _opt.road_side & _patches.signal_side; |
3502
d41ccd2fb5c5
(svn r4353) Codechange: Move global _signal_position into the only function that uses it and convert the bit-hacking into a struct
celestar
parents:
3493
diff
changeset
|
1047 |
static const Point SignalPositions[2][12] = { |
d41ccd2fb5c5
(svn r4353) Codechange: Move global _signal_position into the only function that uses it and convert the bit-hacking into a struct
celestar
parents:
3493
diff
changeset
|
1048 |
{ /* Signals on the left side */ |
d41ccd2fb5c5
(svn r4353) Codechange: Move global _signal_position into the only function that uses it and convert the bit-hacking into a struct
celestar
parents:
3493
diff
changeset
|
1049 |
/* LEFT LEFT RIGHT RIGHT UPPER UPPER */ |
d41ccd2fb5c5
(svn r4353) Codechange: Move global _signal_position into the only function that uses it and convert the bit-hacking into a struct
celestar
parents:
3493
diff
changeset
|
1050 |
{ 8, 5}, {14, 1}, { 1, 14}, { 9, 11}, { 1, 0}, { 3, 10}, |
d41ccd2fb5c5
(svn r4353) Codechange: Move global _signal_position into the only function that uses it and convert the bit-hacking into a struct
celestar
parents:
3493
diff
changeset
|
1051 |
/* LOWER LOWER X X Y Y */ |
d41ccd2fb5c5
(svn r4353) Codechange: Move global _signal_position into the only function that uses it and convert the bit-hacking into a struct
celestar
parents:
3493
diff
changeset
|
1052 |
{11, 4}, {14, 14}, {11, 3}, { 4, 13}, { 3, 4}, {11, 13} |
d41ccd2fb5c5
(svn r4353) Codechange: Move global _signal_position into the only function that uses it and convert the bit-hacking into a struct
celestar
parents:
3493
diff
changeset
|
1053 |
}, { /* Signals on the right side */ |
d41ccd2fb5c5
(svn r4353) Codechange: Move global _signal_position into the only function that uses it and convert the bit-hacking into a struct
celestar
parents:
3493
diff
changeset
|
1054 |
/* LEFT LEFT RIGHT RIGHT UPPER UPPER */ |
d41ccd2fb5c5
(svn r4353) Codechange: Move global _signal_position into the only function that uses it and convert the bit-hacking into a struct
celestar
parents:
3493
diff
changeset
|
1055 |
{14, 1}, {12, 10}, { 4, 6}, { 1, 14}, {10, 4}, { 0, 1}, |
d41ccd2fb5c5
(svn r4353) Codechange: Move global _signal_position into the only function that uses it and convert the bit-hacking into a struct
celestar
parents:
3493
diff
changeset
|
1056 |
/* LOWER LOWER X X Y Y */ |
d41ccd2fb5c5
(svn r4353) Codechange: Move global _signal_position into the only function that uses it and convert the bit-hacking into a struct
celestar
parents:
3493
diff
changeset
|
1057 |
{14, 14}, { 5, 12}, {11, 13}, { 4, 3}, {13, 4}, { 3, 11} |
d41ccd2fb5c5
(svn r4353) Codechange: Move global _signal_position into the only function that uses it and convert the bit-hacking into a struct
celestar
parents:
3493
diff
changeset
|
1058 |
} |
d41ccd2fb5c5
(svn r4353) Codechange: Move global _signal_position into the only function that uses it and convert the bit-hacking into a struct
celestar
parents:
3493
diff
changeset
|
1059 |
}; |
0 | 1060 |
|
3506
9a9489c7896f
(svn r4357) -Codechange: Moved global _signal_base_sprites into the only function where it is used and use a better array arrangement for it
celestar
parents:
3503
diff
changeset
|
1061 |
static const SpriteID SignalBase[2][2][4] = { |
9a9489c7896f
(svn r4357) -Codechange: Moved global _signal_base_sprites into the only function where it is used and use a better array arrangement for it
celestar
parents:
3503
diff
changeset
|
1062 |
{ /* Signals on left side */ |
9a9489c7896f
(svn r4357) -Codechange: Moved global _signal_base_sprites into the only function where it is used and use a better array arrangement for it
celestar
parents:
3503
diff
changeset
|
1063 |
{ 0x4FB, 0x1323, 0x1333, 0x1343}, /* light signals */ |
9a9489c7896f
(svn r4357) -Codechange: Moved global _signal_base_sprites into the only function where it is used and use a better array arrangement for it
celestar
parents:
3503
diff
changeset
|
1064 |
{ 0x1353, 0x1363, 0x1373, 0x1383} /* semaphores */ |
9a9489c7896f
(svn r4357) -Codechange: Moved global _signal_base_sprites into the only function where it is used and use a better array arrangement for it
celestar
parents:
3503
diff
changeset
|
1065 |
}, { /* Signals on right side */ |
9a9489c7896f
(svn r4357) -Codechange: Moved global _signal_base_sprites into the only function where it is used and use a better array arrangement for it
celestar
parents:
3503
diff
changeset
|
1066 |
{ 0x4FB, 0x1323, 0x1333, 0x1343}, /* light signals */ |
9a9489c7896f
(svn r4357) -Codechange: Moved global _signal_base_sprites into the only function where it is used and use a better array arrangement for it
celestar
parents:
3503
diff
changeset
|
1067 |
{ 0x1446, 0x1456, 0x1466, 0x1476} /* semaphores */ |
9a9489c7896f
(svn r4357) -Codechange: Moved global _signal_base_sprites into the only function where it is used and use a better array arrangement for it
celestar
parents:
3503
diff
changeset
|
1068 |
/* | | | | */ |
9a9489c7896f
(svn r4357) -Codechange: Moved global _signal_base_sprites into the only function where it is used and use a better array arrangement for it
celestar
parents:
3503
diff
changeset
|
1069 |
/* normal, entry, exit, combo */ |
9a9489c7896f
(svn r4357) -Codechange: Moved global _signal_base_sprites into the only function where it is used and use a better array arrangement for it
celestar
parents:
3503
diff
changeset
|
1070 |
} |
9a9489c7896f
(svn r4357) -Codechange: Moved global _signal_base_sprites into the only function where it is used and use a better array arrangement for it
celestar
parents:
3503
diff
changeset
|
1071 |
}; |
9a9489c7896f
(svn r4357) -Codechange: Moved global _signal_base_sprites into the only function where it is used and use a better array arrangement for it
celestar
parents:
3503
diff
changeset
|
1072 |
|
3575
867df1ec208a
(svn r4461) -Codechange: Add and make use of map accessor functions for signal drawing. Includes some basic cleanup of the drawing functions
celestar
parents:
3562
diff
changeset
|
1073 |
uint x = TileX(tile) * TILE_SIZE + SignalPositions[side][pos].x; |
867df1ec208a
(svn r4461) -Codechange: Add and make use of map accessor functions for signal drawing. Includes some basic cleanup of the drawing functions
celestar
parents:
3562
diff
changeset
|
1074 |
uint y = TileY(tile) * TILE_SIZE + SignalPositions[side][pos].y; |
867df1ec208a
(svn r4461) -Codechange: Add and make use of map accessor functions for signal drawing. Includes some basic cleanup of the drawing functions
celestar
parents:
3562
diff
changeset
|
1075 |
|
3638
6e0b43d905d4
(svn r4546) - NewGRF: add support for Action 0x05, type 0x04: replacement signal graphics. Thanks to Purno for supplying data to test
peter1138
parents:
3636
diff
changeset
|
1076 |
SpriteID sprite; |
6e0b43d905d4
(svn r4546) - NewGRF: add support for Action 0x05, type 0x04: replacement signal graphics. Thanks to Purno for supplying data to test
peter1138
parents:
3636
diff
changeset
|
1077 |
|
6e0b43d905d4
(svn r4546) - NewGRF: add support for Action 0x05, type 0x04: replacement signal graphics. Thanks to Purno for supplying data to test
peter1138
parents:
3636
diff
changeset
|
1078 |
/* _signal_base is set by our NewGRF Action 5 loader. If it is 0 then we |
6e0b43d905d4
(svn r4546) - NewGRF: add support for Action 0x05, type 0x04: replacement signal graphics. Thanks to Purno for supplying data to test
peter1138
parents:
3636
diff
changeset
|
1079 |
* just draw the standard signals, else we get the offset from _signal_base |
6e0b43d905d4
(svn r4546) - NewGRF: add support for Action 0x05, type 0x04: replacement signal graphics. Thanks to Purno for supplying data to test
peter1138
parents:
3636
diff
changeset
|
1080 |
* and draw that sprite. All the signal sprites are loaded sequentially. */ |
6e0b43d905d4
(svn r4546) - NewGRF: add support for Action 0x05, type 0x04: replacement signal graphics. Thanks to Purno for supplying data to test
peter1138
parents:
3636
diff
changeset
|
1081 |
if (_signal_base == 0 || (GetSignalType(tile) == 0 && GetSignalVariant(tile) == SIG_ELECTRIC)) { |
6e0b43d905d4
(svn r4546) - NewGRF: add support for Action 0x05, type 0x04: replacement signal graphics. Thanks to Purno for supplying data to test
peter1138
parents:
3636
diff
changeset
|
1082 |
sprite = SignalBase[side][GetSignalVariant(tile)][GetSignalType(tile)] + image + condition; |
6e0b43d905d4
(svn r4546) - NewGRF: add support for Action 0x05, type 0x04: replacement signal graphics. Thanks to Purno for supplying data to test
peter1138
parents:
3636
diff
changeset
|
1083 |
} else { |
6e0b43d905d4
(svn r4546) - NewGRF: add support for Action 0x05, type 0x04: replacement signal graphics. Thanks to Purno for supplying data to test
peter1138
parents:
3636
diff
changeset
|
1084 |
sprite = _signal_base + (GetSignalType(tile) - 1) * 16 + GetSignalVariant(tile) * 64 + image + condition; |
6e0b43d905d4
(svn r4546) - NewGRF: add support for Action 0x05, type 0x04: replacement signal graphics. Thanks to Purno for supplying data to test
peter1138
parents:
3636
diff
changeset
|
1085 |
} |
3575
867df1ec208a
(svn r4461) -Codechange: Add and make use of map accessor functions for signal drawing. Includes some basic cleanup of the drawing functions
celestar
parents:
3562
diff
changeset
|
1086 |
|
0 | 1087 |
AddSortableSpriteToDraw(sprite, x, y, 1, 1, 10, GetSlopeZ(x,y)); |
1088 |
} |
|
1089 |
||
1090 |
static uint32 _drawtile_track_palette; |
|
1091 |
||
1092 |
||
2436
177cb6a8339f
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2425
diff
changeset
|
1093 |
static void DrawTrackFence_NW(const TileInfo *ti) |
0 | 1094 |
{ |
1095 |
uint32 image = 0x515; |
|
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3575
diff
changeset
|
1096 |
if (ti->tileh != SLOPE_FLAT) image = (ti->tileh & SLOPE_S) ? 0x519 : 0x51B; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1097 |
AddSortableSpriteToDraw(image | _drawtile_track_palette, |
2951 | 1098 |
ti->x, ti->y + 1, 16, 1, 4, ti->z); |
0 | 1099 |
} |
1100 |
||
2436
177cb6a8339f
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2425
diff
changeset
|
1101 |
static void DrawTrackFence_SE(const TileInfo *ti) |
0 | 1102 |
{ |
1103 |
uint32 image = 0x515; |
|
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3575
diff
changeset
|
1104 |
if (ti->tileh != SLOPE_FLAT) image = (ti->tileh & SLOPE_S) ? 0x519 : 0x51B; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1105 |
AddSortableSpriteToDraw(image | _drawtile_track_palette, |
3645
86af43f87885
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3638
diff
changeset
|
1106 |
ti->x, ti->y + TILE_SIZE - 1, 16, 1, 4, ti->z); |
0 | 1107 |
} |
1108 |
||
2436
177cb6a8339f
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2425
diff
changeset
|
1109 |
static void DrawTrackFence_NW_SE(const TileInfo *ti) |
0 | 1110 |
{ |
1111 |
DrawTrackFence_NW(ti); |
|
1112 |
DrawTrackFence_SE(ti); |
|
1113 |
} |
|
1114 |
||
2436
177cb6a8339f
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2425
diff
changeset
|
1115 |
static void DrawTrackFence_NE(const TileInfo *ti) |
0 | 1116 |
{ |
1117 |
uint32 image = 0x516; |
|
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3575
diff
changeset
|
1118 |
if (ti->tileh != SLOPE_FLAT) image = (ti->tileh & SLOPE_S) ? 0x51A : 0x51C; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1119 |
AddSortableSpriteToDraw(image | _drawtile_track_palette, |
2951 | 1120 |
ti->x + 1, ti->y, 1, 16, 4, ti->z); |
0 | 1121 |
} |
1122 |
||
2436
177cb6a8339f
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2425
diff
changeset
|
1123 |
static void DrawTrackFence_SW(const TileInfo *ti) |
0 | 1124 |
{ |
1125 |
uint32 image = 0x516; |
|
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3575
diff
changeset
|
1126 |
if (ti->tileh != SLOPE_FLAT) image = (ti->tileh & SLOPE_S) ? 0x51A : 0x51C; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1127 |
AddSortableSpriteToDraw(image | _drawtile_track_palette, |
3645
86af43f87885
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3638
diff
changeset
|
1128 |
ti->x + TILE_SIZE - 1, ti->y, 1, 16, 4, ti->z); |
0 | 1129 |
} |
1130 |
||
2436
177cb6a8339f
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2425
diff
changeset
|
1131 |
static void DrawTrackFence_NE_SW(const TileInfo *ti) |
0 | 1132 |
{ |
1133 |
DrawTrackFence_NE(ti); |
|
1134 |
DrawTrackFence_SW(ti); |
|
1135 |
} |
|
1136 |
||
2436
177cb6a8339f
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2425
diff
changeset
|
1137 |
static void DrawTrackFence_NS_1(const TileInfo *ti) |
0 | 1138 |
{ |
1139 |
int z = ti->z; |
|
3645
86af43f87885
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3638
diff
changeset
|
1140 |
if (ti->tileh & SLOPE_W) z += TILE_HEIGHT; |
0 | 1141 |
AddSortableSpriteToDraw(0x517 | _drawtile_track_palette, |
3645
86af43f87885
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3638
diff
changeset
|
1142 |
ti->x + TILE_SIZE / 2, ti->y + TILE_SIZE / 2, 1, 1, 4, z); |
0 | 1143 |
} |
1144 |
||
2436
177cb6a8339f
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2425
diff
changeset
|
1145 |
static void DrawTrackFence_NS_2(const TileInfo *ti) |
0 | 1146 |
{ |
1147 |
int z = ti->z; |
|
3645
86af43f87885
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3638
diff
changeset
|
1148 |
if (ti->tileh & SLOPE_E) z += TILE_HEIGHT; |
0 | 1149 |
AddSortableSpriteToDraw(0x517 | _drawtile_track_palette, |
3645
86af43f87885
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3638
diff
changeset
|
1150 |
ti->x + TILE_SIZE / 2, ti->y + TILE_SIZE / 2, 1, 1, 4, z); |
0 | 1151 |
} |
1152 |
||
2436
177cb6a8339f
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2425
diff
changeset
|
1153 |
static void DrawTrackFence_WE_1(const TileInfo *ti) |
0 | 1154 |
{ |
1155 |
int z = ti->z; |
|
3645
86af43f87885
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3638
diff
changeset
|
1156 |
if (ti->tileh & SLOPE_N) z += TILE_HEIGHT; |
0 | 1157 |
AddSortableSpriteToDraw(0x518 | _drawtile_track_palette, |
3645
86af43f87885
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3638
diff
changeset
|
1158 |
ti->x + TILE_SIZE / 2, ti->y + TILE_SIZE / 2, 1, 1, 4, z); |
0 | 1159 |
} |
1160 |
||
2436
177cb6a8339f
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2425
diff
changeset
|
1161 |
static void DrawTrackFence_WE_2(const TileInfo *ti) |
0 | 1162 |
{ |
1163 |
int z = ti->z; |
|
3645
86af43f87885
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3638
diff
changeset
|
1164 |
if (ti->tileh & SLOPE_S) z += TILE_HEIGHT; |
0 | 1165 |
AddSortableSpriteToDraw(0x518 | _drawtile_track_palette, |
3645
86af43f87885
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3638
diff
changeset
|
1166 |
ti->x + TILE_SIZE / 2, ti->y + TILE_SIZE / 2, 1, 1, 4, z); |
0 | 1167 |
} |
1168 |
||
4040
3c5fc0aea78d
(svn r5308) Replace an array of function pointers with a switch: It's shorter, more comprehensible, less dependent on magic numbers
tron
parents:
4000
diff
changeset
|
1169 |
|
3c5fc0aea78d
(svn r5308) Replace an array of function pointers with a switch: It's shorter, more comprehensible, less dependent on magic numbers
tron
parents:
4000
diff
changeset
|
1170 |
static void DrawTrackDetails(const TileInfo* ti) |
0 | 1171 |
{ |
4040
3c5fc0aea78d
(svn r5308) Replace an array of function pointers with a switch: It's shorter, more comprehensible, less dependent on magic numbers
tron
parents:
4000
diff
changeset
|
1172 |
switch (GetRailGroundType(ti->tile)) { |
3c5fc0aea78d
(svn r5308) Replace an array of function pointers with a switch: It's shorter, more comprehensible, less dependent on magic numbers
tron
parents:
4000
diff
changeset
|
1173 |
case RAIL_GROUND_FENCE_NW: DrawTrackFence_NW(ti); break; |
3c5fc0aea78d
(svn r5308) Replace an array of function pointers with a switch: It's shorter, more comprehensible, less dependent on magic numbers
tron
parents:
4000
diff
changeset
|
1174 |
case RAIL_GROUND_FENCE_SE: DrawTrackFence_SE(ti); break; |
3c5fc0aea78d
(svn r5308) Replace an array of function pointers with a switch: It's shorter, more comprehensible, less dependent on magic numbers
tron
parents:
4000
diff
changeset
|
1175 |
case RAIL_GROUND_FENCE_SENW: DrawTrackFence_NW_SE(ti); break; |
3c5fc0aea78d
(svn r5308) Replace an array of function pointers with a switch: It's shorter, more comprehensible, less dependent on magic numbers
tron
parents:
4000
diff
changeset
|
1176 |
case RAIL_GROUND_FENCE_NE: DrawTrackFence_NE(ti); break; |
3c5fc0aea78d
(svn r5308) Replace an array of function pointers with a switch: It's shorter, more comprehensible, less dependent on magic numbers
tron
parents:
4000
diff
changeset
|
1177 |
case RAIL_GROUND_FENCE_SW: DrawTrackFence_SW(ti); break; |
3c5fc0aea78d
(svn r5308) Replace an array of function pointers with a switch: It's shorter, more comprehensible, less dependent on magic numbers
tron
parents:
4000
diff
changeset
|
1178 |
case RAIL_GROUND_FENCE_NESW: DrawTrackFence_NE_SW(ti); break; |
3c5fc0aea78d
(svn r5308) Replace an array of function pointers with a switch: It's shorter, more comprehensible, less dependent on magic numbers
tron
parents:
4000
diff
changeset
|
1179 |
case RAIL_GROUND_FENCE_VERT1: DrawTrackFence_NS_1(ti); break; |
3c5fc0aea78d
(svn r5308) Replace an array of function pointers with a switch: It's shorter, more comprehensible, less dependent on magic numbers
tron
parents:
4000
diff
changeset
|
1180 |
case RAIL_GROUND_FENCE_VERT2: DrawTrackFence_NS_2(ti); break; |
3c5fc0aea78d
(svn r5308) Replace an array of function pointers with a switch: It's shorter, more comprehensible, less dependent on magic numbers
tron
parents:
4000
diff
changeset
|
1181 |
case RAIL_GROUND_FENCE_HORIZ1: DrawTrackFence_WE_1(ti); break; |
3c5fc0aea78d
(svn r5308) Replace an array of function pointers with a switch: It's shorter, more comprehensible, less dependent on magic numbers
tron
parents:
4000
diff
changeset
|
1182 |
case RAIL_GROUND_FENCE_HORIZ2: DrawTrackFence_WE_2(ti); break; |
3c5fc0aea78d
(svn r5308) Replace an array of function pointers with a switch: It's shorter, more comprehensible, less dependent on magic numbers
tron
parents:
4000
diff
changeset
|
1183 |
default: break; |
3c5fc0aea78d
(svn r5308) Replace an array of function pointers with a switch: It's shorter, more comprehensible, less dependent on magic numbers
tron
parents:
4000
diff
changeset
|
1184 |
} |
0 | 1185 |
} |
1186 |
||
1187 |
||
2951 | 1188 |
static void DrawSpecialBuilding( |
1189 |
uint32 image, uint32 offset, |
|
1190 |
const TileInfo* ti, |
|
1191 |
byte x, byte y, byte z, |
|
1192 |
byte xsize, byte ysize, byte zsize) |
|
389
2d394eeba5e5
(svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents:
337
diff
changeset
|
1193 |
{ |
2549 | 1194 |
if (image & PALETTE_MODIFIER_COLOR) image |= _drawtile_track_palette; |
2254
72f8883ff3ac
(svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents:
2236
diff
changeset
|
1195 |
image += offset; |
2549 | 1196 |
if (_display_opt & DO_TRANS_BUILDINGS) MAKE_TRANSPARENT(image); |
389
2d394eeba5e5
(svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents:
337
diff
changeset
|
1197 |
AddSortableSpriteToDraw(image, ti->x + x, ti->y + y, xsize, ysize, zsize, ti->z + z); |
2d394eeba5e5
(svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents:
337
diff
changeset
|
1198 |
} |
2d394eeba5e5
(svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents:
337
diff
changeset
|
1199 |
|
2472
60c843b7ea28
(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
|
1200 |
/** |
60c843b7ea28
(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
|
1201 |
* Draw ground sprite and track bits |
60c843b7ea28
(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
|
1202 |
* @param ti TileInfo |
60c843b7ea28
(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
|
1203 |
* @param track TrackBits to draw |
60c843b7ea28
(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
|
1204 |
* @param earth Draw as earth |
60c843b7ea28
(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
|
1205 |
* @param snow Draw as snow |
60c843b7ea28
(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
|
1206 |
* @param flat Always draw foundation |
60c843b7ea28
(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
|
1207 |
*/ |
3523
168ee460418b
(svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents:
3522
diff
changeset
|
1208 |
static void DrawTrackBits(TileInfo* ti, TrackBits track, bool flat) |
2472
60c843b7ea28
(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
|
1209 |
{ |
60c843b7ea28
(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
|
1210 |
const RailtypeInfo *rti = GetRailTypeInfo(GetRailType(ti->tile)); |
60c843b7ea28
(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
|
1211 |
PalSpriteID image; |
60c843b7ea28
(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
|
1212 |
bool junction = false; |
3523
168ee460418b
(svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents:
3522
diff
changeset
|
1213 |
bool earth = IsBarrenRailGround(ti->tile); |
168ee460418b
(svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents:
3522
diff
changeset
|
1214 |
bool snow = IsSnowRailGround(ti->tile); |
2472
60c843b7ea28
(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
|
1215 |
|
60c843b7ea28
(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
|
1216 |
// Select the sprite to use. |
3102
fde95020fc8e
(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
|
1217 |
(image = rti->base_sprites.track_y, track == TRACK_BIT_Y) || |
fde95020fc8e
(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
|
1218 |
(image++, track == TRACK_BIT_X) || |
2472
60c843b7ea28
(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
|
1219 |
(image++, track == TRACK_BIT_UPPER) || |
60c843b7ea28
(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
|
1220 |
(image++, track == TRACK_BIT_LOWER) || |
60c843b7ea28
(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
|
1221 |
(image++, track == TRACK_BIT_RIGHT) || |
60c843b7ea28
(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
|
1222 |
(image++, track == TRACK_BIT_LEFT) || |
3258
94a915e7485f
(svn r3946) Add short hand names for common track combinations
tron
parents:
3254
diff
changeset
|
1223 |
(image++, track == TRACK_BIT_CROSS) || |
2472
60c843b7ea28
(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
|
1224 |
|
3258
94a915e7485f
(svn r3946) Add short hand names for common track combinations
tron
parents:
3254
diff
changeset
|
1225 |
(image = rti->base_sprites.track_ns, track == TRACK_BIT_HORZ) || |
94a915e7485f
(svn r3946) Add short hand names for common track combinations
tron
parents:
3254
diff
changeset
|
1226 |
(image++, track == TRACK_BIT_VERT) || |
2472
60c843b7ea28
(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
|
1227 |
|
60c843b7ea28
(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
|
1228 |
(junction = true, false) || |
3258
94a915e7485f
(svn r3946) Add short hand names for common track combinations
tron
parents:
3254
diff
changeset
|
1229 |
(image = rti->base_sprites.ground, (track & TRACK_BIT_3WAY_NE) == 0) || |
94a915e7485f
(svn r3946) Add short hand names for common track combinations
tron
parents:
3254
diff
changeset
|
1230 |
(image++, (track & TRACK_BIT_3WAY_SW) == 0) || |
94a915e7485f
(svn r3946) Add short hand names for common track combinations
tron
parents:
3254
diff
changeset
|
1231 |
(image++, (track & TRACK_BIT_3WAY_NW) == 0) || |
94a915e7485f
(svn r3946) Add short hand names for common track combinations
tron
parents:
3254
diff
changeset
|
1232 |
(image++, (track & TRACK_BIT_3WAY_SE) == 0) || |
2472
60c843b7ea28
(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 |
(image++, true); |
60c843b7ea28
(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 |
|
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3575
diff
changeset
|
1235 |
if (ti->tileh != SLOPE_FLAT) { |
2472
60c843b7ea28
(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 |
int foundation; |
60c843b7ea28
(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 |
|
60c843b7ea28
(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 |
if (flat) { |
60c843b7ea28
(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 |
foundation = ti->tileh; |
60c843b7ea28
(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
|
1240 |
} else { |
60c843b7ea28
(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 |
foundation = GetRailFoundation(ti->tileh, track); |
60c843b7ea28
(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 |
} |
60c843b7ea28
(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 |
|
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4067
diff
changeset
|
1244 |
if (foundation != 0) DrawFoundation(ti, foundation); |
2472
60c843b7ea28
(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 |
|
60c843b7ea28
(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 |
// DrawFoundation() modifies ti. |
60c843b7ea28
(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
|
1247 |
// Default sloped sprites.. |
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3575
diff
changeset
|
1248 |
if (ti->tileh != SLOPE_FLAT) |
2472
60c843b7ea28
(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_sloped_sprites[ti->tileh - 1] + rti->base_sprites.track_y; |
60c843b7ea28
(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 |
} |
60c843b7ea28
(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 |
|
60c843b7ea28
(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 |
if (earth) { |
60c843b7ea28
(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
|
1253 |
image = (image & SPRITE_MASK) | PALETTE_TO_BARE_LAND; // Use brown palette |
60c843b7ea28
(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 |
} else if (snow) { |
60c843b7ea28
(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
|
1255 |
image += rti->snow_offset; |
60c843b7ea28
(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
|
1256 |
} |
60c843b7ea28
(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 |
|
60c843b7ea28
(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 |
DrawGroundSprite(image); |
60c843b7ea28
(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
|
1259 |
|
60c843b7ea28
(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
|
1260 |
// Draw track pieces individually for junction tiles |
60c843b7ea28
(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
|
1261 |
if (junction) { |
3102
fde95020fc8e
(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
|
1262 |
if (track & TRACK_BIT_X) DrawGroundSprite(rti->base_sprites.single_y); |
fde95020fc8e
(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
|
1263 |
if (track & TRACK_BIT_Y) DrawGroundSprite(rti->base_sprites.single_x); |
2472
60c843b7ea28
(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 |
if (track & TRACK_BIT_UPPER) DrawGroundSprite(rti->base_sprites.single_n); |
60c843b7ea28
(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 (track & TRACK_BIT_LOWER) DrawGroundSprite(rti->base_sprites.single_s); |
60c843b7ea28
(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 |
if (track & TRACK_BIT_LEFT) DrawGroundSprite(rti->base_sprites.single_w); |
60c843b7ea28
(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 |
if (track & TRACK_BIT_RIGHT) DrawGroundSprite(rti->base_sprites.single_e); |
60c843b7ea28
(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 |
} |
3355
a653b8e47f27
(svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
3333
diff
changeset
|
1269 |
|
3361
47e190d820e0
(svn r4156) CodeChange : Little cleanup after Celestar's elrail merge
belugas
parents:
3355
diff
changeset
|
1270 |
if (GetRailType(ti->tile) == RAILTYPE_ELECTRIC) DrawCatenary(ti); |
3355
a653b8e47f27
(svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
3333
diff
changeset
|
1271 |
|
2472
60c843b7ea28
(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 |
} |
60c843b7ea28
(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 |
|
3519
22391e5d1bbf
(svn r4375) -Codechange: Move the signal drawing bit to an own function and rename DrawSignalHelper to DrawSingleSignal
celestar
parents:
3507
diff
changeset
|
1274 |
static void DrawSignals(TileIndex tile, TrackBits rails) |
22391e5d1bbf
(svn r4375) -Codechange: Move the signal drawing bit to an own function and rename DrawSignalHelper to DrawSingleSignal
celestar
parents:
3507
diff
changeset
|
1275 |
{ |
3575
867df1ec208a
(svn r4461) -Codechange: Add and make use of map accessor functions for signal drawing. Includes some basic cleanup of the drawing functions
celestar
parents:
3562
diff
changeset
|
1276 |
#define MAYBE_DRAW_SIGNAL(x,y,z) if (IsSignalPresent(tile, x)) DrawSingleSignal(tile, GetSingleSignalState(tile, x), y - 0x4FB, z) |
3519
22391e5d1bbf
(svn r4375) -Codechange: Move the signal drawing bit to an own function and rename DrawSignalHelper to DrawSingleSignal
celestar
parents:
3507
diff
changeset
|
1277 |
|
22391e5d1bbf
(svn r4375) -Codechange: Move the signal drawing bit to an own function and rename DrawSignalHelper to DrawSingleSignal
celestar
parents:
3507
diff
changeset
|
1278 |
if (!(rails & TRACK_BIT_Y)) { |
22391e5d1bbf
(svn r4375) -Codechange: Move the signal drawing bit to an own function and rename DrawSignalHelper to DrawSingleSignal
celestar
parents:
3507
diff
changeset
|
1279 |
if (!(rails & TRACK_BIT_X)) { |
22391e5d1bbf
(svn r4375) -Codechange: Move the signal drawing bit to an own function and rename DrawSignalHelper to DrawSingleSignal
celestar
parents:
3507
diff
changeset
|
1280 |
if (rails & TRACK_BIT_LEFT) { |
22391e5d1bbf
(svn r4375) -Codechange: Move the signal drawing bit to an own function and rename DrawSignalHelper to DrawSingleSignal
celestar
parents:
3507
diff
changeset
|
1281 |
MAYBE_DRAW_SIGNAL(2, 0x509, 0); |
22391e5d1bbf
(svn r4375) -Codechange: Move the signal drawing bit to an own function and rename DrawSignalHelper to DrawSingleSignal
celestar
parents:
3507
diff
changeset
|
1282 |
MAYBE_DRAW_SIGNAL(3, 0x507, 1); |
22391e5d1bbf
(svn r4375) -Codechange: Move the signal drawing bit to an own function and rename DrawSignalHelper to DrawSingleSignal
celestar
parents:
3507
diff
changeset
|
1283 |
} |
22391e5d1bbf
(svn r4375) -Codechange: Move the signal drawing bit to an own function and rename DrawSignalHelper to DrawSingleSignal
celestar
parents:
3507
diff
changeset
|
1284 |
if (rails & TRACK_BIT_RIGHT) { |
22391e5d1bbf
(svn r4375) -Codechange: Move the signal drawing bit to an own function and rename DrawSignalHelper to DrawSingleSignal
celestar
parents:
3507
diff
changeset
|
1285 |
MAYBE_DRAW_SIGNAL(0, 0x509, 2); |
22391e5d1bbf
(svn r4375) -Codechange: Move the signal drawing bit to an own function and rename DrawSignalHelper to DrawSingleSignal
celestar
parents:
3507
diff
changeset
|
1286 |
MAYBE_DRAW_SIGNAL(1, 0x507, 3); |
22391e5d1bbf
(svn r4375) -Codechange: Move the signal drawing bit to an own function and rename DrawSignalHelper to DrawSingleSignal
celestar
parents:
3507
diff
changeset
|
1287 |
} |
22391e5d1bbf
(svn r4375) -Codechange: Move the signal drawing bit to an own function and rename DrawSignalHelper to DrawSingleSignal
celestar
parents:
3507
diff
changeset
|
1288 |
if (rails & TRACK_BIT_UPPER) { |
22391e5d1bbf
(svn r4375) -Codechange: Move the signal drawing bit to an own function and rename DrawSignalHelper to DrawSingleSignal
celestar
parents:
3507
diff
changeset
|
1289 |
MAYBE_DRAW_SIGNAL(3, 0x505, 4); |
22391e5d1bbf
(svn r4375) -Codechange: Move the signal drawing bit to an own function and rename DrawSignalHelper to DrawSingleSignal
celestar
parents:
3507
diff
changeset
|
1290 |
MAYBE_DRAW_SIGNAL(2, 0x503, 5); |
22391e5d1bbf
(svn r4375) -Codechange: Move the signal drawing bit to an own function and rename DrawSignalHelper to DrawSingleSignal
celestar
parents:
3507
diff
changeset
|
1291 |
} |
22391e5d1bbf
(svn r4375) -Codechange: Move the signal drawing bit to an own function and rename DrawSignalHelper to DrawSingleSignal
celestar
parents:
3507
diff
changeset
|
1292 |
if (rails & TRACK_BIT_LOWER) { |
22391e5d1bbf
(svn r4375) -Codechange: Move the signal drawing bit to an own function and rename DrawSignalHelper to DrawSingleSignal
celestar
parents:
3507
diff
changeset
|
1293 |
MAYBE_DRAW_SIGNAL(1, 0x505, 6); |
22391e5d1bbf
(svn r4375) -Codechange: Move the signal drawing bit to an own function and rename DrawSignalHelper to DrawSingleSignal
celestar
parents:
3507
diff
changeset
|
1294 |
MAYBE_DRAW_SIGNAL(0, 0x503, 7); |
22391e5d1bbf
(svn r4375) -Codechange: Move the signal drawing bit to an own function and rename DrawSignalHelper to DrawSingleSignal
celestar
parents:
3507
diff
changeset
|
1295 |
} |
22391e5d1bbf
(svn r4375) -Codechange: Move the signal drawing bit to an own function and rename DrawSignalHelper to DrawSingleSignal
celestar
parents:
3507
diff
changeset
|
1296 |
} else { |
22391e5d1bbf
(svn r4375) -Codechange: Move the signal drawing bit to an own function and rename DrawSignalHelper to DrawSingleSignal
celestar
parents:
3507
diff
changeset
|
1297 |
MAYBE_DRAW_SIGNAL(3, 0x4FB, 8); |
22391e5d1bbf
(svn r4375) -Codechange: Move the signal drawing bit to an own function and rename DrawSignalHelper to DrawSingleSignal
celestar
parents:
3507
diff
changeset
|
1298 |
MAYBE_DRAW_SIGNAL(2, 0x4FD, 9); |
22391e5d1bbf
(svn r4375) -Codechange: Move the signal drawing bit to an own function and rename DrawSignalHelper to DrawSingleSignal
celestar
parents:
3507
diff
changeset
|
1299 |
} |
22391e5d1bbf
(svn r4375) -Codechange: Move the signal drawing bit to an own function and rename DrawSignalHelper to DrawSingleSignal
celestar
parents:
3507
diff
changeset
|
1300 |
} else { |
22391e5d1bbf
(svn r4375) -Codechange: Move the signal drawing bit to an own function and rename DrawSignalHelper to DrawSingleSignal
celestar
parents:
3507
diff
changeset
|
1301 |
MAYBE_DRAW_SIGNAL(3, 0x4FF, 10); |
22391e5d1bbf
(svn r4375) -Codechange: Move the signal drawing bit to an own function and rename DrawSignalHelper to DrawSingleSignal
celestar
parents:
3507
diff
changeset
|
1302 |
MAYBE_DRAW_SIGNAL(2, 0x501, 11); |
22391e5d1bbf
(svn r4375) -Codechange: Move the signal drawing bit to an own function and rename DrawSignalHelper to DrawSingleSignal
celestar
parents:
3507
diff
changeset
|
1303 |
} |
22391e5d1bbf
(svn r4375) -Codechange: Move the signal drawing bit to an own function and rename DrawSignalHelper to DrawSingleSignal
celestar
parents:
3507
diff
changeset
|
1304 |
} |
22391e5d1bbf
(svn r4375) -Codechange: Move the signal drawing bit to an own function and rename DrawSignalHelper to DrawSingleSignal
celestar
parents:
3507
diff
changeset
|
1305 |
|
0 | 1306 |
static void DrawTile_Track(TileInfo *ti) |
1307 |
{ |
|
2233
146e2e405ec1
(svn r2753) -Codechange: Introduced a new struct "RailtypeInfo" to store rail type specific information. Begun populating it with a bunch of sprites, more to come later. This should result in cleaner, more compact code which allows easy introduction of new railtypes.
celestar
parents:
2187
diff
changeset
|
1308 |
const RailtypeInfo *rti = GetRailTypeInfo(GetRailType(ti->tile)); |
2472
60c843b7ea28
(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
|
1309 |
PalSpriteID image; |
0 | 1310 |
|
1901
fb05044cf5c3
(svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents:
1891
diff
changeset
|
1311 |
_drawtile_track_palette = SPRITE_PALETTE(PLAYER_SPRITE_COLOR(GetTileOwner(ti->tile))); |
0 | 1312 |
|
3792
2eb8388731bf
(svn r4788) - Codechange: RAILTYPE_{NORMAL,ELECTRIC,...} and RAIL_TYPE_{NORMAL,SIGNAL,...} have nearly the same name, rename RAIL_TYPE_* to RAIL_TILE_* of extra clarity
rubidium
parents:
3778
diff
changeset
|
1313 |
if (GetRailTileType(ti->tile) != RAIL_TILE_DEPOT_WAYPOINT) { |
3267
591027d10884
(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 |
TrackBits rails = GetTrackBits(ti->tile); |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1315 |
|
3523
168ee460418b
(svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents:
3522
diff
changeset
|
1316 |
DrawTrackBits(ti, rails, false); |
2008
c9d6585c96c8
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2007
diff
changeset
|
1317 |
|
4040
3c5fc0aea78d
(svn r5308) Replace an array of function pointers with a switch: It's shorter, more comprehensible, less dependent on magic numbers
tron
parents:
4000
diff
changeset
|
1318 |
if (_display_opt & DO_FULL_DETAIL) DrawTrackDetails(ti); |
0 | 1319 |
|
1320 |
/* draw signals also? */ |
|
3792
2eb8388731bf
(svn r4788) - Codechange: RAILTYPE_{NORMAL,ELECTRIC,...} and RAIL_TYPE_{NORMAL,SIGNAL,...} have nearly the same name, rename RAIL_TYPE_* to RAIL_TILE_* of extra clarity
rubidium
parents:
3778
diff
changeset
|
1321 |
if (GetRailTileType(ti->tile) == RAIL_TILE_SIGNALS) DrawSignals(ti->tile, rails); |
0 | 1322 |
} else { |
395
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
393
diff
changeset
|
1323 |
/* draw depots / waypoints */ |
0 | 1324 |
const DrawTrackSeqStruct *drss; |
3528 | 1325 |
bool is_depot = GetRailTileSubtype(ti->tile) == RAIL_SUBTYPE_DEPOT; |
0 | 1326 |
|
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3575
diff
changeset
|
1327 |
if (ti->tileh != SLOPE_FLAT) DrawFoundation(ti, ti->tileh); |
0 | 1328 |
|
4052
7edea464c3a9
(svn r5326) Remove the indicator bit for custom waypoint graphics, because it just contains redundant information
tron
parents:
4046
diff
changeset
|
1329 |
if (IsRailWaypoint(ti->tile)) { |
389
2d394eeba5e5
(svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents:
337
diff
changeset
|
1330 |
// look for customization |
2670
34970983ef08
(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
|
1331 |
byte stat_id = GetWaypointByTile(ti->tile)->stat_id; |
3676
48444d881fbe
(svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents:
3671
diff
changeset
|
1332 |
const StationSpec *statspec = GetCustomStationSpec(STAT_CLASS_WAYP, stat_id); |
389
2d394eeba5e5
(svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents:
337
diff
changeset
|
1333 |
|
3676
48444d881fbe
(svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents:
3671
diff
changeset
|
1334 |
if (statspec != NULL) { |
389
2d394eeba5e5
(svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents:
337
diff
changeset
|
1335 |
DrawTileSeqStruct const *seq; |
403
bfb365c74e80
(svn r600) -newgrf: Relocation offset for custom station sprites is now stored separately, making it possible to show different sprites in waypoint selection dialog (pasky).
darkvater
parents:
399
diff
changeset
|
1336 |
// emulate station tile - open with building |
3757
a0bba34a94ba
(svn r4748) - Newstations: use custom sprite layout callback for waypoints as well as stations. Supports merging of adjacent waypoints if the GRF supports it (newstatsw.grf)
peter1138
parents:
3751
diff
changeset
|
1337 |
uint tile = 2; |
a0bba34a94ba
(svn r4748) - Newstations: use custom sprite layout callback for waypoints as well as stations. Supports merging of adjacent waypoints if the GRF supports it (newstatsw.grf)
peter1138
parents:
3751
diff
changeset
|
1338 |
const DrawTileSprites *cust; |
a0bba34a94ba
(svn r4748) - Newstations: use custom sprite layout callback for waypoints as well as stations. Supports merging of adjacent waypoints if the GRF supports it (newstatsw.grf)
peter1138
parents:
3751
diff
changeset
|
1339 |
Station *st = ComposeWaypointStation(ti->tile); |
389
2d394eeba5e5
(svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents:
337
diff
changeset
|
1340 |
|
3757
a0bba34a94ba
(svn r4748) - Newstations: use custom sprite layout callback for waypoints as well as stations. Supports merging of adjacent waypoints if the GRF supports it (newstatsw.grf)
peter1138
parents:
3751
diff
changeset
|
1341 |
uint32 relocation = GetCustomStationRelocation(statspec, st, ti->tile); |
a0bba34a94ba
(svn r4748) - Newstations: use custom sprite layout callback for waypoints as well as stations. Supports merging of adjacent waypoints if the GRF supports it (newstatsw.grf)
peter1138
parents:
3751
diff
changeset
|
1342 |
|
a0bba34a94ba
(svn r4748) - Newstations: use custom sprite layout callback for waypoints as well as stations. Supports merging of adjacent waypoints if the GRF supports it (newstatsw.grf)
peter1138
parents:
3751
diff
changeset
|
1343 |
if (HASBIT(statspec->callbackmask, CBM_CUSTOM_LAYOUT)) { |
a0bba34a94ba
(svn r4748) - Newstations: use custom sprite layout callback for waypoints as well as stations. Supports merging of adjacent waypoints if the GRF supports it (newstatsw.grf)
peter1138
parents:
3751
diff
changeset
|
1344 |
uint16 callback = GetStationCallback(CBID_STATION_SPRITE_LAYOUT, 0, 0, statspec, st, ti->tile); |
a0bba34a94ba
(svn r4748) - Newstations: use custom sprite layout callback for waypoints as well as stations. Supports merging of adjacent waypoints if the GRF supports it (newstatsw.grf)
peter1138
parents:
3751
diff
changeset
|
1345 |
if (callback != CALLBACK_FAILED) tile = callback; |
a0bba34a94ba
(svn r4748) - Newstations: use custom sprite layout callback for waypoints as well as stations. Supports merging of adjacent waypoints if the GRF supports it (newstatsw.grf)
peter1138
parents:
3751
diff
changeset
|
1346 |
} |
a0bba34a94ba
(svn r4748) - Newstations: use custom sprite layout callback for waypoints as well as stations. Supports merging of adjacent waypoints if the GRF supports it (newstatsw.grf)
peter1138
parents:
3751
diff
changeset
|
1347 |
|
3763
460bbb4a8154
(svn r4754) - Newstations: expose default station display data via a function so we can use it (rarely) in other places.
peter1138
parents:
3757
diff
changeset
|
1348 |
if (statspec->renderdata == NULL) { |
460bbb4a8154
(svn r4754) - Newstations: expose default station display data via a function so we can use it (rarely) in other places.
peter1138
parents:
3757
diff
changeset
|
1349 |
cust = GetStationTileLayout(tile); |
460bbb4a8154
(svn r4754) - Newstations: expose default station display data via a function so we can use it (rarely) in other places.
peter1138
parents:
3757
diff
changeset
|
1350 |
} else { |
460bbb4a8154
(svn r4754) - Newstations: expose default station display data via a function so we can use it (rarely) in other places.
peter1138
parents:
3757
diff
changeset
|
1351 |
cust = &statspec->renderdata[(tile < statspec->tiles ? tile : 0) + GetWaypointAxis(ti->tile)]; |
460bbb4a8154
(svn r4754) - Newstations: expose default station display data via a function so we can use it (rarely) in other places.
peter1138
parents:
3757
diff
changeset
|
1352 |
} |
447
aaf1f59a8957
(svn r657) Do not touch 0x8000 bit in sprite index for custom waypoints. (pasky)
celestar
parents:
438
diff
changeset
|
1353 |
|
3737
26341085bbbf
(svn r4719) - Newstations: instead of drawing nothing, fall back to the default sprite layout if a station layout specifies so.
peter1138
parents:
3676
diff
changeset
|
1354 |
/* If there is no sprite layout, we fall back to the default waypoint graphics. */ |
26341085bbbf
(svn r4719) - Newstations: instead of drawing nothing, fall back to the default sprite layout if a station layout specifies so.
peter1138
parents:
3676
diff
changeset
|
1355 |
if (cust != NULL && cust->seq != NULL) { |
26341085bbbf
(svn r4719) - Newstations: instead of drawing nothing, fall back to the default sprite layout if a station layout specifies so.
peter1138
parents:
3676
diff
changeset
|
1356 |
image = cust->ground_sprite; |
3775
f3f1ba3111fa
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3763
diff
changeset
|
1357 |
if (HASBIT(image, 31)) { |
f3f1ba3111fa
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3763
diff
changeset
|
1358 |
CLRBIT(image, 31); |
f3f1ba3111fa
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3763
diff
changeset
|
1359 |
image += GetCustomStationGroundRelocation(statspec, st, ti->tile); |
f3f1ba3111fa
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3763
diff
changeset
|
1360 |
image += rti->custom_ground_offset; |
f3f1ba3111fa
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3763
diff
changeset
|
1361 |
} else { |
f3f1ba3111fa
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3763
diff
changeset
|
1362 |
image += rti->total_offset; |
f3f1ba3111fa
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3763
diff
changeset
|
1363 |
} |
3355
a653b8e47f27
(svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
3333
diff
changeset
|
1364 |
|
3737
26341085bbbf
(svn r4719) - Newstations: instead of drawing nothing, fall back to the default sprite layout if a station layout specifies so.
peter1138
parents:
3676
diff
changeset
|
1365 |
DrawGroundSprite(image); |
26341085bbbf
(svn r4719) - Newstations: instead of drawing nothing, fall back to the default sprite layout if a station layout specifies so.
peter1138
parents:
3676
diff
changeset
|
1366 |
|
26341085bbbf
(svn r4719) - Newstations: instead of drawing nothing, fall back to the default sprite layout if a station layout specifies so.
peter1138
parents:
3676
diff
changeset
|
1367 |
if (GetRailType(ti->tile) == RAILTYPE_ELECTRIC) DrawCatenary(ti); |
26341085bbbf
(svn r4719) - Newstations: instead of drawing nothing, fall back to the default sprite layout if a station layout specifies so.
peter1138
parents:
3676
diff
changeset
|
1368 |
|
26341085bbbf
(svn r4719) - Newstations: instead of drawing nothing, fall back to the default sprite layout if a station layout specifies so.
peter1138
parents:
3676
diff
changeset
|
1369 |
foreach_draw_tile_seq(seq, cust->seq) { |
26341085bbbf
(svn r4719) - Newstations: instead of drawing nothing, fall back to the default sprite layout if a station layout specifies so.
peter1138
parents:
3676
diff
changeset
|
1370 |
DrawSpecialBuilding( |
26341085bbbf
(svn r4719) - Newstations: instead of drawing nothing, fall back to the default sprite layout if a station layout specifies so.
peter1138
parents:
3676
diff
changeset
|
1371 |
seq->image + relocation, 0, ti, |
26341085bbbf
(svn r4719) - Newstations: instead of drawing nothing, fall back to the default sprite layout if a station layout specifies so.
peter1138
parents:
3676
diff
changeset
|
1372 |
seq->delta_x, seq->delta_y, seq->delta_z, |
26341085bbbf
(svn r4719) - Newstations: instead of drawing nothing, fall back to the default sprite layout if a station layout specifies so.
peter1138
parents:
3676
diff
changeset
|
1373 |
seq->width, seq->height, seq->unk |
26341085bbbf
(svn r4719) - Newstations: instead of drawing nothing, fall back to the default sprite layout if a station layout specifies so.
peter1138
parents:
3676
diff
changeset
|
1374 |
); |
26341085bbbf
(svn r4719) - Newstations: instead of drawing nothing, fall back to the default sprite layout if a station layout specifies so.
peter1138
parents:
3676
diff
changeset
|
1375 |
} |
26341085bbbf
(svn r4719) - Newstations: instead of drawing nothing, fall back to the default sprite layout if a station layout specifies so.
peter1138
parents:
3676
diff
changeset
|
1376 |
return; |
389
2d394eeba5e5
(svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents:
337
diff
changeset
|
1377 |
} |
2d394eeba5e5
(svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents:
337
diff
changeset
|
1378 |
} |
2d394eeba5e5
(svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents:
337
diff
changeset
|
1379 |
} |
2d394eeba5e5
(svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents:
337
diff
changeset
|
1380 |
|
3528 | 1381 |
drss = is_depot ? _track_depot_layout_table[GetRailDepotDirection(ti->tile)] : _track_waypoint_layout_table[GetWaypointAxis(ti->tile)]; |
0 | 1382 |
|
1399
4503bd2bfb82
(svn r1903) Replace some casts and macro magic with proper typing, similar to r1902
tron
parents:
1363
diff
changeset
|
1383 |
image = drss++->image; |
2254
72f8883ff3ac
(svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents:
2236
diff
changeset
|
1384 |
/* @note This is kind of an ugly hack, as the PALETTE_MODIFIER_COLOR indicates |
3737
26341085bbbf
(svn r4719) - Newstations: instead of drawing nothing, fall back to the default sprite layout if a station layout specifies so.
peter1138
parents:
3676
diff
changeset
|
1385 |
* whether the sprite is railtype dependent. Rewrite this asap */ |
2254
72f8883ff3ac
(svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents:
2236
diff
changeset
|
1386 |
if (image & PALETTE_MODIFIER_COLOR) image = (image & SPRITE_MASK) + rti->total_offset; |
0 | 1387 |
|
1388 |
// adjust ground tile for desert |
|
283
c1a99d78e5a3
(svn r289) Fix: Checkpoints on snow have correct ground now
dominik
parents:
282
diff
changeset
|
1389 |
// (don't adjust for arctic depots, because snow in depots looks weird) |
2254
72f8883ff3ac
(svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents:
2236
diff
changeset
|
1390 |
// type >= 4 means waypoints |
3528 | 1391 |
if (IsSnowRailGround(ti->tile) && (_opt.landscape == LT_DESERT || !is_depot)) { |
2549 | 1392 |
if (image != SPR_FLAT_GRASS_TILE) { |
2254
72f8883ff3ac
(svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents:
2236
diff
changeset
|
1393 |
image += rti->snow_offset; // tile with tracks |
2549 | 1394 |
} else { |
2254
72f8883ff3ac
(svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents:
2236
diff
changeset
|
1395 |
image = SPR_FLAT_SNOWY_TILE; // flat ground |
2549 | 1396 |
} |
0 | 1397 |
} |
1398 |
||
1399 |
DrawGroundSprite(image); |
|
1400 |
||
3355
a653b8e47f27
(svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
3333
diff
changeset
|
1401 |
if (GetRailType(ti->tile) == RAILTYPE_ELECTRIC) DrawCatenary(ti); |
a653b8e47f27
(svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
3333
diff
changeset
|
1402 |
|
2549 | 1403 |
for (; drss->image != 0; drss++) { |
2951 | 1404 |
DrawSpecialBuilding( |
3528 | 1405 |
drss->image, is_depot ? rti->total_offset : 0, ti, |
2951 | 1406 |
drss->subcoord_x, drss->subcoord_y, 0, |
1407 |
drss->width, drss->height, 0x17 |
|
1408 |
); |
|
0 | 1409 |
} |
1410 |
} |
|
1411 |
} |
|
1412 |
||
2520
75eb66d6e371
(svn r3049) Replace byte/int/uint by RailType where appropriate
tron
parents:
2502
diff
changeset
|
1413 |
void DrawTrainDepotSprite(int x, int y, int image, RailType railtype) |
0 | 1414 |
{ |
1415 |
uint32 ormod, img; |
|
2254
72f8883ff3ac
(svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents:
2236
diff
changeset
|
1416 |
const RailtypeInfo *rti = GetRailTypeInfo(railtype); |
0 | 1417 |
const DrawTrackSeqStruct *dtss; |
1418 |
||
1419 |
ormod = PLAYER_SPRITE_COLOR(_local_player); |
|
1420 |
||
1399
4503bd2bfb82
(svn r1903) Replace some casts and macro magic with proper typing, similar to r1902
tron
parents:
1363
diff
changeset
|
1421 |
dtss = _track_depot_layout_table[image]; |
0 | 1422 |
|
2549 | 1423 |
x += 33; |
1424 |
y += 17; |
|
0 | 1425 |
|
1399
4503bd2bfb82
(svn r1903) Replace some casts and macro magic with proper typing, similar to r1902
tron
parents:
1363
diff
changeset
|
1426 |
img = dtss++->image; |
2254
72f8883ff3ac
(svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents:
2236
diff
changeset
|
1427 |
/* @note This is kind of an ugly hack, as the PALETTE_MODIFIER_COLOR indicates |
72f8883ff3ac
(svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents:
2236
diff
changeset
|
1428 |
* whether the sprite is railtype dependent. Rewrite this asap */ |
72f8883ff3ac
(svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents:
2236
diff
changeset
|
1429 |
if (img & PALETTE_MODIFIER_COLOR) img = (img & SPRITE_MASK) + rti->total_offset; |
0 | 1430 |
DrawSprite(img, x, y); |
1431 |
||
1399
4503bd2bfb82
(svn r1903) Replace some casts and macro magic with proper typing, similar to r1902
tron
parents:
1363
diff
changeset
|
1432 |
for (; dtss->image != 0; dtss++) { |
0 | 1433 |
Point pt = RemapCoords(dtss->subcoord_x, dtss->subcoord_y, 0); |
1434 |
image = dtss->image; |
|
2187
2a51f8925eeb
(svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents:
2186
diff
changeset
|
1435 |
if (image & PALETTE_MODIFIER_COLOR) image |= ormod; |
2254
72f8883ff3ac
(svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents:
2236
diff
changeset
|
1436 |
DrawSprite(image + rti->total_offset, x + pt.x, y + pt.y); |
0 | 1437 |
} |
1438 |
} |
|
1439 |
||
2520
75eb66d6e371
(svn r3049) Replace byte/int/uint by RailType where appropriate
tron
parents:
2502
diff
changeset
|
1440 |
void DrawDefaultWaypointSprite(int x, int y, RailType railtype) |
2261
3f78323707bb
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2254
diff
changeset
|
1441 |
{ |
3549
305bfac8b7d8
(svn r4415) Fix bug introduced in r4384 where drawing a default waypoint for the GUI
peter1138
parents:
3530
diff
changeset
|
1442 |
const DrawTrackSeqStruct *dtss = _track_waypoint_layout_table[0]; |
2261
3f78323707bb
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2254
diff
changeset
|
1443 |
const RailtypeInfo *rti = GetRailTypeInfo(railtype); |
3f78323707bb
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2254
diff
changeset
|
1444 |
uint32 img; |
3f78323707bb
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2254
diff
changeset
|
1445 |
|
3f78323707bb
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2254
diff
changeset
|
1446 |
img = dtss++->image; |
3f78323707bb
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2254
diff
changeset
|
1447 |
if (img & PALETTE_MODIFIER_COLOR) img = (img & SPRITE_MASK) + rti->total_offset; |
3f78323707bb
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2254
diff
changeset
|
1448 |
DrawSprite(img, x, y); |
3f78323707bb
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2254
diff
changeset
|
1449 |
|
3f78323707bb
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2254
diff
changeset
|
1450 |
for (; dtss->image != 0; dtss++) { |
3f78323707bb
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2254
diff
changeset
|
1451 |
Point pt = RemapCoords(dtss->subcoord_x, dtss->subcoord_y, 0); |
3f78323707bb
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2254
diff
changeset
|
1452 |
img = dtss->image; |
3f78323707bb
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2254
diff
changeset
|
1453 |
if (img & PALETTE_MODIFIER_COLOR) img |= PLAYER_SPRITE_COLOR(_local_player); |
3f78323707bb
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2254
diff
changeset
|
1454 |
DrawSprite(img, x + pt.x, y + pt.y); |
3f78323707bb
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2254
diff
changeset
|
1455 |
} |
3f78323707bb
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2254
diff
changeset
|
1456 |
} |
3f78323707bb
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2254
diff
changeset
|
1457 |
|
0 | 1458 |
typedef struct SetSignalsData { |
1459 |
int cur; |
|
1460 |
int cur_stack; |
|
1461 |
bool stop; |
|
1462 |
bool has_presignal; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1463 |
|
0 | 1464 |
// presignal info |
1465 |
int presignal_exits; |
|
1466 |
int presignal_exits_free; |
|
1467 |
||
1468 |
// these are used to keep track of the signals that change. |
|
1469 |
byte bit[NUM_SSD_ENTRY]; |
|
1470 |
TileIndex tile[NUM_SSD_ENTRY]; |
|
1471 |
||
1472 |
// these are used to keep track of the stack that modifies presignals recursively |
|
1473 |
TileIndex next_tile[NUM_SSD_STACK]; |
|
1474 |
byte next_dir[NUM_SSD_STACK]; |
|
1475 |
||
1476 |
} SetSignalsData; |
|
1477 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1963
diff
changeset
|
1478 |
static bool SetSignalsEnumProc(TileIndex tile, SetSignalsData *ssd, int track, uint length, byte *state) |
0 | 1479 |
{ |
3017
915fae59d5e0
(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
|
1480 |
if (!IsTileType(tile, MP_RAILWAY)) return false; |
915fae59d5e0
(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
|
1481 |
|
0 | 1482 |
// the tile has signals? |
3017
915fae59d5e0
(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
|
1483 |
if (HasSignalOnTrack(tile, TrackdirToTrack(track))) { |
915fae59d5e0
(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
|
1484 |
if (HasSignalOnTrackdir(tile, ReverseTrackdir(track))) { |
915fae59d5e0
(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
|
1485 |
// yes, add the signal to the list of signals |
915fae59d5e0
(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
|
1486 |
if (ssd->cur != NUM_SSD_ENTRY) { |
915fae59d5e0
(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
|
1487 |
ssd->tile[ssd->cur] = tile; // remember the tile index |
915fae59d5e0
(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
|
1488 |
ssd->bit[ssd->cur] = track; // and the controlling bit number |
915fae59d5e0
(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
|
1489 |
ssd->cur++; |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
1490 |
} |
0 | 1491 |
|
3017
915fae59d5e0
(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
|
1492 |
// remember if this block has a presignal. |
3521
c5dda2dbd977
(svn r4377) -Add and make use of a function that finds out whether a signal is an entry or and exit signal to a presignal block (as combos act as both)
celestar
parents:
3520
diff
changeset
|
1493 |
ssd->has_presignal |= IsPresignalEntry(tile); |
3017
915fae59d5e0
(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
|
1494 |
} |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
1495 |
|
3521
c5dda2dbd977
(svn r4377) -Add and make use of a function that finds out whether a signal is an entry or and exit signal to a presignal block (as combos act as both)
celestar
parents:
3520
diff
changeset
|
1496 |
if (HasSignalOnTrackdir(tile, track) && IsPresignalExit(tile)) { |
3017
915fae59d5e0
(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
|
1497 |
// this is an exit signal that points out from the segment |
915fae59d5e0
(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
|
1498 |
ssd->presignal_exits++; |
3520
092efede26b3
(svn r4376) -Codechange Renamed GetSignalState to GetSignalStateByTrackdir
celestar
parents:
3519
diff
changeset
|
1499 |
if (GetSignalStateByTrackdir(tile, track) != SIGNAL_STATE_RED) |
3017
915fae59d5e0
(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 |
ssd->presignal_exits_free++; |
2549 | 1501 |
} |
3017
915fae59d5e0
(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
|
1502 |
|
915fae59d5e0
(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 |
return true; |
915fae59d5e0
(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 |
} else if (IsTileDepotType(tile, TRANSPORT_RAIL)) { |
915fae59d5e0
(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 |
return true; // don't look further if the tile is a depot |
0 | 1506 |
} |
3017
915fae59d5e0
(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 |
|
0 | 1508 |
return false; |
1509 |
} |
|
1510 |
||
1555
c7e5bb32f536
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1511 |
/* Struct to parse data from VehicleFromPos to SignalVehicleCheckProc */ |
c7e5bb32f536
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1512 |
typedef struct SignalVehicleCheckStruct { |
c7e5bb32f536
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1513 |
TileIndex tile; |
c7e5bb32f536
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1514 |
uint track; |
c7e5bb32f536
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1515 |
} SignalVehicleCheckStruct; |
c7e5bb32f536
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1516 |
|
c7e5bb32f536
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1517 |
static void *SignalVehicleCheckProc(Vehicle *v, void *data) |
c7e5bb32f536
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1518 |
{ |
2549 | 1519 |
const SignalVehicleCheckStruct* dest = data; |
3977
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
1520 |
TileIndex tile; |
1555
c7e5bb32f536
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1521 |
|
2549 | 1522 |
if (v->type != VEH_Train) return NULL; |
1609
b4d11170cbb5
(svn r2113) -Fix: first check if a vehicle is a train, before accessing u.rail
truelight
parents:
1598
diff
changeset
|
1523 |
|
3977
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
1524 |
/* Find the tile outside the tunnel, for signalling */ |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
1525 |
if (v->u.rail.track == 0x40) { |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
1526 |
tile = GetVehicleOutOfTunnelTile(v); |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
1527 |
} else { |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
1528 |
tile = v->tile; |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
1529 |
} |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
1530 |
|
1555
c7e5bb32f536
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1531 |
/* Wrong tile, or no train? Not a match */ |
3977
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
1532 |
if (tile != dest->tile) return NULL; |
1555
c7e5bb32f536
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1533 |
|
c7e5bb32f536
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1534 |
/* Are we on the same piece of track? */ |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4067
diff
changeset
|
1535 |
if (dest->track & v->u.rail.track * 0x101) return v; |
1555
c7e5bb32f536
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1536 |
|
c7e5bb32f536
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1537 |
return NULL; |
c7e5bb32f536
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1538 |
} |
c7e5bb32f536
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1539 |
|
c7e5bb32f536
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1540 |
/* Special check for SetSignalsAfterProc, to see if there is a vehicle on this tile */ |
2752 | 1541 |
static bool SignalVehicleCheck(TileIndex tile, uint track) |
1555
c7e5bb32f536
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1542 |
{ |
c7e5bb32f536
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1543 |
SignalVehicleCheckStruct dest; |
c7e5bb32f536
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1544 |
|
c7e5bb32f536
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1545 |
dest.tile = tile; |
c7e5bb32f536
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1546 |
dest.track = track; |
c7e5bb32f536
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1547 |
|
3977
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
1548 |
/** @todo "Hackish" fix for the tunnel problems. This is needed because a tunnel |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
1549 |
* is some kind of invisible black hole, and there is some special magic going |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
1550 |
* on in there. This 'workaround' can be removed once the maprewrite is done. |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
1551 |
*/ |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
1552 |
if (IsTunnelTile(tile)) { |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
1553 |
// It is a tunnel we're checking, we need to do some special stuff |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
1554 |
// because VehicleFromPos will not find the vihicle otherwise |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
1555 |
TileIndex end = GetOtherTunnelEnd(tile); |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
1556 |
DiagDirection direction = GetTunnelDirection(tile); |
3154 | 1557 |
|
1816
e96c4a8136bf
(svn r2320) - Fix: [ 1185176 ] Train in tunnel is not properly detected by signal code (Hackykid)
matthijs
parents:
1813
diff
changeset
|
1558 |
dest.track = 1 << (direction & 1); // get the trackbit the vehicle would have if it has not entered the tunnel yet (ie is still visible) |
e96c4a8136bf
(svn r2320) - Fix: [ 1185176 ] Train in tunnel is not properly detected by signal code (Hackykid)
matthijs
parents:
1813
diff
changeset
|
1559 |
|
e96c4a8136bf
(svn r2320) - Fix: [ 1185176 ] Train in tunnel is not properly detected by signal code (Hackykid)
matthijs
parents:
1813
diff
changeset
|
1560 |
// check for a vehicle with that trackdir on the start tile of the tunnel |
1818
88ab405a9dfc
(svn r2322) - CodeChange: doxygen commented the tunnel-crash fix. Also if (bla) {return;} else {return;} is not proper code. It's if (bla) {return;} return; ;)
Darkvater
parents:
1816
diff
changeset
|
1561 |
if (VehicleFromPos(tile, &dest, SignalVehicleCheckProc) != NULL) return true; |
1816
e96c4a8136bf
(svn r2320) - Fix: [ 1185176 ] Train in tunnel is not properly detected by signal code (Hackykid)
matthijs
parents:
1813
diff
changeset
|
1562 |
|
e96c4a8136bf
(svn r2320) - Fix: [ 1185176 ] Train in tunnel is not properly detected by signal code (Hackykid)
matthijs
parents:
1813
diff
changeset
|
1563 |
// check for a vehicle with that trackdir on the end tile of the tunnel |
3154 | 1564 |
if (VehicleFromPos(end, &dest, SignalVehicleCheckProc) != NULL) return true; |
1816
e96c4a8136bf
(svn r2320) - Fix: [ 1185176 ] Train in tunnel is not properly detected by signal code (Hackykid)
matthijs
parents:
1813
diff
changeset
|
1565 |
|
3977
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
1566 |
// now check all tiles from start to end for a "hidden" vehicle |
1816
e96c4a8136bf
(svn r2320) - Fix: [ 1185176 ] Train in tunnel is not properly detected by signal code (Hackykid)
matthijs
parents:
1813
diff
changeset
|
1567 |
// NOTE: the hashes for tiles may overlap, so this could maybe be optimised a bit by not checking every tile? |
3977
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
1568 |
dest.track = 0x40; // trackbit for vehicles "hidden" inside a tunnel |
3154 | 1569 |
for (; tile != end; tile += TileOffsByDir(direction)) { |
1816
e96c4a8136bf
(svn r2320) - Fix: [ 1185176 ] Train in tunnel is not properly detected by signal code (Hackykid)
matthijs
parents:
1813
diff
changeset
|
1570 |
if (VehicleFromPos(tile, &dest, SignalVehicleCheckProc) != NULL) |
e96c4a8136bf
(svn r2320) - Fix: [ 1185176 ] Train in tunnel is not properly detected by signal code (Hackykid)
matthijs
parents:
1813
diff
changeset
|
1571 |
return true; |
e96c4a8136bf
(svn r2320) - Fix: [ 1185176 ] Train in tunnel is not properly detected by signal code (Hackykid)
matthijs
parents:
1813
diff
changeset
|
1572 |
} |
e96c4a8136bf
(svn r2320) - Fix: [ 1185176 ] Train in tunnel is not properly detected by signal code (Hackykid)
matthijs
parents:
1813
diff
changeset
|
1573 |
|
e96c4a8136bf
(svn r2320) - Fix: [ 1185176 ] Train in tunnel is not properly detected by signal code (Hackykid)
matthijs
parents:
1813
diff
changeset
|
1574 |
// no vehicle found |
e96c4a8136bf
(svn r2320) - Fix: [ 1185176 ] Train in tunnel is not properly detected by signal code (Hackykid)
matthijs
parents:
1813
diff
changeset
|
1575 |
return false; |
1818
88ab405a9dfc
(svn r2322) - CodeChange: doxygen commented the tunnel-crash fix. Also if (bla) {return;} else {return;} is not proper code. It's if (bla) {return;} return; ;)
Darkvater
parents:
1816
diff
changeset
|
1576 |
} |
88ab405a9dfc
(svn r2322) - CodeChange: doxygen commented the tunnel-crash fix. Also if (bla) {return;} else {return;} is not proper code. It's if (bla) {return;} return; ;)
Darkvater
parents:
1816
diff
changeset
|
1577 |
|
88ab405a9dfc
(svn r2322) - CodeChange: doxygen commented the tunnel-crash fix. Also if (bla) {return;} else {return;} is not proper code. It's if (bla) {return;} return; ;)
Darkvater
parents:
1816
diff
changeset
|
1578 |
return VehicleFromPos(tile, &dest, SignalVehicleCheckProc) != NULL; |
1555
c7e5bb32f536
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1579 |
} |
c7e5bb32f536
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1580 |
|
0 | 1581 |
static void SetSignalsAfterProc(TrackPathFinder *tpf) |
1582 |
{ |
|
1583 |
SetSignalsData *ssd = tpf->userdata; |
|
2548
97ada3bd2702
(svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents:
2544
diff
changeset
|
1584 |
const TrackPathFinderLink* link; |
1555
c7e5bb32f536
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1585 |
uint offs; |
c7e5bb32f536
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1586 |
uint i; |
0 | 1587 |
|
1588 |
ssd->stop = false; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1589 |
|
1555
c7e5bb32f536
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1590 |
/* Go through all the PF tiles */ |
c7e5bb32f536
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1591 |
for (i = 0; i < lengthof(tpf->hash_head); i++) { |
c7e5bb32f536
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1592 |
/* Empty hash item */ |
2639 | 1593 |
if (tpf->hash_head[i] == 0) continue; |
0 | 1594 |
|
1555
c7e5bb32f536
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1595 |
/* If 0x8000 is not set, there is only 1 item */ |
c7e5bb32f536
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1596 |
if (!(tpf->hash_head[i] & 0x8000)) { |
c7e5bb32f536
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1597 |
/* Check if there is a vehicle on this tile */ |
c7e5bb32f536
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1598 |
if (SignalVehicleCheck(tpf->hash_tile[i], tpf->hash_head[i])) { |
c7e5bb32f536
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1599 |
ssd->stop = true; |
c7e5bb32f536
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1600 |
return; |
c7e5bb32f536
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1601 |
} |
0 | 1602 |
} else { |
1555
c7e5bb32f536
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1603 |
/* There are multiple items, where hash_tile points to the first item in the list */ |
c7e5bb32f536
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1604 |
offs = tpf->hash_tile[i]; |
0 | 1605 |
do { |
1555
c7e5bb32f536
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1606 |
/* Find the next item */ |
0 | 1607 |
link = PATHFIND_GET_LINK_PTR(tpf, offs); |
1555
c7e5bb32f536
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1608 |
/* Check if there is a vehicle on this tile */ |
c7e5bb32f536
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1609 |
if (SignalVehicleCheck(link->tile, link->flags)) { |
c7e5bb32f536
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1610 |
ssd->stop = true; |
c7e5bb32f536
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1611 |
return; |
0 | 1612 |
} |
1555
c7e5bb32f536
(svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents:
1542
diff
changeset
|
1613 |
/* Goto the next item */ |
2951 | 1614 |
} while ((offs = link->next) != 0xFFFF); |
0 | 1615 |
} |
1616 |
} |
|
1617 |
} |
|
1618 |
||
1619 |
static const byte _dir_from_track[14] = { |
|
1620 |
0,1,0,1,2,1, 0,0, |
|
1621 |
2,3,3,2,3,0, |
|
1622 |
}; |
|
1623 |
||
1624 |
||
1625 |
static void ChangeSignalStates(SetSignalsData *ssd) |
|
1626 |
{ |
|
1627 |
int i; |
|
1628 |
||
1629 |
// thinking about presignals... |
|
1630 |
// the presignal is green if, |
|
1631 |
// if no train is in the segment AND |
|
1632 |
// there is at least one green exit signal OR |
|
1633 |
// there are no exit signals in the segment |
|
1634 |
||
1635 |
// then mark the signals in the segment accordingly |
|
2549 | 1636 |
for (i = 0; i != ssd->cur; i++) { |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1963
diff
changeset
|
1637 |
TileIndex tile = ssd->tile[i]; |
2821
ba75b5f98725
(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
|
1638 |
byte bit = SignalAgainstTrackdir(ssd->bit[i]); |
2049
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2020
diff
changeset
|
1639 |
uint16 m2 = _m[tile].m2; |
0 | 1640 |
|
1641 |
// presignals don't turn green if there is at least one presignal exit and none are free |
|
3521
c5dda2dbd977
(svn r4377) -Add and make use of a function that finds out whether a signal is an entry or and exit signal to a presignal block (as combos act as both)
celestar
parents:
3520
diff
changeset
|
1642 |
if (IsPresignalEntry(tile)) { |
0 | 1643 |
int ex = ssd->presignal_exits, exfree = ssd->presignal_exits_free; |
1644 |
||
1645 |
// subtract for dual combo signals so they don't count themselves |
|
3521
c5dda2dbd977
(svn r4377) -Add and make use of a function that finds out whether a signal is an entry or and exit signal to a presignal block (as combos act as both)
celestar
parents:
3520
diff
changeset
|
1646 |
if (IsPresignalExit(tile) && HasSignalOnTrackdir(tile, ssd->bit[i])) { |
0 | 1647 |
ex--; |
3520
092efede26b3
(svn r4376) -Codechange Renamed GetSignalState to GetSignalStateByTrackdir
celestar
parents:
3519
diff
changeset
|
1648 |
if (GetSignalStateByTrackdir(tile, ssd->bit[i]) != SIGNAL_STATE_RED) exfree--; |
0 | 1649 |
} |
1650 |
||
1651 |
// if we have exits and none are free, make red. |
|
1652 |
if (ex && !exfree) goto make_red; |
|
1653 |
} |
|
1654 |
||
1655 |
// check if the signal is unaffected. |
|
1656 |
if (ssd->stop) { |
|
1657 |
make_red: |
|
1658 |
// turn red |
|
2951 | 1659 |
if ((bit & m2) == 0) continue; |
0 | 1660 |
} else { |
1661 |
// turn green |
|
2951 | 1662 |
if ((bit & m2) != 0) continue; |
0 | 1663 |
} |
1664 |
||
1813
a4b17980b9e4
(svn r2317) - Fix: [ 1193048 ] Pre-signal stays red when there is only a single exit signal (dinno)
Darkvater
parents:
1796
diff
changeset
|
1665 |
/* Update signals on the other side of this exit-combo signal; it changed. */ |
3521
c5dda2dbd977
(svn r4377) -Add and make use of a function that finds out whether a signal is an entry or and exit signal to a presignal block (as combos act as both)
celestar
parents:
3520
diff
changeset
|
1666 |
if (IsPresignalExit(tile)) { |
0 | 1667 |
if (ssd->cur_stack != NUM_SSD_STACK) { |
1668 |
ssd->next_tile[ssd->cur_stack] = tile; |
|
1669 |
ssd->next_dir[ssd->cur_stack] = _dir_from_track[ssd->bit[i]]; |
|
1670 |
ssd->cur_stack++; |
|
1671 |
} else { |
|
1813
a4b17980b9e4
(svn r2317) - Fix: [ 1193048 ] Pre-signal stays red when there is only a single exit signal (dinno)
Darkvater
parents:
1796
diff
changeset
|
1672 |
printf("NUM_SSD_STACK too small\n"); /// @todo WTF is this??? |
0 | 1673 |
} |
1674 |
} |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1675 |
|
0 | 1676 |
// it changed, so toggle it |
2049
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2020
diff
changeset
|
1677 |
_m[tile].m2 = m2 ^ bit; |
0 | 1678 |
MarkTileDirtyByTile(tile); |
1679 |
} |
|
1680 |
} |
|
1681 |
||
1682 |
||
3172
1605cb59ccd9
(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
|
1683 |
bool UpdateSignalsOnSegment(TileIndex tile, DiagDirection direction) |
0 | 1684 |
{ |
1685 |
SetSignalsData ssd; |
|
1686 |
int result = -1; |
|
1687 |
||
1688 |
ssd.cur_stack = 0; |
|
1689 |
||
2951 | 1690 |
for (;;) { |
0 | 1691 |
// go through one segment and update all signals pointing into that segment. |
2916
8f1aa489701f
(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
|
1692 |
ssd.cur = ssd.presignal_exits = ssd.presignal_exits_free = 0; |
0 | 1693 |
ssd.has_presignal = false; |
1694 |
||
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
149
diff
changeset
|
1695 |
FollowTrack(tile, 0xC000 | TRANSPORT_RAIL, direction, (TPFEnumProc*)SetSignalsEnumProc, SetSignalsAfterProc, &ssd); |
0 | 1696 |
ChangeSignalStates(&ssd); |
1697 |
||
1698 |
// remember the result only for the first iteration. |
|
3900
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3884
diff
changeset
|
1699 |
if (result < 0) { |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3884
diff
changeset
|
1700 |
// stay in depot while segment is occupied or while all presignal exits are blocked |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3884
diff
changeset
|
1701 |
result = ssd.stop || (ssd.presignal_exits > 0 && ssd.presignal_exits_free == 0); |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3884
diff
changeset
|
1702 |
} |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1703 |
|
0 | 1704 |
// if any exit signals were changed, we need to keep going to modify the stuff behind those. |
2639 | 1705 |
if (ssd.cur_stack == 0) break; |
0 | 1706 |
|
1707 |
// one or more exit signals were changed, so we need to update another segment too. |
|
1708 |
tile = ssd.next_tile[--ssd.cur_stack]; |
|
1709 |
direction = ssd.next_dir[ssd.cur_stack]; |
|
1710 |
} |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1711 |
|
3017
915fae59d5e0
(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
|
1712 |
return result != 0; |
0 | 1713 |
} |
1714 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1963
diff
changeset
|
1715 |
void SetSignalsOnBothDir(TileIndex tile, byte track) |
0 | 1716 |
{ |
3172
1605cb59ccd9
(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
|
1717 |
static const DiagDirection _search_dir_1[] = { |
1605cb59ccd9
(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
|
1718 |
DIAGDIR_NE, DIAGDIR_SE, DIAGDIR_NE, DIAGDIR_SE, DIAGDIR_SW, DIAGDIR_SE |
1605cb59ccd9
(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
|
1719 |
}; |
1605cb59ccd9
(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
|
1720 |
static const DiagDirection _search_dir_2[] = { |
1605cb59ccd9
(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
|
1721 |
DIAGDIR_SW, DIAGDIR_NW, DIAGDIR_NW, DIAGDIR_SW, DIAGDIR_NW, DIAGDIR_NE |
1605cb59ccd9
(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
|
1722 |
}; |
0 | 1723 |
|
1724 |
UpdateSignalsOnSegment(tile, _search_dir_1[track]); |
|
1725 |
UpdateSignalsOnSegment(tile, _search_dir_2[track]); |
|
1726 |
} |
|
1727 |
||
2537 | 1728 |
static uint GetSlopeZ_Track(const TileInfo* ti) |
0 | 1729 |
{ |
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3575
diff
changeset
|
1730 |
Slope tileh = ti->tileh; |
0 | 1731 |
uint z = ti->z; |
2951 | 1732 |
|
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3575
diff
changeset
|
1733 |
if (tileh == SLOPE_FLAT) return z; |
3792
2eb8388731bf
(svn r4788) - Codechange: RAILTYPE_{NORMAL,ELECTRIC,...} and RAIL_TYPE_{NORMAL,SIGNAL,...} have nearly the same name, rename RAIL_TYPE_* to RAIL_TILE_* of extra clarity
rubidium
parents:
3778
diff
changeset
|
1734 |
if (GetRailTileType(ti->tile) == RAIL_TILE_DEPOT_WAYPOINT) { |
3645
86af43f87885
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3638
diff
changeset
|
1735 |
return z + TILE_HEIGHT; |
3286
3250f1488eb2
(svn r4000) Rewrite GetSlope{Tileh,Z}_{Road,Track} in a less confusing way
tron
parents:
3284
diff
changeset
|
1736 |
} else { |
3250f1488eb2
(svn r4000) Rewrite GetSlope{Tileh,Z}_{Road,Track} in a less confusing way
tron
parents:
3284
diff
changeset
|
1737 |
uint f = GetRailFoundation(ti->tileh, GetTrackBits(ti->tile)); |
3250f1488eb2
(svn r4000) Rewrite GetSlope{Tileh,Z}_{Road,Track} in a less confusing way
tron
parents:
3284
diff
changeset
|
1738 |
|
3250f1488eb2
(svn r4000) Rewrite GetSlope{Tileh,Z}_{Road,Track} in a less confusing way
tron
parents:
3284
diff
changeset
|
1739 |
if (f != 0) { |
3645
86af43f87885
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3638
diff
changeset
|
1740 |
if (f < 15) return z + TILE_HEIGHT; // leveled foundation |
3286
3250f1488eb2
(svn r4000) Rewrite GetSlope{Tileh,Z}_{Road,Track} in a less confusing way
tron
parents:
3284
diff
changeset
|
1741 |
tileh = _inclined_tileh[f - 15]; // inclined foundation |
0 | 1742 |
} |
3286
3250f1488eb2
(svn r4000) Rewrite GetSlope{Tileh,Z}_{Road,Track} in a less confusing way
tron
parents:
3284
diff
changeset
|
1743 |
return z + GetPartialZ(ti->x & 0xF, ti->y & 0xF, tileh); |
0 | 1744 |
} |
1745 |
} |
|
1746 |
||
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3575
diff
changeset
|
1747 |
static Slope GetSlopeTileh_Track(TileIndex tile, Slope tileh) |
39 | 1748 |
{ |
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3575
diff
changeset
|
1749 |
if (tileh == SLOPE_FLAT) return SLOPE_FLAT; |
3792
2eb8388731bf
(svn r4788) - Codechange: RAILTYPE_{NORMAL,ELECTRIC,...} and RAIL_TYPE_{NORMAL,SIGNAL,...} have nearly the same name, rename RAIL_TYPE_* to RAIL_TILE_* of extra clarity
rubidium
parents:
3778
diff
changeset
|
1750 |
if (GetRailTileType(tile) == RAIL_TILE_DEPOT_WAYPOINT) { |
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3575
diff
changeset
|
1751 |
return SLOPE_FLAT; |
3286
3250f1488eb2
(svn r4000) Rewrite GetSlope{Tileh,Z}_{Road,Track} in a less confusing way
tron
parents:
3284
diff
changeset
|
1752 |
} else { |
3418
a592d40a4d04
(svn r4242) Pass TileIndex and slope to GetSlopeTileh_*() instead of TileInfo
tron
parents:
3379
diff
changeset
|
1753 |
uint f = GetRailFoundation(tileh, GetTrackBits(tile)); |
3286
3250f1488eb2
(svn r4000) Rewrite GetSlope{Tileh,Z}_{Road,Track} in a less confusing way
tron
parents:
3284
diff
changeset
|
1754 |
|
3418
a592d40a4d04
(svn r4242) Pass TileIndex and slope to GetSlopeTileh_*() instead of TileInfo
tron
parents:
3379
diff
changeset
|
1755 |
if (f == 0) return tileh; |
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3575
diff
changeset
|
1756 |
if (f < 15) return SLOPE_FLAT; // leveled foundation |
3286
3250f1488eb2
(svn r4000) Rewrite GetSlope{Tileh,Z}_{Road,Track} in a less confusing way
tron
parents:
3284
diff
changeset
|
1757 |
return _inclined_tileh[f - 15]; // inclined foundation |
39 | 1758 |
} |
1759 |
} |
|
1760 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1963
diff
changeset
|
1761 |
static void GetAcceptedCargo_Track(TileIndex tile, AcceptedCargo ac) |
0 | 1762 |
{ |
1763 |
/* not used */ |
|
1764 |
} |
|
1765 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1963
diff
changeset
|
1766 |
static void AnimateTile_Track(TileIndex tile) |
0 | 1767 |
{ |
1768 |
/* not used */ |
|
1769 |
} |
|
1770 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1963
diff
changeset
|
1771 |
static void TileLoop_Track(TileIndex tile) |
0 | 1772 |
{ |
3523
168ee460418b
(svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents:
3522
diff
changeset
|
1773 |
RailGroundType old_ground = GetRailGroundType(tile); |
168ee460418b
(svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents:
3522
diff
changeset
|
1774 |
RailGroundType new_ground = old_ground; |
3562
c308f20e8388
(svn r4440) - Fix: Yoyo-effect of rail in desert/snow introduced by r4379. When a special groundtype below the track is encountered in the tileloop, always return even if groundtype hasn't changed.
Darkvater
parents:
3549
diff
changeset
|
1775 |
bool quick_return = false; |
0 | 1776 |
|
2631
13daba67f217
(svn r3173) Use the trinary operator and switch to improve readability
tron
parents:
2626
diff
changeset
|
1777 |
switch (_opt.landscape) { |
13daba67f217
(svn r3173) Use the trinary operator and switch to improve readability
tron
parents:
2626
diff
changeset
|
1778 |
case LT_HILLY: |
3562
c308f20e8388
(svn r4440) - Fix: Yoyo-effect of rail in desert/snow introduced by r4379. When a special groundtype below the track is encountered in the tileloop, always return even if groundtype hasn't changed.
Darkvater
parents:
3549
diff
changeset
|
1779 |
if (GetTileZ(tile) > _opt.snow_line) { |
c308f20e8388
(svn r4440) - Fix: Yoyo-effect of rail in desert/snow introduced by r4379. When a special groundtype below the track is encountered in the tileloop, always return even if groundtype hasn't changed.
Darkvater
parents:
3549
diff
changeset
|
1780 |
new_ground = RAIL_GROUND_ICE_DESERT; |
c308f20e8388
(svn r4440) - Fix: Yoyo-effect of rail in desert/snow introduced by r4379. When a special groundtype below the track is encountered in the tileloop, always return even if groundtype hasn't changed.
Darkvater
parents:
3549
diff
changeset
|
1781 |
quick_return = true; |
c308f20e8388
(svn r4440) - Fix: Yoyo-effect of rail in desert/snow introduced by r4379. When a special groundtype below the track is encountered in the tileloop, always return even if groundtype hasn't changed.
Darkvater
parents:
3549
diff
changeset
|
1782 |
} |
2631
13daba67f217
(svn r3173) Use the trinary operator and switch to improve readability
tron
parents:
2626
diff
changeset
|
1783 |
break; |
0 | 1784 |
|
2631
13daba67f217
(svn r3173) Use the trinary operator and switch to improve readability
tron
parents:
2626
diff
changeset
|
1785 |
case LT_DESERT: |
3562
c308f20e8388
(svn r4440) - Fix: Yoyo-effect of rail in desert/snow introduced by r4379. When a special groundtype below the track is encountered in the tileloop, always return even if groundtype hasn't changed.
Darkvater
parents:
3549
diff
changeset
|
1786 |
if (GetTropicZone(tile) == TROPICZONE_DESERT) { |
c308f20e8388
(svn r4440) - Fix: Yoyo-effect of rail in desert/snow introduced by r4379. When a special groundtype below the track is encountered in the tileloop, always return even if groundtype hasn't changed.
Darkvater
parents:
3549
diff
changeset
|
1787 |
new_ground = RAIL_GROUND_ICE_DESERT; |
c308f20e8388
(svn r4440) - Fix: Yoyo-effect of rail in desert/snow introduced by r4379. When a special groundtype below the track is encountered in the tileloop, always return even if groundtype hasn't changed.
Darkvater
parents:
3549
diff
changeset
|
1788 |
quick_return = true; |
c308f20e8388
(svn r4440) - Fix: Yoyo-effect of rail in desert/snow introduced by r4379. When a special groundtype below the track is encountered in the tileloop, always return even if groundtype hasn't changed.
Darkvater
parents:
3549
diff
changeset
|
1789 |
} |
3523
168ee460418b
(svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents:
3522
diff
changeset
|
1790 |
break; |
168ee460418b
(svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents:
3522
diff
changeset
|
1791 |
} |
168ee460418b
(svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents:
3522
diff
changeset
|
1792 |
|
168ee460418b
(svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents:
3522
diff
changeset
|
1793 |
if (new_ground != old_ground) { |
168ee460418b
(svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents:
3522
diff
changeset
|
1794 |
SetRailGroundType(tile, new_ground); |
168ee460418b
(svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents:
3522
diff
changeset
|
1795 |
MarkTileDirtyByTile(tile); |
0 | 1796 |
} |
1797 |
||
3562
c308f20e8388
(svn r4440) - Fix: Yoyo-effect of rail in desert/snow introduced by r4379. When a special groundtype below the track is encountered in the tileloop, always return even if groundtype hasn't changed.
Darkvater
parents:
3549
diff
changeset
|
1798 |
if (quick_return) return; |
c308f20e8388
(svn r4440) - Fix: Yoyo-effect of rail in desert/snow introduced by r4379. When a special groundtype below the track is encountered in the tileloop, always return even if groundtype hasn't changed.
Darkvater
parents:
3549
diff
changeset
|
1799 |
|
0 | 1800 |
// Don't continue tile loop for depots |
3792
2eb8388731bf
(svn r4788) - Codechange: RAILTYPE_{NORMAL,ELECTRIC,...} and RAIL_TYPE_{NORMAL,SIGNAL,...} have nearly the same name, rename RAIL_TYPE_* to RAIL_TILE_* of extra clarity
rubidium
parents:
3778
diff
changeset
|
1801 |
if (GetRailTileType(tile) == RAIL_TILE_DEPOT_WAYPOINT) return; |
0 | 1802 |
|
3523
168ee460418b
(svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents:
3522
diff
changeset
|
1803 |
new_ground = RAIL_GROUND_GRASS; |
0 | 1804 |
|
3523
168ee460418b
(svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents:
3522
diff
changeset
|
1805 |
if (old_ground != RAIL_GROUND_BARREN) { /* wait until bottom is green */ |
0 | 1806 |
/* determine direction of fence */ |
3267
591027d10884
(svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents:
3265
diff
changeset
|
1807 |
TrackBits rail = GetTrackBits(tile); |
0 | 1808 |
|
2839
665d7c92448b
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1809 |
switch (rail) { |
665d7c92448b
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1810 |
case TRACK_BIT_UPPER: new_ground = RAIL_GROUND_FENCE_HORIZ1; break; |
665d7c92448b
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1811 |
case TRACK_BIT_LOWER: new_ground = RAIL_GROUND_FENCE_HORIZ2; break; |
665d7c92448b
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1812 |
case TRACK_BIT_LEFT: new_ground = RAIL_GROUND_FENCE_VERT1; break; |
665d7c92448b
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1813 |
case TRACK_BIT_RIGHT: new_ground = RAIL_GROUND_FENCE_VERT2; break; |
0 | 1814 |
|
2839
665d7c92448b
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1815 |
default: { |
665d7c92448b
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1816 |
PlayerID owner = GetTileOwner(tile); |
0 | 1817 |
|
2839
665d7c92448b
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1818 |
if (rail == (TRACK_BIT_LOWER | TRACK_BIT_RIGHT) || ( |
3258
94a915e7485f
(svn r3946) Add short hand names for common track combinations
tron
parents:
3254
diff
changeset
|
1819 |
(rail & TRACK_BIT_3WAY_NW) == 0 && |
3102
fde95020fc8e
(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
|
1820 |
(rail & TRACK_BIT_X) |
2839
665d7c92448b
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1821 |
)) { |
665d7c92448b
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1822 |
TileIndex n = tile + TileDiffXY(0, -1); |
3524
be2b44204623
(svn r4380) -Codechange: Make use of GetTrackBits where appropriate
celestar
parents:
3523
diff
changeset
|
1823 |
TrackBits nrail = GetTrackBits(n); |
0 | 1824 |
|
2839
665d7c92448b
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1825 |
if (!IsTileType(n, MP_RAILWAY) || |
665d7c92448b
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1826 |
!IsTileOwner(n, owner) || |
3524
be2b44204623
(svn r4380) -Codechange: Make use of GetTrackBits where appropriate
celestar
parents:
3523
diff
changeset
|
1827 |
nrail == TRACK_BIT_UPPER || |
be2b44204623
(svn r4380) -Codechange: Make use of GetTrackBits where appropriate
celestar
parents:
3523
diff
changeset
|
1828 |
nrail == TRACK_BIT_LEFT) { |
2839
665d7c92448b
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1829 |
new_ground = RAIL_GROUND_FENCE_NW; |
665d7c92448b
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1830 |
} |
665d7c92448b
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1831 |
} |
665d7c92448b
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1832 |
|
665d7c92448b
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1833 |
if (rail == (TRACK_BIT_UPPER | TRACK_BIT_LEFT) || ( |
3258
94a915e7485f
(svn r3946) Add short hand names for common track combinations
tron
parents:
3254
diff
changeset
|
1834 |
(rail & TRACK_BIT_3WAY_SE) == 0 && |
3102
fde95020fc8e
(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
665d7c92448b
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1836 |
)) { |
665d7c92448b
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1837 |
TileIndex n = tile + TileDiffXY(0, 1); |
3524
be2b44204623
(svn r4380) -Codechange: Make use of GetTrackBits where appropriate
celestar
parents:
3523
diff
changeset
|
1838 |
TrackBits nrail = GetTrackBits(n); |
2839
665d7c92448b
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1839 |
|
665d7c92448b
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1840 |
if (!IsTileType(n, MP_RAILWAY) || |
665d7c92448b
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1841 |
!IsTileOwner(n, owner) || |
3524
be2b44204623
(svn r4380) -Codechange: Make use of GetTrackBits where appropriate
celestar
parents:
3523
diff
changeset
|
1842 |
nrail == TRACK_BIT_LOWER || |
be2b44204623
(svn r4380) -Codechange: Make use of GetTrackBits where appropriate
celestar
parents:
3523
diff
changeset
|
1843 |
nrail == TRACK_BIT_RIGHT) { |
2839
665d7c92448b
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1844 |
new_ground = (new_ground == RAIL_GROUND_FENCE_NW) ? |
665d7c92448b
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1845 |
RAIL_GROUND_FENCE_SENW : RAIL_GROUND_FENCE_SE; |
665d7c92448b
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1846 |
} |
665d7c92448b
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1847 |
} |
665d7c92448b
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1848 |
|
665d7c92448b
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1849 |
if (rail == (TRACK_BIT_LOWER | TRACK_BIT_LEFT) || ( |
3258
94a915e7485f
(svn r3946) Add short hand names for common track combinations
tron
parents:
3254
diff
changeset
|
1850 |
(rail & TRACK_BIT_3WAY_NE) == 0 && |
3102
fde95020fc8e
(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
|
1851 |
(rail & TRACK_BIT_Y) |
2839
665d7c92448b
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1852 |
)) { |
665d7c92448b
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1853 |
TileIndex n = tile + TileDiffXY(-1, 0); |
3524
be2b44204623
(svn r4380) -Codechange: Make use of GetTrackBits where appropriate
celestar
parents:
3523
diff
changeset
|
1854 |
TrackBits nrail = GetTrackBits(n); |
2839
665d7c92448b
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1855 |
|
665d7c92448b
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1856 |
if (!IsTileType(n, MP_RAILWAY) || |
665d7c92448b
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1857 |
!IsTileOwner(n, owner) || |
3524
be2b44204623
(svn r4380) -Codechange: Make use of GetTrackBits where appropriate
celestar
parents:
3523
diff
changeset
|
1858 |
nrail == TRACK_BIT_UPPER || |
be2b44204623
(svn r4380) -Codechange: Make use of GetTrackBits where appropriate
celestar
parents:
3523
diff
changeset
|
1859 |
nrail == TRACK_BIT_RIGHT) { |
2839
665d7c92448b
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1860 |
new_ground = RAIL_GROUND_FENCE_NE; |
665d7c92448b
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1861 |
} |
665d7c92448b
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1862 |
} |
665d7c92448b
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1863 |
|
665d7c92448b
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1864 |
if (rail == (TRACK_BIT_UPPER | TRACK_BIT_RIGHT) || ( |
3265 | 1865 |
(rail & TRACK_BIT_3WAY_SW) == 0 && |
3102
fde95020fc8e
(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
|
1866 |
(rail & TRACK_BIT_Y) |
2839
665d7c92448b
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1867 |
)) { |
665d7c92448b
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1868 |
TileIndex n = tile + TileDiffXY(1, 0); |
3524
be2b44204623
(svn r4380) -Codechange: Make use of GetTrackBits where appropriate
celestar
parents:
3523
diff
changeset
|
1869 |
TrackBits nrail = GetTrackBits(n); |
2839
665d7c92448b
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1870 |
|
665d7c92448b
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1871 |
if (!IsTileType(n, MP_RAILWAY) || |
665d7c92448b
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1872 |
!IsTileOwner(n, owner) || |
3524
be2b44204623
(svn r4380) -Codechange: Make use of GetTrackBits where appropriate
celestar
parents:
3523
diff
changeset
|
1873 |
nrail == TRACK_BIT_LOWER || |
be2b44204623
(svn r4380) -Codechange: Make use of GetTrackBits where appropriate
celestar
parents:
3523
diff
changeset
|
1874 |
nrail == TRACK_BIT_LEFT) { |
2839
665d7c92448b
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1875 |
new_ground = (new_ground == RAIL_GROUND_FENCE_NE) ? |
665d7c92448b
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1876 |
RAIL_GROUND_FENCE_NESW : RAIL_GROUND_FENCE_SW; |
665d7c92448b
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1877 |
} |
665d7c92448b
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1878 |
} |
665d7c92448b
(svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents:
2821
diff
changeset
|
1879 |
break; |
0 | 1880 |
} |
1881 |
} |
|
1882 |
} |
|
1883 |
||
2667
78b3c154afa4
(svn r3209) In TileLoop_Track(), use names based on function rather than their place in the map array.
peter1138
parents:
2645
diff
changeset
|
1884 |
if (old_ground != new_ground) { |
3523
168ee460418b
(svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents:
3522
diff
changeset
|
1885 |
SetRailGroundType(tile, new_ground); |
0 | 1886 |
MarkTileDirtyByTile(tile); |
1887 |
} |
|
1888 |
} |
|
1889 |
||
1890 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1963
diff
changeset
|
1891 |
static uint32 GetTileTrackStatus_Track(TileIndex tile, TransportType mode) |
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1963
diff
changeset
|
1892 |
{ |
3267
591027d10884
(svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents:
3265
diff
changeset
|
1893 |
byte a; |
817
4f9377b7fd2b
(svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents:
679
diff
changeset
|
1894 |
uint16 b; |
0 | 1895 |
|
2639 | 1896 |
if (mode != TRANSPORT_RAIL) return 0; |
0 | 1897 |
|
3792
2eb8388731bf
(svn r4788) - Codechange: RAILTYPE_{NORMAL,ELECTRIC,...} and RAIL_TYPE_{NORMAL,SIGNAL,...} have nearly the same name, rename RAIL_TYPE_* to RAIL_TILE_* of extra clarity
rubidium
parents:
3778
diff
changeset
|
1898 |
if (GetRailTileType(tile) != RAIL_TILE_DEPOT_WAYPOINT) { |
3267
591027d10884
(svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents:
3265
diff
changeset
|
1899 |
TrackBits rails = GetTrackBits(tile); |
591027d10884
(svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents:
3265
diff
changeset
|
1900 |
uint32 ret = rails * 0x101; |
591027d10884
(svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents:
3265
diff
changeset
|
1901 |
|
3792
2eb8388731bf
(svn r4788) - Codechange: RAILTYPE_{NORMAL,ELECTRIC,...} and RAIL_TYPE_{NORMAL,SIGNAL,...} have nearly the same name, rename RAIL_TYPE_* to RAIL_TILE_* of extra clarity
rubidium
parents:
3778
diff
changeset
|
1902 |
if (GetRailTileType(tile) != RAIL_TILE_SIGNALS) { |
3267
591027d10884
(svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents:
3265
diff
changeset
|
1903 |
if (rails == TRACK_BIT_CROSS) ret |= 0x40; |
0 | 1904 |
} else { |
1905 |
/* has_signals */ |
|
1906 |
||
2049
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2020
diff
changeset
|
1907 |
a = _m[tile].m3; |
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2020
diff
changeset
|
1908 |
b = _m[tile].m2; |
0 | 1909 |
|
1910 |
b &= a; |
|
1911 |
||
22 | 1912 |
/* When signals are not present (in neither |
1913 |
* direction), we pretend them to be green. (So if |
|
1914 |
* signals are only one way, the other way will |
|
1915 |
* implicitely become `red' */ |
|
2549 | 1916 |
if ((a & 0xC0) == 0) b |= 0xC0; |
1917 |
if ((a & 0x30) == 0) b |= 0x30; |
|
0 | 1918 |
|
2639 | 1919 |
if ((b & 0x80) == 0) ret |= 0x10070000; |
1920 |
if ((b & 0x40) == 0) ret |= 0x07100000; |
|
1921 |
if ((b & 0x20) == 0) ret |= 0x20080000; |
|
1922 |
if ((b & 0x10) == 0) ret |= 0x08200000; |
|
0 | 1923 |
} |
3267
591027d10884
(svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents:
3265
diff
changeset
|
1924 |
return ret; |
591027d10884
(svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents:
3265
diff
changeset
|
1925 |
} else { |
3269
95e7bffcb3c5
(svn r3981) More work for the rail accessing functions and enums
tron
parents:
3267
diff
changeset
|
1926 |
if (GetRailTileSubtype(tile) == RAIL_SUBTYPE_DEPOT) { |
3270
7531dde127ea
(svn r3982) Fix last commit. I got confused by some strange test, which did nothing
tron
parents:
3269
diff
changeset
|
1927 |
return (DiagDirToAxis(GetRailDepotDirection(tile)) == AXIS_X ? TRACK_BIT_X : TRACK_BIT_Y) * 0x101; |
3269
95e7bffcb3c5
(svn r3981) More work for the rail accessing functions and enums
tron
parents:
3267
diff
changeset
|
1928 |
} else { |
3267
591027d10884
(svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents:
3265
diff
changeset
|
1929 |
return GetRailWaypointBits(tile) * 0x101; |
591027d10884
(svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents:
3265
diff
changeset
|
1930 |
} |
591027d10884
(svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents:
3265
diff
changeset
|
1931 |
} |
0 | 1932 |
} |
1933 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1963
diff
changeset
|
1934 |
static void ClickTile_Track(TileIndex tile) |
0 | 1935 |
{ |
2548
97ada3bd2702
(svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents:
2544
diff
changeset
|
1936 |
if (IsTileDepotType(tile, TRANSPORT_RAIL)) { |
0 | 1937 |
ShowTrainDepotWindow(tile); |
2668
54d9f9d4dca3
(svn r3210) -Codechange: use IsRailWaypoint where possible (instead of magicnumbers)
truelight
parents:
2667
diff
changeset
|
1938 |
} else if (IsRailWaypoint(tile)) { |
1542
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1536
diff
changeset
|
1939 |
ShowRenameWaypointWindow(GetWaypointByTile(tile)); |
2548
97ada3bd2702
(svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents:
2544
diff
changeset
|
1940 |
} |
0 | 1941 |
} |
1942 |
||
1590
4e39d1da10c7
(svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron
parents:
1555
diff
changeset
|
1943 |
static void GetTileDesc_Track(TileIndex tile, TileDesc *td) |
0 | 1944 |
{ |
1901
fb05044cf5c3
(svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents:
1891
diff
changeset
|
1945 |
td->owner = GetTileOwner(tile); |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1928
diff
changeset
|
1946 |
switch (GetRailTileType(tile)) { |
3792
2eb8388731bf
(svn r4788) - Codechange: RAILTYPE_{NORMAL,ELECTRIC,...} and RAIL_TYPE_{NORMAL,SIGNAL,...} have nearly the same name, rename RAIL_TYPE_* to RAIL_TILE_* of extra clarity
rubidium
parents:
3778
diff
changeset
|
1947 |
case RAIL_TILE_NORMAL: |
0 | 1948 |
td->str = STR_1021_RAILROAD_TRACK; |
1590
4e39d1da10c7
(svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron
parents:
1555
diff
changeset
|
1949 |
break; |
4e39d1da10c7
(svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron
parents:
1555
diff
changeset
|
1950 |
|
3792
2eb8388731bf
(svn r4788) - Codechange: RAILTYPE_{NORMAL,ELECTRIC,...} and RAIL_TYPE_{NORMAL,SIGNAL,...} have nearly the same name, rename RAIL_TYPE_* to RAIL_TILE_* of extra clarity
rubidium
parents:
3778
diff
changeset
|
1951 |
case RAIL_TILE_SIGNALS: { |
2916
8f1aa489701f
(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
|
1952 |
const StringID signal_type[] = { |
1590
4e39d1da10c7
(svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron
parents:
1555
diff
changeset
|
1953 |
STR_RAILROAD_TRACK_WITH_NORMAL_SIGNALS, |
4e39d1da10c7
(svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron
parents:
1555
diff
changeset
|
1954 |
STR_RAILROAD_TRACK_WITH_PRESIGNALS, |
4e39d1da10c7
(svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron
parents:
1555
diff
changeset
|
1955 |
STR_RAILROAD_TRACK_WITH_EXITSIGNALS, |
2916
8f1aa489701f
(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
|
1956 |
STR_RAILROAD_TRACK_WITH_COMBOSIGNALS |
1590
4e39d1da10c7
(svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron
parents:
1555
diff
changeset
|
1957 |
}; |
4e39d1da10c7
(svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron
parents:
1555
diff
changeset
|
1958 |
|
3238
a100405fe221
(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
|
1959 |
td->str = signal_type[GetSignalType(tile)]; |
1590
4e39d1da10c7
(svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron
parents:
1555
diff
changeset
|
1960 |
break; |
0 | 1961 |
} |
1590
4e39d1da10c7
(svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron
parents:
1555
diff
changeset
|
1962 |
|
3792
2eb8388731bf
(svn r4788) - Codechange: RAILTYPE_{NORMAL,ELECTRIC,...} and RAIL_TYPE_{NORMAL,SIGNAL,...} have nearly the same name, rename RAIL_TYPE_* to RAIL_TILE_* of extra clarity
rubidium
parents:
3778
diff
changeset
|
1963 |
case RAIL_TILE_DEPOT_WAYPOINT: |
1590
4e39d1da10c7
(svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron
parents:
1555
diff
changeset
|
1964 |
default: |
3269
95e7bffcb3c5
(svn r3981) More work for the rail accessing functions and enums
tron
parents:
3267
diff
changeset
|
1965 |
td->str = (GetRailTileSubtype(tile) == RAIL_SUBTYPE_DEPOT) ? |
1590
4e39d1da10c7
(svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron
parents:
1555
diff
changeset
|
1966 |
STR_1023_RAILROAD_TRAIN_DEPOT : STR_LANDINFO_WAYPOINT; |
4e39d1da10c7
(svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron
parents:
1555
diff
changeset
|
1967 |
break; |
0 | 1968 |
} |
1969 |
} |
|
1970 |
||
2436
177cb6a8339f
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2425
diff
changeset
|
1971 |
static void ChangeTileOwner_Track(TileIndex tile, PlayerID old_player, PlayerID new_player) |
0 | 1972 |
{ |
1901
fb05044cf5c3
(svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents:
1891
diff
changeset
|
1973 |
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
|
1974 |
|
2502 | 1975 |
if (new_player != OWNER_SPECTATOR) { |
1902 | 1976 |
SetTileOwner(tile, new_player); |
0 | 1977 |
} else { |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3486
diff
changeset
|
1978 |
DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); |
0 | 1979 |
} |
1980 |
} |
|
1981 |
||
1982 |
static const byte _fractcoords_behind[4] = { 0x8F, 0x8, 0x80, 0xF8 }; |
|
1983 |
static const byte _fractcoords_enter[4] = { 0x8A, 0x48, 0x84, 0xA8 }; |
|
1922
797081e56d13
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1903
diff
changeset
|
1984 |
static const byte _deltacoord_leaveoffset[8] = { |
797081e56d13
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1903
diff
changeset
|
1985 |
-1, 0, 1, 0, /* x */ |
797081e56d13
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1903
diff
changeset
|
1986 |
0, 1, 0, -1 /* y */ |
797081e56d13
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1903
diff
changeset
|
1987 |
}; |
0 | 1988 |
|
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1963
diff
changeset
|
1989 |
static uint32 VehicleEnter_Track(Vehicle *v, TileIndex tile, int x, int y) |
0 | 1990 |
{ |
1991 |
byte fract_coord; |
|
1922
797081e56d13
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1903
diff
changeset
|
1992 |
byte fract_coord_leave; |
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3154
diff
changeset
|
1993 |
DiagDirection dir; |
1922
797081e56d13
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1903
diff
changeset
|
1994 |
int length; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1995 |
|
0 | 1996 |
// this routine applies only to trains in depot tiles |
2639 | 1997 |
if (v->type != VEH_Train || !IsTileDepotType(tile, TRANSPORT_RAIL)) return 0; |
0 | 1998 |
|
1999 |
/* depot direction */ |
|
3185 | 2000 |
dir = GetRailDepotDirection(tile); |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
2001 |
|
1922
797081e56d13
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1903
diff
changeset
|
2002 |
/* calculate the point where the following wagon should be activated */ |
797081e56d13
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1903
diff
changeset
|
2003 |
/* this depends on the length of the current vehicle */ |
797081e56d13
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1903
diff
changeset
|
2004 |
length = v->u.rail.cached_veh_length; |
797081e56d13
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1903
diff
changeset
|
2005 |
|
797081e56d13
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1903
diff
changeset
|
2006 |
fract_coord_leave = |
797081e56d13
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1903
diff
changeset
|
2007 |
((_fractcoords_enter[dir] & 0x0F) + // x |
797081e56d13
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1903
diff
changeset
|
2008 |
(length + 1) * _deltacoord_leaveoffset[dir]) + |
797081e56d13
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1903
diff
changeset
|
2009 |
(((_fractcoords_enter[dir] >> 4) + // y |
797081e56d13
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1903
diff
changeset
|
2010 |
((length + 1) * _deltacoord_leaveoffset[dir+4])) << 4); |
797081e56d13
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1903
diff
changeset
|
2011 |
|
0 | 2012 |
fract_coord = (x & 0xF) + ((y & 0xF) << 4); |
1922
797081e56d13
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1903
diff
changeset
|
2013 |
|
0 | 2014 |
if (_fractcoords_behind[dir] == fract_coord) { |
2015 |
/* make sure a train is not entering the tile from behind */ |
|
2016 |
return 8; |
|
2017 |
} else if (_fractcoords_enter[dir] == fract_coord) { |
|
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3154
diff
changeset
|
2018 |
if (DiagDirToDir(ReverseDiagDir(dir)) == v->direction) { |
0 | 2019 |
/* enter the depot */ |
2020 |
v->u.rail.track = 0x80, |
|
2021 |
v->vehstatus |= VS_HIDDEN; /* hide it */ |
|
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3154
diff
changeset
|
2022 |
v->direction = ReverseDir(v->direction); |
0 | 2023 |
if (v->next == NULL) |
2024 |
TrainEnterDepot(v, tile); |
|
2025 |
v->tile = tile; |
|
2026 |
InvalidateWindow(WC_VEHICLE_DEPOT, tile); |
|
2027 |
return 4; |
|
2028 |
} |
|
1922
797081e56d13
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1903
diff
changeset
|
2029 |
} else if (fract_coord_leave == fract_coord) { |
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3154
diff
changeset
|
2030 |
if (DiagDirToDir(dir) == v->direction) { |
0 | 2031 |
/* leave the depot? */ |
2951 | 2032 |
if ((v = v->next) != NULL) { |
0 | 2033 |
v->vehstatus &= ~VS_HIDDEN; |
3483
612a0ab8b7d2
(svn r4332) Turn a table lookup into a ternary operator
tron
parents:
3435
diff
changeset
|
2034 |
v->u.rail.track = (DiagDirToAxis(dir) == AXIS_X ? 1 : 2); |
0 | 2035 |
} |
2036 |
} |
|
2037 |
} |
|
2038 |
||
2039 |
return 0; |
|
2040 |
} |
|
2041 |
||
2042 |
||
2043 |
const TileTypeProcs _tile_type_rail_procs = { |
|
2044 |
DrawTile_Track, /* draw_tile_proc */ |
|
2045 |
GetSlopeZ_Track, /* get_slope_z_proc */ |
|
2046 |
ClearTile_Track, /* clear_tile_proc */ |
|
2047 |
GetAcceptedCargo_Track, /* get_accepted_cargo_proc */ |
|
2048 |
GetTileDesc_Track, /* get_tile_desc_proc */ |
|
2049 |
GetTileTrackStatus_Track, /* get_tile_track_status_proc */ |
|
2050 |
ClickTile_Track, /* click_tile_proc */ |
|
2051 |
AnimateTile_Track, /* animate_tile_proc */ |
|
2052 |
TileLoop_Track, /* tile_loop_clear */ |
|
2053 |
ChangeTileOwner_Track, /* change_tile_owner_clear */ |
|
2054 |
NULL, /* get_produced_cargo_proc */ |
|
2055 |
VehicleEnter_Track, /* vehicle_enter_tile_proc */ |
|
39 | 2056 |
GetSlopeTileh_Track, /* get_slope_tileh_proc */ |
0 | 2057 |
}; |