author | tron |
Sat, 04 Jun 2005 11:56:32 +0000 | |
changeset 1901 | fb05044cf5c3 |
parent 1891 | 92a3b0aa0946 |
child 1902 | 5d653da1abb7 |
permissions | -rw-r--r-- |
0 | 1 |
#include "stdafx.h" |
1891
92a3b0aa0946
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1785
diff
changeset
|
2 |
#include "openttd.h" |
507
8aa8100b0b22
(svn r815) Include strings.h only in the files which need it.
tron
parents:
497
diff
changeset
|
3 |
#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:
541
diff
changeset
|
4 |
#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:
1095
diff
changeset
|
5 |
#include "tile.h" |
0 | 6 |
#include "vehicle.h" |
7 |
#include "viewport.h" |
|
8 |
#include "command.h" |
|
9 |
#include "player.h" |
|
10 |
#include "town.h" |
|
11 |
#include "gfx.h" |
|
1247 | 12 |
#include "npf.h" |
337
66647f97e7c0
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
241
diff
changeset
|
13 |
#include "sound.h" |
1313
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1281
diff
changeset
|
14 |
#include "depot.h" |
0 | 15 |
|
22 | 16 |
/* When true, GetTrackStatus for roads will treat roads under reconstruction |
17 |
* as normal roads instead of impassable. This is used when detecting whether |
|
18 |
* a road can be removed. This is of course ugly, but I don't know a better |
|
19 |
* solution just like that... */ |
|
0 | 20 |
static bool _road_special_gettrackstatus; |
21 |
||
22 |
void RoadVehEnterDepot(Vehicle *v); |
|
23 |
||
24 |
||
1095 | 25 |
static bool HasTileRoadAt(uint tile, int i) |
0 | 26 |
{ |
27 |
int mask; |
|
28 |
byte b; |
|
29 |
||
1214
33e07bbb7779
(svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents:
1209
diff
changeset
|
30 |
switch (GetTileType(tile)) { |
0 | 31 |
case MP_STREET: |
32 |
b = _map5[tile]; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
33 |
|
0 | 34 |
if ((b & 0xF0) == 0) { |
35 |
} else if ((b & 0xF0) == 0x10) { |
|
36 |
b = (b&8)?5:10; |
|
37 |
} else if ((b & 0xF0) == 0x20) { |
|
38 |
return (~b & 3) == i; |
|
39 |
} else |
|
40 |
return false; |
|
41 |
break; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
42 |
|
0 | 43 |
case MP_STATION: |
44 |
b = _map5[tile]; |
|
45 |
if (!IS_BYTE_INSIDE(b, 0x43, 0x43+8)) |
|
46 |
return false; |
|
47 |
return ((~(b - 0x43) & 3) == i); |
|
48 |
||
49 |
case MP_TUNNELBRIDGE: |
|
50 |
mask = GetRoadBitsByTile(tile); |
|
51 |
b = 10; if (mask & 1) break; |
|
52 |
b = 5; if (mask & 2) break; |
|
53 |
return false; |
|
54 |
||
55 |
default: |
|
56 |
return false; |
|
57 |
} |
|
58 |
||
59 |
return HASBIT(b, i); |
|
60 |
} |
|
61 |
||
62 |
static bool CheckAllowRemoveRoad(uint tile, uint br, bool *edge_road) |
|
63 |
{ |
|
64 |
int blocks; |
|
65 |
byte owner; |
|
66 |
uint n; |
|
67 |
*edge_road = true; |
|
68 |
||
69 |
if (_game_mode == GM_EDITOR) |
|
70 |
return true; |
|
71 |
||
72 |
blocks = GetRoadBitsByTile(tile); |
|
73 |
if (blocks == 0) |
|
74 |
return true; |
|
75 |
||
76 |
// Only do the special processing for actual players. |
|
77 |
if (_current_player >= MAX_PLAYERS) |
|
78 |
return true; |
|
79 |
||
80 |
// A railway crossing has the road owner in the map3_lo byte. |
|
1035
0a170deb6e33
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1005
diff
changeset
|
81 |
if (IsTileType(tile, MP_STREET) && (_map5[tile] & 0xF0) == 0x10) { |
0 | 82 |
owner = _map3_lo[tile]; |
83 |
} else { |
|
1901
fb05044cf5c3
(svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents:
1891
diff
changeset
|
84 |
owner = GetTileOwner(tile); |
0 | 85 |
} |
86 |
// Only do the special processing if the road is owned |
|
87 |
// by a town |
|
88 |
if (owner != OWNER_TOWN) { |
|
89 |
return owner == OWNER_NONE || CheckOwnership(owner); |
|
90 |
} |
|
91 |
||
92 |
if (_cheats.magic_bulldozer.value) |
|
93 |
return true; |
|
94 |
||
95 |
// Get a bitmask of which neighbouring roads has a tile |
|
96 |
n = 0; |
|
97 |
if (blocks&0x25 && HasTileRoadAt(TILE_ADDXY(tile,-1, 0), 1)) n |= 8; |
|
98 |
if (blocks&0x2A && HasTileRoadAt(TILE_ADDXY(tile, 0, 1), 0)) n |= 4; |
|
99 |
if (blocks&0x19 && HasTileRoadAt(TILE_ADDXY(tile, 1, 0), 3)) n |= 2; |
|
100 |
if (blocks&0x16 && HasTileRoadAt(TILE_ADDXY(tile, 0,-1), 2)) n |= 1; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
101 |
|
0 | 102 |
// If 0 or 1 bits are set in n, or if no bits that match the bits to remove, |
103 |
// then allow it |
|
104 |
if ((n & (n-1)) != 0 && (n & br) != 0) { |
|
105 |
Town *t; |
|
106 |
*edge_road = false; |
|
107 |
// you can remove all kind of roads with extra dynamite |
|
108 |
if (_patches.extra_dynamite) |
|
109 |
return true; |
|
110 |
||
1638
aae181b00846
(svn r2142) - Fix: Game no longer crashes when you want to remove a piece of road under a bridge that belongs to the town. TODO: railcrossings store owner somewhere else, put it into _map_owner[]!
Darkvater
parents:
1398
diff
changeset
|
111 |
t = ClosestTownFromTile(tile, _patches.dist_local_authority); |
aae181b00846
(svn r2142) - Fix: Game no longer crashes when you want to remove a piece of road under a bridge that belongs to the town. TODO: railcrossings store owner somewhere else, put it into _map_owner[]!
Darkvater
parents:
1398
diff
changeset
|
112 |
|
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
113 |
SetDParam(0, t->index); |
0 | 114 |
_error_message = STR_2009_LOCAL_AUTHORITY_REFUSES; |
115 |
return false; |
|
116 |
} |
|
117 |
||
118 |
return true; |
|
119 |
} |
|
120 |
||
121 |
uint GetRoadBitsByTile(TileIndex tile) |
|
122 |
{ |
|
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
149
diff
changeset
|
123 |
uint32 r = GetTileTrackStatus(tile, TRANSPORT_ROAD); |
0 | 124 |
return (byte)(r | (r >> 8)); |
125 |
} |
|
126 |
||
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
127 |
/** Delete a piece of road. |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
128 |
* @param x,y tile coordinates for road construction |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
129 |
* @param p1 road piece flags |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
130 |
* @param p2 unused |
0 | 131 |
*/ |
132 |
int32 CmdRemoveRoad(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
133 |
{ |
|
1638
aae181b00846
(svn r2142) - Fix: Game no longer crashes when you want to remove a piece of road under a bridge that belongs to the town. TODO: railcrossings store owner somewhere else, put it into _map_owner[]!
Darkvater
parents:
1398
diff
changeset
|
134 |
// cost for removing inner/edge -roads |
aae181b00846
(svn r2142) - Fix: Game no longer crashes when you want to remove a piece of road under a bridge that belongs to the town. TODO: railcrossings store owner somewhere else, put it into _map_owner[]!
Darkvater
parents:
1398
diff
changeset
|
135 |
static const uint16 road_remove_cost[2] = {50, 18}; |
aae181b00846
(svn r2142) - Fix: Game no longer crashes when you want to remove a piece of road under a bridge that belongs to the town. TODO: railcrossings store owner somewhere else, put it into _map_owner[]!
Darkvater
parents:
1398
diff
changeset
|
136 |
|
0 | 137 |
TileInfo ti; |
138 |
int32 cost; |
|
1638
aae181b00846
(svn r2142) - Fix: Game no longer crashes when you want to remove a piece of road under a bridge that belongs to the town. TODO: railcrossings store owner somewhere else, put it into _map_owner[]!
Darkvater
parents:
1398
diff
changeset
|
139 |
TileIndex tile; |
aae181b00846
(svn r2142) - Fix: Game no longer crashes when you want to remove a piece of road under a bridge that belongs to the town. TODO: railcrossings store owner somewhere else, put it into _map_owner[]!
Darkvater
parents:
1398
diff
changeset
|
140 |
byte owner; |
0 | 141 |
Town *t; |
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
142 |
/* true if the roadpiece was always removeable, |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
143 |
* false if it was a center piece. Affects town ratings drop */ |
0 | 144 |
bool edge_road; |
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
145 |
byte pieces = (byte)p1; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
146 |
|
0 | 147 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
148 |
||
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
149 |
/* Road pieces are max 4 bitset values (NE, NW, SE, SW) */ |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
150 |
if (pieces >> 4) return CMD_ERROR; |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
151 |
|
0 | 152 |
FindLandscapeHeight(&ti, x, y); |
153 |
tile = ti.tile; |
|
1638
aae181b00846
(svn r2142) - Fix: Game no longer crashes when you want to remove a piece of road under a bridge that belongs to the town. TODO: railcrossings store owner somewhere else, put it into _map_owner[]!
Darkvater
parents:
1398
diff
changeset
|
154 |
|
aae181b00846
(svn r2142) - Fix: Game no longer crashes when you want to remove a piece of road under a bridge that belongs to the town. TODO: railcrossings store owner somewhere else, put it into _map_owner[]!
Darkvater
parents:
1398
diff
changeset
|
155 |
// owner for railraod crossing is stored somewhere else |
aae181b00846
(svn r2142) - Fix: Game no longer crashes when you want to remove a piece of road under a bridge that belongs to the town. TODO: railcrossings store owner somewhere else, put it into _map_owner[]!
Darkvater
parents:
1398
diff
changeset
|
156 |
// XXX - Fix this so for a given tiletype the owner of the type is in the same variable |
aae181b00846
(svn r2142) - Fix: Game no longer crashes when you want to remove a piece of road under a bridge that belongs to the town. TODO: railcrossings store owner somewhere else, put it into _map_owner[]!
Darkvater
parents:
1398
diff
changeset
|
157 |
if (IsTileType(tile, MP_STREET) && (_map5[tile] & 0xF0) == 0x10) { |
aae181b00846
(svn r2142) - Fix: Game no longer crashes when you want to remove a piece of road under a bridge that belongs to the town. TODO: railcrossings store owner somewhere else, put it into _map_owner[]!
Darkvater
parents:
1398
diff
changeset
|
158 |
owner = _map3_lo[tile]; |
aae181b00846
(svn r2142) - Fix: Game no longer crashes when you want to remove a piece of road under a bridge that belongs to the town. TODO: railcrossings store owner somewhere else, put it into _map_owner[]!
Darkvater
parents:
1398
diff
changeset
|
159 |
} else |
1901
fb05044cf5c3
(svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents:
1891
diff
changeset
|
160 |
owner = GetTileOwner(tile); |
1638
aae181b00846
(svn r2142) - Fix: Game no longer crashes when you want to remove a piece of road under a bridge that belongs to the town. TODO: railcrossings store owner somewhere else, put it into _map_owner[]!
Darkvater
parents:
1398
diff
changeset
|
161 |
|
aae181b00846
(svn r2142) - Fix: Game no longer crashes when you want to remove a piece of road under a bridge that belongs to the town. TODO: railcrossings store owner somewhere else, put it into _map_owner[]!
Darkvater
parents:
1398
diff
changeset
|
162 |
if (owner == OWNER_TOWN && _game_mode != GM_EDITOR) { |
aae181b00846
(svn r2142) - Fix: Game no longer crashes when you want to remove a piece of road under a bridge that belongs to the town. TODO: railcrossings store owner somewhere else, put it into _map_owner[]!
Darkvater
parents:
1398
diff
changeset
|
163 |
if (IsTileType(tile, MP_TUNNELBRIDGE)) { // index of town is not saved for bridge (no space) |
aae181b00846
(svn r2142) - Fix: Game no longer crashes when you want to remove a piece of road under a bridge that belongs to the town. TODO: railcrossings store owner somewhere else, put it into _map_owner[]!
Darkvater
parents:
1398
diff
changeset
|
164 |
t = ClosestTownFromTile(tile, _patches.dist_local_authority); |
aae181b00846
(svn r2142) - Fix: Game no longer crashes when you want to remove a piece of road under a bridge that belongs to the town. TODO: railcrossings store owner somewhere else, put it into _map_owner[]!
Darkvater
parents:
1398
diff
changeset
|
165 |
} else |
aae181b00846
(svn r2142) - Fix: Game no longer crashes when you want to remove a piece of road under a bridge that belongs to the town. TODO: railcrossings store owner somewhere else, put it into _map_owner[]!
Darkvater
parents:
1398
diff
changeset
|
166 |
t = GetTown(_map2[tile]); |
aae181b00846
(svn r2142) - Fix: Game no longer crashes when you want to remove a piece of road under a bridge that belongs to the town. TODO: railcrossings store owner somewhere else, put it into _map_owner[]!
Darkvater
parents:
1398
diff
changeset
|
167 |
} else |
1280
b6925875de49
(svn r1784) -Fix: removed ClosestTownFromTile where possible, or replaced it
truelight
parents:
1264
diff
changeset
|
168 |
t = NULL; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
169 |
|
0 | 170 |
// allow deleting road under bridge |
171 |
if (ti.type != MP_TUNNELBRIDGE && !EnsureNoVehicle(tile)) |
|
172 |
return CMD_ERROR; |
|
173 |
||
174 |
{ |
|
175 |
bool b; |
|
176 |
_road_special_gettrackstatus = true; |
|
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
177 |
b = CheckAllowRemoveRoad(tile, pieces, &edge_road); |
0 | 178 |
_road_special_gettrackstatus = false; |
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
179 |
if (!b) return CMD_ERROR; |
0 | 180 |
} |
181 |
||
182 |
if (ti.type == MP_TUNNELBRIDGE) { |
|
1041
be151b7bc909
(svn r1542) Rename TileHeight to TilePixelHeight, because this is what it actually returns
tron
parents:
1035
diff
changeset
|
183 |
if (!EnsureNoVehicleZ(tile, TilePixelHeight(tile))) |
0 | 184 |
return CMD_ERROR; |
185 |
||
186 |
if ((ti.map5 & 0xE9) == 0xE8) { |
|
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
187 |
if (pieces & 10) goto return_error; |
0 | 188 |
} else if ((ti.map5 & 0xE9) == 0xE9) { |
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
189 |
if (pieces & 5) goto return_error; |
0 | 190 |
} else |
191 |
goto return_error; |
|
192 |
||
193 |
cost = _price.remove_road * 2; |
|
194 |
||
195 |
if (flags & DC_EXEC) { |
|
1638
aae181b00846
(svn r2142) - Fix: Game no longer crashes when you want to remove a piece of road under a bridge that belongs to the town. TODO: railcrossings store owner somewhere else, put it into _map_owner[]!
Darkvater
parents:
1398
diff
changeset
|
196 |
ChangeTownRating(t, -road_remove_cost[(byte)edge_road], RATING_ROAD_MINIMUM); |
0 | 197 |
_map5[tile] = ti.map5 & 0xC7; |
198 |
_map_owner[tile] = OWNER_NONE; |
|
199 |
MarkTileDirtyByTile(tile); |
|
200 |
} |
|
201 |
return cost; |
|
202 |
} else if (ti.type == MP_STREET) { |
|
1638
aae181b00846
(svn r2142) - Fix: Game no longer crashes when you want to remove a piece of road under a bridge that belongs to the town. TODO: railcrossings store owner somewhere else, put it into _map_owner[]!
Darkvater
parents:
1398
diff
changeset
|
203 |
// check if you're allowed to remove the street owned by a town |
aae181b00846
(svn r2142) - Fix: Game no longer crashes when you want to remove a piece of road under a bridge that belongs to the town. TODO: railcrossings store owner somewhere else, put it into _map_owner[]!
Darkvater
parents:
1398
diff
changeset
|
204 |
// removal allowance depends on difficulty setting |
aae181b00846
(svn r2142) - Fix: Game no longer crashes when you want to remove a piece of road under a bridge that belongs to the town. TODO: railcrossings store owner somewhere else, put it into _map_owner[]!
Darkvater
parents:
1398
diff
changeset
|
205 |
if (!CheckforTownRating(tile, flags, t, ROAD_REMOVE)) return CMD_ERROR; |
aae181b00846
(svn r2142) - Fix: Game no longer crashes when you want to remove a piece of road under a bridge that belongs to the town. TODO: railcrossings store owner somewhere else, put it into _map_owner[]!
Darkvater
parents:
1398
diff
changeset
|
206 |
|
aae181b00846
(svn r2142) - Fix: Game no longer crashes when you want to remove a piece of road under a bridge that belongs to the town. TODO: railcrossings store owner somewhere else, put it into _map_owner[]!
Darkvater
parents:
1398
diff
changeset
|
207 |
// XXX - change cascading ifs to switch when doing rewrite |
aae181b00846
(svn r2142) - Fix: Game no longer crashes when you want to remove a piece of road under a bridge that belongs to the town. TODO: railcrossings store owner somewhere else, put it into _map_owner[]!
Darkvater
parents:
1398
diff
changeset
|
208 |
if ((ti.map5 & 0xF0) == 0) { // normal road |
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
209 |
byte c = pieces, t2; |
0 | 210 |
|
211 |
if (ti.tileh != 0 && (ti.map5 == 5 || ti.map5 == 10)) { |
|
212 |
c |= (c & 0xC) >> 2; |
|
213 |
c |= (c & 0x3) << 2; |
|
214 |
} |
|
215 |
||
216 |
// limit the bits to delete to the existing bits. |
|
217 |
if ((c &= ti.map5) == 0) goto return_error; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
218 |
|
0 | 219 |
// calculate the cost |
220 |
t2 = c; |
|
221 |
cost = 0; |
|
222 |
do { |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
223 |
if (t2&1) cost += _price.remove_road; |
0 | 224 |
} while(t2>>=1); |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
225 |
|
0 | 226 |
if (flags & DC_EXEC) { |
1638
aae181b00846
(svn r2142) - Fix: Game no longer crashes when you want to remove a piece of road under a bridge that belongs to the town. TODO: railcrossings store owner somewhere else, put it into _map_owner[]!
Darkvater
parents:
1398
diff
changeset
|
227 |
ChangeTownRating(t, -road_remove_cost[(byte)edge_road], RATING_ROAD_MINIMUM); |
0 | 228 |
|
229 |
_map5[tile] ^= c; |
|
230 |
if ((_map5[tile]&0xF) == 0) |
|
231 |
DoClearSquare(tile); |
|
232 |
else |
|
233 |
MarkTileDirtyByTile(tile); |
|
234 |
||
235 |
} |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
236 |
return cost; |
1638
aae181b00846
(svn r2142) - Fix: Game no longer crashes when you want to remove a piece of road under a bridge that belongs to the town. TODO: railcrossings store owner somewhere else, put it into _map_owner[]!
Darkvater
parents:
1398
diff
changeset
|
237 |
} else if ((ti.map5 & 0xE0) == 0) { // railroad crossing |
0 | 238 |
byte c; |
239 |
||
240 |
if (!(ti.map5 & 8)) { |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
241 |
c = 2; |
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
242 |
if (pieces & 5) goto return_error; |
0 | 243 |
} else { |
244 |
c = 1; |
|
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
245 |
if (pieces & 10) goto return_error; |
0 | 246 |
} |
247 |
||
248 |
cost = _price.remove_road * 2; |
|
249 |
if (flags & DC_EXEC) { |
|
1638
aae181b00846
(svn r2142) - Fix: Game no longer crashes when you want to remove a piece of road under a bridge that belongs to the town. TODO: railcrossings store owner somewhere else, put it into _map_owner[]!
Darkvater
parents:
1398
diff
changeset
|
250 |
ChangeTownRating(t, -road_remove_cost[(byte)edge_road], RATING_ROAD_MINIMUM); |
aae181b00846
(svn r2142) - Fix: Game no longer crashes when you want to remove a piece of road under a bridge that belongs to the town. TODO: railcrossings store owner somewhere else, put it into _map_owner[]!
Darkvater
parents:
1398
diff
changeset
|
251 |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
252 |
ModifyTile(tile, |
0 | 253 |
MP_SETTYPE(MP_RAILWAY) | |
254 |
MP_MAP2_CLEAR | MP_MAP3LO | MP_MAP3HI_CLEAR | MP_MAP5, |
|
255 |
_map3_hi[tile] & 0xF, /* map3_lo */ |
|
256 |
c /* map5 */ |
|
257 |
); |
|
258 |
} |
|
259 |
return cost; |
|
260 |
} else |
|
261 |
goto return_error; |
|
262 |
||
263 |
} else { |
|
264 |
return_error:; |
|
265 |
return_cmd_error(INVALID_STRING_ID); |
|
266 |
} |
|
267 |
} |
|
268 |
||
269 |
||
270 |
enum { |
|
271 |
ROAD_NW = 1, // NW road track |
|
272 |
ROAD_SW = 2, // SW road track |
|
273 |
ROAD_SE = 4, // SE road track |
|
274 |
ROAD_NE = 8, // NE road track |
|
275 |
ROAD_ALL = (ROAD_NW | ROAD_SW | ROAD_SE | ROAD_NE) |
|
276 |
}; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
277 |
|
13
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
278 |
static const byte _valid_tileh_slopes_road[3][15] = { |
0 | 279 |
// set of normal ones |
280 |
{ |
|
281 |
ROAD_ALL, 0, 0, |
|
282 |
ROAD_SW | ROAD_NE, 0, 0, // 3, 4, 5 |
|
283 |
ROAD_NW | ROAD_SE, 0, 0, |
|
284 |
ROAD_NW | ROAD_SE, 0, 0, // 9, 10, 11 |
|
285 |
ROAD_SW | ROAD_NE, 0, 0 |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
286 |
}, |
0 | 287 |
// allowed road for an evenly raised platform |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
288 |
{ |
0 | 289 |
0, |
290 |
ROAD_SW | ROAD_NW, |
|
291 |
ROAD_SW | ROAD_SE, |
|
292 |
ROAD_NW | ROAD_SE | ROAD_SW, |
|
293 |
||
294 |
ROAD_SE | ROAD_NE, // 4 |
|
295 |
ROAD_ALL, |
|
296 |
ROAD_SW | ROAD_NE | ROAD_SE, |
|
297 |
ROAD_ALL, |
|
298 |
||
299 |
ROAD_NW | ROAD_NE, // 8 |
|
300 |
ROAD_SW | ROAD_NE | ROAD_NW, |
|
301 |
ROAD_ALL, |
|
302 |
ROAD_ALL, |
|
303 |
||
304 |
ROAD_NW | ROAD_SE | ROAD_NE, // 12 |
|
305 |
ROAD_ALL, |
|
306 |
ROAD_ALL |
|
13
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
307 |
}, |
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
308 |
// valid railway crossings on slopes |
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
309 |
{ |
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
310 |
1, 0, 0, // 0, 1, 2 |
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
311 |
0, 0, 1, // 3, 4, 5 |
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
312 |
0, 1, 0, // 6, 7, 8 |
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
313 |
0, 1, 1, // 9, 10, 11 |
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
314 |
0, 1, 1, // 12, 13, 14 |
0 | 315 |
} |
316 |
}; |
|
317 |
||
318 |
||
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
319 |
static uint32 CheckRoadSlope(int tileh, byte *pieces, byte existing) |
0 | 320 |
{ |
321 |
if (!(tileh & 0x10)) { |
|
322 |
byte road_bits = *pieces | existing; |
|
323 |
||
324 |
// no special foundation |
|
325 |
if ((~_valid_tileh_slopes_road[0][tileh] & road_bits) == 0) { |
|
326 |
// force that all bits are set when we have slopes |
|
327 |
if (tileh != 0) *pieces |= _valid_tileh_slopes_road[0][tileh]; |
|
328 |
return 0; // no extra cost |
|
329 |
} |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
330 |
|
0 | 331 |
// foundation is used. Whole tile is leveled up |
332 |
if ((~_valid_tileh_slopes_road[1][tileh] & road_bits) == 0) { |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
333 |
return existing ? 0 : _price.terraform; |
0 | 334 |
} |
335 |
||
336 |
// partly leveled up tile, only if there's no road on that tile |
|
337 |
if ( !existing && (tileh == 1 || tileh == 2 || tileh == 4 || tileh == 8) ) { |
|
338 |
// force full pieces. |
|
339 |
*pieces |= (*pieces & 0xC) >> 2; |
|
340 |
*pieces |= (*pieces & 0x3) << 2; |
|
72
24bdf837198c
(svn r73) -Fix: Wrong building of road-slopes for a future AI/Town
darkvater
parents:
39
diff
changeset
|
341 |
return (*pieces == (ROAD_NE|ROAD_SW) || *pieces == (ROAD_SE|ROAD_NW)) ? _price.terraform : CMD_ERROR; |
0 | 342 |
} |
343 |
} |
|
344 |
return CMD_ERROR; |
|
345 |
} |
|
346 |
||
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
347 |
/** Build a piece of road. |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
348 |
* @param x,y tile coordinates for road construction |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
349 |
* @param p1 road piece flags |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
350 |
* @param p2 the town that is building the road (0 if not applicable) |
0 | 351 |
*/ |
352 |
int32 CmdBuildRoad(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
353 |
{ |
|
354 |
TileInfo ti; |
|
355 |
int32 cost; |
|
356 |
byte pieces = (byte)p1, existing = 0; |
|
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
357 |
TileIndex tile; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
358 |
|
0 | 359 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
360 |
||
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
361 |
/* Road pieces are max 4 bitset values (NE, NW, SE, SW) and town can only be non-zero |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
362 |
* if a non-player is building the road */ |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
363 |
if ((pieces >> 4) || (_current_player < MAX_PLAYERS && p2 != 0) || !IsTownIndex(p2)) return CMD_ERROR; |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
364 |
|
0 | 365 |
FindLandscapeHeight(&ti, x, y); |
366 |
tile = ti.tile; |
|
367 |
||
368 |
// allow building road under bridge |
|
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
369 |
if (ti.type != MP_TUNNELBRIDGE && !EnsureNoVehicle(tile)) return CMD_ERROR; |
0 | 370 |
|
371 |
if (ti.type == MP_STREET) { |
|
372 |
if (!(ti.map5 & 0xF0)) { |
|
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
373 |
if ( (pieces & (byte)(ti.map5)) == (pieces)) |
0 | 374 |
return_cmd_error(STR_1007_ALREADY_BUILT); |
375 |
existing = ti.map5; |
|
376 |
} else { |
|
377 |
if (!(ti.map5 & 0xE0) && pieces != ((ti.map5 & 8) ? 5 : 10)) |
|
378 |
return_cmd_error(STR_1007_ALREADY_BUILT); |
|
379 |
goto do_clear; |
|
380 |
} |
|
381 |
} else if (ti.type == MP_RAILWAY) { |
|
382 |
byte m5; |
|
383 |
||
13
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
384 |
if (ti.tileh & 0x10) // very steep tile |
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
385 |
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); |
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
386 |
|
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
387 |
if(!_valid_tileh_slopes_road[2][ti.tileh]) // prevent certain slopes |
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
388 |
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); |
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
389 |
|
0 | 390 |
if (ti.map5 == 2) { |
391 |
if (pieces & 5) goto do_clear; |
|
392 |
m5 = 0x10; |
|
393 |
} else if (ti.map5 == 1) { |
|
394 |
if (pieces & 10) goto do_clear; |
|
395 |
m5 = 0x18; |
|
396 |
} else |
|
397 |
goto do_clear; |
|
398 |
||
399 |
if (flags & DC_EXEC) { |
|
400 |
ModifyTile(tile, |
|
401 |
MP_SETTYPE(MP_STREET) | |
|
1264
280792016b02
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1247
diff
changeset
|
402 |
MP_MAP2 | MP_MAP3LO | MP_MAP3HI | MP_MAP5, |
280792016b02
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1247
diff
changeset
|
403 |
p2, |
0 | 404 |
_current_player, /* map3_lo */ |
405 |
_map3_lo[tile] & 0xF, /* map3_hi */ |
|
406 |
m5 /* map5 */ |
|
407 |
); |
|
408 |
} |
|
409 |
return _price.build_road * 2; |
|
410 |
} else if (ti.type == MP_TUNNELBRIDGE) { |
|
411 |
||
412 |
/* check for flat land */ |
|
13
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
413 |
if (ti.tileh & 0x10) // very steep tile |
0 | 414 |
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); |
415 |
||
416 |
/* is this middle part of a bridge? */ |
|
417 |
if ((ti.map5 & 0xC0) != 0xC0) |
|
418 |
goto do_clear; |
|
419 |
||
420 |
/* only allow roads pertendicular to bridge */ |
|
959
b031d88c76f3
(svn r1451) Fix some of the signed/unsigned comparison warnings
tron
parents:
926
diff
changeset
|
421 |
if ((pieces & 5U) == (ti.map5 & 0x01U)) |
0 | 422 |
goto do_clear; |
423 |
||
424 |
/* check if clear land under bridge */ |
|
425 |
if ((ti.map5 & 0xF8) == 0xE8) /* road under bridge */ |
|
426 |
return_cmd_error(STR_1007_ALREADY_BUILT); |
|
427 |
else if ((ti.map5 & 0xE0) == 0xE0) /* other transport route under bridge */ |
|
428 |
return_cmd_error(STR_1008_MUST_REMOVE_RAILROAD_TRACK); |
|
429 |
else if ((ti.map5 & 0xF8) == 0xC8) /* water under bridge */ |
|
430 |
return_cmd_error(STR_3807_CAN_T_BUILD_ON_WATER); |
|
431 |
||
432 |
/* all checked, can build road now! */ |
|
433 |
cost = _price.build_road * 2; |
|
434 |
if (flags & DC_EXEC) { |
|
435 |
ModifyTile(tile, |
|
436 |
MP_MAPOWNER_CURRENT | MP_MAP5, |
|
437 |
(ti.map5 & 0xC7) | 0x28 // map5 |
|
438 |
); |
|
439 |
} |
|
440 |
return cost; |
|
441 |
} else { |
|
442 |
do_clear:; |
|
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
443 |
if (CmdFailed(DoCommandByTile(tile, 0, 0, flags & ~DC_EXEC, CMD_LANDSCAPE_CLEAR))) |
0 | 444 |
return CMD_ERROR; |
445 |
} |
|
446 |
||
447 |
cost = CheckRoadSlope(ti.tileh, &pieces, existing); |
|
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
448 |
if (CmdFailed(cost)) return_cmd_error(STR_1800_LAND_SLOPED_IN_WRONG_DIRECTION); |
0 | 449 |
|
84
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
72
diff
changeset
|
450 |
if (cost && (!_patches.build_on_slopes || (!_patches.ainew_active && _is_ai_player))) |
0 | 451 |
return CMD_ERROR; |
452 |
||
453 |
if (!(ti.type == MP_STREET && (ti.map5 & 0xF0) == 0)) { |
|
454 |
cost += DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
|
455 |
} else { |
|
456 |
// Don't put the pieces that already exist |
|
457 |
pieces &= ~ti.map5; |
|
458 |
} |
|
459 |
||
460 |
{ |
|
461 |
byte t = pieces; |
|
462 |
while (t) { |
|
463 |
if (t & 1) cost += _price.build_road; |
|
464 |
t >>= 1; |
|
465 |
} |
|
466 |
} |
|
467 |
||
468 |
if (flags & DC_EXEC) { |
|
469 |
if (ti.type != MP_STREET) { |
|
1059
c28c6be74291
(svn r1560) Introduce SetTileType() and SetTileHeight()
tron
parents:
1041
diff
changeset
|
470 |
SetTileType(tile, MP_STREET); |
0 | 471 |
_map5[tile] = 0; |
1264
280792016b02
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1247
diff
changeset
|
472 |
_map2[tile] = p2; |
0 | 473 |
_map_owner[tile] = _current_player; |
474 |
} |
|
475 |
||
476 |
_map5[tile] |= (byte)pieces; |
|
477 |
||
478 |
MarkTileDirtyByTile(tile); |
|
479 |
} |
|
480 |
return cost; |
|
481 |
} |
|
482 |
||
483 |
int32 DoConvertStreetRail(uint tile, uint totype, bool exec) |
|
484 |
{ |
|
485 |
// not a railroad crossing? |
|
486 |
if ((_map5[tile] & 0xF0) != 0x10) return CMD_ERROR; |
|
487 |
||
488 |
// not owned by me? |
|
489 |
if (!CheckTileOwnership(tile) || !EnsureNoVehicle(tile)) return CMD_ERROR; |
|
490 |
||
491 |
// tile is already of requested type? |
|
492 |
if ( (uint)(_map3_hi[tile] & 0xF) == totype) return CMD_ERROR; |
|
493 |
||
494 |
if (exec) { |
|
495 |
// change type. |
|
496 |
_map3_hi[tile] = (_map3_hi[tile] & 0xF0) + totype; |
|
497 |
MarkTileDirtyByTile(tile); |
|
498 |
} |
|
499 |
||
500 |
return _price.build_rail >> 1; |
|
501 |
} |
|
502 |
||
503 |
||
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
504 |
/** Build a long piece of road. |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
505 |
* @param x,y end tile of drag |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
506 |
* @param p1 start tile of drag |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
507 |
* @param p2 various bitstuffed elements |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
508 |
* - p2 = (bit 0) - start tile starts in the 2nd half of tile (p2 & 1) |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
509 |
* - p2 = (bit 1) - end tile starts in the 2nd half of tile (p2 & 2) |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
510 |
* - p2 = (bit 2) - direction: 0 = along x-axis, 1 = along y-axis (p2 & 4) |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
511 |
*/ |
0 | 512 |
int32 CmdBuildLongRoad(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
513 |
{ |
|
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
514 |
TileIndex start_tile, end_tile, tile; |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
515 |
int32 cost, ret; |
0 | 516 |
|
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:
817
diff
changeset
|
517 |
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:
817
diff
changeset
|
518 |
|
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
519 |
if (p1 > MapSize()) return CMD_ERROR; |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
520 |
|
0 | 521 |
start_tile = p1; |
522 |
end_tile = TILE_FROM_XY(x, y); |
|
523 |
||
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
524 |
/* Only drag in X or Y direction dictated by the direction variable */ |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
525 |
if (!HASBIT(p2, 2) && TileY(start_tile) != TileY(end_tile)) return CMD_ERROR; // x-axis |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
526 |
if (HASBIT(p2, 2) && TileX(start_tile) != TileX(end_tile)) return CMD_ERROR; // y-axis |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
527 |
|
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
528 |
/* Swap start and ending tile, also the half-tile drag var (bit 0 and 1) */ |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
529 |
if (start_tile > end_tile || (start_tile == end_tile && HASBIT(p2, 0))) { |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
530 |
TileIndex t = start_tile; |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
531 |
start_tile = end_tile; |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
532 |
end_tile = t; |
0 | 533 |
p2 ^= IS_INT_INSIDE(p2&3, 1, 3) ? 3 : 0; |
534 |
} |
|
535 |
||
536 |
cost = 0; |
|
537 |
tile = start_tile; |
|
538 |
// Start tile is the small number. |
|
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
539 |
for (;;) { |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
540 |
uint bits = HASBIT(p2, 2) ? ROAD_SE | ROAD_NW : ROAD_SW | ROAD_NE; |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
541 |
if (tile == end_tile && !HASBIT(p2, 1)) bits &= ROAD_NW | ROAD_NE; |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
542 |
if (tile == start_tile && HASBIT(p2, 0)) bits &= ROAD_SE | ROAD_SW; |
0 | 543 |
|
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
544 |
ret = DoCommandByTile(tile, bits, 0, flags, CMD_BUILD_ROAD); |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
545 |
if (CmdFailed(ret)) { |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
546 |
if (_error_message != STR_1007_ALREADY_BUILT) return CMD_ERROR; |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
547 |
} else |
0 | 548 |
cost += ret; |
549 |
||
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
550 |
if (tile == end_tile) break; |
0 | 551 |
|
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
552 |
tile += HASBIT(p2, 2) ? TILE_XY(0, 1) : TILE_XY(1, 0); |
0 | 553 |
} |
554 |
||
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
555 |
return (cost == 0) ? CMD_ERROR : cost; |
0 | 556 |
} |
557 |
||
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
558 |
/** Remove a long piece of road. |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
559 |
* @param x,y end tile of drag |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
560 |
* @param p1 start tile of drag |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
561 |
* @param p2 various bitstuffed elements |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
562 |
* - p2 = (bit 0) - start tile starts in the 2nd half of tile (p2 & 1) |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
563 |
* - p2 = (bit 1) - end tile starts in the 2nd half of tile (p2 & 2) |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
564 |
* - p2 = (bit 2) - direction: 0 = along x-axis, 1 = along y-axis (p2 & 4) |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
565 |
*/ |
0 | 566 |
int32 CmdRemoveLongRoad(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
567 |
{ |
|
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
568 |
TileIndex start_tile, end_tile, tile; |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
569 |
int32 cost, ret; |
0 | 570 |
|
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:
817
diff
changeset
|
571 |
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:
817
diff
changeset
|
572 |
|
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
573 |
if (p1 > MapSize()) return CMD_ERROR; |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
574 |
|
0 | 575 |
start_tile = p1; |
576 |
end_tile = TILE_FROM_XY(x, y); |
|
577 |
||
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
578 |
/* Only drag in X or Y direction dictated by the direction variable */ |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
579 |
if (!HASBIT(p2, 2) && TileY(start_tile) != TileY(end_tile)) return CMD_ERROR; // x-axis |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
580 |
if (HASBIT(p2, 2) && TileX(start_tile) != TileX(end_tile)) return CMD_ERROR; // y-axis |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
581 |
|
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
582 |
/* Swap start and ending tile, also the half-tile drag var (bit 0 and 1) */ |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
583 |
if (start_tile > end_tile || (start_tile == end_tile && HASBIT(p2, 0))) { |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
584 |
TileIndex t = start_tile; |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
585 |
start_tile = end_tile; |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
586 |
end_tile = t; |
0 | 587 |
p2 ^= IS_INT_INSIDE(p2&3, 1, 3) ? 3 : 0; |
588 |
} |
|
589 |
||
590 |
cost = 0; |
|
591 |
tile = start_tile; |
|
592 |
// Start tile is the small number. |
|
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
593 |
for (;;) { |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
594 |
uint bits = HASBIT(p2, 2) ? ROAD_SE | ROAD_NW : ROAD_SW | ROAD_NE; |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
595 |
if (tile == end_tile && !HASBIT(p2, 1)) bits &= ROAD_NW | ROAD_NE; |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
596 |
if (tile == start_tile && HASBIT(p2, 0)) bits &= ROAD_SE | ROAD_SW; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
597 |
|
0 | 598 |
// try to remove the halves. |
599 |
if (bits) { |
|
600 |
ret = DoCommandByTile(tile, bits, 0, flags, CMD_REMOVE_ROAD); |
|
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
601 |
if (!CmdFailed(ret)) cost += ret; |
0 | 602 |
} |
603 |
||
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
604 |
if (tile == end_tile) break; |
0 | 605 |
|
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
606 |
tile += HASBIT(p2, 2) ? TILE_XY(0, 1) : TILE_XY(1, 0); |
0 | 607 |
} |
608 |
||
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
609 |
return (cost == 0) ? CMD_ERROR : cost; |
0 | 610 |
} |
611 |
||
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
612 |
/** Build a road depot. |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
613 |
* @param x,y tile coordinates where the depot will be built |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
614 |
* @param p1 depot direction (0 through 3), where 0 is NW, 1 is NE, etc. |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
615 |
* @param p2 unused |
0 | 616 |
*/ |
617 |
int32 CmdBuildRoadDepot(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
618 |
{ |
|
619 |
TileInfo ti; |
|
620 |
int32 cost; |
|
621 |
Depot *dep; |
|
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
622 |
TileIndex tile; |
0 | 623 |
|
624 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
625 |
||
1785
998f4b5eec29
(svn r2289) - Fix (regression): check p1 param of road-depot building instead of unused p2 (typo). Thanks peter1138.
Darkvater
parents:
1784
diff
changeset
|
626 |
if (p1 > 3) return CMD_ERROR; // check direction |
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
627 |
|
0 | 628 |
FindLandscapeHeight(&ti, x, y); |
629 |
||
630 |
tile = ti.tile; |
|
631 |
||
632 |
if (!EnsureNoVehicle(tile)) |
|
633 |
return CMD_ERROR; |
|
634 |
||
635 |
if (ti.tileh != 0) { |
|
84
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
72
diff
changeset
|
636 |
if (!_patches.build_on_slopes || (ti.tileh & 0x10 || !((0x4C >> p1) & ti.tileh) )) |
0 | 637 |
return_cmd_error(STR_0007_FLAT_LAND_REQUIRED); |
638 |
} |
|
639 |
||
640 |
cost = DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
|
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
641 |
if (CmdFailed(cost)) return CMD_ERROR; |
0 | 642 |
|
643 |
dep = AllocateDepot(); |
|
644 |
if (dep == NULL) |
|
645 |
return CMD_ERROR; |
|
646 |
||
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
647 |
if (flags & DC_EXEC) { |
0 | 648 |
if (_current_player == _local_player) |
649 |
_last_built_road_depot_tile = (TileIndex)tile; |
|
650 |
||
651 |
dep->xy = tile; |
|
652 |
dep->town_index = ClosestTownFromTile(tile, (uint)-1)->index; |
|
653 |
||
654 |
ModifyTile(tile, |
|
655 |
MP_SETTYPE(MP_STREET) | |
|
656 |
MP_MAPOWNER_CURRENT | MP_MAP5, |
|
657 |
(p1 | 0x20) /* map5 */ |
|
658 |
); |
|
659 |
||
660 |
} |
|
661 |
return cost + _price.build_road_depot; |
|
662 |
} |
|
663 |
||
664 |
static int32 RemoveRoadDepot(uint tile, uint32 flags) |
|
665 |
{ |
|
149
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
84
diff
changeset
|
666 |
if (!CheckTileOwnership(tile) && _current_player != OWNER_WATER) |
0 | 667 |
return CMD_ERROR; |
668 |
||
669 |
if (!EnsureNoVehicle(tile)) |
|
670 |
return CMD_ERROR; |
|
671 |
||
672 |
if (flags & DC_EXEC) { |
|
673 |
DoDeleteDepot(tile); |
|
674 |
} |
|
675 |
||
676 |
return _price.remove_road_depot; |
|
677 |
} |
|
678 |
||
679 |
#define M(x) (1<<(x)) |
|
680 |
||
681 |
static int32 ClearTile_Road(uint tile, byte flags) { |
|
682 |
int32 ret; |
|
683 |
byte m5 = _map5[tile]; |
|
684 |
||
685 |
if ( (m5 & 0xF0) == 0) { |
|
686 |
byte b = m5 & 0xF; |
|
687 |
||
688 |
if (! ((1 << b) & (M(1)|M(2)|M(4)|M(8))) ) { |
|
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
|
689 |
if ((!(flags & DC_AI_BUILDING) || !IsTileOwner(tile, OWNER_TOWN)) && flags & DC_AUTO) |
0 | 690 |
return_cmd_error(STR_1801_MUST_REMOVE_ROAD_FIRST); |
691 |
} |
|
692 |
return DoCommandByTile(tile, b, 0, flags, CMD_REMOVE_ROAD); |
|
693 |
} else if ( (m5 & 0xE0) == 0) { |
|
694 |
if (flags & DC_AUTO) |
|
695 |
return_cmd_error(STR_1801_MUST_REMOVE_ROAD_FIRST); |
|
696 |
||
697 |
ret = DoCommandByTile(tile, (m5&8)?5:10, 0, flags, CMD_REMOVE_ROAD); |
|
698 |
if (ret == CMD_ERROR) |
|
699 |
return CMD_ERROR; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
700 |
|
0 | 701 |
if (flags & DC_EXEC) { |
702 |
DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
703 |
} |
0 | 704 |
|
705 |
return ret; |
|
706 |
} else { |
|
707 |
if (flags & DC_AUTO) |
|
708 |
return_cmd_error(STR_2004_BUILDING_MUST_BE_DEMOLISHED); |
|
709 |
return RemoveRoadDepot(tile,flags); |
|
710 |
} |
|
711 |
} |
|
712 |
||
713 |
||
714 |
typedef struct DrawRoadTileStruct { |
|
715 |
uint16 image; |
|
716 |
byte subcoord_x; |
|
717 |
byte subcoord_y; |
|
718 |
} DrawRoadTileStruct; |
|
719 |
||
720 |
typedef struct DrawRoadSeqStruct { |
|
721 |
uint32 image; |
|
722 |
byte subcoord_x; |
|
723 |
byte subcoord_y; |
|
724 |
byte width; |
|
725 |
byte height; |
|
726 |
} DrawRoadSeqStruct; |
|
727 |
||
728 |
#include "table/road_land.h" |
|
729 |
||
730 |
||
84
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
72
diff
changeset
|
731 |
uint GetRoadFoundation(uint tileh, uint bits) { |
0 | 732 |
int i; |
733 |
// normal level sloped building |
|
734 |
if ((~_valid_tileh_slopes_road[1][tileh] & bits) == 0) |
|
735 |
return tileh; |
|
736 |
||
737 |
// inclined sloped building |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
738 |
if ( ((i=0, tileh == 1) || (i+=2, tileh == 2) || (i+=2, tileh == 4) || (i+=2, tileh == 8)) && |
0 | 739 |
((bits == (ROAD_SW | ROAD_NE)) || (i++, bits == (ROAD_NW | ROAD_SE)))) |
740 |
return i + 15; |
|
741 |
||
13
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
742 |
// rail crossing |
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
743 |
if ((bits & 0x10) && _valid_tileh_slopes_road[2][tileh]) |
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
744 |
return tileh; |
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
745 |
|
0 | 746 |
return 0; |
747 |
} |
|
748 |
||
749 |
const byte _road_sloped_sprites[14] = { |
|
750 |
0, 0, 2, 0, |
|
751 |
0, 1, 0, 0, |
|
752 |
3, 0, 0, 0, |
|
753 |
0, 0 |
|
754 |
}; |
|
755 |
||
756 |
static void DrawTile_Road(TileInfo *ti) |
|
757 |
{ |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
758 |
uint32 image; |
817
4f9377b7fd2b
(svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents:
679
diff
changeset
|
759 |
uint16 m2; |
0 | 760 |
|
761 |
if ( (ti->map5 & 0xF0) == 0) { // if it is a road the upper 4 bits are 0 |
|
762 |
const DrawRoadTileStruct *drts; |
|
763 |
||
764 |
if (ti->tileh != 0) { |
|
765 |
int f = GetRoadFoundation(ti->tileh, ti->map5 & 0xF); |
|
766 |
if (f) DrawFoundation(ti, f); |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
767 |
|
0 | 768 |
// default sloped sprites.. |
769 |
if (ti->tileh != 0) { |
|
770 |
image = _road_sloped_sprites[ti->tileh - 1] + 0x53F; |
|
771 |
} else { |
|
772 |
image = _road_tile_sprites_1[ti->map5 & 0xF]; |
|
773 |
} |
|
774 |
} else { |
|
775 |
image = _road_tile_sprites_1[ti->map5 & 0xF]; |
|
776 |
} |
|
777 |
||
1264
280792016b02
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1247
diff
changeset
|
778 |
m2 = (_map3_hi[ti->tile] & 0x70) >> 4; |
0 | 779 |
|
780 |
if (m2 == 0) image |= 0x3178000; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
781 |
|
0 | 782 |
if (_map3_hi[ti->tile] & 0x80) { |
783 |
image += 19; |
|
784 |
} else if (m2 > 1 && m2 != 6) { |
|
785 |
image -= 19; /* pavement along the road? */ |
|
786 |
} |
|
787 |
||
788 |
DrawGroundSprite(image); |
|
789 |
||
790 |
if (!(_display_opt & DO_FULL_DETAIL) || _cur_dpi->zoom == 2) |
|
791 |
return; |
|
792 |
||
793 |
if (m2 >= 6) { |
|
794 |
// roadwork |
|
795 |
DrawGroundSprite(0x586 + ((ti->map5&8)!=0 ? 0 : 1)); |
|
796 |
return; |
|
797 |
} |
|
798 |
||
1398 | 799 |
drts = _road_display_table[m2][ti->map5 & 0xF]; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
800 |
|
0 | 801 |
while ((image = drts->image) != 0) { |
802 |
int x = ti->x | drts->subcoord_x; |
|
803 |
int y = ti->y | drts->subcoord_y; |
|
804 |
byte z = ti->z; |
|
805 |
if (ti->tileh != 0) z = GetSlopeZ(x, y); |
|
806 |
AddSortableSpriteToDraw(image, x, y, 2, 2, 0x10, z); |
|
807 |
drts++; |
|
808 |
} |
|
13
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
809 |
} else if ( (ti->map5 & 0xE0) == 0) { // railroad crossing |
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
810 |
int f = GetRoadFoundation(ti->tileh, ti->map5 & 0xF); |
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
811 |
if (f) DrawFoundation(ti, f); |
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
812 |
|
0 | 813 |
image = 0x55B; |
814 |
||
815 |
if ( (ti->map5 & 8) != 0) |
|
816 |
image--; |
|
817 |
||
818 |
if ( (ti->map5 & 4) != 0) |
|
819 |
image += 2; |
|
820 |
||
821 |
if ( _map3_hi[ti->tile] & 0x80) { |
|
822 |
image += 8; |
|
823 |
} else { |
|
1264
280792016b02
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1247
diff
changeset
|
824 |
m2 = (_map3_hi[ti->tile] & 0x70) >> 4; |
0 | 825 |
if (m2 == 0) image |= 0x3178000; |
826 |
if (m2 > 1) image += 4; |
|
827 |
} |
|
828 |
||
829 |
DrawGroundSprite(image + (_map3_hi[ti->tile] & 0xF) * 12); |
|
830 |
} else { |
|
831 |
uint32 ormod; |
|
832 |
int player; |
|
833 |
const DrawRoadSeqStruct *drss; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
834 |
|
0 | 835 |
if (ti->tileh != 0) { DrawFoundation(ti, ti->tileh); } |
836 |
||
837 |
ormod = 0x315; |
|
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
|
838 |
player = GetTileOwner(ti->tile); |
0 | 839 |
if (player < MAX_PLAYERS) |
840 |
ormod = PLAYER_SPRITE_COLOR(player); |
|
841 |
||
1398 | 842 |
drss = _road_display_datas[ti->map5 & 0xF]; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
843 |
|
1398 | 844 |
DrawGroundSprite(drss++->image); |
0 | 845 |
|
1398 | 846 |
for (; drss->image != 0; drss++) { |
847 |
uint32 image = drss->image; |
|
848 |
||
0 | 849 |
if (image & 0x8000) |
850 |
image |= ormod; |
|
497
2d6d31173813
(svn r787) Invert the sense of the DO_TRANS_BUILDINGS flag to be consistent with its own name and all other DO_* flags.
tron
parents:
473
diff
changeset
|
851 |
if (_display_opt & DO_TRANS_BUILDINGS) // show transparent depots |
204
1646d7049950
(svn r205) -Fix: [1026271] Vehicle depots not transparent with transparent buildings.
darkvater
parents:
201
diff
changeset
|
852 |
image = (image & 0x3FFF) | 0x3224000; |
0 | 853 |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
854 |
AddSortableSpriteToDraw(image, ti->x | drss->subcoord_x, |
0 | 855 |
ti->y | drss->subcoord_y, drss->width, drss->height, 0x14, ti->z); |
856 |
} |
|
857 |
} |
|
858 |
} |
|
859 |
||
860 |
void DrawRoadDepotSprite(int x, int y, int image) |
|
861 |
{ |
|
862 |
uint32 ormod; |
|
863 |
const DrawRoadSeqStruct *dtss; |
|
864 |
||
865 |
ormod = PLAYER_SPRITE_COLOR(_local_player); |
|
866 |
||
1398 | 867 |
dtss = _road_display_datas[image]; |
0 | 868 |
|
869 |
x+=33; |
|
870 |
y+=17; |
|
871 |
||
1398 | 872 |
DrawSprite(dtss++->image, x, y); |
0 | 873 |
|
1398 | 874 |
for(; dtss->image != 0; dtss++) { |
0 | 875 |
Point pt = RemapCoords(dtss->subcoord_x, dtss->subcoord_y, 0); |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
876 |
|
0 | 877 |
image = dtss->image; |
878 |
if (image & 0x8000) |
|
879 |
image |= ormod; |
|
880 |
||
881 |
DrawSprite(image, x + pt.x, y + pt.y); |
|
882 |
} |
|
883 |
} |
|
884 |
||
410 | 885 |
static uint GetSlopeZ_Road(TileInfo *ti) |
0 | 886 |
{ |
887 |
uint z = ti->z; |
|
888 |
int th = ti->tileh; |
|
889 |
||
890 |
// check if it's a foundation |
|
891 |
if (ti->tileh != 0) { |
|
13
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
892 |
if ((ti->map5 & 0xE0) == 0) { /* road or crossing */ |
0 | 893 |
uint f = GetRoadFoundation(ti->tileh, ti->map5 & 0x3F); |
894 |
if (f != 0) { |
|
895 |
if (f < 15) { |
|
896 |
// leveled foundation |
|
897 |
return z + 8; |
|
898 |
} |
|
899 |
// inclined foundation |
|
900 |
th = _inclined_tileh[f - 15]; |
|
901 |
} |
|
902 |
} else if ((ti->map5 & 0xF0) == 0x20) { |
|
903 |
// depot |
|
904 |
return z + 8; |
|
905 |
} |
|
906 |
return GetPartialZ(ti->x&0xF, ti->y&0xF, th) + z; |
|
907 |
} |
|
39 | 908 |
return z; // normal Z if no slope |
909 |
} |
|
910 |
||
1095 | 911 |
static uint GetSlopeTileh_Road(TileInfo *ti) |
39 | 912 |
{ |
913 |
// check if it's a foundation |
|
914 |
if (ti->tileh != 0) { |
|
915 |
if ((ti->map5 & 0xE0) == 0) { /* road or crossing */ |
|
916 |
uint f = GetRoadFoundation(ti->tileh, ti->map5 & 0x3F); |
|
917 |
if (f != 0) { |
|
918 |
if (f < 15) { |
|
919 |
// leveled foundation |
|
920 |
return 0; |
|
921 |
} |
|
922 |
// inclined foundation |
|
923 |
return _inclined_tileh[f - 15]; |
|
924 |
} |
|
925 |
} else if ((ti->map5 & 0xF0) == 0x20) { |
|
926 |
// depot |
|
927 |
return 0; |
|
928 |
} |
|
929 |
} |
|
930 |
return ti->tileh; |
|
0 | 931 |
} |
932 |
||
473
0da86c59e3ae
(svn r724) Remove restriction that a tile can only accept 3 cargo types.
tron
parents:
410
diff
changeset
|
933 |
static void GetAcceptedCargo_Road(uint tile, AcceptedCargo ac) |
0 | 934 |
{ |
935 |
/* not used */ |
|
936 |
} |
|
937 |
||
938 |
static void AnimateTile_Road(uint tile) |
|
939 |
{ |
|
940 |
if ((_map5[tile] & 0xF0) == 0x10) { |
|
941 |
MarkTileDirtyByTile(tile); |
|
942 |
} |
|
943 |
} |
|
944 |
||
945 |
static const byte _town_road_types[5][2] = { |
|
946 |
{1,1}, |
|
947 |
{2,2}, |
|
948 |
{2,2}, |
|
949 |
{5,5}, |
|
950 |
{3,2}, |
|
951 |
}; |
|
952 |
||
953 |
static const byte _town_road_types_2[5][2] = { |
|
954 |
{1,1}, |
|
955 |
{2,2}, |
|
956 |
{3,2}, |
|
957 |
{3,2}, |
|
958 |
{3,2}, |
|
959 |
}; |
|
960 |
||
961 |
||
962 |
static void TileLoop_Road(uint tile) |
|
963 |
{ |
|
964 |
Town *t; |
|
965 |
int grp; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
966 |
|
0 | 967 |
if (_opt.landscape == LT_HILLY) { |
968 |
// Fix snow style if the road is above the snowline |
|
969 |
if ((_map3_hi[tile] & 0x80) != ((GetTileZ(tile) > _opt.snow_line) ? 0x80 : 0x00)) { |
|
970 |
_map3_hi[tile] ^= 0x80; |
|
971 |
MarkTileDirtyByTile(tile); |
|
972 |
} |
|
973 |
} else if (_opt.landscape == LT_DESERT) { |
|
974 |
// Fix desert style |
|
975 |
if (GetMapExtraBits(tile) == 1 && !(_map3_hi[tile] & 0x80)) { |
|
976 |
_map3_hi[tile] |= 0x80; |
|
977 |
MarkTileDirtyByTile(tile); |
|
978 |
} |
|
979 |
} |
|
980 |
||
981 |
if (_map5[tile] & 0xE0) |
|
982 |
return; |
|
983 |
||
1264
280792016b02
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1247
diff
changeset
|
984 |
if (((_map3_hi[tile] & 0x70) >> 4) < 6) { |
1281
1573d0e4e7a1
(svn r1785) -Fix: space-correctness in road_cmd.c, and one wrong line from last
truelight
parents:
1280
diff
changeset
|
985 |
t = ClosestTownFromTile(tile, (uint)-1); |
1280
b6925875de49
(svn r1784) -Fix: removed ClosestTownFromTile where possible, or replaced it
truelight
parents:
1264
diff
changeset
|
986 |
|
0 | 987 |
grp = 0; |
988 |
if (t != NULL) { |
|
989 |
grp = GetTownRadiusGroup(t, tile); |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
990 |
|
0 | 991 |
// Show an animation to indicate road work |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
992 |
if (t->road_build_months != 0 && |
1245
768d9bc95aaa
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1214
diff
changeset
|
993 |
!(DistanceManhattan(t->xy, tile) >= 8 && grp == 0) && |
0 | 994 |
(_map5[tile]==5 || _map5[tile]==10)) { |
995 |
if (GetTileSlope(tile, NULL) == 0 && EnsureNoVehicle(tile) && CHANCE16(1,20)) { |
|
1264
280792016b02
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1247
diff
changeset
|
996 |
_map3_hi[tile] |= ((((_map3_hi[tile] & 0x70) >> 4 ) <= 2) ? 7 : 6) << 4; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
997 |
|
541 | 998 |
SndPlayTileFx(SND_21_JACKHAMMER, tile); |
0 | 999 |
CreateEffectVehicleAbove( |
926
bd4312619522
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
889
diff
changeset
|
1000 |
TileX(tile) * 16 + 7, |
bd4312619522
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
889
diff
changeset
|
1001 |
TileY(tile) * 16 + 7, |
0 | 1002 |
0, |
1359
8ba976aed634
(svn r1863) Give the effect vehicle type enums more descriptive names and use the enum as parameter type for CreateEffectVehicle*()
tron
parents:
1327
diff
changeset
|
1003 |
EV_BULLDOZER); |
0 | 1004 |
MarkTileDirtyByTile(tile); |
1005 |
return; |
|
1006 |
} |
|
1007 |
} |
|
1008 |
} |
|
1009 |
||
1010 |
{ |
|
1011 |
const byte *p = (_opt.landscape == LT_CANDY) ? _town_road_types_2[grp] : _town_road_types[grp]; |
|
1264
280792016b02
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1247
diff
changeset
|
1012 |
byte b = (_map3_hi[tile] & 0x70) >> 4; |
0 | 1013 |
|
1014 |
if (b == p[0]) |
|
1015 |
return; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1016 |
|
0 | 1017 |
if (b == p[1]) { |
1018 |
b = p[0]; |
|
1019 |
} else if (b == 0) { |
|
1020 |
b = p[1]; |
|
1021 |
} else { |
|
1022 |
b = 0; |
|
1023 |
} |
|
1264
280792016b02
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1247
diff
changeset
|
1024 |
_map3_hi[tile] = (_map3_hi[tile] & ~0x70) | (b << 4); |
0 | 1025 |
MarkTileDirtyByTile(tile); |
1026 |
} |
|
1027 |
} else { |
|
1028 |
// Handle road work |
|
1264
280792016b02
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1247
diff
changeset
|
1029 |
//XXX undocumented |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1030 |
|
1264
280792016b02
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1247
diff
changeset
|
1031 |
byte b = _map3_hi[tile]; |
280792016b02
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1247
diff
changeset
|
1032 |
//roadworks take place only |
280792016b02
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1247
diff
changeset
|
1033 |
//keep roadworks running for 16 loops |
280792016b02
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1247
diff
changeset
|
1034 |
//lower 4 bits of map3_hi store the counter now |
280792016b02
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1247
diff
changeset
|
1035 |
if ((b & 0xF) != 0xF) { |
280792016b02
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1247
diff
changeset
|
1036 |
_map3_hi[tile] = b + 1; |
0 | 1037 |
return; |
1038 |
} |
|
1264
280792016b02
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1247
diff
changeset
|
1039 |
//roadworks finished |
280792016b02
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1247
diff
changeset
|
1040 |
_map3_hi[tile] = ((((b& 0x70) >> 4)== 6) ? 1 : 2) << 4; |
0 | 1041 |
MarkTileDirtyByTile(tile); |
1042 |
} |
|
1043 |
} |
|
1044 |
||
1045 |
void ShowRoadDepotWindow(uint tile); |
|
1046 |
||
1047 |
static void ClickTile_Road(uint tile) |
|
1048 |
{ |
|
1049 |
if ((_map5[tile] & 0xF0) == 0x20) { |
|
1050 |
ShowRoadDepotWindow(tile); |
|
1051 |
} |
|
1052 |
} |
|
1053 |
||
1054 |
static const byte _road_trackbits[16] = { |
|
1055 |
0x0, 0x0, 0x0, 0x10, 0x0, 0x2, 0x8, 0x1A, 0x0, 0x4, 0x1, 0x15, 0x20, 0x26, 0x29, 0x3F, |
|
1056 |
}; |
|
1057 |
||
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
149
diff
changeset
|
1058 |
static uint32 GetTileTrackStatus_Road(uint tile, TransportType mode) { |
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
149
diff
changeset
|
1059 |
if (mode == TRANSPORT_RAIL) { |
0 | 1060 |
if ((_map5[tile] & 0xF0) != 0x10) |
1061 |
return 0; |
|
1062 |
return _map5[tile] & 8 ? 0x101 : 0x202; |
|
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
149
diff
changeset
|
1063 |
} else if (mode == TRANSPORT_ROAD) { |
0 | 1064 |
byte b = _map5[tile]; |
1065 |
if ((b & 0xF0) == 0) { |
|
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
149
diff
changeset
|
1066 |
/* Ordinary road */ |
1264
280792016b02
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1247
diff
changeset
|
1067 |
if (!_road_special_gettrackstatus && ((_map3_hi[tile]&0x70) >> 4) >= 6) |
0 | 1068 |
return 0; |
1069 |
return _road_trackbits[b&0xF] * 0x101; |
|
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
149
diff
changeset
|
1070 |
} else if ((b&0xF0) == 0x10) { |
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
149
diff
changeset
|
1071 |
/* Crossing */ |
0 | 1072 |
uint32 r = 0x101; |
1073 |
if (b&8) r <<= 1; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1074 |
|
0 | 1075 |
if (b&4) { |
1076 |
r *= 0x10001; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1077 |
} |
0 | 1078 |
return r; |
1079 |
} |
|
1080 |
} |
|
1081 |
return 0; |
|
1082 |
} |
|
1083 |
||
1084 |
static const StringID _road_tile_strings[] = { |
|
1085 |
STR_1818_ROAD_RAIL_LEVEL_CROSSING, |
|
1086 |
STR_1817_ROAD_VEHICLE_DEPOT, |
|
1087 |
||
1088 |
STR_1814_ROAD, |
|
1089 |
STR_1814_ROAD, |
|
1090 |
STR_1814_ROAD, |
|
1091 |
STR_1815_ROAD_WITH_STREETLIGHTS, |
|
1092 |
STR_1814_ROAD, |
|
1093 |
STR_1816_TREE_LINED_ROAD, |
|
1094 |
STR_1814_ROAD, |
|
1095 |
STR_1814_ROAD, |
|
1096 |
}; |
|
1097 |
||
1098 |
static void GetTileDesc_Road(uint tile, TileDesc *td) |
|
1099 |
{ |
|
1100 |
int i = (_map5[tile] >> 4); |
|
1101 |
if (i == 0) |
|
1264
280792016b02
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1247
diff
changeset
|
1102 |
i = ((_map3_hi[tile] & 0x70) >> 4) + 3; |
0 | 1103 |
td->str = _road_tile_strings[i - 1]; |
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
|
1104 |
td->owner = GetTileOwner(tile); |
0 | 1105 |
} |
1106 |
||
1107 |
static const byte _roadveh_enter_depot_unk0[4] = { |
|
1108 |
8, 9, 0, 1 |
|
1109 |
}; |
|
1110 |
||
1111 |
static uint32 VehicleEnter_Road(Vehicle *v, uint tile, int x, int y) |
|
1112 |
{ |
|
1113 |
if ((_map5[tile] & 0xF0) == 0x10) { |
|
1114 |
if (v->type == VEH_Train && (_map5[tile] & 4) == 0) { |
|
1115 |
/* train crossing a road */ |
|
541 | 1116 |
SndPlayVehicleFx(SND_0E_LEVEL_CROSSING, v); |
0 | 1117 |
_map5[tile] |= 4; |
1118 |
MarkTileDirtyByTile(tile); |
|
1119 |
} |
|
1120 |
} else if ((_map5[tile]&0xF0) == 0x20){ |
|
1121 |
if (v->type == VEH_Road && v->u.road.frame == 11) { |
|
1122 |
if (_roadveh_enter_depot_unk0[_map5[tile]&3] == v->u.road.state) { |
|
1123 |
RoadVehEnterDepot(v); |
|
1124 |
return 4; |
|
1125 |
} |
|
1126 |
} |
|
1127 |
} |
|
1128 |
return 0; |
|
1129 |
} |
|
1130 |
||
1131 |
static void VehicleLeave_Road(Vehicle *v, uint tile, int x, int y) |
|
1132 |
{ |
|
1133 |
if ((_map5[tile] & 0xF0) == 0x10 && v->type == VEH_Train && v->next == NULL) { |
|
1134 |
_map5[tile] &= ~4; |
|
1135 |
MarkTileDirtyByTile(tile); |
|
1136 |
} |
|
1137 |
} |
|
1138 |
||
1139 |
static void ChangeTileOwner_Road(uint tile, byte old_player, byte new_player) |
|
1140 |
{ |
|
1141 |
byte b; |
|
1142 |
||
1143 |
// road/rail crossing where the road is owned by the current player? |
|
1144 |
if (old_player == _map3_lo[tile] && (_map5[tile]&0xF0) == 0x10) { |
|
1145 |
_map3_lo[tile] = (new_player == 0xFF) ? OWNER_NONE : new_player; |
|
1146 |
} |
|
1147 |
||
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
|
1148 |
if (!IsTileOwner(tile, old_player)) return; |
0 | 1149 |
|
1150 |
if (new_player != 255) { |
|
1151 |
_map_owner[tile] = new_player; |
|
1152 |
} else { |
|
1153 |
b = _map5[tile]&0xF0; |
|
1154 |
if (b == 0) { |
|
1155 |
_map_owner[tile] = OWNER_NONE; |
|
1156 |
} else if (b == 0x10) { |
|
1157 |
_map5[tile] = (_map5[tile]&8) ? 0x5 : 0xA; |
|
1158 |
_map_owner[tile] = _map3_lo[tile]; |
|
1159 |
_map3_lo[tile] = 0; |
|
1160 |
_map3_hi[tile] &= 0x80; |
|
1161 |
} else { |
|
1162 |
DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); |
|
1163 |
} |
|
1164 |
} |
|
1165 |
} |
|
1166 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1059
diff
changeset
|
1167 |
void InitializeRoad(void) |
0 | 1168 |
{ |
1169 |
_last_built_road_depot_tile = 0; |
|
1170 |
} |
|
1171 |
||
1172 |
const TileTypeProcs _tile_type_road_procs = { |
|
1173 |
DrawTile_Road, /* draw_tile_proc */ |
|
1174 |
GetSlopeZ_Road, /* get_slope_z_proc */ |
|
1175 |
ClearTile_Road, /* clear_tile_proc */ |
|
1176 |
GetAcceptedCargo_Road, /* get_accepted_cargo_proc */ |
|
1177 |
GetTileDesc_Road, /* get_tile_desc_proc */ |
|
1178 |
GetTileTrackStatus_Road, /* get_tile_track_status_proc */ |
|
1179 |
ClickTile_Road, /* click_tile_proc */ |
|
1180 |
AnimateTile_Road, /* animate_tile_proc */ |
|
1181 |
TileLoop_Road, /* tile_loop_clear */ |
|
1182 |
ChangeTileOwner_Road, /* change_tile_owner_clear */ |
|
1183 |
NULL, /* get_produced_cargo_proc */ |
|
1184 |
VehicleEnter_Road, /* vehicle_enter_tile_proc */ |
|
1185 |
VehicleLeave_Road, /* vehicle_leave_tile_proc */ |
|
39 | 1186 |
GetSlopeTileh_Road, /* get_slope_tileh_proc */ |
0 | 1187 |
}; |