author | miham |
Mon, 11 Dec 2006 18:29:59 +0000 | |
changeset 5321 | dea98c4e14c9 |
parent 5212 | b299ce9bb39f |
child 5427 | 63ce73145566 |
child 5573 | afa6f92a71fd |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
0 | 3 |
#include "stdafx.h" |
1891
92a3b0aa0946
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1785
diff
changeset
|
4 |
#include "openttd.h" |
3189
1af302c5abd0
(svn r3846) Add functions to set the type of stuff (clear, water, rail, road) under bridges
tron
parents:
3176
diff
changeset
|
5 |
#include "bridge_map.h" |
3101
e2fdb8802c2f
(svn r3696) Add functions to turn a tile into a normal rail tile/depot/waypoint. This is just a tiny step, the rail code needs way more love and caring
tron
parents:
3100
diff
changeset
|
6 |
#include "rail_map.h" |
3144
426b825578f9
(svn r3763) Adapt to the new 'map accessors go in foo_map.h'-scheme
tron
parents:
3104
diff
changeset
|
7 |
#include "road_map.h" |
4232
628628eaa4fc
(svn r5796) Use DrawTileSprites/DrawTileSeqStruct for road depot drawing data, too
tron
parents:
4231
diff
changeset
|
8 |
#include "sprite.h" |
2008
c9d6585c96c8
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
1986
diff
changeset
|
9 |
#include "table/sprites.h" |
507
8aa8100b0b22
(svn r815) Include strings.h only in the files which need it.
tron
parents:
497
diff
changeset
|
10 |
#include "table/strings.h" |
2163
637ec3c361f5
(svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents:
2148
diff
changeset
|
11 |
#include "functions.h" |
679
e959706a3e4d
(svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
541
diff
changeset
|
12 |
#include "map.h" |
1209
a1ac96655b79
(svn r1713) Split off several functions which query/set information about a single tile from map.h and put them into a seperate file tile.h
tron
parents:
1095
diff
changeset
|
13 |
#include "tile.h" |
3319
7d04847e4689
(svn r4085) Add GetTown{Index,ByTile}() to get the town index resp. the town from a tile
tron
parents:
3286
diff
changeset
|
14 |
#include "town_map.h" |
0 | 15 |
#include "vehicle.h" |
16 |
#include "viewport.h" |
|
17 |
#include "command.h" |
|
18 |
#include "player.h" |
|
19 |
#include "town.h" |
|
20 |
#include "gfx.h" |
|
337
66647f97e7c0
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
241
diff
changeset
|
21 |
#include "sound.h" |
3900
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3884
diff
changeset
|
22 |
#include "yapf/yapf.h" |
1313
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1281
diff
changeset
|
23 |
#include "depot.h" |
0 | 24 |
|
25 |
||
3381
ebdcc12845c7
(svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents:
3379
diff
changeset
|
26 |
static uint CountRoadBits(RoadBits r) |
ebdcc12845c7
(svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents:
3379
diff
changeset
|
27 |
{ |
ebdcc12845c7
(svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents:
3379
diff
changeset
|
28 |
uint count = 0; |
ebdcc12845c7
(svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents:
3379
diff
changeset
|
29 |
|
ebdcc12845c7
(svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents:
3379
diff
changeset
|
30 |
if (r & ROAD_NW) ++count; |
ebdcc12845c7
(svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents:
3379
diff
changeset
|
31 |
if (r & ROAD_SW) ++count; |
ebdcc12845c7
(svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents:
3379
diff
changeset
|
32 |
if (r & ROAD_SE) ++count; |
ebdcc12845c7
(svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents:
3379
diff
changeset
|
33 |
if (r & ROAD_NE) ++count; |
ebdcc12845c7
(svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents:
3379
diff
changeset
|
34 |
return count; |
ebdcc12845c7
(svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents:
3379
diff
changeset
|
35 |
} |
ebdcc12845c7
(svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents:
3379
diff
changeset
|
36 |
|
ebdcc12845c7
(svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents:
3379
diff
changeset
|
37 |
|
3149
2b54fc654019
(svn r3770) Remove the _road_special_gettrackstatus hack. Egladil and me deem it unnecessary
tron
parents:
3146
diff
changeset
|
38 |
static bool CheckAllowRemoveRoad(TileIndex tile, RoadBits remove, bool* edge_road) |
0 | 39 |
{ |
3149
2b54fc654019
(svn r3770) Remove the _road_special_gettrackstatus hack. Egladil and me deem it unnecessary
tron
parents:
3146
diff
changeset
|
40 |
RoadBits present; |
2b54fc654019
(svn r3770) Remove the _road_special_gettrackstatus hack. Egladil and me deem it unnecessary
tron
parents:
3146
diff
changeset
|
41 |
RoadBits n; |
4849
9a3c3ae7f62f
(svn r6775) -Codechange: Use some more proper types, especially Owner and PlayerID as
Darkvater
parents:
4848
diff
changeset
|
42 |
Owner owner; |
0 | 43 |
*edge_road = true; |
44 |
||
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
45 |
if (_game_mode == GM_EDITOR) return true; |
0 | 46 |
|
47 |
// Only do the special processing for actual players. |
|
4850
b4e9be22945f
(svn r6776) -Codechange: Use IsValidPlayer() function to determine of a PlayerID is an
Darkvater
parents:
4849
diff
changeset
|
48 |
if (!IsValidPlayer(_current_player)) return true; |
0 | 49 |
|
3560
4389ae5ad967
(svn r4435) - Fix: an assertion triggered when trying to remove a bridge with the remove-tool (r4348 surfaced this). In CmdRemoveRoad tiletype was not checked for ownership. Intorudce IsLevelCrossingTile() which checks if a tile is a crossing without knowing the type. Suggested by peter1138 and Tron.
Darkvater
parents:
3491
diff
changeset
|
50 |
owner = IsLevelCrossingTile(tile) ? GetCrossingRoadOwner(tile) : GetTileOwner(tile); |
4389ae5ad967
(svn r4435) - Fix: an assertion triggered when trying to remove a bridge with the remove-tool (r4348 surfaced this). In CmdRemoveRoad tiletype was not checked for ownership. Intorudce IsLevelCrossingTile() which checks if a tile is a crossing without knowing the type. Suggested by peter1138 and Tron.
Darkvater
parents:
3491
diff
changeset
|
51 |
|
0 | 52 |
// Only do the special processing if the road is owned |
53 |
// by a town |
|
4849
9a3c3ae7f62f
(svn r6775) -Codechange: Use some more proper types, especially Owner and PlayerID as
Darkvater
parents:
4848
diff
changeset
|
54 |
if (owner != OWNER_TOWN) return (owner == OWNER_NONE) || CheckOwnership(owner); |
0 | 55 |
|
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
56 |
if (_cheats.magic_bulldozer.value) return true; |
0 | 57 |
|
58 |
// Get a bitmask of which neighbouring roads has a tile |
|
59 |
n = 0; |
|
3149
2b54fc654019
(svn r3770) Remove the _road_special_gettrackstatus hack. Egladil and me deem it unnecessary
tron
parents:
3146
diff
changeset
|
60 |
present = GetAnyRoadBits(tile); |
2b54fc654019
(svn r3770) Remove the _road_special_gettrackstatus hack. Egladil and me deem it unnecessary
tron
parents:
3146
diff
changeset
|
61 |
if (present & ROAD_NE && GetAnyRoadBits(TILE_ADDXY(tile,-1, 0)) & ROAD_SW) n |= ROAD_NE; |
2b54fc654019
(svn r3770) Remove the _road_special_gettrackstatus hack. Egladil and me deem it unnecessary
tron
parents:
3146
diff
changeset
|
62 |
if (present & ROAD_SE && GetAnyRoadBits(TILE_ADDXY(tile, 0, 1)) & ROAD_NW) n |= ROAD_SE; |
2b54fc654019
(svn r3770) Remove the _road_special_gettrackstatus hack. Egladil and me deem it unnecessary
tron
parents:
3146
diff
changeset
|
63 |
if (present & ROAD_SW && GetAnyRoadBits(TILE_ADDXY(tile, 1, 0)) & ROAD_NE) n |= ROAD_SW; |
2b54fc654019
(svn r3770) Remove the _road_special_gettrackstatus hack. Egladil and me deem it unnecessary
tron
parents:
3146
diff
changeset
|
64 |
if (present & ROAD_NW && GetAnyRoadBits(TILE_ADDXY(tile, 0,-1)) & ROAD_SE) n |= ROAD_NW; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
65 |
|
0 | 66 |
// If 0 or 1 bits are set in n, or if no bits that match the bits to remove, |
67 |
// then allow it |
|
3149
2b54fc654019
(svn r3770) Remove the _road_special_gettrackstatus hack. Egladil and me deem it unnecessary
tron
parents:
3146
diff
changeset
|
68 |
if ((n & (n - 1)) != 0 && (n & remove) != 0) { |
0 | 69 |
Town *t; |
70 |
*edge_road = false; |
|
71 |
// you can remove all kind of roads with extra dynamite |
|
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
72 |
if (_patches.extra_dynamite) return true; |
0 | 73 |
|
1638
aae181b00846
(svn r2142) - Fix: Game no longer crashes when you want to remove a piece of road under a bridge that belongs to the town. TODO: railcrossings store owner somewhere else, put it into _map_owner[]!
Darkvater
parents:
1398
diff
changeset
|
74 |
t = ClosestTownFromTile(tile, _patches.dist_local_authority); |
aae181b00846
(svn r2142) - Fix: Game no longer crashes when you want to remove a piece of road under a bridge that belongs to the town. TODO: railcrossings store owner somewhere else, put it into _map_owner[]!
Darkvater
parents:
1398
diff
changeset
|
75 |
|
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
76 |
SetDParam(0, t->index); |
0 | 77 |
_error_message = STR_2009_LOCAL_AUTHORITY_REFUSES; |
78 |
return false; |
|
79 |
} |
|
80 |
||
81 |
return true; |
|
82 |
} |
|
83 |
||
84 |
||
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
85 |
/** Delete a piece of road. |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3435
diff
changeset
|
86 |
* @param tile tile where to remove road from |
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
87 |
* @param p1 road piece flags |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
88 |
* @param p2 unused |
0 | 89 |
*/ |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3435
diff
changeset
|
90 |
int32 CmdRemoveRoad(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 91 |
{ |
1638
aae181b00846
(svn r2142) - Fix: Game no longer crashes when you want to remove a piece of road under a bridge that belongs to the town. TODO: railcrossings store owner somewhere else, put it into _map_owner[]!
Darkvater
parents:
1398
diff
changeset
|
92 |
// cost for removing inner/edge -roads |
aae181b00846
(svn r2142) - Fix: Game no longer crashes when you want to remove a piece of road under a bridge that belongs to the town. TODO: railcrossings store owner somewhere else, put it into _map_owner[]!
Darkvater
parents:
1398
diff
changeset
|
93 |
static const uint16 road_remove_cost[2] = {50, 18}; |
aae181b00846
(svn r2142) - Fix: Game no longer crashes when you want to remove a piece of road under a bridge that belongs to the town. TODO: railcrossings store owner somewhere else, put it into _map_owner[]!
Darkvater
parents:
1398
diff
changeset
|
94 |
|
4849
9a3c3ae7f62f
(svn r6775) -Codechange: Use some more proper types, especially Owner and PlayerID as
Darkvater
parents:
4848
diff
changeset
|
95 |
Owner owner; |
0 | 96 |
Town *t; |
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
97 |
/* true if the roadpiece was always removeable, |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
98 |
* false if it was a center piece. Affects town ratings drop */ |
0 | 99 |
bool edge_road; |
3069
0e6aca11c3da
(svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents:
3068
diff
changeset
|
100 |
RoadBits pieces; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
101 |
|
0 | 102 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
103 |
||
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
104 |
/* Road pieces are max 4 bitset values (NE, NW, SE, SW) */ |
3069
0e6aca11c3da
(svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents:
3068
diff
changeset
|
105 |
if (p1 >> 4) return CMD_ERROR; |
0e6aca11c3da
(svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents:
3068
diff
changeset
|
106 |
pieces = p1; |
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
107 |
|
3977
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
108 |
if (!IsTileType(tile, MP_STREET) && !IsTileType(tile, MP_TUNNELBRIDGE)) return CMD_ERROR; |
2074
f23dcde246da
(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
|
109 |
|
3560
4389ae5ad967
(svn r4435) - Fix: an assertion triggered when trying to remove a bridge with the remove-tool (r4348 surfaced this). In CmdRemoveRoad tiletype was not checked for ownership. Intorudce IsLevelCrossingTile() which checks if a tile is a crossing without knowing the type. Suggested by peter1138 and Tron.
Darkvater
parents:
3491
diff
changeset
|
110 |
owner = IsLevelCrossingTile(tile) ? GetCrossingRoadOwner(tile) : GetTileOwner(tile); |
1638
aae181b00846
(svn r2142) - Fix: Game no longer crashes when you want to remove a piece of road under a bridge that belongs to the town. TODO: railcrossings store owner somewhere else, put it into _map_owner[]!
Darkvater
parents:
1398
diff
changeset
|
111 |
|
aae181b00846
(svn r2142) - Fix: Game no longer crashes when you want to remove a piece of road under a bridge that belongs to the town. TODO: railcrossings store owner somewhere else, put it into _map_owner[]!
Darkvater
parents:
1398
diff
changeset
|
112 |
if (owner == OWNER_TOWN && _game_mode != GM_EDITOR) { |
5009
437645a303b4
(svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents:
4850
diff
changeset
|
113 |
/* Are we removing a piece of road below a bridge, or not. If below |
437645a303b4
(svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents:
4850
diff
changeset
|
114 |
* a bridge we need to calculate the town's index as it is not saved |
437645a303b4
(svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents:
4850
diff
changeset
|
115 |
* in the map array (no space) */ |
437645a303b4
(svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents:
4850
diff
changeset
|
116 |
if (IsTileType(tile, MP_TUNNELBRIDGE)) { |
3977
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
117 |
t = ClosestTownFromTile(tile, _patches.dist_local_authority); |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
118 |
} else { |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
119 |
t = GetTownByTile(tile); |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
120 |
} |
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
121 |
} else { |
1280
b6925875de49
(svn r1784) -Fix: removed ClosestTownFromTile where possible, or replaced it
truelight
parents:
1264
diff
changeset
|
122 |
t = NULL; |
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
123 |
} |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
124 |
|
3149
2b54fc654019
(svn r3770) Remove the _road_special_gettrackstatus hack. Egladil and me deem it unnecessary
tron
parents:
3146
diff
changeset
|
125 |
if (!CheckAllowRemoveRoad(tile, pieces, &edge_road)) return CMD_ERROR; |
0 | 126 |
|
3977
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
127 |
switch (GetTileType(tile)) { |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
128 |
case MP_TUNNELBRIDGE: |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
129 |
if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR; |
3933 | 130 |
|
3977
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
131 |
if (!IsBridge(tile) || |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
132 |
!IsBridgeMiddle(tile) || |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
133 |
!IsTransportUnderBridge(tile) || |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
134 |
GetTransportTypeUnderBridge(tile) != TRANSPORT_ROAD || |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
135 |
(pieces & ComplementRoadBits(GetRoadBitsUnderBridge(tile))) != 0) { |
3176 | 136 |
return CMD_ERROR; |
0 | 137 |
} |
138 |
||
139 |
if (flags & DC_EXEC) { |
|
1638
aae181b00846
(svn r2142) - Fix: Game no longer crashes when you want to remove a piece of road under a bridge that belongs to the town. TODO: railcrossings store owner somewhere else, put it into _map_owner[]!
Darkvater
parents:
1398
diff
changeset
|
140 |
ChangeTownRating(t, -road_remove_cost[(byte)edge_road], RATING_ROAD_MINIMUM); |
3977
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
141 |
SetClearUnderBridge(tile); |
3060 | 142 |
MarkTileDirtyByTile(tile); |
0 | 143 |
} |
3381
ebdcc12845c7
(svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents:
3379
diff
changeset
|
144 |
return _price.remove_road * 2; |
3060 | 145 |
|
3977
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
146 |
case MP_STREET: |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
147 |
if (!EnsureNoVehicle(tile)) return CMD_ERROR; |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
148 |
|
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
149 |
// check if you're allowed to remove the street owned by a town |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
150 |
// removal allowance depends on difficulty setting |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
151 |
if (!CheckforTownRating(flags, t, ROAD_REMOVE)) return CMD_ERROR; |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
152 |
|
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
153 |
switch (GetRoadTileType(tile)) { |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
154 |
case ROAD_TILE_NORMAL: { |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
155 |
RoadBits present = GetRoadBits(tile); |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
156 |
RoadBits c = pieces; |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
157 |
|
4046
566de0b02064
(svn r5315) -Fix: Prohibit altering a road tile while road works are in progress
tron
parents:
4000
diff
changeset
|
158 |
if (HasRoadWorks(tile)) return_cmd_error(STR_ROAD_WORKS_IN_PROGRESS); |
566de0b02064
(svn r5315) -Fix: Prohibit altering a road tile while road works are in progress
tron
parents:
4000
diff
changeset
|
159 |
|
3977
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
160 |
if (GetTileSlope(tile, NULL) != SLOPE_FLAT && |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
161 |
(present == ROAD_Y || present == ROAD_X)) { |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
162 |
c |= (c & 0xC) >> 2; |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
163 |
c |= (c & 0x3) << 2; |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
164 |
} |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
165 |
|
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
166 |
// limit the bits to delete to the existing bits. |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
167 |
c &= present; |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
168 |
if (c == 0) return CMD_ERROR; |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
169 |
|
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
170 |
if (flags & DC_EXEC) { |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
171 |
ChangeTownRating(t, -road_remove_cost[(byte)edge_road], RATING_ROAD_MINIMUM); |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
172 |
|
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
173 |
present ^= c; |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
174 |
if (present == 0) { |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
175 |
DoClearSquare(tile); |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
176 |
} else { |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
177 |
SetRoadBits(tile, present); |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
178 |
MarkTileDirtyByTile(tile); |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
179 |
} |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
180 |
} |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
181 |
return CountRoadBits(c) * _price.remove_road; |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
182 |
} |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
183 |
|
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
184 |
case ROAD_TILE_CROSSING: { |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
185 |
if (pieces & ComplementRoadBits(GetCrossingRoadBits(tile))) { |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
186 |
return CMD_ERROR; |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
187 |
} |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
188 |
|
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
189 |
if (flags & DC_EXEC) { |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
190 |
ChangeTownRating(t, -road_remove_cost[(byte)edge_road], RATING_ROAD_MINIMUM); |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
191 |
|
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
192 |
MakeRailNormal(tile, GetTileOwner(tile), GetCrossingRailBits(tile), GetRailTypeCrossing(tile)); |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
193 |
MarkTileDirtyByTile(tile); |
5212
b299ce9bb39f
(svn r7327) -Fix: [YAPF] missing YAPF cache notification when building road on rail (new crossing) or removing road from crossing
KUDr
parents:
5148
diff
changeset
|
194 |
YapfNotifyTrackLayoutChange(tile, FIND_FIRST_BIT(GetTrackBits(tile))); |
3977
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
195 |
} |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
196 |
return _price.remove_road * 2; |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
197 |
} |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
198 |
|
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
199 |
default: |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
200 |
case ROAD_TILE_DEPOT: |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
201 |
return CMD_ERROR; |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
202 |
} |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
203 |
|
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
204 |
default: return CMD_ERROR; |
0 | 205 |
} |
206 |
} |
|
207 |
||
208 |
||
3104
106ca8c3d959
(svn r3699) Replace some magic numbers for checking for a suitable slope for a level crossing by some less magic numbers
tron
parents:
3103
diff
changeset
|
209 |
static const RoadBits _valid_tileh_slopes_road[][15] = { |
0 | 210 |
// set of normal ones |
211 |
{ |
|
212 |
ROAD_ALL, 0, 0, |
|
3098
4c1320da876d
(svn r3687) Complete some bits I missed whenn adding accessor functions for road types and pieces
tron
parents:
3097
diff
changeset
|
213 |
ROAD_X, 0, 0, // 3, 4, 5 |
4c1320da876d
(svn r3687) Complete some bits I missed whenn adding accessor functions for road types and pieces
tron
parents:
3097
diff
changeset
|
214 |
ROAD_Y, 0, 0, |
4c1320da876d
(svn r3687) Complete some bits I missed whenn adding accessor functions for road types and pieces
tron
parents:
3097
diff
changeset
|
215 |
ROAD_Y, 0, 0, // 9, 10, 11 |
4c1320da876d
(svn r3687) Complete some bits I missed whenn adding accessor functions for road types and pieces
tron
parents:
3097
diff
changeset
|
216 |
ROAD_X, 0, 0 |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
217 |
}, |
0 | 218 |
// 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
|
219 |
{ |
0 | 220 |
0, |
221 |
ROAD_SW | ROAD_NW, |
|
222 |
ROAD_SW | ROAD_SE, |
|
3098
4c1320da876d
(svn r3687) Complete some bits I missed whenn adding accessor functions for road types and pieces
tron
parents:
3097
diff
changeset
|
223 |
ROAD_Y | ROAD_SW, |
0 | 224 |
|
225 |
ROAD_SE | ROAD_NE, // 4 |
|
226 |
ROAD_ALL, |
|
3098
4c1320da876d
(svn r3687) Complete some bits I missed whenn adding accessor functions for road types and pieces
tron
parents:
3097
diff
changeset
|
227 |
ROAD_X | ROAD_SE, |
0 | 228 |
ROAD_ALL, |
229 |
||
230 |
ROAD_NW | ROAD_NE, // 8 |
|
3098
4c1320da876d
(svn r3687) Complete some bits I missed whenn adding accessor functions for road types and pieces
tron
parents:
3097
diff
changeset
|
231 |
ROAD_X | ROAD_NW, |
0 | 232 |
ROAD_ALL, |
233 |
ROAD_ALL, |
|
234 |
||
3098
4c1320da876d
(svn r3687) Complete some bits I missed whenn adding accessor functions for road types and pieces
tron
parents:
3097
diff
changeset
|
235 |
ROAD_Y | ROAD_NE, // 12 |
0 | 236 |
ROAD_ALL, |
237 |
ROAD_ALL |
|
13
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
238 |
}, |
0 | 239 |
}; |
240 |
||
241 |
||
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3560
diff
changeset
|
242 |
static uint32 CheckRoadSlope(Slope tileh, RoadBits* pieces, RoadBits existing) |
0 | 243 |
{ |
3381
ebdcc12845c7
(svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents:
3379
diff
changeset
|
244 |
RoadBits road_bits; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
245 |
|
4246
14a8849c32df
(svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents:
4232
diff
changeset
|
246 |
if (IsSteepSlope(tileh)) { |
14a8849c32df
(svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents:
4232
diff
changeset
|
247 |
if (existing == 0) { |
14a8849c32df
(svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents:
4232
diff
changeset
|
248 |
// force full pieces. |
14a8849c32df
(svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents:
4232
diff
changeset
|
249 |
*pieces |= (*pieces & 0xC) >> 2; |
14a8849c32df
(svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents:
4232
diff
changeset
|
250 |
*pieces |= (*pieces & 0x3) << 2; |
14a8849c32df
(svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents:
4232
diff
changeset
|
251 |
if (*pieces == ROAD_X || *pieces == ROAD_Y) return _price.terraform; |
14a8849c32df
(svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents:
4232
diff
changeset
|
252 |
} |
14a8849c32df
(svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents:
4232
diff
changeset
|
253 |
return CMD_ERROR; |
14a8849c32df
(svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents:
4232
diff
changeset
|
254 |
} |
3381
ebdcc12845c7
(svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents:
3379
diff
changeset
|
255 |
road_bits = *pieces | existing; |
0 | 256 |
|
3381
ebdcc12845c7
(svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents:
3379
diff
changeset
|
257 |
// no special foundation |
ebdcc12845c7
(svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents:
3379
diff
changeset
|
258 |
if ((~_valid_tileh_slopes_road[0][tileh] & road_bits) == 0) { |
ebdcc12845c7
(svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents:
3379
diff
changeset
|
259 |
// force that all bits are set when we have slopes |
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3560
diff
changeset
|
260 |
if (tileh != SLOPE_FLAT) *pieces |= _valid_tileh_slopes_road[0][tileh]; |
3381
ebdcc12845c7
(svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents:
3379
diff
changeset
|
261 |
return 0; // no extra cost |
ebdcc12845c7
(svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents:
3379
diff
changeset
|
262 |
} |
ebdcc12845c7
(svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents:
3379
diff
changeset
|
263 |
|
ebdcc12845c7
(svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents:
3379
diff
changeset
|
264 |
// foundation is used. Whole tile is leveled up |
ebdcc12845c7
(svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents:
3379
diff
changeset
|
265 |
if ((~_valid_tileh_slopes_road[1][tileh] & road_bits) == 0) { |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4048
diff
changeset
|
266 |
return existing != 0 ? 0 : _price.terraform; |
3381
ebdcc12845c7
(svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents:
3379
diff
changeset
|
267 |
} |
ebdcc12845c7
(svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents:
3379
diff
changeset
|
268 |
|
ebdcc12845c7
(svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents:
3379
diff
changeset
|
269 |
// partly leveled up tile, only if there's no road on that tile |
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3560
diff
changeset
|
270 |
if (existing == 0 && (tileh == SLOPE_W || tileh == SLOPE_S || tileh == SLOPE_E || tileh == SLOPE_N)) { |
3381
ebdcc12845c7
(svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents:
3379
diff
changeset
|
271 |
// force full pieces. |
ebdcc12845c7
(svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents:
3379
diff
changeset
|
272 |
*pieces |= (*pieces & 0xC) >> 2; |
ebdcc12845c7
(svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents:
3379
diff
changeset
|
273 |
*pieces |= (*pieces & 0x3) << 2; |
ebdcc12845c7
(svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents:
3379
diff
changeset
|
274 |
if (*pieces == ROAD_X || *pieces == ROAD_Y) return _price.terraform; |
0 | 275 |
} |
276 |
return CMD_ERROR; |
|
277 |
} |
|
278 |
||
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
279 |
/** Build a piece of road. |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3435
diff
changeset
|
280 |
* @param tile tile where to build road |
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
281 |
* @param p1 road piece flags |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
282 |
* @param p2 the town that is building the road (0 if not applicable) |
0 | 283 |
*/ |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3435
diff
changeset
|
284 |
int32 CmdBuildRoad(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 285 |
{ |
3381
ebdcc12845c7
(svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents:
3379
diff
changeset
|
286 |
int32 cost = 0; |
ebdcc12845c7
(svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents:
3379
diff
changeset
|
287 |
int32 ret; |
3150
025fe8cd7104
(svn r3773) Shove some semantics down ottd's throat by replacing ints and magic numbers by enums and some related changes
tron
parents:
3149
diff
changeset
|
288 |
RoadBits existing = 0; |
025fe8cd7104
(svn r3773) Shove some semantics down ottd's throat by replacing ints and magic numbers by enums and some related changes
tron
parents:
3149
diff
changeset
|
289 |
RoadBits pieces; |
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3560
diff
changeset
|
290 |
Slope tileh; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
291 |
|
0 | 292 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
293 |
||
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
294 |
/* Road pieces are max 4 bitset values (NE, NW, SE, SW) and town can only be non-zero |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
295 |
* if a non-player is building the road */ |
4850
b4e9be22945f
(svn r6776) -Codechange: Use IsValidPlayer() function to determine of a PlayerID is an
Darkvater
parents:
4849
diff
changeset
|
296 |
if ((p1 >> 4) || (IsValidPlayer(_current_player) && p2 != 0) || !IsValidTownID(p2)) return CMD_ERROR; |
3150
025fe8cd7104
(svn r3773) Shove some semantics down ottd's throat by replacing ints and magic numbers by enums and some related changes
tron
parents:
3149
diff
changeset
|
297 |
pieces = p1; |
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
298 |
|
3434
21094a78dcdb
(svn r4263) -Codechange: Road building no longer uses FindLandscapeHeight. Last occurence of FindLandscapeTile in the tile-specific functions gone. Thanks to Tron for doing lots of work in this direction
celestar
parents:
3430
diff
changeset
|
299 |
tileh = GetTileSlope(tile, NULL); |
0 | 300 |
|
3434
21094a78dcdb
(svn r4263) -Codechange: Road building no longer uses FindLandscapeHeight. Last occurence of FindLandscapeTile in the tile-specific functions gone. Thanks to Tron for doing lots of work in this direction
celestar
parents:
3430
diff
changeset
|
301 |
switch (GetTileType(tile)) { |
3060 | 302 |
case MP_STREET: |
3793
33cdb5bf7b21
(svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents:
3792
diff
changeset
|
303 |
switch (GetRoadTileType(tile)) { |
33cdb5bf7b21
(svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents:
3792
diff
changeset
|
304 |
case ROAD_TILE_NORMAL: |
4046
566de0b02064
(svn r5315) -Fix: Prohibit altering a road tile while road works are in progress
tron
parents:
4000
diff
changeset
|
305 |
if (HasRoadWorks(tile)) return_cmd_error(STR_ROAD_WORKS_IN_PROGRESS); |
566de0b02064
(svn r5315) -Fix: Prohibit altering a road tile while road works are in progress
tron
parents:
4000
diff
changeset
|
306 |
|
3150
025fe8cd7104
(svn r3773) Shove some semantics down ottd's throat by replacing ints and magic numbers by enums and some related changes
tron
parents:
3149
diff
changeset
|
307 |
existing = GetRoadBits(tile); |
025fe8cd7104
(svn r3773) Shove some semantics down ottd's throat by replacing ints and magic numbers by enums and some related changes
tron
parents:
3149
diff
changeset
|
308 |
if ((existing & pieces) == pieces) { |
3066
0d34dff23d98
(svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents:
3061
diff
changeset
|
309 |
return_cmd_error(STR_1007_ALREADY_BUILT); |
0d34dff23d98
(svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents:
3061
diff
changeset
|
310 |
} |
3381
ebdcc12845c7
(svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents:
3379
diff
changeset
|
311 |
if (!EnsureNoVehicle(tile)) return CMD_ERROR; |
3066
0d34dff23d98
(svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents:
3061
diff
changeset
|
312 |
break; |
0d34dff23d98
(svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents:
3061
diff
changeset
|
313 |
|
3793
33cdb5bf7b21
(svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents:
3792
diff
changeset
|
314 |
case ROAD_TILE_CROSSING: |
3150
025fe8cd7104
(svn r3773) Shove some semantics down ottd's throat by replacing ints and magic numbers by enums and some related changes
tron
parents:
3149
diff
changeset
|
315 |
if (pieces != GetCrossingRoadBits(tile)) { // XXX is this correct? |
3066
0d34dff23d98
(svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents:
3061
diff
changeset
|
316 |
return_cmd_error(STR_1007_ALREADY_BUILT); |
0d34dff23d98
(svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents:
3061
diff
changeset
|
317 |
} |
0d34dff23d98
(svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents:
3061
diff
changeset
|
318 |
goto do_clear; |
0d34dff23d98
(svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents:
3061
diff
changeset
|
319 |
|
3069
0e6aca11c3da
(svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents:
3068
diff
changeset
|
320 |
default: |
3793
33cdb5bf7b21
(svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents:
3792
diff
changeset
|
321 |
case ROAD_TILE_DEPOT: |
3066
0d34dff23d98
(svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents:
3061
diff
changeset
|
322 |
goto do_clear; |
3060 | 323 |
} |
324 |
break; |
|
0 | 325 |
|
3060 | 326 |
case MP_RAILWAY: { |
3099
374e275300e3
(svn r3689) Add functions to turn a tile into either a normal road tile, a level crossing or a road depot
tron
parents:
3098
diff
changeset
|
327 |
Axis roaddir; |
13
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
328 |
|
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3560
diff
changeset
|
329 |
if (IsSteepSlope(tileh)) { |
3060 | 330 |
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); |
331 |
} |
|
332 |
||
3104
106ca8c3d959
(svn r3699) Replace some magic numbers for checking for a suitable slope for a level crossing by some less magic numbers
tron
parents:
3103
diff
changeset
|
333 |
#define M(x) (1 << (x)) |
106ca8c3d959
(svn r3699) Replace some magic numbers for checking for a suitable slope for a level crossing by some less magic numbers
tron
parents:
3103
diff
changeset
|
334 |
/* Level crossings may only be built on these slopes */ |
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3560
diff
changeset
|
335 |
if (!HASBIT(M(SLOPE_SEN) | M(SLOPE_ENW) | M(SLOPE_NWS) | M(SLOPE_NS) | M(SLOPE_WSE) | M(SLOPE_EW) | M(SLOPE_FLAT), tileh)) { |
3060 | 336 |
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); |
337 |
} |
|
3104
106ca8c3d959
(svn r3699) Replace some magic numbers for checking for a suitable slope for a level crossing by some less magic numbers
tron
parents:
3103
diff
changeset
|
338 |
#undef M |
3060 | 339 |
|
3792
2eb8388731bf
(svn r4788) - Codechange: RAILTYPE_{NORMAL,ELECTRIC,...} and RAIL_TYPE_{NORMAL,SIGNAL,...} have nearly the same name, rename RAIL_TYPE_* to RAIL_TILE_* of extra clarity
rubidium
parents:
3673
diff
changeset
|
340 |
if (GetRailTileType(tile) != RAIL_TILE_NORMAL) goto do_clear; |
3269
95e7bffcb3c5
(svn r3981) More work for the rail accessing functions and enums
tron
parents:
3267
diff
changeset
|
341 |
switch (GetTrackBits(tile)) { |
95e7bffcb3c5
(svn r3981) More work for the rail accessing functions and enums
tron
parents:
3267
diff
changeset
|
342 |
case TRACK_BIT_X: |
95e7bffcb3c5
(svn r3981) More work for the rail accessing functions and enums
tron
parents:
3267
diff
changeset
|
343 |
if (pieces & ROAD_X) goto do_clear; |
95e7bffcb3c5
(svn r3981) More work for the rail accessing functions and enums
tron
parents:
3267
diff
changeset
|
344 |
roaddir = AXIS_Y; |
95e7bffcb3c5
(svn r3981) More work for the rail accessing functions and enums
tron
parents:
3267
diff
changeset
|
345 |
break; |
95e7bffcb3c5
(svn r3981) More work for the rail accessing functions and enums
tron
parents:
3267
diff
changeset
|
346 |
|
95e7bffcb3c5
(svn r3981) More work for the rail accessing functions and enums
tron
parents:
3267
diff
changeset
|
347 |
case TRACK_BIT_Y: |
95e7bffcb3c5
(svn r3981) More work for the rail accessing functions and enums
tron
parents:
3267
diff
changeset
|
348 |
if (pieces & ROAD_Y) goto do_clear; |
95e7bffcb3c5
(svn r3981) More work for the rail accessing functions and enums
tron
parents:
3267
diff
changeset
|
349 |
roaddir = AXIS_X; |
95e7bffcb3c5
(svn r3981) More work for the rail accessing functions and enums
tron
parents:
3267
diff
changeset
|
350 |
break; |
95e7bffcb3c5
(svn r3981) More work for the rail accessing functions and enums
tron
parents:
3267
diff
changeset
|
351 |
|
95e7bffcb3c5
(svn r3981) More work for the rail accessing functions and enums
tron
parents:
3267
diff
changeset
|
352 |
default: goto do_clear; |
3060 | 353 |
} |
354 |
||
3381
ebdcc12845c7
(svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents:
3379
diff
changeset
|
355 |
if (!EnsureNoVehicle(tile)) return CMD_ERROR; |
ebdcc12845c7
(svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents:
3379
diff
changeset
|
356 |
|
3060 | 357 |
if (flags & DC_EXEC) { |
5212
b299ce9bb39f
(svn r7327) -Fix: [YAPF] missing YAPF cache notification when building road on rail (new crossing) or removing road from crossing
KUDr
parents:
5148
diff
changeset
|
358 |
YapfNotifyTrackLayoutChange(tile, FIND_FIRST_BIT(GetTrackBits(tile))); |
3242
1cefa03f0d5e
(svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents:
3234
diff
changeset
|
359 |
MakeRoadCrossing(tile, _current_player, GetTileOwner(tile), roaddir, GetRailType(tile), p2); |
3100
552cf19c49cb
(svn r3695) Add 2 MarkTileByTile() which I forgot in r3689 (noticed by Belugas)
tron
parents:
3099
diff
changeset
|
360 |
MarkTileDirtyByTile(tile); |
3060 | 361 |
} |
362 |
return _price.build_road * 2; |
|
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
363 |
} |
0 | 364 |
|
3977
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
365 |
case MP_TUNNELBRIDGE: |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
366 |
if (!IsBridge(tile) || !IsBridgeMiddle(tile)) goto do_clear; |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
367 |
|
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
368 |
/* only allow roads pertendicular to bridge */ |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
369 |
if ((pieces & (GetBridgeAxis(tile) == AXIS_X ? ROAD_X : ROAD_Y)) != 0) { |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
370 |
goto do_clear; |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
371 |
} |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
372 |
|
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
373 |
/* check if clear land under bridge */ |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
374 |
if (IsTransportUnderBridge(tile)) { |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
375 |
switch (GetTransportTypeUnderBridge(tile)) { |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
376 |
case TRANSPORT_ROAD: return_cmd_error(STR_1007_ALREADY_BUILT); |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
377 |
default: return_cmd_error(STR_1008_MUST_REMOVE_RAILROAD_TRACK); |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
378 |
} |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
379 |
} else { |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
380 |
if (IsWaterUnderBridge(tile)) { |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
381 |
return_cmd_error(STR_3807_CAN_T_BUILD_ON_WATER); |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
382 |
} |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
383 |
} |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
384 |
|
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
385 |
if (flags & DC_EXEC) { |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
386 |
SetRoadUnderBridge(tile, _current_player); |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
387 |
MarkTileDirtyByTile(tile); |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
388 |
} |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
389 |
return _price.build_road * 2; |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
390 |
|
3060 | 391 |
default: |
0 | 392 |
do_clear:; |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3435
diff
changeset
|
393 |
ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
3381
ebdcc12845c7
(svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents:
3379
diff
changeset
|
394 |
if (CmdFailed(ret)) return ret; |
ebdcc12845c7
(svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents:
3379
diff
changeset
|
395 |
cost += ret; |
0 | 396 |
} |
397 |
||
3434
21094a78dcdb
(svn r4263) -Codechange: Road building no longer uses FindLandscapeHeight. Last occurence of FindLandscapeTile in the tile-specific functions gone. Thanks to Tron for doing lots of work in this direction
celestar
parents:
3430
diff
changeset
|
398 |
ret = CheckRoadSlope(tileh, &pieces, existing); |
3670
05913fabaebb
(svn r4585) - Fix [FS#130] - Obscure road dragging bug. The road build command did not return the appropiate error message of invalid-slope when building road.
Darkvater
parents:
3657
diff
changeset
|
399 |
/* Return an error if we need to build a foundation (ret != 0) but the |
05913fabaebb
(svn r4585) - Fix [FS#130] - Obscure road dragging bug. The road build command did not return the appropiate error message of invalid-slope when building road.
Darkvater
parents:
3657
diff
changeset
|
400 |
* current patch-setting is turned off (or stupid AI@work) */ |
3673
53c64edf6aeb
(svn r4590) - Fix (r4585): warning: suggest parentheses around && within ||. Sorry
Darkvater
parents:
3671
diff
changeset
|
401 |
if (CmdFailed(ret) || (ret != 0 && (!_patches.build_on_slopes || _is_old_ai_player))) |
3670
05913fabaebb
(svn r4585) - Fix [FS#130] - Obscure road dragging bug. The road build command did not return the appropiate error message of invalid-slope when building road.
Darkvater
parents:
3657
diff
changeset
|
402 |
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); |
05913fabaebb
(svn r4585) - Fix [FS#130] - Obscure road dragging bug. The road build command did not return the appropiate error message of invalid-slope when building road.
Darkvater
parents:
3657
diff
changeset
|
403 |
|
3381
ebdcc12845c7
(svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents:
3379
diff
changeset
|
404 |
cost += ret; |
0 | 405 |
|
3434
21094a78dcdb
(svn r4263) -Codechange: Road building no longer uses FindLandscapeHeight. Last occurence of FindLandscapeTile in the tile-specific functions gone. Thanks to Tron for doing lots of work in this direction
celestar
parents:
3430
diff
changeset
|
406 |
if (IsTileType(tile, MP_STREET)) { |
3150
025fe8cd7104
(svn r3773) Shove some semantics down ottd's throat by replacing ints and magic numbers by enums and some related changes
tron
parents:
3149
diff
changeset
|
407 |
// Don't put the pieces that already exist |
025fe8cd7104
(svn r3773) Shove some semantics down ottd's throat by replacing ints and magic numbers by enums and some related changes
tron
parents:
3149
diff
changeset
|
408 |
pieces &= ComplementRoadBits(existing); |
0 | 409 |
} |
410 |
||
3381
ebdcc12845c7
(svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents:
3379
diff
changeset
|
411 |
cost += CountRoadBits(pieces) * _price.build_road; |
0 | 412 |
|
413 |
if (flags & DC_EXEC) { |
|
3434
21094a78dcdb
(svn r4263) -Codechange: Road building no longer uses FindLandscapeHeight. Last occurence of FindLandscapeTile in the tile-specific functions gone. Thanks to Tron for doing lots of work in this direction
celestar
parents:
3430
diff
changeset
|
414 |
if (IsTileType(tile, MP_STREET)) { |
3150
025fe8cd7104
(svn r3773) Shove some semantics down ottd's throat by replacing ints and magic numbers by enums and some related changes
tron
parents:
3149
diff
changeset
|
415 |
SetRoadBits(tile, existing | pieces); |
025fe8cd7104
(svn r3773) Shove some semantics down ottd's throat by replacing ints and magic numbers by enums and some related changes
tron
parents:
3149
diff
changeset
|
416 |
} else { |
3099
374e275300e3
(svn r3689) Add functions to turn a tile into either a normal road tile, a level crossing or a road depot
tron
parents:
3098
diff
changeset
|
417 |
MakeRoadNormal(tile, _current_player, pieces, p2); |
0 | 418 |
} |
419 |
||
420 |
MarkTileDirtyByTile(tile); |
|
421 |
} |
|
422 |
return cost; |
|
423 |
} |
|
424 |
||
3435
f299c6f48763
(svn r4265) - Fix: compile warning on VS2005 (parameter 2 different from declaration)
Darkvater
parents:
3434
diff
changeset
|
425 |
int32 DoConvertStreetRail(TileIndex tile, RailType totype, bool exec) |
0 | 426 |
{ |
427 |
// not a railroad crossing? |
|
1927
4126e0e3e884
(svn r2433) - CodeChange: unmagicify all road/train crossings with IsLevelCrossing() function (peter1138)
Darkvater
parents:
1902
diff
changeset
|
428 |
if (!IsLevelCrossing(tile)) return CMD_ERROR; |
0 | 429 |
|
430 |
// not owned by me? |
|
431 |
if (!CheckTileOwnership(tile) || !EnsureNoVehicle(tile)) return CMD_ERROR; |
|
432 |
||
3242
1cefa03f0d5e
(svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents:
3234
diff
changeset
|
433 |
if (GetRailTypeCrossing(tile) == totype) return CMD_ERROR; |
0 | 434 |
|
5116
2a33a74925c5
(svn r7195) -Feature: [FS#297, optional elrails] New patches/vehicles option 'disable electrified railways'.
KUDr
parents:
5009
diff
changeset
|
435 |
// 'hidden' elrails can't be downgraded to normal rail when elrails are disabled |
2a33a74925c5
(svn r7195) -Feature: [FS#297, optional elrails] New patches/vehicles option 'disable electrified railways'.
KUDr
parents:
5009
diff
changeset
|
436 |
if (_patches.disable_elrails && totype == RAILTYPE_RAIL && GetRailTypeCrossing(tile) == RAILTYPE_ELECTRIC) return CMD_ERROR; |
2a33a74925c5
(svn r7195) -Feature: [FS#297, optional elrails] New patches/vehicles option 'disable electrified railways'.
KUDr
parents:
5009
diff
changeset
|
437 |
|
0 | 438 |
if (exec) { |
3242
1cefa03f0d5e
(svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents:
3234
diff
changeset
|
439 |
SetRailTypeCrossing(tile, totype); |
0 | 440 |
MarkTileDirtyByTile(tile); |
3900
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3884
diff
changeset
|
441 |
YapfNotifyTrackLayoutChange(tile, FIND_FIRST_BIT(GetCrossingRailBits(tile))); |
0 | 442 |
} |
443 |
||
444 |
return _price.build_rail >> 1; |
|
445 |
} |
|
446 |
||
447 |
||
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
448 |
/** Build a long piece of road. |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3435
diff
changeset
|
449 |
* @param end_tile end tile of drag |
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
450 |
* @param p1 start tile of drag |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
451 |
* @param p2 various bitstuffed elements |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
452 |
* - p2 = (bit 0) - start tile starts in the 2nd half of tile (p2 & 1) |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
453 |
* - p2 = (bit 1) - end tile starts in the 2nd half of tile (p2 & 2) |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
454 |
* - p2 = (bit 2) - direction: 0 = along x-axis, 1 = along y-axis (p2 & 4) |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
455 |
*/ |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3435
diff
changeset
|
456 |
int32 CmdBuildLongRoad(TileIndex end_tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 457 |
{ |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3435
diff
changeset
|
458 |
TileIndex start_tile, tile; |
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
459 |
int32 cost, ret; |
0 | 460 |
|
889
7f8630bfea41
(svn r1375) -Fix: [1050990] Buying trains sometimes accounted for incorrectly. Was the result of the cost getting reset in a recursive call of docommand. That is fixed. In addition all cost-commands are typed explicitely. Please do not forget to do so or your costs will be credited to construction if you are unlucky.
darkvater
parents:
817
diff
changeset
|
461 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
7f8630bfea41
(svn r1375) -Fix: [1050990] Buying trains sometimes accounted for incorrectly. Was the result of the cost getting reset in a recursive call of docommand. That is fixed. In addition all cost-commands are typed explicitely. Please do not forget to do so or your costs will be credited to construction if you are unlucky.
darkvater
parents:
817
diff
changeset
|
462 |
|
2934
3b7eef9871f8
(svn r3490) -Fix: A bunch (10) of off-by-one errors when checking if a TileIndex points to a tile on the map
tron
parents:
2916
diff
changeset
|
463 |
if (p1 >= MapSize()) return CMD_ERROR; |
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
464 |
|
0 | 465 |
start_tile = p1; |
466 |
||
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
467 |
/* Only drag in X or Y direction dictated by the direction variable */ |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
468 |
if (!HASBIT(p2, 2) && TileY(start_tile) != TileY(end_tile)) return CMD_ERROR; // x-axis |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
469 |
if (HASBIT(p2, 2) && TileX(start_tile) != TileX(end_tile)) return CMD_ERROR; // y-axis |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
470 |
|
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
471 |
/* Swap start and ending tile, also the half-tile drag var (bit 0 and 1) */ |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
472 |
if (start_tile > end_tile || (start_tile == end_tile && HASBIT(p2, 0))) { |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
473 |
TileIndex t = start_tile; |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
474 |
start_tile = end_tile; |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
475 |
end_tile = t; |
0 | 476 |
p2 ^= IS_INT_INSIDE(p2&3, 1, 3) ? 3 : 0; |
477 |
} |
|
478 |
||
479 |
cost = 0; |
|
480 |
tile = start_tile; |
|
481 |
// Start tile is the small number. |
|
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
482 |
for (;;) { |
3098
4c1320da876d
(svn r3687) Complete some bits I missed whenn adding accessor functions for road types and pieces
tron
parents:
3097
diff
changeset
|
483 |
RoadBits bits = HASBIT(p2, 2) ? ROAD_Y : ROAD_X; |
4c1320da876d
(svn r3687) Complete some bits I missed whenn adding accessor functions for road types and pieces
tron
parents:
3097
diff
changeset
|
484 |
|
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
485 |
if (tile == end_tile && !HASBIT(p2, 1)) bits &= ROAD_NW | ROAD_NE; |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
486 |
if (tile == start_tile && HASBIT(p2, 0)) bits &= ROAD_SE | ROAD_SW; |
0 | 487 |
|
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3435
diff
changeset
|
488 |
ret = DoCommand(tile, bits, 0, flags, CMD_BUILD_ROAD); |
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
489 |
if (CmdFailed(ret)) { |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
490 |
if (_error_message != STR_1007_ALREADY_BUILT) return CMD_ERROR; |
3671
6d3a34989d05
(svn r4586) - Codechange: Recursive commands that rely on _error_message to handle success/failure can fail if a recursive call fails but doesn't set the error message, thus resulting in an old, possibly erroneous being used (see FS#130 prior to r4585). Now properly reset the global variable _error_message in these cases.
Darkvater
parents:
3670
diff
changeset
|
491 |
_error_message = INVALID_STRING_ID; |
2549 | 492 |
} else { |
0 | 493 |
cost += ret; |
2549 | 494 |
} |
0 | 495 |
|
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
496 |
if (tile == end_tile) break; |
0 | 497 |
|
1981 | 498 |
tile += HASBIT(p2, 2) ? TileDiffXY(0, 1) : TileDiffXY(1, 0); |
0 | 499 |
} |
500 |
||
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
501 |
return (cost == 0) ? CMD_ERROR : cost; |
0 | 502 |
} |
503 |
||
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
504 |
/** Remove a long piece of road. |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3435
diff
changeset
|
505 |
* @param end_tile end tile of drag |
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
506 |
* @param p1 start tile of drag |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
507 |
* @param p2 various bitstuffed elements |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
508 |
* - p2 = (bit 0) - start tile starts in the 2nd half of tile (p2 & 1) |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
509 |
* - p2 = (bit 1) - end tile starts in the 2nd half of tile (p2 & 2) |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
510 |
* - p2 = (bit 2) - direction: 0 = along x-axis, 1 = along y-axis (p2 & 4) |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
511 |
*/ |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3435
diff
changeset
|
512 |
int32 CmdRemoveLongRoad(TileIndex end_tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 513 |
{ |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3435
diff
changeset
|
514 |
TileIndex start_tile, tile; |
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
515 |
int32 cost, ret; |
0 | 516 |
|
889
7f8630bfea41
(svn r1375) -Fix: [1050990] Buying trains sometimes accounted for incorrectly. Was the result of the cost getting reset in a recursive call of docommand. That is fixed. In addition all cost-commands are typed explicitely. Please do not forget to do so or your costs will be credited to construction if you are unlucky.
darkvater
parents:
817
diff
changeset
|
517 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
7f8630bfea41
(svn r1375) -Fix: [1050990] Buying trains sometimes accounted for incorrectly. Was the result of the cost getting reset in a recursive call of docommand. That is fixed. In addition all cost-commands are typed explicitely. Please do not forget to do so or your costs will be credited to construction if you are unlucky.
darkvater
parents:
817
diff
changeset
|
518 |
|
2934
3b7eef9871f8
(svn r3490) -Fix: A bunch (10) of off-by-one errors when checking if a TileIndex points to a tile on the map
tron
parents:
2916
diff
changeset
|
519 |
if (p1 >= MapSize()) return CMD_ERROR; |
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
520 |
|
0 | 521 |
start_tile = p1; |
522 |
||
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
523 |
/* Only drag in X or Y direction dictated by the direction variable */ |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
524 |
if (!HASBIT(p2, 2) && TileY(start_tile) != TileY(end_tile)) return CMD_ERROR; // x-axis |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
525 |
if (HASBIT(p2, 2) && TileX(start_tile) != TileX(end_tile)) return CMD_ERROR; // y-axis |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
526 |
|
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
527 |
/* Swap start and ending tile, also the half-tile drag var (bit 0 and 1) */ |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
528 |
if (start_tile > end_tile || (start_tile == end_tile && HASBIT(p2, 0))) { |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
529 |
TileIndex t = start_tile; |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
530 |
start_tile = end_tile; |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
531 |
end_tile = t; |
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
532 |
p2 ^= IS_INT_INSIDE(p2 & 3, 1, 3) ? 3 : 0; |
0 | 533 |
} |
534 |
||
535 |
cost = 0; |
|
536 |
tile = start_tile; |
|
537 |
// Start tile is the small number. |
|
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
538 |
for (;;) { |
3098
4c1320da876d
(svn r3687) Complete some bits I missed whenn adding accessor functions for road types and pieces
tron
parents:
3097
diff
changeset
|
539 |
RoadBits bits = HASBIT(p2, 2) ? ROAD_Y : ROAD_X; |
4c1320da876d
(svn r3687) Complete some bits I missed whenn adding accessor functions for road types and pieces
tron
parents:
3097
diff
changeset
|
540 |
|
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
541 |
if (tile == end_tile && !HASBIT(p2, 1)) bits &= ROAD_NW | ROAD_NE; |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
542 |
if (tile == start_tile && HASBIT(p2, 0)) bits &= ROAD_SE | ROAD_SW; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
543 |
|
0 | 544 |
// try to remove the halves. |
3098
4c1320da876d
(svn r3687) Complete some bits I missed whenn adding accessor functions for road types and pieces
tron
parents:
3097
diff
changeset
|
545 |
if (bits != 0) { |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3435
diff
changeset
|
546 |
ret = DoCommand(tile, bits, 0, flags, CMD_REMOVE_ROAD); |
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
547 |
if (!CmdFailed(ret)) cost += ret; |
0 | 548 |
} |
549 |
||
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
550 |
if (tile == end_tile) break; |
0 | 551 |
|
1981 | 552 |
tile += HASBIT(p2, 2) ? TileDiffXY(0, 1) : TileDiffXY(1, 0); |
0 | 553 |
} |
554 |
||
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
555 |
return (cost == 0) ? CMD_ERROR : cost; |
0 | 556 |
} |
557 |
||
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
558 |
/** Build a road depot. |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3435
diff
changeset
|
559 |
* @param tile tile where to build the depot |
3333 | 560 |
* @param p1 entrance direction (DiagDirection) |
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
561 |
* @param p2 unused |
2085
ae9e92ffe168
(svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents:
2074
diff
changeset
|
562 |
* |
ae9e92ffe168
(svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents:
2074
diff
changeset
|
563 |
* @todo When checking for the tile slope, |
ae9e92ffe168
(svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents:
2074
diff
changeset
|
564 |
* distingush between "Flat land required" and "land sloped in wrong direction" |
0 | 565 |
*/ |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3435
diff
changeset
|
566 |
int32 CmdBuildRoadDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 567 |
{ |
568 |
int32 cost; |
|
569 |
Depot *dep; |
|
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3560
diff
changeset
|
570 |
Slope tileh; |
0 | 571 |
|
572 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
573 |
||
1785
998f4b5eec29
(svn r2289) - Fix (regression): check p1 param of road-depot building instead of unused p2 (typo). Thanks peter1138.
Darkvater
parents:
1784
diff
changeset
|
574 |
if (p1 > 3) return CMD_ERROR; // check direction |
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
575 |
|
2549 | 576 |
if (!EnsureNoVehicle(tile)) return CMD_ERROR; |
0 | 577 |
|
3055
25fd76668365
(svn r3644) Don't use FindLandscapeHeightByTile() when it's overkill - often it was just a complicated way of writing GetTileSlope(tile, NULL)
tron
parents:
3017
diff
changeset
|
578 |
tileh = GetTileSlope(tile, NULL); |
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3560
diff
changeset
|
579 |
if (tileh != SLOPE_FLAT && ( |
2549 | 580 |
!_patches.build_on_slopes || |
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3560
diff
changeset
|
581 |
IsSteepSlope(tileh) || |
3055
25fd76668365
(svn r3644) Don't use FindLandscapeHeightByTile() when it's overkill - often it was just a complicated way of writing GetTileSlope(tile, NULL)
tron
parents:
3017
diff
changeset
|
582 |
!CanBuildDepotByTileh(p1, tileh) |
2549 | 583 |
)) { |
584 |
return_cmd_error(STR_0007_FLAT_LAND_REQUIRED); |
|
0 | 585 |
} |
586 |
||
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3435
diff
changeset
|
587 |
cost = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
588 |
if (CmdFailed(cost)) return CMD_ERROR; |
0 | 589 |
|
590 |
dep = AllocateDepot(); |
|
2549 | 591 |
if (dep == NULL) return CMD_ERROR; |
0 | 592 |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
593 |
if (flags & DC_EXEC) { |
0 | 594 |
dep->xy = tile; |
595 |
dep->town_index = ClosestTownFromTile(tile, (uint)-1)->index; |
|
596 |
||
3099
374e275300e3
(svn r3689) Add functions to turn a tile into either a normal road tile, a level crossing or a road depot
tron
parents:
3098
diff
changeset
|
597 |
MakeRoadDepot(tile, _current_player, p1); |
3100
552cf19c49cb
(svn r3695) Add 2 MarkTileByTile() which I forgot in r3689 (noticed by Belugas)
tron
parents:
3099
diff
changeset
|
598 |
MarkTileDirtyByTile(tile); |
0 | 599 |
} |
600 |
return cost + _price.build_road_depot; |
|
601 |
} |
|
602 |
||
1979
f4462d4e8e62
(svn r2485) Missed two uint -> TileIndex, thanks _Luca_
tron
parents:
1977
diff
changeset
|
603 |
static int32 RemoveRoadDepot(TileIndex tile, uint32 flags) |
0 | 604 |
{ |
149
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
84
diff
changeset
|
605 |
if (!CheckTileOwnership(tile) && _current_player != OWNER_WATER) |
0 | 606 |
return CMD_ERROR; |
607 |
||
2639 | 608 |
if (!EnsureNoVehicle(tile)) return CMD_ERROR; |
0 | 609 |
|
4388
e5a166837162
(svn r6141) -Codechange: introduced DepotID and used it as much as possible
truelight
parents:
4352
diff
changeset
|
610 |
if (flags & DC_EXEC) DeleteDepot(GetDepotByTile(tile)); |
0 | 611 |
|
612 |
return _price.remove_road_depot; |
|
613 |
} |
|
614 |
||
615 |
#define M(x) (1<<(x)) |
|
616 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
617 |
static int32 ClearTile_Road(TileIndex tile, byte flags) |
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
618 |
{ |
3793
33cdb5bf7b21
(svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents:
3792
diff
changeset
|
619 |
switch (GetRoadTileType(tile)) { |
33cdb5bf7b21
(svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents:
3792
diff
changeset
|
620 |
case ROAD_TILE_NORMAL: { |
3069
0e6aca11c3da
(svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents:
3068
diff
changeset
|
621 |
RoadBits b = GetRoadBits(tile); |
0 | 622 |
|
3060 | 623 |
if (!((1 << b) & (M(1)|M(2)|M(4)|M(8))) && |
624 |
(!(flags & DC_AI_BUILDING) || !IsTileOwner(tile, OWNER_TOWN)) && |
|
625 |
flags & DC_AUTO) { |
|
0 | 626 |
return_cmd_error(STR_1801_MUST_REMOVE_ROAD_FIRST); |
3060 | 627 |
} |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3435
diff
changeset
|
628 |
return DoCommand(tile, b, 0, flags, CMD_REMOVE_ROAD); |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
629 |
} |
0 | 630 |
|
3793
33cdb5bf7b21
(svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents:
3792
diff
changeset
|
631 |
case ROAD_TILE_CROSSING: { |
3060 | 632 |
int32 ret; |
633 |
||
3069
0e6aca11c3da
(svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents:
3068
diff
changeset
|
634 |
if (flags & DC_AUTO) return_cmd_error(STR_1801_MUST_REMOVE_ROAD_FIRST); |
3060 | 635 |
|
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3435
diff
changeset
|
636 |
ret = DoCommand(tile, GetCrossingRoadBits(tile), 0, flags, CMD_REMOVE_ROAD); |
3060 | 637 |
if (CmdFailed(ret)) return CMD_ERROR; |
638 |
||
639 |
if (flags & DC_EXEC) { |
|
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3435
diff
changeset
|
640 |
DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
3060 | 641 |
} |
642 |
return ret; |
|
643 |
} |
|
644 |
||
3069
0e6aca11c3da
(svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents:
3068
diff
changeset
|
645 |
default: |
3793
33cdb5bf7b21
(svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents:
3792
diff
changeset
|
646 |
case ROAD_TILE_DEPOT: |
3060 | 647 |
if (flags & DC_AUTO) { |
648 |
return_cmd_error(STR_2004_BUILDING_MUST_BE_DEMOLISHED); |
|
649 |
} |
|
650 |
return RemoveRoadDepot(tile, flags); |
|
0 | 651 |
} |
652 |
} |
|
653 |
||
654 |
||
655 |
typedef struct DrawRoadTileStruct { |
|
656 |
uint16 image; |
|
657 |
byte subcoord_x; |
|
658 |
byte subcoord_y; |
|
659 |
} DrawRoadTileStruct; |
|
660 |
||
661 |
#include "table/road_land.h" |
|
662 |
||
663 |
||
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3560
diff
changeset
|
664 |
uint GetRoadFoundation(Slope tileh, RoadBits bits) |
2548
97ada3bd2702
(svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents:
2544
diff
changeset
|
665 |
{ |
3878
91a8b87f641e
(svn r4927) Replace 3 big ifs (which regard foundations) by a bit less confusing code
tron
parents:
3794
diff
changeset
|
666 |
uint i; |
91a8b87f641e
(svn r4927) Replace 3 big ifs (which regard foundations) by a bit less confusing code
tron
parents:
3794
diff
changeset
|
667 |
|
0 | 668 |
// normal level sloped building |
4246
14a8849c32df
(svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents:
4232
diff
changeset
|
669 |
if (!IsSteepSlope(tileh) && |
14a8849c32df
(svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents:
4232
diff
changeset
|
670 |
(~_valid_tileh_slopes_road[1][tileh] & bits) == 0) { |
14a8849c32df
(svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents:
4232
diff
changeset
|
671 |
return tileh; |
14a8849c32df
(svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents:
4232
diff
changeset
|
672 |
} |
0 | 673 |
|
674 |
// inclined sloped building |
|
3878
91a8b87f641e
(svn r4927) Replace 3 big ifs (which regard foundations) by a bit less confusing code
tron
parents:
3794
diff
changeset
|
675 |
switch (bits) { |
91a8b87f641e
(svn r4927) Replace 3 big ifs (which regard foundations) by a bit less confusing code
tron
parents:
3794
diff
changeset
|
676 |
case ROAD_X: i = 0; break; |
91a8b87f641e
(svn r4927) Replace 3 big ifs (which regard foundations) by a bit less confusing code
tron
parents:
3794
diff
changeset
|
677 |
case ROAD_Y: i = 1; break; |
91a8b87f641e
(svn r4927) Replace 3 big ifs (which regard foundations) by a bit less confusing code
tron
parents:
3794
diff
changeset
|
678 |
default: return 0; |
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
679 |
} |
3878
91a8b87f641e
(svn r4927) Replace 3 big ifs (which regard foundations) by a bit less confusing code
tron
parents:
3794
diff
changeset
|
680 |
switch (tileh) { |
4246
14a8849c32df
(svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents:
4232
diff
changeset
|
681 |
case SLOPE_W: |
14a8849c32df
(svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents:
4232
diff
changeset
|
682 |
case SLOPE_STEEP_W: i += 0; break; |
14a8849c32df
(svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents:
4232
diff
changeset
|
683 |
case SLOPE_S: |
14a8849c32df
(svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents:
4232
diff
changeset
|
684 |
case SLOPE_STEEP_S: i += 2; break; |
14a8849c32df
(svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents:
4232
diff
changeset
|
685 |
case SLOPE_E: |
14a8849c32df
(svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents:
4232
diff
changeset
|
686 |
case SLOPE_STEEP_E: i += 4; break; |
14a8849c32df
(svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents:
4232
diff
changeset
|
687 |
case SLOPE_N: |
14a8849c32df
(svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents:
4232
diff
changeset
|
688 |
case SLOPE_STEEP_N: i += 6; break; |
14a8849c32df
(svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents:
4232
diff
changeset
|
689 |
default: return 0; |
3878
91a8b87f641e
(svn r4927) Replace 3 big ifs (which regard foundations) by a bit less confusing code
tron
parents:
3794
diff
changeset
|
690 |
} |
91a8b87f641e
(svn r4927) Replace 3 big ifs (which regard foundations) by a bit less confusing code
tron
parents:
3794
diff
changeset
|
691 |
return i + 15; |
0 | 692 |
} |
693 |
||
694 |
const byte _road_sloped_sprites[14] = { |
|
695 |
0, 0, 2, 0, |
|
696 |
0, 1, 0, 0, |
|
697 |
3, 0, 0, 0, |
|
698 |
0, 0 |
|
699 |
}; |
|
700 |
||
2471
14109854e818
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
701 |
/** |
14109854e818
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
702 |
* Draw ground sprite and road pieces |
14109854e818
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
703 |
* @param ti TileInfo |
14109854e818
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
704 |
* @param road RoadBits to draw |
14109854e818
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
705 |
*/ |
4081 | 706 |
static void DrawRoadBits(TileInfo* ti) |
2471
14109854e818
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
707 |
{ |
4081 | 708 |
RoadBits road = GetRoadBits(ti->tile); |
2471
14109854e818
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
709 |
const DrawRoadTileStruct *drts; |
14109854e818
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
710 |
PalSpriteID image = 0; |
4048 | 711 |
Roadside roadside; |
2471
14109854e818
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
712 |
|
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3560
diff
changeset
|
713 |
if (ti->tileh != SLOPE_FLAT) { |
3430
b283bb956a36
(svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents:
3421
diff
changeset
|
714 |
int foundation = GetRoadFoundation(ti->tileh, road); |
2471
14109854e818
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
715 |
|
2639 | 716 |
if (foundation != 0) DrawFoundation(ti, foundation); |
2471
14109854e818
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
717 |
|
14109854e818
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
718 |
// DrawFoundation() modifies ti. |
14109854e818
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
719 |
// Default sloped sprites.. |
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3560
diff
changeset
|
720 |
if (ti->tileh != SLOPE_FLAT) image = _road_sloped_sprites[ti->tileh - 1] + 0x53F; |
2471
14109854e818
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
721 |
} |
14109854e818
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
722 |
|
2639 | 723 |
if (image == 0) image = _road_tile_sprites_1[road]; |
2471
14109854e818
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
724 |
|
4048 | 725 |
roadside = GetRoadside(ti->tile); |
2471
14109854e818
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
726 |
|
3430
b283bb956a36
(svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents:
3421
diff
changeset
|
727 |
if (IsOnSnow(ti->tile)) { |
2471
14109854e818
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
728 |
image += 19; |
4048 | 729 |
} else { |
730 |
switch (roadside) { |
|
731 |
case ROADSIDE_BARREN: image |= PALETTE_TO_BARE_LAND; break; |
|
732 |
case ROADSIDE_GRASS: break; |
|
733 |
case ROADSIDE_GRASS_ROAD_WORKS: break; |
|
734 |
default: image -= 19; break; // Paved |
|
735 |
} |
|
2471
14109854e818
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
736 |
} |
14109854e818
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
737 |
|
14109854e818
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
738 |
DrawGroundSprite(image); |
14109854e818
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
739 |
|
3430
b283bb956a36
(svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents:
3421
diff
changeset
|
740 |
if (HasRoadWorks(ti->tile)) { |
2471
14109854e818
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
741 |
// Road works |
3098
4c1320da876d
(svn r3687) Complete some bits I missed whenn adding accessor functions for road types and pieces
tron
parents:
3097
diff
changeset
|
742 |
DrawGroundSprite(road & ROAD_X ? SPR_EXCAVATION_X : SPR_EXCAVATION_Y); |
2471
14109854e818
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
743 |
return; |
14109854e818
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
744 |
} |
14109854e818
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
745 |
|
5148
00b593a6bae5
(svn r7240) -Fix: Always display the excavation of roadworks even when fully zoomed out (they are quite noticable) or "full details" are off (they are part of the game mechanics)
tron
parents:
5116
diff
changeset
|
746 |
// Return if full detail is disabled, or we are zoomed fully out. |
00b593a6bae5
(svn r7240) -Fix: Always display the excavation of roadworks even when fully zoomed out (they are quite noticable) or "full details" are off (they are part of the game mechanics)
tron
parents:
5116
diff
changeset
|
747 |
if (!(_display_opt & DO_FULL_DETAIL) || _cur_dpi->zoom == 2) return; |
00b593a6bae5
(svn r7240) -Fix: Always display the excavation of roadworks even when fully zoomed out (they are quite noticable) or "full details" are off (they are part of the game mechanics)
tron
parents:
5116
diff
changeset
|
748 |
|
2471
14109854e818
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
749 |
// Draw extra details. |
4048 | 750 |
for (drts = _road_display_table[roadside][road]; drts->image != 0; drts++) { |
2471
14109854e818
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
751 |
int x = ti->x | drts->subcoord_x; |
14109854e818
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
752 |
int y = ti->y | drts->subcoord_y; |
14109854e818
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
753 |
byte z = ti->z; |
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3560
diff
changeset
|
754 |
if (ti->tileh != SLOPE_FLAT) z = GetSlopeZ(x, y); |
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
755 |
AddSortableSpriteToDraw(drts->image, x, y, 2, 2, 0x10, z); |
2471
14109854e818
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
756 |
} |
14109854e818
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
757 |
} |
14109854e818
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents:
2469
diff
changeset
|
758 |
|
0 | 759 |
static void DrawTile_Road(TileInfo *ti) |
760 |
{ |
|
3793
33cdb5bf7b21
(svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents:
3792
diff
changeset
|
761 |
switch (GetRoadTileType(ti->tile)) { |
33cdb5bf7b21
(svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents:
3792
diff
changeset
|
762 |
case ROAD_TILE_NORMAL: |
4081 | 763 |
DrawRoadBits(ti); |
3060 | 764 |
break; |
0 | 765 |
|
3793
33cdb5bf7b21
(svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents:
3792
diff
changeset
|
766 |
case ROAD_TILE_CROSSING: { |
4000
bab1ebc37da0
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3977
diff
changeset
|
767 |
PalSpriteID image; |
bab1ebc37da0
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3977
diff
changeset
|
768 |
|
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3560
diff
changeset
|
769 |
if (ti->tileh != SLOPE_FLAT) DrawFoundation(ti, ti->tileh); |
0 | 770 |
|
3242
1cefa03f0d5e
(svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents:
3234
diff
changeset
|
771 |
image = GetRailTypeInfo(GetRailTypeCrossing(ti->tile))->base_sprites.crossing; |
3060 | 772 |
|
3272
7e556f209503
(svn r3984) Add a function to get the road axis of a level crossing
tron
parents:
3269
diff
changeset
|
773 |
if (GetCrossingRoadAxis(ti->tile) == AXIS_X) image++; |
3322
fa5d46929db9
(svn r4088) -Codechange: Introduce {Unb,B}arCrossing and IsCrossingBarred to put and get the status of a level crossing
celestar
parents:
3319
diff
changeset
|
774 |
if (IsCrossingBarred(ti->tile)) image += 2; |
3060 | 775 |
|
3430
b283bb956a36
(svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents:
3421
diff
changeset
|
776 |
if (IsOnSnow(ti->tile)) { |
3060 | 777 |
image += 8; |
778 |
} else { |
|
4048 | 779 |
switch (GetRoadside(ti->tile)) { |
780 |
case ROADSIDE_BARREN: image |= PALETTE_TO_BARE_LAND; break; |
|
781 |
case ROADSIDE_GRASS: break; |
|
782 |
default: image += 4; break; // Paved |
|
783 |
} |
|
3060 | 784 |
} |
785 |
||
786 |
DrawGroundSprite(image); |
|
3367 | 787 |
if (GetRailTypeCrossing(ti->tile) == RAILTYPE_ELECTRIC) DrawCatenary(ti); |
3060 | 788 |
break; |
0 | 789 |
} |
790 |
||
3098
4c1320da876d
(svn r3687) Complete some bits I missed whenn adding accessor functions for road types and pieces
tron
parents:
3097
diff
changeset
|
791 |
default: |
3793
33cdb5bf7b21
(svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents:
3792
diff
changeset
|
792 |
case ROAD_TILE_DEPOT: { |
4232
628628eaa4fc
(svn r5796) Use DrawTileSprites/DrawTileSeqStruct for road depot drawing data, too
tron
parents:
4231
diff
changeset
|
793 |
const DrawTileSprites* dts; |
628628eaa4fc
(svn r5796) Use DrawTileSprites/DrawTileSeqStruct for road depot drawing data, too
tron
parents:
4231
diff
changeset
|
794 |
const DrawTileSeqStruct* dtss; |
4226
3926da9dc486
(svn r5772) Road depots always have an player as owner, so remove an useless check
tron
parents:
4212
diff
changeset
|
795 |
uint32 palette; |
0 | 796 |
|
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3560
diff
changeset
|
797 |
if (ti->tileh != SLOPE_FLAT) DrawFoundation(ti, ti->tileh); |
1398 | 798 |
|
4226
3926da9dc486
(svn r5772) Road depots always have an player as owner, so remove an useless check
tron
parents:
4212
diff
changeset
|
799 |
palette = PLAYER_SPRITE_COLOR(GetTileOwner(ti->tile)); |
0 | 800 |
|
4232
628628eaa4fc
(svn r5796) Use DrawTileSprites/DrawTileSeqStruct for road depot drawing data, too
tron
parents:
4231
diff
changeset
|
801 |
dts = &_road_depot[GetRoadDepotDirection(ti->tile)]; |
628628eaa4fc
(svn r5796) Use DrawTileSprites/DrawTileSeqStruct for road depot drawing data, too
tron
parents:
4231
diff
changeset
|
802 |
DrawGroundSprite(dts->ground_sprite); |
3060 | 803 |
|
4232
628628eaa4fc
(svn r5796) Use DrawTileSprites/DrawTileSeqStruct for road depot drawing data, too
tron
parents:
4231
diff
changeset
|
804 |
for (dtss = dts->seq; dtss->image != 0; dtss++) { |
628628eaa4fc
(svn r5796) Use DrawTileSprites/DrawTileSeqStruct for road depot drawing data, too
tron
parents:
4231
diff
changeset
|
805 |
uint32 image = dtss->image; |
3060 | 806 |
|
4226
3926da9dc486
(svn r5772) Road depots always have an player as owner, so remove an useless check
tron
parents:
4212
diff
changeset
|
807 |
if (_display_opt & DO_TRANS_BUILDINGS) { |
3926da9dc486
(svn r5772) Road depots always have an player as owner, so remove an useless check
tron
parents:
4212
diff
changeset
|
808 |
MAKE_TRANSPARENT(image); |
3926da9dc486
(svn r5772) Road depots always have an player as owner, so remove an useless check
tron
parents:
4212
diff
changeset
|
809 |
} else if (image & PALETTE_MODIFIER_COLOR) { |
3926da9dc486
(svn r5772) Road depots always have an player as owner, so remove an useless check
tron
parents:
4212
diff
changeset
|
810 |
image |= palette; |
3926da9dc486
(svn r5772) Road depots always have an player as owner, so remove an useless check
tron
parents:
4212
diff
changeset
|
811 |
} |
3060 | 812 |
|
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4048
diff
changeset
|
813 |
AddSortableSpriteToDraw( |
4232
628628eaa4fc
(svn r5796) Use DrawTileSprites/DrawTileSeqStruct for road depot drawing data, too
tron
parents:
4231
diff
changeset
|
814 |
image, |
628628eaa4fc
(svn r5796) Use DrawTileSprites/DrawTileSeqStruct for road depot drawing data, too
tron
parents:
4231
diff
changeset
|
815 |
ti->x + dtss->delta_x, ti->y + dtss->delta_y, |
628628eaa4fc
(svn r5796) Use DrawTileSprites/DrawTileSeqStruct for road depot drawing data, too
tron
parents:
4231
diff
changeset
|
816 |
dtss->size_x, dtss->size_y, |
628628eaa4fc
(svn r5796) Use DrawTileSprites/DrawTileSeqStruct for road depot drawing data, too
tron
parents:
4231
diff
changeset
|
817 |
dtss->size_z, ti->z |
3060 | 818 |
); |
819 |
} |
|
820 |
break; |
|
0 | 821 |
} |
822 |
} |
|
823 |
} |
|
824 |
||
4212
0308ef21b4e1
(svn r5723) - Move the declaration of DrawRoadDepotSprite() out of functions.h (but I'm not too happy with the new header)
tron
parents:
4158
diff
changeset
|
825 |
void DrawRoadDepotSprite(int x, int y, DiagDirection dir) |
0 | 826 |
{ |
4232
628628eaa4fc
(svn r5796) Use DrawTileSprites/DrawTileSeqStruct for road depot drawing data, too
tron
parents:
4231
diff
changeset
|
827 |
uint32 palette = PLAYER_SPRITE_COLOR(_local_player); |
628628eaa4fc
(svn r5796) Use DrawTileSprites/DrawTileSeqStruct for road depot drawing data, too
tron
parents:
4231
diff
changeset
|
828 |
const DrawTileSprites* dts = &_road_depot[dir]; |
628628eaa4fc
(svn r5796) Use DrawTileSprites/DrawTileSeqStruct for road depot drawing data, too
tron
parents:
4231
diff
changeset
|
829 |
const DrawTileSeqStruct* dtss; |
0 | 830 |
|
2639 | 831 |
x += 33; |
832 |
y += 17; |
|
0 | 833 |
|
4232
628628eaa4fc
(svn r5796) Use DrawTileSprites/DrawTileSeqStruct for road depot drawing data, too
tron
parents:
4231
diff
changeset
|
834 |
DrawSprite(dts->ground_sprite, x, y); |
0 | 835 |
|
4232
628628eaa4fc
(svn r5796) Use DrawTileSprites/DrawTileSeqStruct for road depot drawing data, too
tron
parents:
4231
diff
changeset
|
836 |
for (dtss = dts->seq; dtss->image != 0; dtss++) { |
628628eaa4fc
(svn r5796) Use DrawTileSprites/DrawTileSeqStruct for road depot drawing data, too
tron
parents:
4231
diff
changeset
|
837 |
Point pt = RemapCoords(dtss->delta_x, dtss->delta_y, dtss->delta_z); |
4212
0308ef21b4e1
(svn r5723) - Move the declaration of DrawRoadDepotSprite() out of functions.h (but I'm not too happy with the new header)
tron
parents:
4158
diff
changeset
|
838 |
uint32 image = dtss->image; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
839 |
|
4232
628628eaa4fc
(svn r5796) Use DrawTileSprites/DrawTileSeqStruct for road depot drawing data, too
tron
parents:
4231
diff
changeset
|
840 |
if (image & PALETTE_MODIFIER_COLOR) image |= palette; |
0 | 841 |
|
842 |
DrawSprite(image, x + pt.x, y + pt.y); |
|
843 |
} |
|
844 |
} |
|
845 |
||
4231
dea6a63dd058
(svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents:
4226
diff
changeset
|
846 |
static uint GetSlopeZ_Road(TileIndex tile, uint x, uint y) |
0 | 847 |
{ |
4231
dea6a63dd058
(svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents:
4226
diff
changeset
|
848 |
uint z; |
dea6a63dd058
(svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents:
4226
diff
changeset
|
849 |
Slope tileh = GetTileSlope(tile, &z); |
3098
4c1320da876d
(svn r3687) Complete some bits I missed whenn adding accessor functions for road types and pieces
tron
parents:
3097
diff
changeset
|
850 |
|
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3560
diff
changeset
|
851 |
if (tileh == SLOPE_FLAT) return z; |
4231
dea6a63dd058
(svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents:
4226
diff
changeset
|
852 |
if (GetRoadTileType(tile) == ROAD_TILE_NORMAL) { |
dea6a63dd058
(svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents:
4226
diff
changeset
|
853 |
uint f = GetRoadFoundation(tileh, GetRoadBits(tile)); |
3060 | 854 |
|
3286
3250f1488eb2
(svn r4000) Rewrite GetSlope{Tileh,Z}_{Road,Track} in a less confusing way
tron
parents:
3277
diff
changeset
|
855 |
if (f != 0) { |
4246
14a8849c32df
(svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents:
4232
diff
changeset
|
856 |
if (IsSteepSlope(tileh)) { |
14a8849c32df
(svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents:
4232
diff
changeset
|
857 |
z += TILE_HEIGHT; |
14a8849c32df
(svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents:
4232
diff
changeset
|
858 |
} else if (f < 15) { |
14a8849c32df
(svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents:
4232
diff
changeset
|
859 |
return z + TILE_HEIGHT; // leveled foundation |
14a8849c32df
(svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents:
4232
diff
changeset
|
860 |
} |
3286
3250f1488eb2
(svn r4000) Rewrite GetSlope{Tileh,Z}_{Road,Track} in a less confusing way
tron
parents:
3277
diff
changeset
|
861 |
tileh = _inclined_tileh[f - 15]; // inclined foundation |
0 | 862 |
} |
4231
dea6a63dd058
(svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents:
4226
diff
changeset
|
863 |
return z + GetPartialZ(x & 0xF, y & 0xF, tileh); |
3286
3250f1488eb2
(svn r4000) Rewrite GetSlope{Tileh,Z}_{Road,Track} in a less confusing way
tron
parents:
3277
diff
changeset
|
864 |
} else { |
3645
86af43f87885
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3637
diff
changeset
|
865 |
return z + TILE_HEIGHT; |
0 | 866 |
} |
39 | 867 |
} |
868 |
||
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3560
diff
changeset
|
869 |
static Slope GetSlopeTileh_Road(TileIndex tile, Slope tileh) |
39 | 870 |
{ |
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3560
diff
changeset
|
871 |
if (tileh == SLOPE_FLAT) return SLOPE_FLAT; |
3793
33cdb5bf7b21
(svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents:
3792
diff
changeset
|
872 |
if (GetRoadTileType(tile) == ROAD_TILE_NORMAL) { |
3418
a592d40a4d04
(svn r4242) Pass TileIndex and slope to GetSlopeTileh_*() instead of TileInfo
tron
parents:
3415
diff
changeset
|
873 |
uint f = GetRoadFoundation(tileh, GetRoadBits(tile)); |
3098
4c1320da876d
(svn r3687) Complete some bits I missed whenn adding accessor functions for road types and pieces
tron
parents:
3097
diff
changeset
|
874 |
|
3418
a592d40a4d04
(svn r4242) Pass TileIndex and slope to GetSlopeTileh_*() instead of TileInfo
tron
parents:
3415
diff
changeset
|
875 |
if (f == 0) return tileh; |
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3560
diff
changeset
|
876 |
if (f < 15) return SLOPE_FLAT; // leveled foundation |
3286
3250f1488eb2
(svn r4000) Rewrite GetSlope{Tileh,Z}_{Road,Track} in a less confusing way
tron
parents:
3277
diff
changeset
|
877 |
return _inclined_tileh[f - 15]; // inclined foundation |
3250f1488eb2
(svn r4000) Rewrite GetSlope{Tileh,Z}_{Road,Track} in a less confusing way
tron
parents:
3277
diff
changeset
|
878 |
} else { |
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3560
diff
changeset
|
879 |
return SLOPE_FLAT; |
39 | 880 |
} |
0 | 881 |
} |
882 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
883 |
static void GetAcceptedCargo_Road(TileIndex tile, AcceptedCargo ac) |
0 | 884 |
{ |
885 |
/* not used */ |
|
886 |
} |
|
887 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
888 |
static void AnimateTile_Road(TileIndex tile) |
0 | 889 |
{ |
2639 | 890 |
if (IsLevelCrossing(tile)) MarkTileDirtyByTile(tile); |
0 | 891 |
} |
892 |
||
4048 | 893 |
|
894 |
static const Roadside _town_road_types[][2] = { |
|
895 |
{ ROADSIDE_GRASS, ROADSIDE_GRASS }, |
|
896 |
{ ROADSIDE_PAVED, ROADSIDE_PAVED }, |
|
897 |
{ ROADSIDE_PAVED, ROADSIDE_PAVED }, |
|
898 |
{ ROADSIDE_TREES, ROADSIDE_TREES }, |
|
899 |
{ ROADSIDE_STREET_LIGHTS, ROADSIDE_PAVED } |
|
0 | 900 |
}; |
901 |
||
4048 | 902 |
static const Roadside _town_road_types_2[][2] = { |
903 |
{ ROADSIDE_GRASS, ROADSIDE_GRASS }, |
|
904 |
{ ROADSIDE_PAVED, ROADSIDE_PAVED }, |
|
905 |
{ ROADSIDE_STREET_LIGHTS, ROADSIDE_PAVED }, |
|
906 |
{ ROADSIDE_STREET_LIGHTS, ROADSIDE_PAVED }, |
|
907 |
{ ROADSIDE_STREET_LIGHTS, ROADSIDE_PAVED } |
|
0 | 908 |
}; |
909 |
||
910 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
911 |
static void TileLoop_Road(TileIndex tile) |
0 | 912 |
{ |
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
913 |
switch (_opt.landscape) { |
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
914 |
case LT_HILLY: |
3430
b283bb956a36
(svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents:
3421
diff
changeset
|
915 |
if (IsOnSnow(tile) != (GetTileZ(tile) > _opt.snow_line)) { |
b283bb956a36
(svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents:
3421
diff
changeset
|
916 |
ToggleSnow(tile); |
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
917 |
MarkTileDirtyByTile(tile); |
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
918 |
} |
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
919 |
break; |
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
920 |
|
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
921 |
case LT_DESERT: |
3430
b283bb956a36
(svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents:
3421
diff
changeset
|
922 |
if (GetTropicZone(tile) == TROPICZONE_DESERT && !IsOnDesert(tile)) { |
b283bb956a36
(svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents:
3421
diff
changeset
|
923 |
ToggleDesert(tile); |
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
924 |
MarkTileDirtyByTile(tile); |
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
925 |
} |
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
926 |
break; |
0 | 927 |
} |
928 |
||
3793
33cdb5bf7b21
(svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents:
3792
diff
changeset
|
929 |
if (GetRoadTileType(tile) == ROAD_TILE_DEPOT) return; |
0 | 930 |
|
3430
b283bb956a36
(svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents:
3421
diff
changeset
|
931 |
if (!HasRoadWorks(tile)) { |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4048
diff
changeset
|
932 |
const Town* t = ClosestTownFromTile(tile, (uint)-1); |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4048
diff
changeset
|
933 |
int grp = 0; |
1280
b6925875de49
(svn r1784) -Fix: removed ClosestTownFromTile where possible, or replaced it
truelight
parents:
1264
diff
changeset
|
934 |
|
0 | 935 |
if (t != NULL) { |
936 |
grp = GetTownRadiusGroup(t, tile); |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
937 |
|
0 | 938 |
// 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
|
939 |
if (t->road_build_months != 0 && |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4048
diff
changeset
|
940 |
(DistanceManhattan(t->xy, tile) < 8 || grp != 0) && |
3793
33cdb5bf7b21
(svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents:
3792
diff
changeset
|
941 |
GetRoadTileType(tile) == ROAD_TILE_NORMAL && (GetRoadBits(tile) == ROAD_X || GetRoadBits(tile) == ROAD_Y)) { |
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3560
diff
changeset
|
942 |
if (GetTileSlope(tile, NULL) == SLOPE_FLAT && EnsureNoVehicle(tile) && CHANCE16(1, 20)) { |
3430
b283bb956a36
(svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents:
3421
diff
changeset
|
943 |
StartRoadWorks(tile); |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
944 |
|
541 | 945 |
SndPlayTileFx(SND_21_JACKHAMMER, tile); |
0 | 946 |
CreateEffectVehicleAbove( |
3421
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3418
diff
changeset
|
947 |
TileX(tile) * TILE_SIZE + 7, |
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3418
diff
changeset
|
948 |
TileY(tile) * TILE_SIZE + 7, |
0 | 949 |
0, |
1359
8ba976aed634
(svn r1863) Give the effect vehicle type enums more descriptive names and use the enum as parameter type for CreateEffectVehicle*()
tron
parents:
1327
diff
changeset
|
950 |
EV_BULLDOZER); |
0 | 951 |
MarkTileDirtyByTile(tile); |
952 |
return; |
|
953 |
} |
|
954 |
} |
|
955 |
} |
|
956 |
||
957 |
{ |
|
3430
b283bb956a36
(svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents:
3421
diff
changeset
|
958 |
/* Adjust road ground type depending on 'grp' (grp is the distance to the center) */ |
4048 | 959 |
const Roadside* new_rs = (_opt.landscape == LT_CANDY) ? _town_road_types_2[grp] : _town_road_types[grp]; |
960 |
Roadside cur_rs = GetRoadside(tile); |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
961 |
|
3430
b283bb956a36
(svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents:
3421
diff
changeset
|
962 |
/* We have our desired type, do nothing */ |
4048 | 963 |
if (cur_rs == new_rs[0]) return; |
3430
b283bb956a36
(svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents:
3421
diff
changeset
|
964 |
|
b283bb956a36
(svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents:
3421
diff
changeset
|
965 |
/* We have the pre-type of the desired type, switch to the desired type */ |
4048 | 966 |
if (cur_rs == new_rs[1]) { |
967 |
cur_rs = new_rs[0]; |
|
3430
b283bb956a36
(svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents:
3421
diff
changeset
|
968 |
/* We have barren land, install the pre-type */ |
4048 | 969 |
} else if (cur_rs == ROADSIDE_BARREN) { |
970 |
cur_rs = new_rs[1]; |
|
3430
b283bb956a36
(svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents:
3421
diff
changeset
|
971 |
/* We're totally off limits, remove any installation and make barren land */ |
0 | 972 |
} else { |
4048 | 973 |
cur_rs = ROADSIDE_BARREN; |
0 | 974 |
} |
4048 | 975 |
SetRoadside(tile, cur_rs); |
0 | 976 |
MarkTileDirtyByTile(tile); |
977 |
} |
|
3430
b283bb956a36
(svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents:
3421
diff
changeset
|
978 |
} else if (IncreaseRoadWorksCounter(tile)) { |
b283bb956a36
(svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents:
3421
diff
changeset
|
979 |
TerminateRoadWorks(tile); |
0 | 980 |
MarkTileDirtyByTile(tile); |
981 |
} |
|
982 |
} |
|
983 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
984 |
static void ClickTile_Road(TileIndex tile) |
0 | 985 |
{ |
4638
8abe4f10b94b
(svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
4388
diff
changeset
|
986 |
if (GetRoadTileType(tile) == ROAD_TILE_DEPOT) ShowDepotWindow(tile, VEH_Road); |
0 | 987 |
} |
988 |
||
989 |
static const byte _road_trackbits[16] = { |
|
990 |
0x0, 0x0, 0x0, 0x10, 0x0, 0x2, 0x8, 0x1A, 0x0, 0x4, 0x1, 0x15, 0x20, 0x26, 0x29, 0x3F, |
|
991 |
}; |
|
992 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
993 |
static uint32 GetTileTrackStatus_Road(TileIndex tile, TransportType mode) |
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
994 |
{ |
3066
0d34dff23d98
(svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents:
3061
diff
changeset
|
995 |
switch (mode) { |
0d34dff23d98
(svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents:
3061
diff
changeset
|
996 |
case TRANSPORT_RAIL: |
0d34dff23d98
(svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents:
3061
diff
changeset
|
997 |
if (!IsLevelCrossing(tile)) return 0; |
3267
591027d10884
(svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents:
3242
diff
changeset
|
998 |
return GetCrossingRailBits(tile) * 0x101; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
999 |
|
3066
0d34dff23d98
(svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents:
3061
diff
changeset
|
1000 |
case TRANSPORT_ROAD: |
3793
33cdb5bf7b21
(svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents:
3792
diff
changeset
|
1001 |
switch (GetRoadTileType(tile)) { |
33cdb5bf7b21
(svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents:
3792
diff
changeset
|
1002 |
case ROAD_TILE_NORMAL: |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4048
diff
changeset
|
1003 |
return HasRoadWorks(tile) ? 0 : _road_trackbits[GetRoadBits(tile)] * 0x101; |
3066
0d34dff23d98
(svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents:
3061
diff
changeset
|
1004 |
|
3793
33cdb5bf7b21
(svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents:
3792
diff
changeset
|
1005 |
case ROAD_TILE_CROSSING: { |
4158 | 1006 |
uint32 r = AxisToTrackBits(GetCrossingRoadAxis(tile)) * 0x101; |
3272
7e556f209503
(svn r3984) Add a function to get the road axis of a level crossing
tron
parents:
3269
diff
changeset
|
1007 |
|
3367 | 1008 |
if (IsCrossingBarred(tile)) r *= 0x10001; |
3066
0d34dff23d98
(svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents:
3061
diff
changeset
|
1009 |
return r; |
0d34dff23d98
(svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents:
3061
diff
changeset
|
1010 |
} |
0d34dff23d98
(svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents:
3061
diff
changeset
|
1011 |
|
3069
0e6aca11c3da
(svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents:
3068
diff
changeset
|
1012 |
default: |
3793
33cdb5bf7b21
(svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents:
3792
diff
changeset
|
1013 |
case ROAD_TILE_DEPOT: |
4158 | 1014 |
return AxisToTrackBits(DiagDirToAxis(GetRoadDepotDirection(tile))) * 0x101; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1015 |
} |
3066
0d34dff23d98
(svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents:
3061
diff
changeset
|
1016 |
break; |
0d34dff23d98
(svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents:
3061
diff
changeset
|
1017 |
|
0d34dff23d98
(svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents:
3061
diff
changeset
|
1018 |
default: break; |
0 | 1019 |
} |
1020 |
return 0; |
|
1021 |
} |
|
1022 |
||
1023 |
static const StringID _road_tile_strings[] = { |
|
1024 |
STR_1814_ROAD, |
|
1025 |
STR_1814_ROAD, |
|
1026 |
STR_1814_ROAD, |
|
1027 |
STR_1815_ROAD_WITH_STREETLIGHTS, |
|
1028 |
STR_1814_ROAD, |
|
1029 |
STR_1816_TREE_LINED_ROAD, |
|
1030 |
STR_1814_ROAD, |
|
1031 |
STR_1814_ROAD, |
|
1032 |
}; |
|
1033 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
1034 |
static void GetTileDesc_Road(TileIndex tile, TileDesc *td) |
0 | 1035 |
{ |
1901
fb05044cf5c3
(svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents:
1891
diff
changeset
|
1036 |
td->owner = GetTileOwner(tile); |
3793
33cdb5bf7b21
(svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents:
3792
diff
changeset
|
1037 |
switch (GetRoadTileType(tile)) { |
33cdb5bf7b21
(svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents:
3792
diff
changeset
|
1038 |
case ROAD_TILE_CROSSING: td->str = STR_1818_ROAD_RAIL_LEVEL_CROSSING; break; |
33cdb5bf7b21
(svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents:
3792
diff
changeset
|
1039 |
case ROAD_TILE_DEPOT: td->str = STR_1817_ROAD_VEHICLE_DEPOT; break; |
4048 | 1040 |
default: td->str = _road_tile_strings[GetRoadside(tile)]; break; |
3069
0e6aca11c3da
(svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents:
3068
diff
changeset
|
1041 |
} |
0 | 1042 |
} |
1043 |
||
1044 |
static const byte _roadveh_enter_depot_unk0[4] = { |
|
1045 |
8, 9, 0, 1 |
|
1046 |
}; |
|
1047 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
1048 |
static uint32 VehicleEnter_Road(Vehicle *v, TileIndex tile, int x, int y) |
0 | 1049 |
{ |
3793
33cdb5bf7b21
(svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents:
3792
diff
changeset
|
1050 |
switch (GetRoadTileType(tile)) { |
33cdb5bf7b21
(svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents:
3792
diff
changeset
|
1051 |
case ROAD_TILE_CROSSING: |
3322
fa5d46929db9
(svn r4088) -Codechange: Introduce {Unb,B}arCrossing and IsCrossingBarred to put and get the status of a level crossing
celestar
parents:
3319
diff
changeset
|
1052 |
if (v->type == VEH_Train && !IsCrossingBarred(tile)) { |
3060 | 1053 |
/* train crossing a road */ |
1054 |
SndPlayVehicleFx(SND_0E_LEVEL_CROSSING, v); |
|
3322
fa5d46929db9
(svn r4088) -Codechange: Introduce {Unb,B}arCrossing and IsCrossingBarred to put and get the status of a level crossing
celestar
parents:
3319
diff
changeset
|
1055 |
BarCrossing(tile); |
3060 | 1056 |
MarkTileDirtyByTile(tile); |
0 | 1057 |
} |
3060 | 1058 |
break; |
1059 |
||
3793
33cdb5bf7b21
(svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents:
3792
diff
changeset
|
1060 |
case ROAD_TILE_DEPOT: |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4048
diff
changeset
|
1061 |
if (v->type == VEH_Road && |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4048
diff
changeset
|
1062 |
v->u.road.frame == 11 && |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4048
diff
changeset
|
1063 |
_roadveh_enter_depot_unk0[GetRoadDepotDirection(tile)] == v->u.road.state) { |
4725
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4638
diff
changeset
|
1064 |
VehicleEnterDepot(v); |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4048
diff
changeset
|
1065 |
return 4; |
3060 | 1066 |
} |
1067 |
break; |
|
1068 |
||
1069 |
default: break; |
|
0 | 1070 |
} |
1071 |
return 0; |
|
1072 |
} |
|
1073 |
||
1074 |
||
2436
177cb6a8339f
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2425
diff
changeset
|
1075 |
static void ChangeTileOwner_Road(TileIndex tile, PlayerID old_player, PlayerID new_player) |
0 | 1076 |
{ |
3274 | 1077 |
if (IsLevelCrossing(tile) && GetCrossingRoadOwner(tile) == old_player) { |
4848
56549aa3e234
(svn r6774) -Codechange: Rename the badly named OWNER_SPECTATOR to PLAYER_SPECTATOR and
Darkvater
parents:
4725
diff
changeset
|
1078 |
SetCrossingRoadOwner(tile, new_player == PLAYER_SPECTATOR ? OWNER_NONE : new_player); |
0 | 1079 |
} |
1080 |
||
1901
fb05044cf5c3
(svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents:
1891
diff
changeset
|
1081 |
if (!IsTileOwner(tile, old_player)) return; |
0 | 1082 |
|
4848
56549aa3e234
(svn r6774) -Codechange: Rename the badly named OWNER_SPECTATOR to PLAYER_SPECTATOR and
Darkvater
parents:
4725
diff
changeset
|
1083 |
if (new_player != PLAYER_SPECTATOR) { |
1902 | 1084 |
SetTileOwner(tile, new_player); |
4000
bab1ebc37da0
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3977
diff
changeset
|
1085 |
} else { |
3793
33cdb5bf7b21
(svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents:
3792
diff
changeset
|
1086 |
switch (GetRoadTileType(tile)) { |
33cdb5bf7b21
(svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents:
3792
diff
changeset
|
1087 |
case ROAD_TILE_NORMAL: |
3060 | 1088 |
SetTileOwner(tile, OWNER_NONE); |
1089 |
break; |
|
1090 |
||
3793
33cdb5bf7b21
(svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents:
3792
diff
changeset
|
1091 |
case ROAD_TILE_CROSSING: |
3319
7d04847e4689
(svn r4085) Add GetTown{Index,ByTile}() to get the town index resp. the town from a tile
tron
parents:
3286
diff
changeset
|
1092 |
MakeRoadNormal(tile, GetCrossingRoadOwner(tile), GetCrossingRoadBits(tile), GetTownIndex(tile)); |
3060 | 1093 |
break; |
1094 |
||
3069
0e6aca11c3da
(svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents:
3068
diff
changeset
|
1095 |
default: |
3793
33cdb5bf7b21
(svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents:
3792
diff
changeset
|
1096 |
case ROAD_TILE_DEPOT: |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3435
diff
changeset
|
1097 |
DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); |
3060 | 1098 |
break; |
0 | 1099 |
} |
1100 |
} |
|
1101 |
} |
|
1102 |
||
1103 |
||
1104 |
const TileTypeProcs _tile_type_road_procs = { |
|
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4246
diff
changeset
|
1105 |
DrawTile_Road, /* draw_tile_proc */ |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4246
diff
changeset
|
1106 |
GetSlopeZ_Road, /* get_slope_z_proc */ |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4246
diff
changeset
|
1107 |
ClearTile_Road, /* clear_tile_proc */ |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4246
diff
changeset
|
1108 |
GetAcceptedCargo_Road, /* get_accepted_cargo_proc */ |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4246
diff
changeset
|
1109 |
GetTileDesc_Road, /* get_tile_desc_proc */ |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4246
diff
changeset
|
1110 |
GetTileTrackStatus_Road, /* get_tile_track_status_proc */ |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4246
diff
changeset
|
1111 |
ClickTile_Road, /* click_tile_proc */ |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4246
diff
changeset
|
1112 |
AnimateTile_Road, /* animate_tile_proc */ |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4246
diff
changeset
|
1113 |
TileLoop_Road, /* tile_loop_clear */ |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4246
diff
changeset
|
1114 |
ChangeTileOwner_Road, /* change_tile_owner_clear */ |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4246
diff
changeset
|
1115 |
NULL, /* get_produced_cargo_proc */ |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4246
diff
changeset
|
1116 |
VehicleEnter_Road, /* vehicle_enter_tile_proc */ |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4246
diff
changeset
|
1117 |
GetSlopeTileh_Road, /* get_slope_tileh_proc */ |
0 | 1118 |
}; |