author | peter1138 |
Mon, 23 Jan 2006 17:43:46 +0000 | |
changeset 2872 | 2c0da1a94364 |
parent 2865 | 97cb78a1d02c |
child 2916 | b687477adcba |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
0 | 3 |
#include "stdafx.h" |
1891
862800791170
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1785
diff
changeset
|
4 |
#include "openttd.h" |
2008
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
1986
diff
changeset
|
5 |
#include "table/sprites.h" |
507
04b5403aaf6b
(svn r815) Include strings.h only in the files which need it.
tron
parents:
497
diff
changeset
|
6 |
#include "table/strings.h" |
2163
b17b313113a0
(svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents:
2148
diff
changeset
|
7 |
#include "functions.h" |
679
04ca2cd69420
(svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
541
diff
changeset
|
8 |
#include "map.h" |
1209
2e00193652b2
(svn r1713) Split off several functions which query/set information about a single tile from map.h and put them into a seperate file tile.h
tron
parents:
1095
diff
changeset
|
9 |
#include "tile.h" |
0 | 10 |
#include "vehicle.h" |
11 |
#include "viewport.h" |
|
12 |
#include "command.h" |
|
13 |
#include "player.h" |
|
14 |
#include "town.h" |
|
15 |
#include "gfx.h" |
|
337
cbe0c766c947
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
241
diff
changeset
|
16 |
#include "sound.h" |
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1281
diff
changeset
|
17 |
#include "depot.h" |
2008
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
1986
diff
changeset
|
18 |
#include "pbs.h" |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
1986
diff
changeset
|
19 |
#include "debug.h" |
0 | 20 |
|
22 | 21 |
/* When true, GetTrackStatus for roads will treat roads under reconstruction |
22 |
* as normal roads instead of impassable. This is used when detecting whether |
|
23 |
* a road can be removed. This is of course ugly, but I don't know a better |
|
24 |
* solution just like that... */ |
|
0 | 25 |
static bool _road_special_gettrackstatus; |
26 |
||
27 |
void RoadVehEnterDepot(Vehicle *v); |
|
28 |
||
29 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
30 |
static bool HasTileRoadAt(TileIndex tile, int i) |
0 | 31 |
{ |
32 |
int mask; |
|
33 |
byte b; |
|
34 |
||
1214
8262981ac274
(svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents:
1209
diff
changeset
|
35 |
switch (GetTileType(tile)) { |
0 | 36 |
case MP_STREET: |
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2008
diff
changeset
|
37 |
b = _m[tile].m5; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
38 |
|
0 | 39 |
if ((b & 0xF0) == 0) { |
1927
1181e7652e2f
(svn r2433) - CodeChange: unmagicify all road/train crossings with IsLevelCrossing() function (peter1138)
Darkvater
parents:
1902
diff
changeset
|
40 |
} else if (IsLevelCrossing(tile)) { |
0 | 41 |
b = (b&8)?5:10; |
42 |
} else if ((b & 0xF0) == 0x20) { |
|
43 |
return (~b & 3) == i; |
|
44 |
} else |
|
45 |
return false; |
|
46 |
break; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
47 |
|
0 | 48 |
case MP_STATION: |
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2008
diff
changeset
|
49 |
b = _m[tile].m5; |
0 | 50 |
if (!IS_BYTE_INSIDE(b, 0x43, 0x43+8)) |
51 |
return false; |
|
52 |
return ((~(b - 0x43) & 3) == i); |
|
53 |
||
54 |
case MP_TUNNELBRIDGE: |
|
55 |
mask = GetRoadBitsByTile(tile); |
|
56 |
b = 10; if (mask & 1) break; |
|
57 |
b = 5; if (mask & 2) break; |
|
58 |
return false; |
|
59 |
||
60 |
default: |
|
61 |
return false; |
|
62 |
} |
|
63 |
||
64 |
return HASBIT(b, i); |
|
65 |
} |
|
66 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
67 |
static bool CheckAllowRemoveRoad(TileIndex tile, uint br, bool *edge_road) |
0 | 68 |
{ |
69 |
int blocks; |
|
70 |
byte owner; |
|
71 |
uint n; |
|
72 |
*edge_road = true; |
|
73 |
||
74 |
if (_game_mode == GM_EDITOR) |
|
75 |
return true; |
|
76 |
||
77 |
blocks = GetRoadBitsByTile(tile); |
|
78 |
if (blocks == 0) |
|
79 |
return true; |
|
80 |
||
81 |
// Only do the special processing for actual players. |
|
82 |
if (_current_player >= MAX_PLAYERS) |
|
83 |
return true; |
|
84 |
||
85 |
// A railway crossing has the road owner in the map3_lo byte. |
|
1927
1181e7652e2f
(svn r2433) - CodeChange: unmagicify all road/train crossings with IsLevelCrossing() function (peter1138)
Darkvater
parents:
1902
diff
changeset
|
86 |
if (IsTileType(tile, MP_STREET) && IsLevelCrossing(tile)) { |
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2008
diff
changeset
|
87 |
owner = _m[tile].m3; |
0 | 88 |
} else { |
1901
03bf9bf99319
(svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents:
1891
diff
changeset
|
89 |
owner = GetTileOwner(tile); |
0 | 90 |
} |
91 |
// Only do the special processing if the road is owned |
|
92 |
// by a town |
|
93 |
if (owner != OWNER_TOWN) { |
|
94 |
return owner == OWNER_NONE || CheckOwnership(owner); |
|
95 |
} |
|
96 |
||
97 |
if (_cheats.magic_bulldozer.value) |
|
98 |
return true; |
|
99 |
||
100 |
// Get a bitmask of which neighbouring roads has a tile |
|
101 |
n = 0; |
|
102 |
if (blocks&0x25 && HasTileRoadAt(TILE_ADDXY(tile,-1, 0), 1)) n |= 8; |
|
103 |
if (blocks&0x2A && HasTileRoadAt(TILE_ADDXY(tile, 0, 1), 0)) n |= 4; |
|
104 |
if (blocks&0x19 && HasTileRoadAt(TILE_ADDXY(tile, 1, 0), 3)) n |= 2; |
|
105 |
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
|
106 |
|
0 | 107 |
// If 0 or 1 bits are set in n, or if no bits that match the bits to remove, |
108 |
// then allow it |
|
109 |
if ((n & (n-1)) != 0 && (n & br) != 0) { |
|
110 |
Town *t; |
|
111 |
*edge_road = false; |
|
112 |
// you can remove all kind of roads with extra dynamite |
|
113 |
if (_patches.extra_dynamite) |
|
114 |
return true; |
|
115 |
||
1638
4779658c2d03
(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
|
116 |
t = ClosestTownFromTile(tile, _patches.dist_local_authority); |
4779658c2d03
(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
|
117 |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
118 |
SetDParam(0, t->index); |
0 | 119 |
_error_message = STR_2009_LOCAL_AUTHORITY_REFUSES; |
120 |
return false; |
|
121 |
} |
|
122 |
||
123 |
return true; |
|
124 |
} |
|
125 |
||
126 |
uint GetRoadBitsByTile(TileIndex tile) |
|
127 |
{ |
|
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
149
diff
changeset
|
128 |
uint32 r = GetTileTrackStatus(tile, TRANSPORT_ROAD); |
0 | 129 |
return (byte)(r | (r >> 8)); |
130 |
} |
|
131 |
||
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
132 |
/** Delete a piece of road. |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
133 |
* @param x,y tile coordinates for road construction |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
134 |
* @param p1 road piece flags |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
135 |
* @param p2 unused |
0 | 136 |
*/ |
137 |
int32 CmdRemoveRoad(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
138 |
{ |
|
1638
4779658c2d03
(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 |
// cost for removing inner/edge -roads |
4779658c2d03
(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 |
static const uint16 road_remove_cost[2] = {50, 18}; |
4779658c2d03
(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
|
141 |
|
0 | 142 |
TileInfo ti; |
143 |
int32 cost; |
|
1638
4779658c2d03
(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
|
144 |
TileIndex tile; |
2074
089fab08189c
(svn r2584) - Fix: Game no longer asserts when you use the remove-road tool on a town building or industry.
Darkvater
parents:
2049
diff
changeset
|
145 |
PlayerID owner; |
0 | 146 |
Town *t; |
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
147 |
/* true if the roadpiece was always removeable, |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
148 |
* false if it was a center piece. Affects town ratings drop */ |
0 | 149 |
bool edge_road; |
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
150 |
byte pieces = (byte)p1; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
151 |
|
0 | 152 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
153 |
||
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
154 |
/* Road pieces are max 4 bitset values (NE, NW, SE, SW) */ |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
155 |
if (pieces >> 4) return CMD_ERROR; |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
156 |
|
0 | 157 |
FindLandscapeHeight(&ti, x, y); |
158 |
tile = ti.tile; |
|
1638
4779658c2d03
(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 |
|
2074
089fab08189c
(svn r2584) - Fix: Game no longer asserts when you use the remove-road tool on a town building or industry.
Darkvater
parents:
2049
diff
changeset
|
160 |
if (!IsTileType(tile, MP_STREET) && !IsTileType(tile, MP_TUNNELBRIDGE)) return CMD_ERROR; |
089fab08189c
(svn r2584) - Fix: Game no longer asserts when you use the remove-road tool on a town building or industry.
Darkvater
parents:
2049
diff
changeset
|
161 |
|
089fab08189c
(svn r2584) - Fix: Game no longer asserts when you use the remove-road tool on a town building or industry.
Darkvater
parents:
2049
diff
changeset
|
162 |
// owner for railroad crossing is stored somewhere else |
1638
4779658c2d03
(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 |
// XXX - Fix this so for a given tiletype the owner of the type is in the same variable |
2074
089fab08189c
(svn r2584) - Fix: Game no longer asserts when you use the remove-road tool on a town building or industry.
Darkvater
parents:
2049
diff
changeset
|
164 |
owner = IsLevelCrossing(tile) ? _m[tile].m3 : GetTileOwner(tile); |
1638
4779658c2d03
(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 |
|
4779658c2d03
(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 |
if (owner == OWNER_TOWN && _game_mode != GM_EDITOR) { |
4779658c2d03
(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 |
if (IsTileType(tile, MP_TUNNELBRIDGE)) { // index of town is not saved for bridge (no space) |
4779658c2d03
(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
|
168 |
t = ClosestTownFromTile(tile, _patches.dist_local_authority); |
4779658c2d03
(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
|
169 |
} else |
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2008
diff
changeset
|
170 |
t = GetTown(_m[tile].m2); |
1638
4779658c2d03
(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
|
171 |
} else |
1280
33a251c30758
(svn r1784) -Fix: removed ClosestTownFromTile where possible, or replaced it
truelight
parents:
1264
diff
changeset
|
172 |
t = NULL; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
173 |
|
0 | 174 |
// allow deleting road under bridge |
175 |
if (ti.type != MP_TUNNELBRIDGE && !EnsureNoVehicle(tile)) |
|
176 |
return CMD_ERROR; |
|
177 |
||
178 |
{ |
|
179 |
bool b; |
|
180 |
_road_special_gettrackstatus = true; |
|
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
181 |
b = CheckAllowRemoveRoad(tile, pieces, &edge_road); |
0 | 182 |
_road_special_gettrackstatus = false; |
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
183 |
if (!b) return CMD_ERROR; |
0 | 184 |
} |
185 |
||
186 |
if (ti.type == MP_TUNNELBRIDGE) { |
|
1041
94db182c3614
(svn r1542) Rename TileHeight to TilePixelHeight, because this is what it actually returns
tron
parents:
1035
diff
changeset
|
187 |
if (!EnsureNoVehicleZ(tile, TilePixelHeight(tile))) |
0 | 188 |
return CMD_ERROR; |
189 |
||
190 |
if ((ti.map5 & 0xE9) == 0xE8) { |
|
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
191 |
if (pieces & 10) goto return_error; |
0 | 192 |
} else if ((ti.map5 & 0xE9) == 0xE9) { |
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
193 |
if (pieces & 5) goto return_error; |
0 | 194 |
} else |
195 |
goto return_error; |
|
196 |
||
197 |
cost = _price.remove_road * 2; |
|
198 |
||
199 |
if (flags & DC_EXEC) { |
|
1638
4779658c2d03
(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
|
200 |
ChangeTownRating(t, -road_remove_cost[(byte)edge_road], RATING_ROAD_MINIMUM); |
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2008
diff
changeset
|
201 |
_m[tile].m5 = ti.map5 & 0xC7; |
1902 | 202 |
SetTileOwner(tile, OWNER_NONE); |
0 | 203 |
MarkTileDirtyByTile(tile); |
204 |
} |
|
205 |
return cost; |
|
206 |
} else if (ti.type == MP_STREET) { |
|
1638
4779658c2d03
(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 |
// check if you're allowed to remove the street owned by a town |
4779658c2d03
(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 |
// removal allowance depends on difficulty setting |
4779658c2d03
(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
|
209 |
if (!CheckforTownRating(tile, flags, t, ROAD_REMOVE)) return CMD_ERROR; |
4779658c2d03
(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
|
210 |
|
4779658c2d03
(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
|
211 |
// XXX - change cascading ifs to switch when doing rewrite |
4779658c2d03
(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
|
212 |
if ((ti.map5 & 0xF0) == 0) { // normal road |
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
213 |
byte c = pieces, t2; |
0 | 214 |
|
215 |
if (ti.tileh != 0 && (ti.map5 == 5 || ti.map5 == 10)) { |
|
216 |
c |= (c & 0xC) >> 2; |
|
217 |
c |= (c & 0x3) << 2; |
|
218 |
} |
|
219 |
||
220 |
// limit the bits to delete to the existing bits. |
|
221 |
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
|
222 |
|
0 | 223 |
// calculate the cost |
224 |
t2 = c; |
|
225 |
cost = 0; |
|
226 |
do { |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
227 |
if (t2&1) cost += _price.remove_road; |
0 | 228 |
} while(t2>>=1); |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
229 |
|
0 | 230 |
if (flags & DC_EXEC) { |
1638
4779658c2d03
(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
|
231 |
ChangeTownRating(t, -road_remove_cost[(byte)edge_road], RATING_ROAD_MINIMUM); |
0 | 232 |
|
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2008
diff
changeset
|
233 |
_m[tile].m5 ^= c; |
2493
f6b4300cc2b0
(svn r3019) -Codechange: Replace explicit shifting/anding/oring with GB and SB
tron
parents:
2471
diff
changeset
|
234 |
if (GB(_m[tile].m5, 0, 4) == 0) { |
0 | 235 |
DoClearSquare(tile); |
2493
f6b4300cc2b0
(svn r3019) -Codechange: Replace explicit shifting/anding/oring with GB and SB
tron
parents:
2471
diff
changeset
|
236 |
} else { |
0 | 237 |
MarkTileDirtyByTile(tile); |
2493
f6b4300cc2b0
(svn r3019) -Codechange: Replace explicit shifting/anding/oring with GB and SB
tron
parents:
2471
diff
changeset
|
238 |
} |
0 | 239 |
} |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
240 |
return cost; |
1638
4779658c2d03
(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
|
241 |
} else if ((ti.map5 & 0xE0) == 0) { // railroad crossing |
0 | 242 |
byte c; |
243 |
||
244 |
if (!(ti.map5 & 8)) { |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
245 |
c = 2; |
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
246 |
if (pieces & 5) goto return_error; |
0 | 247 |
} else { |
248 |
c = 1; |
|
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
249 |
if (pieces & 10) goto return_error; |
0 | 250 |
} |
251 |
||
252 |
cost = _price.remove_road * 2; |
|
253 |
if (flags & DC_EXEC) { |
|
2008
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
1986
diff
changeset
|
254 |
byte pbs_track = PBSTileReserved(tile); |
1638
4779658c2d03
(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
|
255 |
ChangeTownRating(t, -road_remove_cost[(byte)edge_road], RATING_ROAD_MINIMUM); |
4779658c2d03
(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
|
256 |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
257 |
ModifyTile(tile, |
0 | 258 |
MP_SETTYPE(MP_RAILWAY) | |
259 |
MP_MAP2_CLEAR | MP_MAP3LO | MP_MAP3HI_CLEAR | MP_MAP5, |
|
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2008
diff
changeset
|
260 |
_m[tile].m4 & 0xF, /* map3_lo */ |
0 | 261 |
c /* map5 */ |
262 |
); |
|
2008
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
1986
diff
changeset
|
263 |
if (pbs_track != 0) |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
1986
diff
changeset
|
264 |
PBSReserveTrack(tile, FIND_FIRST_BIT(pbs_track)); |
0 | 265 |
} |
266 |
return cost; |
|
267 |
} else |
|
268 |
goto return_error; |
|
269 |
||
270 |
} else { |
|
271 |
return_error:; |
|
272 |
return_cmd_error(INVALID_STRING_ID); |
|
273 |
} |
|
274 |
} |
|
275 |
||
276 |
||
277 |
enum { |
|
278 |
ROAD_NW = 1, // NW road track |
|
279 |
ROAD_SW = 2, // SW road track |
|
280 |
ROAD_SE = 4, // SE road track |
|
281 |
ROAD_NE = 8, // NE road track |
|
282 |
ROAD_ALL = (ROAD_NW | ROAD_SW | ROAD_SE | ROAD_NE) |
|
283 |
}; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
284 |
|
13
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
285 |
static const byte _valid_tileh_slopes_road[3][15] = { |
0 | 286 |
// set of normal ones |
287 |
{ |
|
288 |
ROAD_ALL, 0, 0, |
|
289 |
ROAD_SW | ROAD_NE, 0, 0, // 3, 4, 5 |
|
290 |
ROAD_NW | ROAD_SE, 0, 0, |
|
291 |
ROAD_NW | ROAD_SE, 0, 0, // 9, 10, 11 |
|
292 |
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
|
293 |
}, |
0 | 294 |
// 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
|
295 |
{ |
0 | 296 |
0, |
297 |
ROAD_SW | ROAD_NW, |
|
298 |
ROAD_SW | ROAD_SE, |
|
299 |
ROAD_NW | ROAD_SE | ROAD_SW, |
|
300 |
||
301 |
ROAD_SE | ROAD_NE, // 4 |
|
302 |
ROAD_ALL, |
|
303 |
ROAD_SW | ROAD_NE | ROAD_SE, |
|
304 |
ROAD_ALL, |
|
305 |
||
306 |
ROAD_NW | ROAD_NE, // 8 |
|
307 |
ROAD_SW | ROAD_NE | ROAD_NW, |
|
308 |
ROAD_ALL, |
|
309 |
ROAD_ALL, |
|
310 |
||
311 |
ROAD_NW | ROAD_SE | ROAD_NE, // 12 |
|
312 |
ROAD_ALL, |
|
313 |
ROAD_ALL |
|
13
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
314 |
}, |
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
315 |
// valid railway crossings on slopes |
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
316 |
{ |
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
317 |
1, 0, 0, // 0, 1, 2 |
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
318 |
0, 0, 1, // 3, 4, 5 |
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
319 |
0, 1, 0, // 6, 7, 8 |
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
320 |
0, 1, 1, // 9, 10, 11 |
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
321 |
0, 1, 1, // 12, 13, 14 |
0 | 322 |
} |
323 |
}; |
|
324 |
||
325 |
||
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
326 |
static uint32 CheckRoadSlope(int tileh, byte *pieces, byte existing) |
0 | 327 |
{ |
2085
876f20a0e843
(svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents:
2074
diff
changeset
|
328 |
if (!IsSteepTileh(tileh)) { |
0 | 329 |
byte road_bits = *pieces | existing; |
330 |
||
331 |
// no special foundation |
|
332 |
if ((~_valid_tileh_slopes_road[0][tileh] & road_bits) == 0) { |
|
333 |
// force that all bits are set when we have slopes |
|
334 |
if (tileh != 0) *pieces |= _valid_tileh_slopes_road[0][tileh]; |
|
335 |
return 0; // no extra cost |
|
336 |
} |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
337 |
|
0 | 338 |
// foundation is used. Whole tile is leveled up |
339 |
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
|
340 |
return existing ? 0 : _price.terraform; |
0 | 341 |
} |
342 |
||
343 |
// partly leveled up tile, only if there's no road on that tile |
|
344 |
if ( !existing && (tileh == 1 || tileh == 2 || tileh == 4 || tileh == 8) ) { |
|
345 |
// force full pieces. |
|
346 |
*pieces |= (*pieces & 0xC) >> 2; |
|
347 |
*pieces |= (*pieces & 0x3) << 2; |
|
72
24bdf837198c
(svn r73) -Fix: Wrong building of road-slopes for a future AI/Town
darkvater
parents:
39
diff
changeset
|
348 |
return (*pieces == (ROAD_NE|ROAD_SW) || *pieces == (ROAD_SE|ROAD_NW)) ? _price.terraform : CMD_ERROR; |
0 | 349 |
} |
350 |
} |
|
351 |
return CMD_ERROR; |
|
352 |
} |
|
353 |
||
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
354 |
/** Build a piece of road. |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
355 |
* @param x,y tile coordinates for road construction |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
356 |
* @param p1 road piece flags |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
357 |
* @param p2 the town that is building the road (0 if not applicable) |
0 | 358 |
*/ |
359 |
int32 CmdBuildRoad(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
360 |
{ |
|
361 |
TileInfo ti; |
|
362 |
int32 cost; |
|
363 |
byte pieces = (byte)p1, existing = 0; |
|
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
364 |
TileIndex tile; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
365 |
|
0 | 366 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
367 |
||
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
368 |
/* Road pieces are max 4 bitset values (NE, NW, SE, SW) and town can only be non-zero |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
369 |
* if a non-player is building the road */ |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
370 |
if ((pieces >> 4) || (_current_player < MAX_PLAYERS && p2 != 0) || !IsTownIndex(p2)) return CMD_ERROR; |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
371 |
|
0 | 372 |
FindLandscapeHeight(&ti, x, y); |
373 |
tile = ti.tile; |
|
374 |
||
375 |
// allow building road under bridge |
|
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
376 |
if (ti.type != MP_TUNNELBRIDGE && !EnsureNoVehicle(tile)) return CMD_ERROR; |
0 | 377 |
|
378 |
if (ti.type == MP_STREET) { |
|
379 |
if (!(ti.map5 & 0xF0)) { |
|
2639 | 380 |
if ((pieces & (byte)ti.map5) == pieces) |
0 | 381 |
return_cmd_error(STR_1007_ALREADY_BUILT); |
382 |
existing = ti.map5; |
|
383 |
} else { |
|
384 |
if (!(ti.map5 & 0xE0) && pieces != ((ti.map5 & 8) ? 5 : 10)) |
|
385 |
return_cmd_error(STR_1007_ALREADY_BUILT); |
|
386 |
goto do_clear; |
|
387 |
} |
|
388 |
} else if (ti.type == MP_RAILWAY) { |
|
389 |
byte m5; |
|
390 |
||
2124
868ae25e586b
(svn r2634) Fix typo: IsSteepTile expects a tileh, not a TileIndex (thanks to peter1138)
tron
parents:
2085
diff
changeset
|
391 |
if (IsSteepTileh(ti.tileh)) // very steep tile |
13
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
392 |
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
|
393 |
|
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
394 |
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
|
395 |
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
|
396 |
|
0 | 397 |
if (ti.map5 == 2) { |
398 |
if (pieces & 5) goto do_clear; |
|
399 |
m5 = 0x10; |
|
400 |
} else if (ti.map5 == 1) { |
|
401 |
if (pieces & 10) goto do_clear; |
|
402 |
m5 = 0x18; |
|
403 |
} else |
|
404 |
goto do_clear; |
|
405 |
||
406 |
if (flags & DC_EXEC) { |
|
2008
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
1986
diff
changeset
|
407 |
byte pbs_track = PBSTileReserved(tile); |
0 | 408 |
ModifyTile(tile, |
409 |
MP_SETTYPE(MP_STREET) | |
|
1264
acebb2b01e32
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1247
diff
changeset
|
410 |
MP_MAP2 | MP_MAP3LO | MP_MAP3HI | MP_MAP5, |
acebb2b01e32
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1247
diff
changeset
|
411 |
p2, |
0 | 412 |
_current_player, /* map3_lo */ |
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2008
diff
changeset
|
413 |
_m[tile].m3 & 0xF, /* map3_hi */ |
0 | 414 |
m5 /* map5 */ |
415 |
); |
|
2008
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
1986
diff
changeset
|
416 |
if (pbs_track != 0) |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
1986
diff
changeset
|
417 |
PBSReserveTrack(tile, FIND_FIRST_BIT(pbs_track)); |
0 | 418 |
} |
419 |
return _price.build_road * 2; |
|
420 |
} else if (ti.type == MP_TUNNELBRIDGE) { |
|
421 |
||
422 |
/* check for flat land */ |
|
2085
876f20a0e843
(svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents:
2074
diff
changeset
|
423 |
if (IsSteepTileh(ti.tileh)) // very steep tile |
0 | 424 |
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); |
425 |
||
426 |
/* is this middle part of a bridge? */ |
|
427 |
if ((ti.map5 & 0xC0) != 0xC0) |
|
428 |
goto do_clear; |
|
429 |
||
430 |
/* only allow roads pertendicular to bridge */ |
|
2865
97cb78a1d02c
(svn r3413) - Fix: Under certain conditions placing a road tile parallel under a bridge would, instead of failing, succeed and place a perpendicular piece.
peter1138
parents:
2817
diff
changeset
|
431 |
if (((pieces & 5U) != 0) == ((ti.map5 & 0x01U) != 0)) |
0 | 432 |
goto do_clear; |
433 |
||
434 |
/* check if clear land under bridge */ |
|
435 |
if ((ti.map5 & 0xF8) == 0xE8) /* road under bridge */ |
|
436 |
return_cmd_error(STR_1007_ALREADY_BUILT); |
|
437 |
else if ((ti.map5 & 0xE0) == 0xE0) /* other transport route under bridge */ |
|
438 |
return_cmd_error(STR_1008_MUST_REMOVE_RAILROAD_TRACK); |
|
439 |
else if ((ti.map5 & 0xF8) == 0xC8) /* water under bridge */ |
|
440 |
return_cmd_error(STR_3807_CAN_T_BUILD_ON_WATER); |
|
441 |
||
442 |
/* all checked, can build road now! */ |
|
443 |
cost = _price.build_road * 2; |
|
444 |
if (flags & DC_EXEC) { |
|
445 |
ModifyTile(tile, |
|
446 |
MP_MAPOWNER_CURRENT | MP_MAP5, |
|
447 |
(ti.map5 & 0xC7) | 0x28 // map5 |
|
448 |
); |
|
449 |
} |
|
450 |
return cost; |
|
451 |
} else { |
|
452 |
do_clear:; |
|
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
453 |
if (CmdFailed(DoCommandByTile(tile, 0, 0, flags & ~DC_EXEC, CMD_LANDSCAPE_CLEAR))) |
0 | 454 |
return CMD_ERROR; |
455 |
} |
|
456 |
||
457 |
cost = CheckRoadSlope(ti.tileh, &pieces, existing); |
|
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
458 |
if (CmdFailed(cost)) return_cmd_error(STR_1800_LAND_SLOPED_IN_WRONG_DIRECTION); |
0 | 459 |
|
2422
897a01f7c624
(svn r2948) -Fix: the old AI needs a special flag that triggers all kind of special
truelight
parents:
2187
diff
changeset
|
460 |
if (cost && (!_patches.build_on_slopes || _is_old_ai_player)) |
0 | 461 |
return CMD_ERROR; |
462 |
||
2549 | 463 |
if (ti.type != MP_STREET || (ti.map5 & 0xF0) != 0) { |
0 | 464 |
cost += DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
465 |
} else { |
|
466 |
// Don't put the pieces that already exist |
|
467 |
pieces &= ~ti.map5; |
|
468 |
} |
|
469 |
||
470 |
{ |
|
471 |
byte t = pieces; |
|
472 |
while (t) { |
|
473 |
if (t & 1) cost += _price.build_road; |
|
474 |
t >>= 1; |
|
475 |
} |
|
476 |
} |
|
477 |
||
478 |
if (flags & DC_EXEC) { |
|
479 |
if (ti.type != MP_STREET) { |
|
1059
fe97d81a1b4f
(svn r1560) Introduce SetTileType() and SetTileHeight()
tron
parents:
1041
diff
changeset
|
480 |
SetTileType(tile, MP_STREET); |
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2008
diff
changeset
|
481 |
_m[tile].m5 = 0; |
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2008
diff
changeset
|
482 |
_m[tile].m2 = p2; |
1902 | 483 |
SetTileOwner(tile, _current_player); |
0 | 484 |
} |
485 |
||
2549 | 486 |
_m[tile].m5 |= pieces; |
0 | 487 |
|
488 |
MarkTileDirtyByTile(tile); |
|
489 |
} |
|
490 |
return cost; |
|
491 |
} |
|
492 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
493 |
int32 DoConvertStreetRail(TileIndex tile, uint totype, bool exec) |
0 | 494 |
{ |
495 |
// not a railroad crossing? |
|
1927
1181e7652e2f
(svn r2433) - CodeChange: unmagicify all road/train crossings with IsLevelCrossing() function (peter1138)
Darkvater
parents:
1902
diff
changeset
|
496 |
if (!IsLevelCrossing(tile)) return CMD_ERROR; |
0 | 497 |
|
498 |
// not owned by me? |
|
499 |
if (!CheckTileOwnership(tile) || !EnsureNoVehicle(tile)) return CMD_ERROR; |
|
500 |
||
501 |
// tile is already of requested type? |
|
2493
f6b4300cc2b0
(svn r3019) -Codechange: Replace explicit shifting/anding/oring with GB and SB
tron
parents:
2471
diff
changeset
|
502 |
if (GB(_m[tile].m4, 0, 4) == totype) return CMD_ERROR; |
0 | 503 |
|
504 |
if (exec) { |
|
505 |
// change type. |
|
2493
f6b4300cc2b0
(svn r3019) -Codechange: Replace explicit shifting/anding/oring with GB and SB
tron
parents:
2471
diff
changeset
|
506 |
SB(_m[tile].m4, 0, 4, totype); |
0 | 507 |
MarkTileDirtyByTile(tile); |
508 |
} |
|
509 |
||
510 |
return _price.build_rail >> 1; |
|
511 |
} |
|
512 |
||
513 |
||
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
514 |
/** Build a long piece of road. |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
515 |
* @param x,y end tile of drag |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
516 |
* @param p1 start tile of drag |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
517 |
* @param p2 various bitstuffed elements |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
518 |
* - p2 = (bit 0) - start tile starts in the 2nd half of tile (p2 & 1) |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
519 |
* - p2 = (bit 1) - end tile starts in the 2nd half of tile (p2 & 2) |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
520 |
* - p2 = (bit 2) - direction: 0 = along x-axis, 1 = along y-axis (p2 & 4) |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
521 |
*/ |
0 | 522 |
int32 CmdBuildLongRoad(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
523 |
{ |
|
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
524 |
TileIndex start_tile, end_tile, tile; |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
525 |
int32 cost, ret; |
0 | 526 |
|
889
64d2f7d5f02b
(svn r1375) -Fix: [1050990] Buying trains sometimes accounted for incorrectly. Was the result of the cost getting reset in a recursive call of docommand. That is fixed. In addition all cost-commands are typed explicitely. Please do not forget to do so or your costs will be credited to construction if you are unlucky.
darkvater
parents:
817
diff
changeset
|
527 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
64d2f7d5f02b
(svn r1375) -Fix: [1050990] Buying trains sometimes accounted for incorrectly. Was the result of the cost getting reset in a recursive call of docommand. That is fixed. In addition all cost-commands are typed explicitely. Please do not forget to do so or your costs will be credited to construction if you are unlucky.
darkvater
parents:
817
diff
changeset
|
528 |
|
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
529 |
if (p1 > MapSize()) return CMD_ERROR; |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
530 |
|
0 | 531 |
start_tile = p1; |
1980
6c5917cfcb78
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1979
diff
changeset
|
532 |
end_tile = TileVirtXY(x, y); |
0 | 533 |
|
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
534 |
/* Only drag in X or Y direction dictated by the direction variable */ |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
535 |
if (!HASBIT(p2, 2) && TileY(start_tile) != TileY(end_tile)) return CMD_ERROR; // x-axis |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
536 |
if (HASBIT(p2, 2) && TileX(start_tile) != TileX(end_tile)) return CMD_ERROR; // y-axis |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
537 |
|
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
538 |
/* Swap start and ending tile, also the half-tile drag var (bit 0 and 1) */ |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
539 |
if (start_tile > end_tile || (start_tile == end_tile && HASBIT(p2, 0))) { |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
540 |
TileIndex t = start_tile; |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
541 |
start_tile = end_tile; |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
542 |
end_tile = t; |
0 | 543 |
p2 ^= IS_INT_INSIDE(p2&3, 1, 3) ? 3 : 0; |
544 |
} |
|
545 |
||
546 |
cost = 0; |
|
547 |
tile = start_tile; |
|
548 |
// Start tile is the small number. |
|
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
549 |
for (;;) { |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
550 |
uint bits = HASBIT(p2, 2) ? ROAD_SE | ROAD_NW : ROAD_SW | ROAD_NE; |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
551 |
if (tile == end_tile && !HASBIT(p2, 1)) bits &= ROAD_NW | ROAD_NE; |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
552 |
if (tile == start_tile && HASBIT(p2, 0)) bits &= ROAD_SE | ROAD_SW; |
0 | 553 |
|
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
554 |
ret = DoCommandByTile(tile, bits, 0, flags, CMD_BUILD_ROAD); |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
555 |
if (CmdFailed(ret)) { |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
556 |
if (_error_message != STR_1007_ALREADY_BUILT) return CMD_ERROR; |
2549 | 557 |
} else { |
0 | 558 |
cost += ret; |
2549 | 559 |
} |
0 | 560 |
|
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
561 |
if (tile == end_tile) break; |
0 | 562 |
|
1981 | 563 |
tile += HASBIT(p2, 2) ? TileDiffXY(0, 1) : TileDiffXY(1, 0); |
0 | 564 |
} |
565 |
||
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
566 |
return (cost == 0) ? CMD_ERROR : cost; |
0 | 567 |
} |
568 |
||
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
569 |
/** Remove a long piece of road. |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
570 |
* @param x,y end tile of drag |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
571 |
* @param p1 start tile of drag |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
572 |
* @param p2 various bitstuffed elements |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
573 |
* - p2 = (bit 0) - start tile starts in the 2nd half of tile (p2 & 1) |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
574 |
* - p2 = (bit 1) - end tile starts in the 2nd half of tile (p2 & 2) |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
575 |
* - p2 = (bit 2) - direction: 0 = along x-axis, 1 = along y-axis (p2 & 4) |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
576 |
*/ |
0 | 577 |
int32 CmdRemoveLongRoad(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
578 |
{ |
|
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
579 |
TileIndex start_tile, end_tile, tile; |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
580 |
int32 cost, ret; |
0 | 581 |
|
889
64d2f7d5f02b
(svn r1375) -Fix: [1050990] Buying trains sometimes accounted for incorrectly. Was the result of the cost getting reset in a recursive call of docommand. That is fixed. In addition all cost-commands are typed explicitely. Please do not forget to do so or your costs will be credited to construction if you are unlucky.
darkvater
parents:
817
diff
changeset
|
582 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
64d2f7d5f02b
(svn r1375) -Fix: [1050990] Buying trains sometimes accounted for incorrectly. Was the result of the cost getting reset in a recursive call of docommand. That is fixed. In addition all cost-commands are typed explicitely. Please do not forget to do so or your costs will be credited to construction if you are unlucky.
darkvater
parents:
817
diff
changeset
|
583 |
|
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
584 |
if (p1 > MapSize()) return CMD_ERROR; |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
585 |
|
0 | 586 |
start_tile = p1; |
1980
6c5917cfcb78
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1979
diff
changeset
|
587 |
end_tile = TileVirtXY(x, y); |
0 | 588 |
|
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
589 |
/* Only drag in X or Y direction dictated by the direction variable */ |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
590 |
if (!HASBIT(p2, 2) && TileY(start_tile) != TileY(end_tile)) return CMD_ERROR; // x-axis |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
591 |
if (HASBIT(p2, 2) && TileX(start_tile) != TileX(end_tile)) return CMD_ERROR; // y-axis |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
592 |
|
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
593 |
/* Swap start and ending tile, also the half-tile drag var (bit 0 and 1) */ |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
594 |
if (start_tile > end_tile || (start_tile == end_tile && HASBIT(p2, 0))) { |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
595 |
TileIndex t = start_tile; |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
596 |
start_tile = end_tile; |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
597 |
end_tile = t; |
0 | 598 |
p2 ^= IS_INT_INSIDE(p2&3, 1, 3) ? 3 : 0; |
599 |
} |
|
600 |
||
601 |
cost = 0; |
|
602 |
tile = start_tile; |
|
603 |
// Start tile is the small number. |
|
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
604 |
for (;;) { |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
605 |
uint bits = HASBIT(p2, 2) ? ROAD_SE | ROAD_NW : ROAD_SW | ROAD_NE; |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
606 |
if (tile == end_tile && !HASBIT(p2, 1)) bits &= ROAD_NW | ROAD_NE; |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
607 |
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
|
608 |
|
0 | 609 |
// try to remove the halves. |
610 |
if (bits) { |
|
611 |
ret = DoCommandByTile(tile, bits, 0, flags, CMD_REMOVE_ROAD); |
|
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
612 |
if (!CmdFailed(ret)) cost += ret; |
0 | 613 |
} |
614 |
||
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
615 |
if (tile == end_tile) break; |
0 | 616 |
|
1981 | 617 |
tile += HASBIT(p2, 2) ? TileDiffXY(0, 1) : TileDiffXY(1, 0); |
0 | 618 |
} |
619 |
||
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
620 |
return (cost == 0) ? CMD_ERROR : cost; |
0 | 621 |
} |
622 |
||
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
623 |
/** Build a road depot. |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
624 |
* @param x,y tile coordinates where the depot will be built |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
625 |
* @param p1 depot direction (0 through 3), where 0 is NW, 1 is NE, etc. |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
626 |
* @param p2 unused |
2085
876f20a0e843
(svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents:
2074
diff
changeset
|
627 |
* |
876f20a0e843
(svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents:
2074
diff
changeset
|
628 |
* @todo When checking for the tile slope, |
876f20a0e843
(svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents:
2074
diff
changeset
|
629 |
* distingush between "Flat land required" and "land sloped in wrong direction" |
0 | 630 |
*/ |
631 |
int32 CmdBuildRoadDepot(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
632 |
{ |
|
633 |
TileInfo ti; |
|
634 |
int32 cost; |
|
635 |
Depot *dep; |
|
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
636 |
TileIndex tile; |
0 | 637 |
|
638 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
639 |
||
1785
d3f3496b5943
(svn r2289) - Fix (regression): check p1 param of road-depot building instead of unused p2 (typo). Thanks peter1138.
Darkvater
parents:
1784
diff
changeset
|
640 |
if (p1 > 3) return CMD_ERROR; // check direction |
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
641 |
|
0 | 642 |
FindLandscapeHeight(&ti, x, y); |
643 |
||
644 |
tile = ti.tile; |
|
645 |
||
2549 | 646 |
if (!EnsureNoVehicle(tile)) return CMD_ERROR; |
0 | 647 |
|
2549 | 648 |
if (ti.tileh != 0 && ( |
649 |
!_patches.build_on_slopes || |
|
650 |
IsSteepTileh(ti.tileh) || |
|
651 |
!CanBuildDepotByTileh(p1, ti.tileh) |
|
652 |
)) { |
|
653 |
return_cmd_error(STR_0007_FLAT_LAND_REQUIRED); |
|
0 | 654 |
} |
655 |
||
656 |
cost = DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
|
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
657 |
if (CmdFailed(cost)) return CMD_ERROR; |
0 | 658 |
|
659 |
dep = AllocateDepot(); |
|
2549 | 660 |
if (dep == NULL) return CMD_ERROR; |
0 | 661 |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
662 |
if (flags & DC_EXEC) { |
2425
e755ee29133a
(svn r2951) - Fix: [ 1259345 ] Changing engine in netgame opens train window for everyone
Darkvater
parents:
2422
diff
changeset
|
663 |
if (IsLocalPlayer()) _last_built_road_depot_tile = tile; |
0 | 664 |
|
665 |
dep->xy = tile; |
|
666 |
dep->town_index = ClosestTownFromTile(tile, (uint)-1)->index; |
|
667 |
||
668 |
ModifyTile(tile, |
|
669 |
MP_SETTYPE(MP_STREET) | |
|
670 |
MP_MAPOWNER_CURRENT | MP_MAP5, |
|
671 |
(p1 | 0x20) /* map5 */ |
|
672 |
); |
|
673 |
||
674 |
} |
|
675 |
return cost + _price.build_road_depot; |
|
676 |
} |
|
677 |
||
1979
82d8bcc16ce2
(svn r2485) Missed two uint -> TileIndex, thanks _Luca_
tron
parents:
1977
diff
changeset
|
678 |
static int32 RemoveRoadDepot(TileIndex tile, uint32 flags) |
0 | 679 |
{ |
149
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
84
diff
changeset
|
680 |
if (!CheckTileOwnership(tile) && _current_player != OWNER_WATER) |
0 | 681 |
return CMD_ERROR; |
682 |
||
2639 | 683 |
if (!EnsureNoVehicle(tile)) return CMD_ERROR; |
0 | 684 |
|
2639 | 685 |
if (flags & DC_EXEC) DoDeleteDepot(tile); |
0 | 686 |
|
687 |
return _price.remove_road_depot; |
|
688 |
} |
|
689 |
||
690 |
#define M(x) (1<<(x)) |
|
691 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
692 |
static int32 ClearTile_Road(TileIndex tile, byte flags) |
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
693 |
{ |
0 | 694 |
int32 ret; |
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2008
diff
changeset
|
695 |
byte m5 = _m[tile].m5; |
0 | 696 |
|
697 |
if ( (m5 & 0xF0) == 0) { |
|
698 |
byte b = m5 & 0xF; |
|
699 |
||
700 |
if (! ((1 << b) & (M(1)|M(2)|M(4)|M(8))) ) { |
|
1901
03bf9bf99319
(svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents:
1891
diff
changeset
|
701 |
if ((!(flags & DC_AI_BUILDING) || !IsTileOwner(tile, OWNER_TOWN)) && flags & DC_AUTO) |
0 | 702 |
return_cmd_error(STR_1801_MUST_REMOVE_ROAD_FIRST); |
703 |
} |
|
704 |
return DoCommandByTile(tile, b, 0, flags, CMD_REMOVE_ROAD); |
|
705 |
} else if ( (m5 & 0xE0) == 0) { |
|
706 |
if (flags & DC_AUTO) |
|
707 |
return_cmd_error(STR_1801_MUST_REMOVE_ROAD_FIRST); |
|
708 |
||
709 |
ret = DoCommandByTile(tile, (m5&8)?5:10, 0, flags, CMD_REMOVE_ROAD); |
|
2737
fb1556b8f5e0
(svn r3282) - Codechange: Replace tests against CMD_ERROR with CmdFailed()
peter1138
parents:
2709
diff
changeset
|
710 |
if (CmdFailed(ret)) return CMD_ERROR; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
711 |
|
0 | 712 |
if (flags & DC_EXEC) { |
713 |
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
|
714 |
} |
0 | 715 |
|
716 |
return ret; |
|
717 |
} else { |
|
718 |
if (flags & DC_AUTO) |
|
719 |
return_cmd_error(STR_2004_BUILDING_MUST_BE_DEMOLISHED); |
|
720 |
return RemoveRoadDepot(tile,flags); |
|
721 |
} |
|
722 |
} |
|
723 |
||
724 |
||
725 |
typedef struct DrawRoadTileStruct { |
|
726 |
uint16 image; |
|
727 |
byte subcoord_x; |
|
728 |
byte subcoord_y; |
|
729 |
} DrawRoadTileStruct; |
|
730 |
||
731 |
typedef struct DrawRoadSeqStruct { |
|
732 |
uint32 image; |
|
733 |
byte subcoord_x; |
|
734 |
byte subcoord_y; |
|
735 |
byte width; |
|
736 |
byte height; |
|
737 |
} DrawRoadSeqStruct; |
|
738 |
||
739 |
#include "table/road_land.h" |
|
740 |
||
741 |
||
2548
49c8a096033f
(svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents:
2544
diff
changeset
|
742 |
uint GetRoadFoundation(uint tileh, uint bits) |
49c8a096033f
(svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents:
2544
diff
changeset
|
743 |
{ |
0 | 744 |
int i; |
745 |
// normal level sloped building |
|
746 |
if ((~_valid_tileh_slopes_road[1][tileh] & bits) == 0) |
|
747 |
return tileh; |
|
748 |
||
749 |
// inclined sloped building |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
750 |
if ( ((i=0, tileh == 1) || (i+=2, tileh == 2) || (i+=2, tileh == 4) || (i+=2, tileh == 8)) && |
0 | 751 |
((bits == (ROAD_SW | ROAD_NE)) || (i++, bits == (ROAD_NW | ROAD_SE)))) |
752 |
return i + 15; |
|
753 |
||
13
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
754 |
// rail crossing |
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
755 |
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
|
756 |
return tileh; |
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
757 |
|
0 | 758 |
return 0; |
759 |
} |
|
760 |
||
761 |
const byte _road_sloped_sprites[14] = { |
|
762 |
0, 0, 2, 0, |
|
763 |
0, 1, 0, 0, |
|
764 |
3, 0, 0, 0, |
|
765 |
0, 0 |
|
766 |
}; |
|
767 |
||
2471
5935596f14a8
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
768 |
/** |
5935596f14a8
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
769 |
* Draw ground sprite and road pieces |
5935596f14a8
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
770 |
* @param ti TileInfo |
5935596f14a8
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
771 |
* @param road RoadBits to draw |
5935596f14a8
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
772 |
* @param ground_type Ground type |
5935596f14a8
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
773 |
* @param snow Draw snow |
5935596f14a8
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
774 |
* @param flat Draw foundation |
5935596f14a8
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
775 |
*/ |
2817 | 776 |
static void DrawRoadBits(TileInfo *ti, byte road, byte ground_type, bool snow, bool flat) |
2471
5935596f14a8
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
777 |
{ |
5935596f14a8
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
778 |
const DrawRoadTileStruct *drts; |
5935596f14a8
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
779 |
PalSpriteID image = 0; |
5935596f14a8
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
780 |
|
5935596f14a8
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
781 |
if (ti->tileh != 0) { |
5935596f14a8
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
782 |
int foundation; |
5935596f14a8
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
783 |
if (flat) { |
5935596f14a8
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
784 |
foundation = ti->tileh; |
5935596f14a8
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
785 |
} else { |
5935596f14a8
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
786 |
foundation = GetRoadFoundation(ti->tileh, road); |
5935596f14a8
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
787 |
} |
5935596f14a8
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
788 |
|
2639 | 789 |
if (foundation != 0) DrawFoundation(ti, foundation); |
2471
5935596f14a8
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
790 |
|
5935596f14a8
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
791 |
// DrawFoundation() modifies ti. |
5935596f14a8
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
792 |
// Default sloped sprites.. |
2639 | 793 |
if (ti->tileh != 0) image = _road_sloped_sprites[ti->tileh - 1] + 0x53F; |
2471
5935596f14a8
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
794 |
} |
5935596f14a8
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
795 |
|
2639 | 796 |
if (image == 0) image = _road_tile_sprites_1[road]; |
2471
5935596f14a8
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
797 |
|
2639 | 798 |
if (ground_type == 0) image |= PALETTE_TO_BARE_LAND; |
2471
5935596f14a8
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
799 |
|
5935596f14a8
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
800 |
if (snow) { |
5935596f14a8
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
801 |
image += 19; |
5935596f14a8
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
802 |
} else if (ground_type > 1 && ground_type != 6) { |
5935596f14a8
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
803 |
// Pavement tiles. |
5935596f14a8
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
804 |
image -= 19; |
5935596f14a8
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
805 |
} |
5935596f14a8
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
806 |
|
5935596f14a8
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
807 |
DrawGroundSprite(image); |
5935596f14a8
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
808 |
|
5935596f14a8
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
809 |
// Return if full detail is disabled, or we are zoomed fully out. |
2639 | 810 |
if (!(_display_opt & DO_FULL_DETAIL) || _cur_dpi->zoom == 2) return; |
2471
5935596f14a8
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
811 |
|
5935596f14a8
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
812 |
if (ground_type >= 6) { |
5935596f14a8
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
813 |
// Road works |
2872 | 814 |
DrawGroundSprite(HASBIT(road, 3) ? SPR_EXCAVATION_X : SPR_EXCAVATION_Y); |
2471
5935596f14a8
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
815 |
return; |
5935596f14a8
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
816 |
} |
5935596f14a8
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
817 |
|
5935596f14a8
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
818 |
// Draw extra details. |
5935596f14a8
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
819 |
drts = _road_display_table[ground_type][road]; |
5935596f14a8
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
820 |
while ((image = drts->image) != 0) { |
5935596f14a8
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
821 |
int x = ti->x | drts->subcoord_x; |
5935596f14a8
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
822 |
int y = ti->y | drts->subcoord_y; |
5935596f14a8
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
823 |
byte z = ti->z; |
2639 | 824 |
if (ti->tileh != 0) z = GetSlopeZ(x, y); |
2471
5935596f14a8
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
825 |
AddSortableSpriteToDraw(image, x, y, 2, 2, 0x10, z); |
5935596f14a8
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
826 |
drts++; |
5935596f14a8
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
827 |
} |
5935596f14a8
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
828 |
} |
5935596f14a8
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
829 |
|
0 | 830 |
static void DrawTile_Road(TileInfo *ti) |
831 |
{ |
|
2471
5935596f14a8
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
832 |
PalSpriteID image; |
817
238bbdaa228b
(svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents:
679
diff
changeset
|
833 |
uint16 m2; |
0 | 834 |
|
835 |
if ( (ti->map5 & 0xF0) == 0) { // if it is a road the upper 4 bits are 0 |
|
2471
5935596f14a8
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
836 |
DrawRoadBits(ti, GB(ti->map5, 0, 4), GB(_m[ti->tile].m4, 4, 3), HASBIT(_m[ti->tile].m4, 7), false); |
13
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
837 |
} else if ( (ti->map5 & 0xE0) == 0) { // railroad crossing |
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
838 |
int f = GetRoadFoundation(ti->tileh, ti->map5 & 0xF); |
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
839 |
if (f) DrawFoundation(ti, f); |
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
840 |
|
2511
3eb6cb6b750d
(svn r3037) Don't deduce the sprites for tunnels and level crossings from magic numbers, but fetch them from the central rail info array. This is a preparation step for electrified rails
tron
parents:
2502
diff
changeset
|
841 |
image = GetRailTypeInfo(GB(_m[ti->tile].m4, 0, 4))->base_sprites.crossing; |
0 | 842 |
|
2511
3eb6cb6b750d
(svn r3037) Don't deduce the sprites for tunnels and level crossings from magic numbers, but fetch them from the central rail info array. This is a preparation step for electrified rails
tron
parents:
2502
diff
changeset
|
843 |
if (GB(ti->map5, 3, 1) == 0) image++; /* direction */ |
0 | 844 |
|
845 |
if ( (ti->map5 & 4) != 0) |
|
846 |
image += 2; |
|
847 |
||
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2008
diff
changeset
|
848 |
if ( _m[ti->tile].m4 & 0x80) { |
0 | 849 |
image += 8; |
850 |
} else { |
|
2140
a04d0142ad65
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2133
diff
changeset
|
851 |
m2 = GB(_m[ti->tile].m4, 4, 3); |
2187
a0e206ce9fbf
(svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents:
2186
diff
changeset
|
852 |
if (m2 == 0) image |= PALETTE_TO_BARE_LAND; |
0 | 853 |
if (m2 > 1) image += 4; |
854 |
} |
|
855 |
||
2511
3eb6cb6b750d
(svn r3037) Don't deduce the sprites for tunnels and level crossings from magic numbers, but fetch them from the central rail info array. This is a preparation step for electrified rails
tron
parents:
2502
diff
changeset
|
856 |
DrawGroundSprite(image); |
2008
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
1986
diff
changeset
|
857 |
|
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
1986
diff
changeset
|
858 |
if (_debug_pbs_level >= 1) { |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
1986
diff
changeset
|
859 |
byte pbs = PBSTileReserved(ti->tile); |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
1986
diff
changeset
|
860 |
if (pbs & TRACK_BIT_DIAG1) DrawGroundSprite(0x3ED | PALETTE_CRASH); |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
1986
diff
changeset
|
861 |
if (pbs & TRACK_BIT_DIAG2) DrawGroundSprite(0x3EE | PALETTE_CRASH); |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
1986
diff
changeset
|
862 |
if (pbs & TRACK_BIT_UPPER) DrawGroundSprite(0x3EF | PALETTE_CRASH); |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
1986
diff
changeset
|
863 |
if (pbs & TRACK_BIT_LOWER) DrawGroundSprite(0x3F0 | PALETTE_CRASH); |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
1986
diff
changeset
|
864 |
if (pbs & TRACK_BIT_LEFT) DrawGroundSprite(0x3F2 | PALETTE_CRASH); |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
1986
diff
changeset
|
865 |
if (pbs & TRACK_BIT_RIGHT) DrawGroundSprite(0x3F1 | PALETTE_CRASH); |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
1986
diff
changeset
|
866 |
} |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
1986
diff
changeset
|
867 |
|
0 | 868 |
} else { |
869 |
uint32 ormod; |
|
2544 | 870 |
PlayerID player; |
0 | 871 |
const DrawRoadSeqStruct *drss; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
872 |
|
0 | 873 |
if (ti->tileh != 0) { DrawFoundation(ti, ti->tileh); } |
874 |
||
2187
a0e206ce9fbf
(svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents:
2186
diff
changeset
|
875 |
ormod = PALETTE_TO_GREY; //was this a bug/problem? |
1901
03bf9bf99319
(svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents:
1891
diff
changeset
|
876 |
player = GetTileOwner(ti->tile); |
0 | 877 |
if (player < MAX_PLAYERS) |
878 |
ormod = PLAYER_SPRITE_COLOR(player); |
|
879 |
||
1398 | 880 |
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
|
881 |
|
1398 | 882 |
DrawGroundSprite(drss++->image); |
0 | 883 |
|
1398 | 884 |
for (; drss->image != 0; drss++) { |
885 |
uint32 image = drss->image; |
|
886 |
||
2187
a0e206ce9fbf
(svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents:
2186
diff
changeset
|
887 |
if (image & PALETTE_MODIFIER_COLOR) |
0 | 888 |
image |= ormod; |
497
4d1c889526ee
(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
|
889 |
if (_display_opt & DO_TRANS_BUILDINGS) // show transparent depots |
2148
542ea702738c
(svn r2658) -Codechange: Use MAKE_TRANSPARENT to display a transparented sprite
celestar
parents:
2140
diff
changeset
|
890 |
MAKE_TRANSPARENT(image); |
0 | 891 |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
892 |
AddSortableSpriteToDraw(image, ti->x | drss->subcoord_x, |
0 | 893 |
ti->y | drss->subcoord_y, drss->width, drss->height, 0x14, ti->z); |
894 |
} |
|
895 |
} |
|
896 |
} |
|
897 |
||
898 |
void DrawRoadDepotSprite(int x, int y, int image) |
|
899 |
{ |
|
900 |
uint32 ormod; |
|
901 |
const DrawRoadSeqStruct *dtss; |
|
902 |
||
903 |
ormod = PLAYER_SPRITE_COLOR(_local_player); |
|
904 |
||
1398 | 905 |
dtss = _road_display_datas[image]; |
0 | 906 |
|
2639 | 907 |
x += 33; |
908 |
y += 17; |
|
0 | 909 |
|
1398 | 910 |
DrawSprite(dtss++->image, x, y); |
0 | 911 |
|
1398 | 912 |
for(; dtss->image != 0; dtss++) { |
0 | 913 |
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
|
914 |
|
0 | 915 |
image = dtss->image; |
2639 | 916 |
if (image & PALETTE_MODIFIER_COLOR) image |= ormod; |
0 | 917 |
|
918 |
DrawSprite(image, x + pt.x, y + pt.y); |
|
919 |
} |
|
920 |
} |
|
921 |
||
2537 | 922 |
static uint GetSlopeZ_Road(const TileInfo* ti) |
0 | 923 |
{ |
924 |
uint z = ti->z; |
|
925 |
int th = ti->tileh; |
|
926 |
||
927 |
// check if it's a foundation |
|
928 |
if (ti->tileh != 0) { |
|
13
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
929 |
if ((ti->map5 & 0xE0) == 0) { /* road or crossing */ |
0 | 930 |
uint f = GetRoadFoundation(ti->tileh, ti->map5 & 0x3F); |
931 |
if (f != 0) { |
|
932 |
if (f < 15) { |
|
933 |
// leveled foundation |
|
934 |
return z + 8; |
|
935 |
} |
|
936 |
// inclined foundation |
|
937 |
th = _inclined_tileh[f - 15]; |
|
938 |
} |
|
939 |
} else if ((ti->map5 & 0xF0) == 0x20) { |
|
940 |
// depot |
|
941 |
return z + 8; |
|
942 |
} |
|
943 |
return GetPartialZ(ti->x&0xF, ti->y&0xF, th) + z; |
|
944 |
} |
|
39 | 945 |
return z; // normal Z if no slope |
946 |
} |
|
947 |
||
2436
7d5df545bd5d
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2425
diff
changeset
|
948 |
static uint GetSlopeTileh_Road(const TileInfo *ti) |
39 | 949 |
{ |
950 |
// check if it's a foundation |
|
951 |
if (ti->tileh != 0) { |
|
952 |
if ((ti->map5 & 0xE0) == 0) { /* road or crossing */ |
|
953 |
uint f = GetRoadFoundation(ti->tileh, ti->map5 & 0x3F); |
|
954 |
if (f != 0) { |
|
955 |
if (f < 15) { |
|
956 |
// leveled foundation |
|
957 |
return 0; |
|
958 |
} |
|
959 |
// inclined foundation |
|
960 |
return _inclined_tileh[f - 15]; |
|
961 |
} |
|
962 |
} else if ((ti->map5 & 0xF0) == 0x20) { |
|
963 |
// depot |
|
964 |
return 0; |
|
965 |
} |
|
966 |
} |
|
967 |
return ti->tileh; |
|
0 | 968 |
} |
969 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
970 |
static void GetAcceptedCargo_Road(TileIndex tile, AcceptedCargo ac) |
0 | 971 |
{ |
972 |
/* not used */ |
|
973 |
} |
|
974 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
975 |
static void AnimateTile_Road(TileIndex tile) |
0 | 976 |
{ |
2639 | 977 |
if (IsLevelCrossing(tile)) MarkTileDirtyByTile(tile); |
0 | 978 |
} |
979 |
||
980 |
static const byte _town_road_types[5][2] = { |
|
981 |
{1,1}, |
|
982 |
{2,2}, |
|
983 |
{2,2}, |
|
984 |
{5,5}, |
|
985 |
{3,2}, |
|
986 |
}; |
|
987 |
||
988 |
static const byte _town_road_types_2[5][2] = { |
|
989 |
{1,1}, |
|
990 |
{2,2}, |
|
991 |
{3,2}, |
|
992 |
{3,2}, |
|
993 |
{3,2}, |
|
994 |
}; |
|
995 |
||
996 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
997 |
static void TileLoop_Road(TileIndex tile) |
0 | 998 |
{ |
999 |
Town *t; |
|
1000 |
int grp; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1001 |
|
0 | 1002 |
if (_opt.landscape == LT_HILLY) { |
1003 |
// Fix snow style if the road is above the snowline |
|
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2008
diff
changeset
|
1004 |
if ((_m[tile].m4 & 0x80) != ((GetTileZ(tile) > _opt.snow_line) ? 0x80 : 0x00)) { |
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2008
diff
changeset
|
1005 |
_m[tile].m4 ^= 0x80; |
0 | 1006 |
MarkTileDirtyByTile(tile); |
1007 |
} |
|
1008 |
} else if (_opt.landscape == LT_DESERT) { |
|
1009 |
// Fix desert style |
|
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2008
diff
changeset
|
1010 |
if (GetMapExtraBits(tile) == 1 && !(_m[tile].m4 & 0x80)) { |
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2008
diff
changeset
|
1011 |
_m[tile].m4 |= 0x80; |
0 | 1012 |
MarkTileDirtyByTile(tile); |
1013 |
} |
|
1014 |
} |
|
1015 |
||
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2008
diff
changeset
|
1016 |
if (_m[tile].m5 & 0xE0) |
0 | 1017 |
return; |
1018 |
||
2140
a04d0142ad65
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2133
diff
changeset
|
1019 |
if (GB(_m[tile].m4, 4, 3) < 6) { |
1281
dd226de69402
(svn r1785) -Fix: space-correctness in road_cmd.c, and one wrong line from last
truelight
parents:
1280
diff
changeset
|
1020 |
t = ClosestTownFromTile(tile, (uint)-1); |
1280
33a251c30758
(svn r1784) -Fix: removed ClosestTownFromTile where possible, or replaced it
truelight
parents:
1264
diff
changeset
|
1021 |
|
0 | 1022 |
grp = 0; |
1023 |
if (t != NULL) { |
|
1024 |
grp = GetTownRadiusGroup(t, tile); |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1025 |
|
0 | 1026 |
// 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
|
1027 |
if (t->road_build_months != 0 && |
1245
3822f77cbc53
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1214
diff
changeset
|
1028 |
!(DistanceManhattan(t->xy, tile) >= 8 && grp == 0) && |
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2008
diff
changeset
|
1029 |
(_m[tile].m5==5 || _m[tile].m5==10)) { |
0 | 1030 |
if (GetTileSlope(tile, NULL) == 0 && EnsureNoVehicle(tile) && CHANCE16(1,20)) { |
2140
a04d0142ad65
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2133
diff
changeset
|
1031 |
_m[tile].m4 |= (GB(_m[tile].m4, 4, 3) <= 2 ? 7 : 6) << 4; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1032 |
|
541 | 1033 |
SndPlayTileFx(SND_21_JACKHAMMER, tile); |
0 | 1034 |
CreateEffectVehicleAbove( |
926
a6d140a6a4de
(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
|
1035 |
TileX(tile) * 16 + 7, |
a6d140a6a4de
(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
|
1036 |
TileY(tile) * 16 + 7, |
0 | 1037 |
0, |
1359
52782e5cf7c9
(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
|
1038 |
EV_BULLDOZER); |
0 | 1039 |
MarkTileDirtyByTile(tile); |
1040 |
return; |
|
1041 |
} |
|
1042 |
} |
|
1043 |
} |
|
1044 |
||
1045 |
{ |
|
1046 |
const byte *p = (_opt.landscape == LT_CANDY) ? _town_road_types_2[grp] : _town_road_types[grp]; |
|
2140
a04d0142ad65
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2133
diff
changeset
|
1047 |
byte b = GB(_m[tile].m4, 4, 3); |
0 | 1048 |
|
1049 |
if (b == p[0]) |
|
1050 |
return; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1051 |
|
0 | 1052 |
if (b == p[1]) { |
1053 |
b = p[0]; |
|
1054 |
} else if (b == 0) { |
|
1055 |
b = p[1]; |
|
1056 |
} else { |
|
1057 |
b = 0; |
|
1058 |
} |
|
2493
f6b4300cc2b0
(svn r3019) -Codechange: Replace explicit shifting/anding/oring with GB and SB
tron
parents:
2471
diff
changeset
|
1059 |
SB(_m[tile].m4, 4, 3, b); |
0 | 1060 |
MarkTileDirtyByTile(tile); |
1061 |
} |
|
1062 |
} else { |
|
1063 |
// Handle road work |
|
1264
acebb2b01e32
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1247
diff
changeset
|
1064 |
//XXX undocumented |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1065 |
|
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2008
diff
changeset
|
1066 |
byte b = _m[tile].m4; |
1264
acebb2b01e32
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1247
diff
changeset
|
1067 |
//roadworks take place only |
acebb2b01e32
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1247
diff
changeset
|
1068 |
//keep roadworks running for 16 loops |
acebb2b01e32
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1247
diff
changeset
|
1069 |
//lower 4 bits of map3_hi store the counter now |
acebb2b01e32
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1247
diff
changeset
|
1070 |
if ((b & 0xF) != 0xF) { |
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2008
diff
changeset
|
1071 |
_m[tile].m4 = b + 1; |
0 | 1072 |
return; |
1073 |
} |
|
1264
acebb2b01e32
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1247
diff
changeset
|
1074 |
//roadworks finished |
2140
a04d0142ad65
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2133
diff
changeset
|
1075 |
_m[tile].m4 = (GB(b, 4, 3) == 6 ? 1 : 2) << 4; |
0 | 1076 |
MarkTileDirtyByTile(tile); |
1077 |
} |
|
1078 |
} |
|
1079 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
1080 |
void ShowRoadDepotWindow(TileIndex tile); |
0 | 1081 |
|
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
1082 |
static void ClickTile_Road(TileIndex tile) |
0 | 1083 |
{ |
2493
f6b4300cc2b0
(svn r3019) -Codechange: Replace explicit shifting/anding/oring with GB and SB
tron
parents:
2471
diff
changeset
|
1084 |
if (GB(_m[tile].m5, 4, 4) == 2) ShowRoadDepotWindow(tile); |
0 | 1085 |
} |
1086 |
||
1087 |
static const byte _road_trackbits[16] = { |
|
1088 |
0x0, 0x0, 0x0, 0x10, 0x0, 0x2, 0x8, 0x1A, 0x0, 0x4, 0x1, 0x15, 0x20, 0x26, 0x29, 0x3F, |
|
1089 |
}; |
|
1090 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
1091 |
static uint32 GetTileTrackStatus_Road(TileIndex tile, TransportType mode) |
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
1092 |
{ |
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
149
diff
changeset
|
1093 |
if (mode == TRANSPORT_RAIL) { |
1927
1181e7652e2f
(svn r2433) - CodeChange: unmagicify all road/train crossings with IsLevelCrossing() function (peter1138)
Darkvater
parents:
1902
diff
changeset
|
1094 |
if (!IsLevelCrossing(tile)) |
0 | 1095 |
return 0; |
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2008
diff
changeset
|
1096 |
return _m[tile].m5 & 8 ? 0x101 : 0x202; |
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
149
diff
changeset
|
1097 |
} else if (mode == TRANSPORT_ROAD) { |
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2008
diff
changeset
|
1098 |
byte b = _m[tile].m5; |
0 | 1099 |
if ((b & 0xF0) == 0) { |
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
149
diff
changeset
|
1100 |
/* Ordinary road */ |
2140
a04d0142ad65
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2133
diff
changeset
|
1101 |
if (!_road_special_gettrackstatus && GB(_m[tile].m4, 4, 3) >= 6) |
0 | 1102 |
return 0; |
1103 |
return _road_trackbits[b&0xF] * 0x101; |
|
1927
1181e7652e2f
(svn r2433) - CodeChange: unmagicify all road/train crossings with IsLevelCrossing() function (peter1138)
Darkvater
parents:
1902
diff
changeset
|
1104 |
} else if (IsLevelCrossing(tile)) { |
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
149
diff
changeset
|
1105 |
/* Crossing */ |
0 | 1106 |
uint32 r = 0x101; |
1107 |
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
|
1108 |
|
0 | 1109 |
if (b&4) { |
1110 |
r *= 0x10001; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1111 |
} |
0 | 1112 |
return r; |
1113 |
} |
|
1114 |
} |
|
1115 |
return 0; |
|
1116 |
} |
|
1117 |
||
1118 |
static const StringID _road_tile_strings[] = { |
|
1119 |
STR_1818_ROAD_RAIL_LEVEL_CROSSING, |
|
1120 |
STR_1817_ROAD_VEHICLE_DEPOT, |
|
1121 |
||
1122 |
STR_1814_ROAD, |
|
1123 |
STR_1814_ROAD, |
|
1124 |
STR_1814_ROAD, |
|
1125 |
STR_1815_ROAD_WITH_STREETLIGHTS, |
|
1126 |
STR_1814_ROAD, |
|
1127 |
STR_1816_TREE_LINED_ROAD, |
|
1128 |
STR_1814_ROAD, |
|
1129 |
STR_1814_ROAD, |
|
1130 |
}; |
|
1131 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
1132 |
static void GetTileDesc_Road(TileIndex tile, TileDesc *td) |
0 | 1133 |
{ |
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2008
diff
changeset
|
1134 |
int i = (_m[tile].m5 >> 4); |
0 | 1135 |
if (i == 0) |
2140
a04d0142ad65
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2133
diff
changeset
|
1136 |
i = GB(_m[tile].m4, 4, 3) + 3; |
0 | 1137 |
td->str = _road_tile_strings[i - 1]; |
1901
03bf9bf99319
(svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents:
1891
diff
changeset
|
1138 |
td->owner = GetTileOwner(tile); |
0 | 1139 |
} |
1140 |
||
1141 |
static const byte _roadveh_enter_depot_unk0[4] = { |
|
1142 |
8, 9, 0, 1 |
|
1143 |
}; |
|
1144 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
1145 |
static uint32 VehicleEnter_Road(Vehicle *v, TileIndex tile, int x, int y) |
0 | 1146 |
{ |
1927
1181e7652e2f
(svn r2433) - CodeChange: unmagicify all road/train crossings with IsLevelCrossing() function (peter1138)
Darkvater
parents:
1902
diff
changeset
|
1147 |
if (IsLevelCrossing(tile)) { |
2493
f6b4300cc2b0
(svn r3019) -Codechange: Replace explicit shifting/anding/oring with GB and SB
tron
parents:
2471
diff
changeset
|
1148 |
if (v->type == VEH_Train && GB(_m[tile].m5, 2, 1) == 0) { |
0 | 1149 |
/* train crossing a road */ |
541 | 1150 |
SndPlayVehicleFx(SND_0E_LEVEL_CROSSING, v); |
2493
f6b4300cc2b0
(svn r3019) -Codechange: Replace explicit shifting/anding/oring with GB and SB
tron
parents:
2471
diff
changeset
|
1151 |
SB(_m[tile].m5, 2, 1, 1); |
0 | 1152 |
MarkTileDirtyByTile(tile); |
1153 |
} |
|
2493
f6b4300cc2b0
(svn r3019) -Codechange: Replace explicit shifting/anding/oring with GB and SB
tron
parents:
2471
diff
changeset
|
1154 |
} else if (GB(_m[tile].m5, 4, 4) == 2) { |
0 | 1155 |
if (v->type == VEH_Road && v->u.road.frame == 11) { |
2493
f6b4300cc2b0
(svn r3019) -Codechange: Replace explicit shifting/anding/oring with GB and SB
tron
parents:
2471
diff
changeset
|
1156 |
if (_roadveh_enter_depot_unk0[GB(_m[tile].m5, 0, 2)] == v->u.road.state) { |
0 | 1157 |
RoadVehEnterDepot(v); |
1158 |
return 4; |
|
1159 |
} |
|
1160 |
} |
|
1161 |
} |
|
1162 |
return 0; |
|
1163 |
} |
|
1164 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
1165 |
static void VehicleLeave_Road(Vehicle *v, TileIndex tile, int x, int y) |
0 | 1166 |
{ |
1927
1181e7652e2f
(svn r2433) - CodeChange: unmagicify all road/train crossings with IsLevelCrossing() function (peter1138)
Darkvater
parents:
1902
diff
changeset
|
1167 |
if (IsLevelCrossing(tile) && v->type == VEH_Train && v->next == NULL) { |
1181e7652e2f
(svn r2433) - CodeChange: unmagicify all road/train crossings with IsLevelCrossing() function (peter1138)
Darkvater
parents:
1902
diff
changeset
|
1168 |
// Turn off level crossing lights |
2493
f6b4300cc2b0
(svn r3019) -Codechange: Replace explicit shifting/anding/oring with GB and SB
tron
parents:
2471
diff
changeset
|
1169 |
SB(_m[tile].m5, 2, 1, 0); |
0 | 1170 |
MarkTileDirtyByTile(tile); |
1171 |
} |
|
1172 |
} |
|
1173 |
||
2436
7d5df545bd5d
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2425
diff
changeset
|
1174 |
static void ChangeTileOwner_Road(TileIndex tile, PlayerID old_player, PlayerID new_player) |
0 | 1175 |
{ |
1176 |
// road/rail crossing where the road is owned by the current player? |
|
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2008
diff
changeset
|
1177 |
if (old_player == _m[tile].m3 && IsLevelCrossing(tile)) { |
2469
59a0073914d8
(svn r2995) Replace 0xFF/0xFFFF with CT_INVALID/OWNER_SPECTATOR/INVALID_STATION where appropriate
tron
parents:
2436
diff
changeset
|
1178 |
_m[tile].m3 = (new_player == OWNER_SPECTATOR) ? OWNER_NONE : new_player; |
0 | 1179 |
} |
1180 |
||
1901
03bf9bf99319
(svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents:
1891
diff
changeset
|
1181 |
if (!IsTileOwner(tile, old_player)) return; |
0 | 1182 |
|
2502 | 1183 |
if (new_player != OWNER_SPECTATOR) { |
1902 | 1184 |
SetTileOwner(tile, new_player); |
0 | 1185 |
} else { |
2493
f6b4300cc2b0
(svn r3019) -Codechange: Replace explicit shifting/anding/oring with GB and SB
tron
parents:
2471
diff
changeset
|
1186 |
if (GB(_m[tile].m5, 4, 4) == 0) { |
1902 | 1187 |
SetTileOwner(tile, OWNER_NONE); |
1927
1181e7652e2f
(svn r2433) - CodeChange: unmagicify all road/train crossings with IsLevelCrossing() function (peter1138)
Darkvater
parents:
1902
diff
changeset
|
1188 |
} else if (IsLevelCrossing(tile)) { |
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2008
diff
changeset
|
1189 |
_m[tile].m5 = (_m[tile].m5&8) ? 0x5 : 0xA; |
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2008
diff
changeset
|
1190 |
SetTileOwner(tile, _m[tile].m3); |
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2008
diff
changeset
|
1191 |
_m[tile].m3 = 0; |
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2008
diff
changeset
|
1192 |
_m[tile].m4 &= 0x80; |
0 | 1193 |
} else { |
1194 |
DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); |
|
1195 |
} |
|
1196 |
} |
|
1197 |
} |
|
1198 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1059
diff
changeset
|
1199 |
void InitializeRoad(void) |
0 | 1200 |
{ |
1201 |
_last_built_road_depot_tile = 0; |
|
1202 |
} |
|
1203 |
||
1204 |
const TileTypeProcs _tile_type_road_procs = { |
|
1205 |
DrawTile_Road, /* draw_tile_proc */ |
|
1206 |
GetSlopeZ_Road, /* get_slope_z_proc */ |
|
1207 |
ClearTile_Road, /* clear_tile_proc */ |
|
1208 |
GetAcceptedCargo_Road, /* get_accepted_cargo_proc */ |
|
1209 |
GetTileDesc_Road, /* get_tile_desc_proc */ |
|
1210 |
GetTileTrackStatus_Road, /* get_tile_track_status_proc */ |
|
1211 |
ClickTile_Road, /* click_tile_proc */ |
|
1212 |
AnimateTile_Road, /* animate_tile_proc */ |
|
1213 |
TileLoop_Road, /* tile_loop_clear */ |
|
1214 |
ChangeTileOwner_Road, /* change_tile_owner_clear */ |
|
1215 |
NULL, /* get_produced_cargo_proc */ |
|
1216 |
VehicleEnter_Road, /* vehicle_enter_tile_proc */ |
|
1217 |
VehicleLeave_Road, /* vehicle_leave_tile_proc */ |
|
39 | 1218 |
GetSlopeTileh_Road, /* get_slope_tileh_proc */ |
0 | 1219 |
}; |