author | rubidium |
Sun, 03 Feb 2008 20:17:54 +0000 | |
branch | noai |
changeset 9724 | b39bc69bb2f2 |
parent 9723 | eee46cb39750 |
child 9732 | f8eb3e208514 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
9574 | 3 |
/** @file road_cmd.cpp */ |
4 |
||
0 | 5 |
#include "stdafx.h" |
1891
92a3b0aa0946
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1785
diff
changeset
|
6 |
#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
|
7 |
#include "bridge_map.h" |
6486
4f8af35b11eb
(svn r8908) -Codechange: declaration of DrawBridgeMiddle does not belong in a map accessors header.
rubidium
parents:
6460
diff
changeset
|
8 |
#include "bridge.h" |
6460 | 9 |
#include "cmd_helper.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
|
10 |
#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
|
11 |
#include "road_map.h" |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
12 |
#include "road_internal.h" |
4232
628628eaa4fc
(svn r5796) Use DrawTileSprites/DrawTileSeqStruct for road depot drawing data, too
tron
parents:
4231
diff
changeset
|
13 |
#include "sprite.h" |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
14 |
#include "tile_cmd.h" |
9505 | 15 |
#include "landscape.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
|
16 |
#include "town_map.h" |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
17 |
#include "viewport_func.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
18 |
#include "command_func.h" |
0 | 19 |
#include "town.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
|
20 |
#include "yapf/yapf.h" |
1313
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1281
diff
changeset
|
21 |
#include "depot.h" |
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
22 |
#include "newgrf.h" |
9624 | 23 |
#include "station_map.h" |
24 |
#include "tunnel_map.h" |
|
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
25 |
#include "misc/autoptr.hpp" |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
26 |
#include "variables.h" |
9703
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
27 |
#include "autoslope.h" |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
28 |
#include "transparency.h" |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
29 |
#include "tunnelbridge_map.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
30 |
#include "window_func.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
31 |
#include "strings_func.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
32 |
#include "vehicle_func.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
33 |
#include "vehicle_base.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
34 |
#include "sound_func.h" |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
35 |
#include "road_func.h" |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
36 |
#include "tunnelbridge.h" |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
37 |
|
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
38 |
#include "table/sprites.h" |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
39 |
#include "table/strings.h" |
9703
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
40 |
|
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
41 |
#define M(x) (1 << (x)) |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
42 |
/* Level crossings may only be built on these slopes */ |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
43 |
static const uint32 VALID_LEVEL_CROSSING_SLOPES = (M(SLOPE_SEN) | M(SLOPE_ENW) | M(SLOPE_NWS) | M(SLOPE_NS) | M(SLOPE_WSE) | M(SLOPE_EW) | M(SLOPE_FLAT)); |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
44 |
#undef M |
0 | 45 |
|
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
46 |
Foundation GetRoadFoundation(Slope tileh, RoadBits bits); |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
47 |
|
9624 | 48 |
bool CheckAllowRemoveRoad(TileIndex tile, RoadBits remove, Owner owner, bool *edge_road, RoadType rt) |
0 | 49 |
{ |
3149
2b54fc654019
(svn r3770) Remove the _road_special_gettrackstatus hack. Egladil and me deem it unnecessary
tron
parents:
3146
diff
changeset
|
50 |
RoadBits present; |
2b54fc654019
(svn r3770) Remove the _road_special_gettrackstatus hack. Egladil and me deem it unnecessary
tron
parents:
3146
diff
changeset
|
51 |
RoadBits n; |
0 | 52 |
*edge_road = true; |
53 |
||
9624 | 54 |
if (_game_mode == GM_EDITOR || remove == ROAD_NONE) return true; |
0 | 55 |
|
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
56 |
/* Water can always flood and towns can always remove "normal" road pieces. |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
57 |
* Towns are not be allowed to remove non "normal" road pieces, like tram |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
58 |
* tracks as that would result in trams that cannot turn. */ |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
59 |
if (_current_player == OWNER_WATER || |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
60 |
(rt == ROADTYPE_ROAD && !IsValidPlayer(_current_player))) return true; |
0 | 61 |
|
9574 | 62 |
/* Only do the special processing if the road is owned |
63 |
* by a town */ |
|
4849
9a3c3ae7f62f
(svn r6775) -Codechange: Use some more proper types, especially Owner and PlayerID as
Darkvater
parents:
4848
diff
changeset
|
64 |
if (owner != OWNER_TOWN) return (owner == OWNER_NONE) || CheckOwnership(owner); |
0 | 65 |
|
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
|
66 |
if (_cheats.magic_bulldozer.value) return true; |
0 | 67 |
|
9574 | 68 |
/* Get a bitmask of which neighbouring roads has a tile */ |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
69 |
n = ROAD_NONE; |
9624 | 70 |
present = GetAnyRoadBits(tile, rt); |
71 |
if (present & ROAD_NE && GetAnyRoadBits(TILE_ADDXY(tile, -1, 0), rt) & ROAD_SW) n |= ROAD_NE; |
|
72 |
if (present & ROAD_SE && GetAnyRoadBits(TILE_ADDXY(tile, 0, 1), rt) & ROAD_NW) n |= ROAD_SE; |
|
73 |
if (present & ROAD_SW && GetAnyRoadBits(TILE_ADDXY(tile, 1, 0), rt) & ROAD_NE) n |= ROAD_SW; |
|
74 |
if (present & ROAD_NW && GetAnyRoadBits(TILE_ADDXY(tile, 0, -1), rt) & 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
|
75 |
|
9574 | 76 |
/* If 0 or 1 bits are set in n, or if no bits that match the bits to remove, |
77 |
* then allow it */ |
|
3149
2b54fc654019
(svn r3770) Remove the _road_special_gettrackstatus hack. Egladil and me deem it unnecessary
tron
parents:
3146
diff
changeset
|
78 |
if ((n & (n - 1)) != 0 && (n & remove) != 0) { |
0 | 79 |
Town *t; |
80 |
*edge_road = false; |
|
9574 | 81 |
/* 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
|
82 |
if (_patches.extra_dynamite) return true; |
0 | 83 |
|
6582
5f66659ae048
(svn r9065) -Fix: possible dereference of NULL pointer.
rubidium
parents:
6574
diff
changeset
|
84 |
t = ClosestTownFromTile(tile, (uint)-1); |
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
|
85 |
|
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
86 |
SetDParam(0, t->index); |
0 | 87 |
_error_message = STR_2009_LOCAL_AUTHORITY_REFUSES; |
88 |
return false; |
|
89 |
} |
|
90 |
||
91 |
return true; |
|
92 |
} |
|
93 |
||
9624 | 94 |
static bool CheckAllowRemoveRoad(TileIndex tile, RoadBits remove, bool *edge_road, RoadType rt) |
6442
10b44714b85d
(svn r8852) -Fix (r8735): make the dynamite tool for drive through road stops as if it were removing a normal road tile (consider the local authority and such).
rubidium
parents:
6317
diff
changeset
|
95 |
{ |
9624 | 96 |
return CheckAllowRemoveRoad(tile, remove, GetRoadOwner(tile, rt), edge_road, rt); |
6442
10b44714b85d
(svn r8852) -Fix (r8735): make the dynamite tool for drive through road stops as if it were removing a normal road tile (consider the local authority and such).
rubidium
parents:
6317
diff
changeset
|
97 |
} |
0 | 98 |
|
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
99 |
|
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
100 |
/** 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
|
101 |
* @param tile tile where to remove road from |
9601
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9574
diff
changeset
|
102 |
* @param flags operation to perform |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
103 |
* @param pieces roadbits to remove |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
104 |
* @param rt roadtype to remove |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
105 |
* @param crossing_check should we check if there is a tram track when we are removing road from crossing? |
0 | 106 |
*/ |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
107 |
static CommandCost RemoveRoad(TileIndex tile, uint32 flags, RoadBits pieces, RoadType rt, bool crossing_check) |
0 | 108 |
{ |
9574 | 109 |
/* cost for removing inner/edge -roads */ |
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
|
110 |
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
|
111 |
|
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
112 |
/* 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
|
113 |
* false if it was a center piece. Affects town ratings drop */ |
0 | 114 |
bool edge_road; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
115 |
|
9641
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
116 |
Town *t = NULL; |
9624 | 117 |
switch (GetTileType(tile)) { |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
118 |
case MP_ROAD: |
9641
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
119 |
if (_game_mode != GM_EDITOR && GetRoadOwner(tile, rt) == OWNER_TOWN) t = GetTownByTile(tile); |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
120 |
if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR; |
9624 | 121 |
break; |
122 |
||
123 |
case MP_STATION: |
|
124 |
if (!IsDriveThroughStopTile(tile)) return CMD_ERROR; |
|
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
125 |
if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR; |
9624 | 126 |
break; |
127 |
||
128 |
case MP_TUNNELBRIDGE: |
|
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
129 |
if (GetTunnelBridgeTransportType(tile) != TRANSPORT_ROAD) return CMD_ERROR; |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
130 |
if (GetVehicleTunnelBridge(tile, GetOtherTunnelBridgeEnd(tile)) != NULL) return CMD_ERROR; |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
131 |
break; |
9624 | 132 |
|
133 |
default: |
|
134 |
return CMD_ERROR; |
|
135 |
} |
|
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
|
136 |
|
9624 | 137 |
RoadTypes rts = GetRoadTypes(tile); |
138 |
/* The tile doesn't have the given road type */ |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
139 |
if (!HasBit(rts, rt)) return CMD_ERROR; |
6460 | 140 |
|
9624 | 141 |
if (!CheckAllowRemoveRoad(tile, pieces, &edge_road, rt)) return CMD_ERROR; |
0 | 142 |
|
9574 | 143 |
/* check if you're allowed to remove the street owned by a town |
144 |
* removal allowance depends on difficulty setting */ |
|
5573
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5212
diff
changeset
|
145 |
if (!CheckforTownRating(flags, t, ROAD_REMOVE)) return CMD_ERROR; |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5212
diff
changeset
|
146 |
|
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
147 |
if (!IsTileType(tile, MP_ROAD)) { |
9624 | 148 |
/* If it's the last roadtype, just clear the whole tile */ |
149 |
if (rts == RoadTypeToRoadTypes(rt)) return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
|
150 |
||
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
151 |
CommandCost cost(EXPENSES_CONSTRUCTION); |
9624 | 152 |
if (IsTileType(tile, MP_TUNNELBRIDGE)) { |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
153 |
TileIndex other_end = GetOtherTunnelBridgeEnd(tile); |
9624 | 154 |
/* Pay for *every* tile of the bridge or tunnel */ |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
155 |
cost.AddCost((GetTunnelBridgeLength(other_end, tile) + 2) * _price.remove_road); |
9624 | 156 |
if (flags & DC_EXEC) { |
157 |
SetRoadTypes(other_end, GetRoadTypes(other_end) & ~RoadTypeToRoadTypes(rt)); |
|
158 |
SetRoadTypes(tile, GetRoadTypes(tile) & ~RoadTypeToRoadTypes(rt)); |
|
159 |
||
160 |
/* Mark tiles diry that have been repaved */ |
|
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
161 |
MarkTileDirtyByTile(tile); |
9624 | 162 |
MarkTileDirtyByTile(other_end); |
163 |
if (IsBridge(tile)) { |
|
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
164 |
TileIndexDiff delta = TileOffsByDiagDir(GetTunnelBridgeDirection(tile)); |
9624 | 165 |
|
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
166 |
for (TileIndex t = tile + delta; t != other_end; t += delta) MarkTileDirtyByTile(t); |
9624 | 167 |
} |
168 |
} |
|
169 |
} else { |
|
9629 | 170 |
cost.AddCost(_price.remove_road); |
9624 | 171 |
if (flags & DC_EXEC) { |
172 |
SetRoadTypes(tile, GetRoadTypes(tile) & ~RoadTypeToRoadTypes(rt)); |
|
173 |
MarkTileDirtyByTile(tile); |
|
174 |
} |
|
175 |
} |
|
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
176 |
return cost; |
9624 | 177 |
} |
178 |
||
5573
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5212
diff
changeset
|
179 |
switch (GetRoadTileType(tile)) { |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5212
diff
changeset
|
180 |
case ROAD_TILE_NORMAL: { |
9624 | 181 |
RoadBits present = GetRoadBits(tile, rt); |
5573
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5212
diff
changeset
|
182 |
RoadBits c = pieces; |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5212
diff
changeset
|
183 |
|
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5212
diff
changeset
|
184 |
if (HasRoadWorks(tile)) return_cmd_error(STR_ROAD_WORKS_IN_PROGRESS); |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5212
diff
changeset
|
185 |
|
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5212
diff
changeset
|
186 |
if (GetTileSlope(tile, NULL) != SLOPE_FLAT && |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5212
diff
changeset
|
187 |
(present == ROAD_Y || present == ROAD_X)) { |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
188 |
c |= (RoadBits)((c & 0xC) >> 2); |
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
189 |
c |= (RoadBits)((c & 0x3) << 2); |
5573
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5212
diff
changeset
|
190 |
} |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5212
diff
changeset
|
191 |
|
9574 | 192 |
/* limit the bits to delete to the existing bits. */ |
5573
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5212
diff
changeset
|
193 |
c &= present; |
9624 | 194 |
if (c == ROAD_NONE) return CMD_ERROR; |
5573
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5212
diff
changeset
|
195 |
|
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
196 |
ChangeTownRating(t, -road_remove_cost[(byte)edge_road], RATING_ROAD_MINIMUM); |
5573
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5212
diff
changeset
|
197 |
if (flags & DC_EXEC) { |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5212
diff
changeset
|
198 |
present ^= c; |
9624 | 199 |
if (present == ROAD_NONE) { |
200 |
RoadTypes rts = GetRoadTypes(tile) & ComplementRoadTypes(RoadTypeToRoadTypes(rt)); |
|
201 |
if (rts == ROADTYPES_NONE) { |
|
9703
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
202 |
/* Includes MarkTileDirtyByTile() */ |
9624 | 203 |
DoClearSquare(tile); |
204 |
} else { |
|
205 |
SetRoadBits(tile, ROAD_NONE, rt); |
|
206 |
SetRoadTypes(tile, rts); |
|
9703
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
207 |
MarkTileDirtyByTile(tile); |
9624 | 208 |
} |
5573
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5212
diff
changeset
|
209 |
} else { |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
210 |
/* When bits are removed, you *always* end up with something that |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
211 |
* is not a complete straight road tile. However, trams do not have |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
212 |
* onewayness, so they cannot remove it either. */ |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
213 |
if (rt != ROADTYPE_TRAM) SetDisallowedRoadDirections(tile, DRD_NONE); |
9624 | 214 |
SetRoadBits(tile, present, rt); |
5573
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5212
diff
changeset
|
215 |
MarkTileDirtyByTile(tile); |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5212
diff
changeset
|
216 |
} |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5212
diff
changeset
|
217 |
} |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
218 |
return CommandCost(EXPENSES_CONSTRUCTION, CountBits(c) * _price.remove_road); |
5573
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5212
diff
changeset
|
219 |
} |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5212
diff
changeset
|
220 |
|
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5212
diff
changeset
|
221 |
case ROAD_TILE_CROSSING: { |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5212
diff
changeset
|
222 |
if (pieces & ComplementRoadBits(GetCrossingRoadBits(tile))) { |
3176 | 223 |
return CMD_ERROR; |
0 | 224 |
} |
225 |
||
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
226 |
/* Don't allow road to be removed from the crossing when there is tram; |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
227 |
* we can't draw the crossing without trambits ;) */ |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
228 |
if (rt == ROADTYPE_ROAD && HasBit(GetRoadTypes(tile), ROADTYPE_TRAM) && (flags & DC_EXEC || crossing_check)) return CMD_ERROR; |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
229 |
|
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
230 |
if (rt == ROADTYPE_ROAD) { |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
231 |
ChangeTownRating(t, -road_remove_cost[(byte)edge_road], RATING_ROAD_MINIMUM); |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
232 |
} |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
233 |
|
0 | 234 |
if (flags & DC_EXEC) { |
9624 | 235 |
RoadTypes rts = GetRoadTypes(tile) & ComplementRoadTypes(RoadTypeToRoadTypes(rt)); |
236 |
if (rts == ROADTYPES_NONE) { |
|
237 |
MakeRailNormal(tile, GetTileOwner(tile), GetCrossingRailBits(tile), GetRailType(tile)); |
|
238 |
} else { |
|
239 |
SetRoadTypes(tile, rts); |
|
240 |
} |
|
3060 | 241 |
MarkTileDirtyByTile(tile); |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
242 |
YapfNotifyTrackLayoutChange(tile, FindFirstTrack(GetTrackBits(tile))); |
0 | 243 |
} |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
244 |
return CommandCost(EXPENSES_CONSTRUCTION, _price.remove_road * 2); |
5573
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5212
diff
changeset
|
245 |
} |
3977
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3933
diff
changeset
|
246 |
|
5573
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5212
diff
changeset
|
247 |
default: |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5212
diff
changeset
|
248 |
case ROAD_TILE_DEPOT: |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5212
diff
changeset
|
249 |
return CMD_ERROR; |
0 | 250 |
} |
251 |
} |
|
252 |
||
253 |
||
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
254 |
/** Delete a piece of road. |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
255 |
* @param tile tile where to remove road from |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
256 |
* @param flags operation to perform |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
257 |
* @param p1 bit 0..3 road pieces to remove (RoadBits) |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
258 |
* bit 4..5 road type |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
259 |
* @param p2 unused |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
260 |
*/ |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
261 |
CommandCost CmdRemoveRoad(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
262 |
{ |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
263 |
RoadType rt = (RoadType)GB(p1, 4, 2); |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
264 |
if (!IsValidRoadType(rt)) return CMD_ERROR; |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
265 |
|
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
266 |
RoadBits pieces = Extract<RoadBits, 0>(p1); |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
267 |
|
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
268 |
return RemoveRoad(tile, flags, pieces, rt, true); |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
269 |
} |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
270 |
|
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
271 |
|
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
|
272 |
static const RoadBits _valid_tileh_slopes_road[][15] = { |
9574 | 273 |
/* set of normal ones */ |
0 | 274 |
{ |
9704 | 275 |
ROAD_ALL, // SLOPE_FLAT |
276 |
ROAD_NONE, // SLOPE_W |
|
277 |
ROAD_NONE, // SLOPE_S |
|
278 |
||
279 |
ROAD_X, // SLOPE_SW |
|
280 |
ROAD_NONE, // SLOPE_E |
|
281 |
ROAD_NONE, // SLOPE_EW |
|
282 |
||
283 |
ROAD_Y, // SLOPE_SE |
|
284 |
ROAD_NONE, // SLOPE_WSE |
|
285 |
ROAD_NONE, // SLOPE_N |
|
286 |
||
287 |
ROAD_Y, // SLOPE_NW |
|
288 |
ROAD_NONE, // SLOPE_NS |
|
289 |
ROAD_NONE, // SLOPE_NE |
|
290 |
||
291 |
ROAD_X, // SLOPE_ENW |
|
292 |
ROAD_NONE, // SLOPE_SEN |
|
293 |
ROAD_NONE // SLOPE_ELEVATED |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
294 |
}, |
9574 | 295 |
/* 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
|
296 |
{ |
9704 | 297 |
ROAD_NONE, // SLOPE_FLAT |
298 |
ROAD_SW | ROAD_NW, // SLOPE_W |
|
299 |
ROAD_SW | ROAD_SE, // SLOPE_S |
|
0 | 300 |
|
9704 | 301 |
ROAD_Y | ROAD_SW, // SLOPE_SW |
302 |
ROAD_SE | ROAD_NE, // SLOPE_E |
|
303 |
ROAD_ALL, // SLOPE_EW |
|
0 | 304 |
|
9704 | 305 |
ROAD_X | ROAD_SE, // SLOPE_SE |
306 |
ROAD_ALL, // SLOPE_WSE |
|
307 |
ROAD_NW | ROAD_NE, // SLOPE_N |
|
0 | 308 |
|
9704 | 309 |
ROAD_X | ROAD_NW, // SLOPE_NW |
310 |
ROAD_ALL, // SLOPE_NS |
|
311 |
ROAD_ALL, // SLOPE_NE |
|
312 |
||
313 |
ROAD_Y | ROAD_NE, // SLOPE_ENW |
|
314 |
ROAD_ALL, // SLOPE_SEN |
|
315 |
ROAD_ALL // SLOPE_ELEVATED |
|
316 |
}, |
|
317 |
/* Singe bits on slopes */ |
|
318 |
{ |
|
319 |
ROAD_ALL, // SLOPE_FLAT |
|
320 |
ROAD_NE | ROAD_SE, // SLOPE_W |
|
321 |
ROAD_NE | ROAD_NW, // SLOPE_S |
|
322 |
||
323 |
ROAD_NE, // SLOPE_SW |
|
324 |
ROAD_NW | ROAD_SW, // SLOPE_E |
|
325 |
ROAD_ALL, // SLOPE_EW |
|
326 |
||
327 |
ROAD_NW, // SLOPE_SE |
|
328 |
ROAD_ALL, // SLOPE_WSE |
|
329 |
ROAD_SE | ROAD_SW, // SLOPE_N |
|
330 |
||
331 |
ROAD_SE, // SLOPE_NW |
|
332 |
ROAD_ALL, // SLOPE_NS |
|
333 |
ROAD_ALL, // SLOPE_NE |
|
334 |
||
335 |
ROAD_SW, // SLOPE_ENW |
|
336 |
ROAD_ALL, // SLOPE_SEN |
|
337 |
ROAD_ALL, // SLOPE_ELEVATED |
|
13
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
338 |
}, |
0 | 339 |
}; |
340 |
||
9704 | 341 |
/** |
342 |
* Calculate the costs for roads on slopes |
|
343 |
* Aside modify the RoadBits to fit on the slopes |
|
344 |
* |
|
345 |
* @note The RoadBits are modified too! |
|
346 |
* @param tileh The current slope |
|
347 |
* @param pieces The RoadBits we want to add |
|
348 |
* @param existing The existent RoadBits |
|
349 |
* @return The costs for these RoadBits on this slope |
|
350 |
*/ |
|
9629 | 351 |
static CommandCost CheckRoadSlope(Slope tileh, RoadBits* pieces, RoadBits existing) |
0 | 352 |
{ |
4246
14a8849c32df
(svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents:
4232
diff
changeset
|
353 |
if (IsSteepSlope(tileh)) { |
9704 | 354 |
/* Force straight roads. */ |
355 |
*pieces |= MirrorRoadBits(*pieces); |
|
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
356 |
|
9704 | 357 |
if (existing == ROAD_NONE || existing == *pieces) { |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
358 |
if (*pieces == ROAD_X || *pieces == ROAD_Y) return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform); |
4246
14a8849c32df
(svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents:
4232
diff
changeset
|
359 |
} |
14a8849c32df
(svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents:
4232
diff
changeset
|
360 |
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
|
361 |
} |
9704 | 362 |
|
363 |
RoadBits road_bits = *pieces | existing; |
|
364 |
||
365 |
/* Single bits on slopes. |
|
366 |
* We check for the roads that need at least 2 bits */ |
|
367 |
if (_patches.build_on_slopes && |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
368 |
existing == ROAD_NONE && CountBits(*pieces) == 1 && |
9704 | 369 |
(_valid_tileh_slopes_road[2][tileh] & *pieces) == ROAD_NONE) { |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
370 |
return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform); |
9704 | 371 |
} |
0 | 372 |
|
9574 | 373 |
/* no special foundation */ |
9704 | 374 |
if ((~_valid_tileh_slopes_road[0][tileh] & road_bits) == ROAD_NONE) { |
9574 | 375 |
/* 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
|
376 |
if (tileh != SLOPE_FLAT) *pieces |= _valid_tileh_slopes_road[0][tileh]; |
9629 | 377 |
return CommandCost(); // no extra cost |
3381
ebdcc12845c7
(svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents:
3379
diff
changeset
|
378 |
} |
ebdcc12845c7
(svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents:
3379
diff
changeset
|
379 |
|
9574 | 380 |
/* foundation is used. Whole tile is leveled up */ |
9704 | 381 |
if ((~_valid_tileh_slopes_road[1][tileh] & road_bits) == ROAD_NONE) { |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
382 |
return CommandCost(EXPENSES_CONSTRUCTION, existing != ROAD_NONE ? (Money)0 : _price.terraform); |
3381
ebdcc12845c7
(svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents:
3379
diff
changeset
|
383 |
} |
ebdcc12845c7
(svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents:
3379
diff
changeset
|
384 |
|
9704 | 385 |
/* Force straight roads. */ |
386 |
*pieces |= MirrorRoadBits(*pieces); |
|
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
387 |
|
9574 | 388 |
/* partly leveled up tile, only if there's no road on that tile */ |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
389 |
if ((existing == ROAD_NONE || existing == *pieces) && IsSlopeWithOneCornerRaised(tileh)) { |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
390 |
if (*pieces == ROAD_X || *pieces == ROAD_Y) return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform); |
0 | 391 |
} |
392 |
return CMD_ERROR; |
|
393 |
} |
|
394 |
||
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
395 |
/** 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
|
396 |
* @param tile tile where to build road |
9601
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9574
diff
changeset
|
397 |
* @param flags operation to perform |
6460 | 398 |
* @param p1 bit 0..3 road pieces to build (RoadBits) |
9624 | 399 |
* bit 4..5 road type |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
400 |
* bit 6..7 disallowed directions to toggle |
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
401 |
* @param p2 the town that is building the road (0 if not applicable) |
0 | 402 |
*/ |
9629 | 403 |
CommandCost CmdBuildRoad(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 404 |
{ |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
405 |
CommandCost cost(EXPENSES_CONSTRUCTION); |
9629 | 406 |
CommandCost ret; |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
407 |
RoadBits existing = ROAD_NONE; |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
408 |
RoadBits all_bits = ROAD_NONE; |
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3560
diff
changeset
|
409 |
Slope tileh; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
410 |
|
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
411 |
/* 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
|
412 |
* if a non-player is building the road */ |
6460 | 413 |
if ((IsValidPlayer(_current_player) && p2 != 0) || (_current_player == OWNER_TOWN && !IsValidTownID(p2))) return CMD_ERROR; |
414 |
||
415 |
RoadBits pieces = Extract<RoadBits, 0>(p1); |
|
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
416 |
|
9624 | 417 |
RoadType rt = (RoadType)GB(p1, 4, 2); |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
418 |
if (!IsValidRoadType(rt) || !ValParamRoadType(rt)) return CMD_ERROR; |
9624 | 419 |
|
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
420 |
DisallowedRoadDirections toggle_drd = (DisallowedRoadDirections)GB(p1, 6, 2); |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
421 |
|
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
|
422 |
tileh = GetTileSlope(tile, NULL); |
0 | 423 |
|
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
|
424 |
switch (GetTileType(tile)) { |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
425 |
case MP_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
|
426 |
switch (GetRoadTileType(tile)) { |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
427 |
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
|
428 |
if (HasRoadWorks(tile)) return_cmd_error(STR_ROAD_WORKS_IN_PROGRESS); |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
429 |
if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR; |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
430 |
|
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
431 |
all_bits = GetAllRoadBits(tile); |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
432 |
if (!HasBit(GetRoadTypes(tile), rt)) break; |
4046
566de0b02064
(svn r5315) -Fix: Prohibit altering a road tile while road works are in progress
tron
parents:
4000
diff
changeset
|
433 |
|
9624 | 434 |
existing = GetRoadBits(tile, rt); |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
435 |
RoadBits merged = existing | pieces; |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
436 |
bool crossing = (merged != ROAD_X && merged != ROAD_Y); |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
437 |
if (rt != ROADTYPE_TRAM && (GetDisallowedRoadDirections(tile) != DRD_NONE || toggle_drd != DRD_NONE) && crossing) { |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
438 |
/* Junctions cannot be one-way */ |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
439 |
return_cmd_error(STR_ERR_ONEWAY_ROADS_CAN_T_HAVE_JUNCTION); |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
440 |
} |
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
|
441 |
if ((existing & pieces) == pieces) { |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
442 |
/* We only want to set the (dis)allowed road directions */ |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
443 |
if (toggle_drd != DRD_NONE && rt != ROADTYPE_TRAM && GetRoadOwner(tile, ROADTYPE_ROAD) == _current_player) { |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
444 |
if (crossing) return_cmd_error(STR_ERR_ONEWAY_ROADS_CAN_T_HAVE_JUNCTION); |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
445 |
|
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
446 |
/* Ignore half built tiles */ |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
447 |
if (flags & DC_EXEC && rt != ROADTYPE_TRAM && (existing == ROAD_X || existing == ROAD_Y)) { |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
448 |
SetDisallowedRoadDirections(tile, GetDisallowedRoadDirections(tile) ^ toggle_drd); |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
449 |
MarkTileDirtyByTile(tile); |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
450 |
} |
9629 | 451 |
return CommandCost(); |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
452 |
} |
3066
0d34dff23d98
(svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents:
3061
diff
changeset
|
453 |
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
|
454 |
} |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
455 |
} break; |
3066
0d34dff23d98
(svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents:
3061
diff
changeset
|
456 |
|
3793
33cdb5bf7b21
(svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents:
3792
diff
changeset
|
457 |
case ROAD_TILE_CROSSING: |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
458 |
if (HasBit(GetRoadTypes(tile), rt)) return_cmd_error(STR_1007_ALREADY_BUILT); |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
459 |
all_bits = GetCrossingRoadBits(tile); |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
460 |
if (pieces & ComplementRoadBits(all_bits)) goto do_clear; |
9624 | 461 |
break; |
3066
0d34dff23d98
(svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents:
3061
diff
changeset
|
462 |
|
3069
0e6aca11c3da
(svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents:
3068
diff
changeset
|
463 |
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
|
464 |
case ROAD_TILE_DEPOT: |
3066
0d34dff23d98
(svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents:
3061
diff
changeset
|
465 |
goto do_clear; |
3060 | 466 |
} |
467 |
break; |
|
0 | 468 |
|
3060 | 469 |
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
|
470 |
Axis roaddir; |
13
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
471 |
|
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3560
diff
changeset
|
472 |
if (IsSteepSlope(tileh)) { |
3060 | 473 |
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); |
474 |
} |
|
475 |
||
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
|
476 |
/* Level crossings may only be built on these slopes */ |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
477 |
if (!HasBit(VALID_LEVEL_CROSSING_SLOPES, tileh)) { |
3060 | 478 |
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); |
479 |
} |
|
480 |
||
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
|
481 |
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
|
482 |
switch (GetTrackBits(tile)) { |
95e7bffcb3c5
(svn r3981) More work for the rail accessing functions and enums
tron
parents:
3267
diff
changeset
|
483 |
case TRACK_BIT_X: |
95e7bffcb3c5
(svn r3981) More work for the rail accessing functions and enums
tron
parents:
3267
diff
changeset
|
484 |
if (pieces & ROAD_X) goto do_clear; |
95e7bffcb3c5
(svn r3981) More work for the rail accessing functions and enums
tron
parents:
3267
diff
changeset
|
485 |
roaddir = AXIS_Y; |
95e7bffcb3c5
(svn r3981) More work for the rail accessing functions and enums
tron
parents:
3267
diff
changeset
|
486 |
break; |
95e7bffcb3c5
(svn r3981) More work for the rail accessing functions and enums
tron
parents:
3267
diff
changeset
|
487 |
|
95e7bffcb3c5
(svn r3981) More work for the rail accessing functions and enums
tron
parents:
3267
diff
changeset
|
488 |
case TRACK_BIT_Y: |
95e7bffcb3c5
(svn r3981) More work for the rail accessing functions and enums
tron
parents:
3267
diff
changeset
|
489 |
if (pieces & ROAD_Y) goto do_clear; |
95e7bffcb3c5
(svn r3981) More work for the rail accessing functions and enums
tron
parents:
3267
diff
changeset
|
490 |
roaddir = AXIS_X; |
95e7bffcb3c5
(svn r3981) More work for the rail accessing functions and enums
tron
parents:
3267
diff
changeset
|
491 |
break; |
95e7bffcb3c5
(svn r3981) More work for the rail accessing functions and enums
tron
parents:
3267
diff
changeset
|
492 |
|
95e7bffcb3c5
(svn r3981) More work for the rail accessing functions and enums
tron
parents:
3267
diff
changeset
|
493 |
default: goto do_clear; |
3060 | 494 |
} |
495 |
||
9574 | 496 |
if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR; |
3381
ebdcc12845c7
(svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents:
3379
diff
changeset
|
497 |
|
3060 | 498 |
if (flags & DC_EXEC) { |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
499 |
YapfNotifyTrackLayoutChange(tile, FindFirstTrack(GetTrackBits(tile))); |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
500 |
/* Always add road to the roadtypes (can't draw without it) */ |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
501 |
MakeRoadCrossing(tile, _current_player, _current_player, _current_player, GetTileOwner(tile), roaddir, GetRailType(tile), RoadTypeToRoadTypes(rt) | ROADTYPES_ROAD, p2); |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
502 |
UpdateLevelCrossing(tile, false); |
3100
552cf19c49cb
(svn r3695) Add 2 MarkTileByTile() which I forgot in r3689 (noticed by Belugas)
tron
parents:
3099
diff
changeset
|
503 |
MarkTileDirtyByTile(tile); |
3060 | 504 |
} |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
505 |
return CommandCost(EXPENSES_CONSTRUCTION, _price.build_road * (rt == ROADTYPE_ROAD ? 2 : 4)); |
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
|
506 |
} |
0 | 507 |
|
9624 | 508 |
case MP_STATION: |
509 |
if (!IsDriveThroughStopTile(tile)) return CMD_ERROR; |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
510 |
if (HasBit(GetRoadTypes(tile), rt)) return_cmd_error(STR_1007_ALREADY_BUILT); |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
511 |
/* Don't allow adding roadtype to the roadstop when vehicles are already driving on it */ |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
512 |
if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR; |
9624 | 513 |
break; |
514 |
||
515 |
case MP_TUNNELBRIDGE: |
|
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
516 |
if (GetTunnelBridgeTransportType(tile) != TRANSPORT_ROAD) return CMD_ERROR; |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
517 |
if (HasBit(GetRoadTypes(tile), rt)) return_cmd_error(STR_1007_ALREADY_BUILT); |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
518 |
/* Don't allow adding roadtype to the bridge/tunnel when vehicles are already driving on it */ |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
519 |
if (GetVehicleTunnelBridge(tile, GetOtherTunnelBridgeEnd(tile)) != NULL) return CMD_ERROR; |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
520 |
break; |
9624 | 521 |
|
3060 | 522 |
default: |
0 | 523 |
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
|
524 |
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
|
525 |
if (CmdFailed(ret)) return ret; |
9629 | 526 |
cost.AddCost(ret); |
0 | 527 |
} |
528 |
||
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
529 |
if (all_bits != pieces) { |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
530 |
/* Check the foundation/slopes when adding road/tram bits */ |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
531 |
ret = CheckRoadSlope(tileh, &pieces, all_bits | existing); |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
532 |
/* Return an error if we need to build a foundation (ret != 0) but the |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
533 |
* current patch-setting is turned off (or stupid AI@work) */ |
9629 | 534 |
if (CmdFailed(ret) || (ret.GetCost() != 0 && !_patches.build_on_slopes)) { |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
535 |
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
536 |
} |
9629 | 537 |
cost.AddCost(ret); |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
538 |
} |
0 | 539 |
|
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
540 |
if (IsTileType(tile, MP_ROAD)) { |
9574 | 541 |
/* Don't put the pieces that already exist */ |
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
|
542 |
pieces &= ComplementRoadBits(existing); |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
543 |
|
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
544 |
/* Check if new road bits will have the same foundation as other existing road types */ |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
545 |
if (GetRoadTileType(tile) == ROAD_TILE_NORMAL) { |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
546 |
Slope slope = GetTileSlope(tile, NULL); |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
547 |
Foundation found_new = GetRoadFoundation(slope, pieces | existing); |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
548 |
|
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
549 |
/* Test if all other roadtypes can be built at that foundation */ |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
550 |
for (RoadType rtest = ROADTYPE_ROAD; rtest < ROADTYPE_END; rtest++) { |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
551 |
if (rtest != rt) { // check only other road types |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
552 |
RoadBits bits = GetRoadBits(tile, rtest); |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
553 |
/* do not check if there are not road bits of given type */ |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
554 |
if (bits != ROAD_NONE && GetRoadFoundation(slope, bits) != found_new) { |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
555 |
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
556 |
} |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
557 |
} |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
558 |
} |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
559 |
} |
0 | 560 |
} |
561 |
||
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
562 |
cost.AddCost(CountBits(pieces) * _price.build_road); |
9624 | 563 |
if (IsTileType(tile, MP_TUNNELBRIDGE)) { |
564 |
/* Pay for *every* tile of the bridge or tunnel */ |
|
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
565 |
cost.MultiplyCost(GetTunnelBridgeLength(GetOtherTunnelBridgeEnd(tile), tile) + 2); |
9624 | 566 |
} |
0 | 567 |
|
568 |
if (flags & DC_EXEC) { |
|
9624 | 569 |
switch (GetTileType(tile)) { |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
570 |
case MP_ROAD: { |
9624 | 571 |
RoadTileType rtt = GetRoadTileType(tile); |
572 |
if (existing == ROAD_NONE || rtt == ROAD_TILE_CROSSING) { |
|
573 |
SetRoadTypes(tile, GetRoadTypes(tile) | RoadTypeToRoadTypes(rt)); |
|
574 |
SetRoadOwner(tile, rt, _current_player); |
|
9629 | 575 |
if (_current_player == OWNER_TOWN && rt == ROADTYPE_ROAD) SetTownIndex(tile, p2); |
9624 | 576 |
} |
577 |
if (rtt != ROAD_TILE_CROSSING) SetRoadBits(tile, existing | pieces, rt); |
|
578 |
} break; |
|
579 |
||
580 |
case MP_TUNNELBRIDGE: { |
|
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
581 |
TileIndex other_end = GetOtherTunnelBridgeEnd(tile); |
9624 | 582 |
|
583 |
SetRoadTypes(other_end, GetRoadTypes(other_end) | RoadTypeToRoadTypes(rt)); |
|
584 |
SetRoadTypes(tile, GetRoadTypes(tile) | RoadTypeToRoadTypes(rt)); |
|
585 |
||
586 |
/* Mark tiles diry that have been repaved */ |
|
587 |
MarkTileDirtyByTile(other_end); |
|
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
588 |
MarkTileDirtyByTile(tile); |
9624 | 589 |
if (IsBridge(tile)) { |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
590 |
TileIndexDiff delta = TileOffsByDiagDir(GetTunnelBridgeDirection(tile)); |
9624 | 591 |
|
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
592 |
for (TileIndex t = tile + delta; t != other_end; t += delta) MarkTileDirtyByTile(t); |
9624 | 593 |
} |
594 |
} break; |
|
595 |
||
596 |
case MP_STATION: |
|
597 |
SetRoadTypes(tile, GetRoadTypes(tile) | RoadTypeToRoadTypes(rt)); |
|
598 |
break; |
|
599 |
||
600 |
default: |
|
601 |
MakeRoadNormal(tile, pieces, RoadTypeToRoadTypes(rt), p2, _current_player, _current_player, _current_player); |
|
602 |
break; |
|
0 | 603 |
} |
604 |
||
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
605 |
if (rt != ROADTYPE_TRAM && IsTileType(tile, MP_ROAD) && GetRoadTileType(tile) == ROAD_TILE_NORMAL) { |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
606 |
existing |= pieces; |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
607 |
SetDisallowedRoadDirections(tile, (existing == ROAD_X || existing == ROAD_Y) ? |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
608 |
GetDisallowedRoadDirections(tile) ^ toggle_drd : DRD_NONE); |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
609 |
} |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
610 |
|
0 | 611 |
MarkTileDirtyByTile(tile); |
612 |
} |
|
613 |
return cost; |
|
614 |
} |
|
615 |
||
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
616 |
/** 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
|
617 |
* @param end_tile end tile of drag |
9601
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9574
diff
changeset
|
618 |
* @param flags operation to perform |
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
619 |
* @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
|
620 |
* @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
|
621 |
* - 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
|
622 |
* - 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
|
623 |
* - p2 = (bit 2) - direction: 0 = along x-axis, 1 = along y-axis (p2 & 4) |
9624 | 624 |
* - p2 = (bit 3 + 4) - road type |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
625 |
* - p2 = (bit 5) - set road direction |
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
626 |
*/ |
9629 | 627 |
CommandCost CmdBuildLongRoad(TileIndex end_tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 628 |
{ |
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
|
629 |
TileIndex start_tile, tile; |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
630 |
CommandCost ret, cost(EXPENSES_CONSTRUCTION); |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
631 |
bool had_bridge = false; |
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
632 |
bool had_tunnel = false; |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
633 |
bool had_success = false; |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
634 |
DisallowedRoadDirections drd = DRD_NORTHBOUND; |
0 | 635 |
|
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
|
636 |
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
|
637 |
|
0 | 638 |
start_tile = p1; |
9624 | 639 |
RoadType rt = (RoadType)GB(p2, 3, 2); |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
640 |
if (!IsValidRoadType(rt) || !ValParamRoadType(rt)) return CMD_ERROR; |
0 | 641 |
|
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
642 |
/* Only drag in X or Y direction dictated by the direction variable */ |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
643 |
if (!HasBit(p2, 2) && TileY(start_tile) != TileY(end_tile)) return CMD_ERROR; // x-axis |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
644 |
if (HasBit(p2, 2) && TileX(start_tile) != TileX(end_tile)) return CMD_ERROR; // y-axis |
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
645 |
|
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
646 |
/* Swap start and ending tile, also the half-tile drag var (bit 0 and 1) */ |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
647 |
if (start_tile > end_tile || (start_tile == end_tile && HasBit(p2, 0))) { |
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
648 |
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
|
649 |
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
|
650 |
end_tile = t; |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
651 |
p2 ^= IsInsideMM(p2 & 3, 1, 3) ? 3 : 0; |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
652 |
drd = DRD_SOUTHBOUND; |
0 | 653 |
} |
654 |
||
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
655 |
/* On the X-axis, we have to swap the initial bits, so they |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
656 |
* will be interpreted correctly in the GTTS. Futhermore |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
657 |
* when you just 'click' on one tile to build them. */ |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
658 |
if (HasBit(p2, 2) == (start_tile == end_tile && HasBit(p2, 0) == HasBit(p2, 1))) drd ^= DRD_BOTH; |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
659 |
/* No disallowed direction bits have to be toggled */ |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
660 |
if (!HasBit(p2, 5)) drd = DRD_NONE; |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
661 |
|
0 | 662 |
tile = start_tile; |
9574 | 663 |
/* 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
|
664 |
for (;;) { |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
665 |
RoadBits bits = HasBit(p2, 2) ? ROAD_Y : ROAD_X; |
3098
4c1320da876d
(svn r3687) Complete some bits I missed whenn adding accessor functions for road types and pieces
tron
parents:
3097
diff
changeset
|
666 |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
667 |
if (tile == end_tile && !HasBit(p2, 1)) bits &= ROAD_NW | ROAD_NE; |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
668 |
if (tile == start_tile && HasBit(p2, 0)) bits &= ROAD_SE | ROAD_SW; |
0 | 669 |
|
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
670 |
ret = DoCommand(tile, drd << 6 | rt << 4 | 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
|
671 |
if (CmdFailed(ret)) { |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
672 |
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
|
673 |
_error_message = INVALID_STRING_ID; |
2549 | 674 |
} else { |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
675 |
had_success = true; |
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
676 |
/* Only pay for the upgrade on one side of the bridges and tunnels */ |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
677 |
if (IsTileType(tile, MP_TUNNELBRIDGE)) { |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
678 |
if (IsBridge(tile)) { |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
679 |
if ((!had_bridge || GetTunnelBridgeDirection(tile) == DIAGDIR_SE || GetTunnelBridgeDirection(tile) == DIAGDIR_SW)) { |
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
680 |
cost.AddCost(ret); |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
681 |
} |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
682 |
had_bridge = true; |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
683 |
} else { // IsTunnel(tile) |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
684 |
if ((!had_tunnel || GetTunnelBridgeDirection(tile) == DIAGDIR_SE || GetTunnelBridgeDirection(tile) == DIAGDIR_SW)) { |
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
685 |
cost.AddCost(ret); |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
686 |
} |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
687 |
had_tunnel = true; |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
688 |
} |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
689 |
} else { |
9629 | 690 |
cost.AddCost(ret); |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
691 |
} |
2549 | 692 |
} |
0 | 693 |
|
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
694 |
if (tile == end_tile) break; |
0 | 695 |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
696 |
tile += HasBit(p2, 2) ? TileDiffXY(0, 1) : TileDiffXY(1, 0); |
0 | 697 |
} |
698 |
||
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
699 |
return !had_success ? CMD_ERROR : cost; |
0 | 700 |
} |
701 |
||
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
702 |
/** 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
|
703 |
* @param end_tile end tile of drag |
9601
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9574
diff
changeset
|
704 |
* @param flags operation to perform |
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
705 |
* @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
|
706 |
* @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
|
707 |
* - 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
|
708 |
* - 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
|
709 |
* - p2 = (bit 2) - direction: 0 = along x-axis, 1 = along y-axis (p2 & 4) |
9624 | 710 |
* - p2 = (bit 3 + 4) - road type |
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
711 |
*/ |
9629 | 712 |
CommandCost CmdRemoveLongRoad(TileIndex end_tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 713 |
{ |
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
|
714 |
TileIndex start_tile, tile; |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
715 |
CommandCost ret, cost(EXPENSES_CONSTRUCTION); |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
716 |
Money money; |
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
|
717 |
|
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
|
718 |
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
|
719 |
|
0 | 720 |
start_tile = p1; |
9624 | 721 |
RoadType rt = (RoadType)GB(p2, 3, 2); |
722 |
if (!IsValidRoadType(rt)) return CMD_ERROR; |
|
0 | 723 |
|
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
724 |
/* Only drag in X or Y direction dictated by the direction variable */ |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
725 |
if (!HasBit(p2, 2) && TileY(start_tile) != TileY(end_tile)) return CMD_ERROR; // x-axis |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
726 |
if (HasBit(p2, 2) && TileX(start_tile) != TileX(end_tile)) return CMD_ERROR; // y-axis |
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
727 |
|
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
728 |
/* Swap start and ending tile, also the half-tile drag var (bit 0 and 1) */ |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
729 |
if (start_tile > end_tile || (start_tile == end_tile && HasBit(p2, 0))) { |
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
730 |
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
|
731 |
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
|
732 |
end_tile = t; |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
733 |
p2 ^= IsInsideMM(p2 & 3, 1, 3) ? 3 : 0; |
0 | 734 |
} |
735 |
||
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
736 |
money = GetAvailableMoneyForCommand(); |
0 | 737 |
tile = start_tile; |
9574 | 738 |
/* 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
|
739 |
for (;;) { |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
740 |
RoadBits bits = HasBit(p2, 2) ? ROAD_Y : ROAD_X; |
3098
4c1320da876d
(svn r3687) Complete some bits I missed whenn adding accessor functions for road types and pieces
tron
parents:
3097
diff
changeset
|
741 |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
742 |
if (tile == end_tile && !HasBit(p2, 1)) bits &= ROAD_NW | ROAD_NE; |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
743 |
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
|
744 |
|
9574 | 745 |
/* 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
|
746 |
if (bits != 0) { |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
747 |
ret = RemoveRoad(tile, flags & ~DC_EXEC, bits, rt, true); |
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
748 |
if (CmdSucceeded(ret)) { |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
749 |
if (flags & DC_EXEC) { |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
750 |
money -= ret.GetCost(); |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
751 |
if (money < 0) { |
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
752 |
_additional_cash_required = DoCommand(end_tile, start_tile, p2, flags & ~DC_EXEC, CMD_REMOVE_LONG_ROAD).GetCost(); |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
753 |
return cost; |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
754 |
} |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
755 |
RemoveRoad(tile, flags, bits, rt, true); |
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
756 |
} |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
757 |
cost.AddCost(ret); |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
758 |
} |
0 | 759 |
} |
760 |
||
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
761 |
if (tile == end_tile) break; |
0 | 762 |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
763 |
tile += HasBit(p2, 2) ? TileDiffXY(0, 1) : TileDiffXY(1, 0); |
0 | 764 |
} |
765 |
||
9629 | 766 |
return (cost.GetCost() == 0) ? CMD_ERROR : cost; |
0 | 767 |
} |
768 |
||
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
769 |
/** 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
|
770 |
* @param tile tile where to build the depot |
9601
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9574
diff
changeset
|
771 |
* @param flags operation to perform |
6460 | 772 |
* @param p1 bit 0..1 entrance direction (DiagDirection) |
9624 | 773 |
* bit 2..3 road type |
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1638
diff
changeset
|
774 |
* @param p2 unused |
2085
ae9e92ffe168
(svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents:
2074
diff
changeset
|
775 |
* |
ae9e92ffe168
(svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents:
2074
diff
changeset
|
776 |
* @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
|
777 |
* distingush between "Flat land required" and "land sloped in wrong direction" |
0 | 778 |
*/ |
9629 | 779 |
CommandCost CmdBuildRoadDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 780 |
{ |
9629 | 781 |
CommandCost cost; |
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3560
diff
changeset
|
782 |
Slope tileh; |
0 | 783 |
|
6460 | 784 |
DiagDirection dir = Extract<DiagDirection, 0>(p1); |
9624 | 785 |
RoadType rt = (RoadType)GB(p1, 2, 2); |
786 |
||
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
787 |
if (!IsValidRoadType(rt) || !ValParamRoadType(rt)) 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
|
788 |
|
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
|
789 |
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
|
790 |
if (tileh != SLOPE_FLAT && ( |
2549 | 791 |
!_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
|
792 |
IsSteepSlope(tileh) || |
6460 | 793 |
!CanBuildDepotByTileh(dir, tileh) |
2549 | 794 |
)) { |
795 |
return_cmd_error(STR_0007_FLAT_LAND_REQUIRED); |
|
0 | 796 |
} |
797 |
||
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
|
798 |
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
|
799 |
if (CmdFailed(cost)) return CMD_ERROR; |
0 | 800 |
|
5573
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5212
diff
changeset
|
801 |
if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST); |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5212
diff
changeset
|
802 |
|
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
803 |
Depot *dep = new Depot(tile); |
2549 | 804 |
if (dep == NULL) return CMD_ERROR; |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
805 |
AutoPtrT<Depot> d_auto_delete = dep; |
0 | 806 |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
807 |
if (flags & DC_EXEC) { |
0 | 808 |
dep->town_index = ClosestTownFromTile(tile, (uint)-1)->index; |
809 |
||
9624 | 810 |
MakeRoadDepot(tile, _current_player, dir, rt); |
3100
552cf19c49cb
(svn r3695) Add 2 MarkTileByTile() which I forgot in r3689 (noticed by Belugas)
tron
parents:
3099
diff
changeset
|
811 |
MarkTileDirtyByTile(tile); |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
812 |
d_auto_delete.Detach(); |
0 | 813 |
} |
9629 | 814 |
return cost.AddCost(_price.build_road_depot); |
0 | 815 |
} |
816 |
||
9629 | 817 |
static CommandCost RemoveRoadDepot(TileIndex tile, uint32 flags) |
0 | 818 |
{ |
149
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
84
diff
changeset
|
819 |
if (!CheckTileOwnership(tile) && _current_player != OWNER_WATER) |
0 | 820 |
return CMD_ERROR; |
821 |
||
9718
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9704
diff
changeset
|
822 |
if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR; |
0 | 823 |
|
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
824 |
if (flags & DC_EXEC) { |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
825 |
DoClearSquare(tile); |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
826 |
delete GetDepotByTile(tile); |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
827 |
} |
0 | 828 |
|
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
829 |
return CommandCost(EXPENSES_CONSTRUCTION, _price.remove_road_depot); |
0 | 830 |
} |
831 |
||
9629 | 832 |
static CommandCost ClearTile_Road(TileIndex tile, byte flags) |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
833 |
{ |
3793
33cdb5bf7b21
(svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents:
3792
diff
changeset
|
834 |
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
|
835 |
case ROAD_TILE_NORMAL: { |
9624 | 836 |
RoadBits b = GetAllRoadBits(tile); |
0 | 837 |
|
5888
3117320a611b
(svn r8096) -Codechange: Invert the check if you are allowed to clear a road tile so there are not so many negations (too confusing) and added some comments to further clarify what happens.
Darkvater
parents:
5838
diff
changeset
|
838 |
/* Clear the road if only one piece is on the tile OR the AI tries |
3117320a611b
(svn r8096) -Codechange: Invert the check if you are allowed to clear a road tile so there are not so many negations (too confusing) and added some comments to further clarify what happens.
Darkvater
parents:
5838
diff
changeset
|
839 |
* to clear town road OR we are not using the DC_AUTO flag */ |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
840 |
if ((CountBits(b) == 1 && GetRoadBits(tile, ROADTYPE_TRAM) == ROAD_NONE) || |
9704 | 841 |
IsTileOwner(tile, OWNER_TOWN) || !(flags & DC_AUTO) |
842 |
) { |
|
9624 | 843 |
RoadTypes rts = GetRoadTypes(tile); |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
844 |
CommandCost ret(EXPENSES_CONSTRUCTION); |
9624 | 845 |
for (RoadType rt = ROADTYPE_ROAD; rt < ROADTYPE_END; rt++) { |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
846 |
if (HasBit(rts, rt)) { |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
847 |
CommandCost tmp_ret = RemoveRoad(tile, flags, GetRoadBits(tile, rt), rt, true); |
9624 | 848 |
if (CmdFailed(tmp_ret)) return tmp_ret; |
9629 | 849 |
ret.AddCost(tmp_ret); |
9624 | 850 |
} |
851 |
} |
|
852 |
return ret; |
|
3060 | 853 |
} |
5888
3117320a611b
(svn r8096) -Codechange: Invert the check if you are allowed to clear a road tile so there are not so many negations (too confusing) and added some comments to further clarify what happens.
Darkvater
parents:
5838
diff
changeset
|
854 |
return_cmd_error(STR_1801_MUST_REMOVE_ROAD_FIRST); |
5894
eb5ff472c10f
(svn r8102) -Cleanup: Remove unreachable code (r8096), useless cast
Darkvater
parents:
5888
diff
changeset
|
855 |
} |
0 | 856 |
|
3793
33cdb5bf7b21
(svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents:
3792
diff
changeset
|
857 |
case ROAD_TILE_CROSSING: { |
9626 | 858 |
RoadTypes rts = GetRoadTypes(tile); |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
859 |
CommandCost ret(EXPENSES_CONSTRUCTION); |
3060 | 860 |
|
3069
0e6aca11c3da
(svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents:
3068
diff
changeset
|
861 |
if (flags & DC_AUTO) return_cmd_error(STR_1801_MUST_REMOVE_ROAD_FIRST); |
3060 | 862 |
|
9626 | 863 |
/* Must iterate over the roadtypes in a reverse manner because |
864 |
* tram tracks must be removed before the road bits. */ |
|
865 |
for (RoadType rt = ROADTYPE_HWAY; rt >= ROADTYPE_ROAD; rt--) { |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
866 |
if (HasBit(rts, rt)) { |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
867 |
CommandCost tmp_ret = RemoveRoad(tile, flags, GetCrossingRoadBits(tile), rt, false); |
9626 | 868 |
if (CmdFailed(tmp_ret)) return tmp_ret; |
9629 | 869 |
ret.AddCost(tmp_ret); |
9626 | 870 |
} |
871 |
} |
|
3060 | 872 |
|
873 |
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
|
874 |
DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
3060 | 875 |
} |
876 |
return ret; |
|
877 |
} |
|
878 |
||
3069
0e6aca11c3da
(svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents:
3068
diff
changeset
|
879 |
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
|
880 |
case ROAD_TILE_DEPOT: |
3060 | 881 |
if (flags & DC_AUTO) { |
882 |
return_cmd_error(STR_2004_BUILDING_MUST_BE_DEMOLISHED); |
|
883 |
} |
|
884 |
return RemoveRoadDepot(tile, flags); |
|
0 | 885 |
} |
886 |
} |
|
887 |
||
888 |
||
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6498
diff
changeset
|
889 |
struct DrawRoadTileStruct { |
0 | 890 |
uint16 image; |
891 |
byte subcoord_x; |
|
892 |
byte subcoord_y; |
|
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6498
diff
changeset
|
893 |
}; |
0 | 894 |
|
895 |
#include "table/road_land.h" |
|
896 |
||
897 |
||
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
898 |
Foundation 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
|
899 |
{ |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
900 |
if (!IsSteepSlope(tileh)) { |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
901 |
if ((~_valid_tileh_slopes_road[0][tileh] & bits) == 0) { |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
902 |
/* As one can remove a single road piece when in a corner on a foundation as |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
903 |
* it is on a sloped piece of landscape, one creates a state that cannot be |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
904 |
* created directly, but the state itself is still perfectly drawable. |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
905 |
* However, as we do not want this to be build directly, we need to check |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
906 |
* for that situation in here. */ |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
907 |
return (tileh != 0 && CountBits(bits) == 1) ? FOUNDATION_LEVELED : FOUNDATION_NONE; |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
908 |
} |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
909 |
if ((~_valid_tileh_slopes_road[1][tileh] & bits) == 0) return FOUNDATION_LEVELED; |
4246
14a8849c32df
(svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents:
4232
diff
changeset
|
910 |
} |
0 | 911 |
|
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
912 |
return (bits == ROAD_X ? FOUNDATION_INCLINED_X : FOUNDATION_INCLINED_Y); |
0 | 913 |
} |
914 |
||
915 |
const byte _road_sloped_sprites[14] = { |
|
916 |
0, 0, 2, 0, |
|
917 |
0, 1, 0, 0, |
|
918 |
3, 0, 0, 0, |
|
919 |
0, 0 |
|
920 |
}; |
|
921 |
||
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
|
922 |
/** |
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
923 |
* Whether to draw unpaved roads regardless of the town zone. |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
924 |
* By default, OpenTTD always draws roads as unpaved if they are on a desert |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
925 |
* tile or above the snowline. Newgrf files, however, can set a bit that allows |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
926 |
* paved roads to be built on desert tiles as they would be on grassy tiles. |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
927 |
* |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
928 |
* @param tile The tile the road is on |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
929 |
* @param roadside What sort of road this is |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
930 |
* @return True if the road should be drawn unpaved regardless of the roadside. |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
931 |
*/ |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
932 |
static bool AlwaysDrawUnpavedRoads(TileIndex tile, Roadside roadside) |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
933 |
{ |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
934 |
return (IsOnSnow(tile) && |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
935 |
!(_opt.landscape == LT_TROPIC && HasGrfMiscBit(GMB_DESERT_PAVED_ROADS) && |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
936 |
roadside != ROADSIDE_BARREN && roadside != ROADSIDE_GRASS && roadside != ROADSIDE_GRASS_ROAD_WORKS)); |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
937 |
} |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
938 |
|
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
939 |
/** |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
940 |
* Draws the catenary for the given tile |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
941 |
* @param ti information about the tile (slopes, height etc) |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
942 |
* @param tram the roadbits for the tram |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
943 |
*/ |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
944 |
void DrawTramCatenary(TileInfo *ti, RoadBits tram) |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
945 |
{ |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
946 |
/* Don't draw the catenary under a low bridge */ |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
947 |
if (MayHaveBridgeAbove(ti->tile) && IsBridgeAbove(ti->tile) && !IsTransparencySet(TO_BUILDINGS)) { |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
948 |
uint height = GetBridgeHeight(GetNorthernBridgeEnd(ti->tile)); |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
949 |
|
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
950 |
if (height <= GetTileMaxZ(ti->tile) + TILE_HEIGHT) return; |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
951 |
} |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
952 |
|
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
953 |
SpriteID front; |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
954 |
SpriteID back; |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
955 |
|
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
956 |
if (ti->tileh != SLOPE_FLAT) { |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
957 |
back = SPR_TRAMWAY_BACK_WIRES_SLOPED + _road_sloped_sprites[ti->tileh - 1]; |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
958 |
front = SPR_TRAMWAY_FRONT_WIRES_SLOPED + _road_sloped_sprites[ti->tileh - 1]; |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
959 |
} else { |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
960 |
back = SPR_TRAMWAY_BASE + _road_backpole_sprites_1[tram]; |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
961 |
front = SPR_TRAMWAY_BASE + _road_frontwire_sprites_1[tram]; |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
962 |
} |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
963 |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
964 |
AddSortableSpriteToDraw(back, PAL_NONE, ti->x, ti->y, 16, 16, TILE_HEIGHT + BB_HEIGHT_UNDER_BRIDGE, ti->z, IsTransparencySet(TO_BUILDINGS)); |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
965 |
AddSortableSpriteToDraw(front, PAL_NONE, ti->x, ti->y, 16, 16, TILE_HEIGHT + BB_HEIGHT_UNDER_BRIDGE, ti->z, IsTransparencySet(TO_BUILDINGS)); |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
966 |
} |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
967 |
|
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
968 |
/** |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
969 |
* Draws details on/around the road |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
970 |
* @param img the sprite to draw |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
971 |
* @param ti the tile to draw on |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
972 |
* @param dx the offset from the top of the BB of the tile |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
973 |
* @param dy the offset from the top of the BB of the tile |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
974 |
* @param h the height of the sprite to draw |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
975 |
*/ |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
976 |
static void DrawRoadDetail(SpriteID img, TileInfo *ti, int dx, int dy, int h) |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
977 |
{ |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
978 |
int x = ti->x | dx; |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
979 |
int y = ti->y | dy; |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
980 |
byte z = ti->z; |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
981 |
if (ti->tileh != SLOPE_FLAT) z = GetSlopeZ(x, y); |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
982 |
AddSortableSpriteToDraw(img, PAL_NONE, x, y, 2, 2, h, z); |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
983 |
} |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
984 |
|
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
985 |
/** |
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
|
986 |
* 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
|
987 |
* @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
|
988 |
*/ |
4081 | 989 |
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
|
990 |
{ |
9624 | 991 |
RoadBits road = GetRoadBits(ti->tile, ROADTYPE_ROAD); |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
992 |
RoadBits tram = GetRoadBits(ti->tile, ROADTYPE_TRAM); |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
993 |
|
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
|
994 |
const DrawRoadTileStruct *drts; |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5894
diff
changeset
|
995 |
SpriteID image = 0; |
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5894
diff
changeset
|
996 |
SpriteID pal = PAL_NONE; |
4048 | 997 |
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
|
998 |
|
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3560
diff
changeset
|
999 |
if (ti->tileh != SLOPE_FLAT) { |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
1000 |
DrawFoundation(ti, GetRoadFoundation(ti->tileh, road | tram)); |
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
|
1001 |
|
9574 | 1002 |
/* DrawFoundation() modifies ti. |
1003 |
* 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
|
1004 |
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
|
1005 |
} |
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
|
1006 |
|
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1007 |
if (image == 0) image = _road_tile_sprites_1[road != ROAD_NONE ? road : tram]; |
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
|
1008 |
|
4048 | 1009 |
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
|
1010 |
|
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1011 |
if (AlwaysDrawUnpavedRoads(ti->tile, 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
|
1012 |
image += 19; |
4048 | 1013 |
} else { |
1014 |
switch (roadside) { |
|
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5894
diff
changeset
|
1015 |
case ROADSIDE_BARREN: pal = PALETTE_TO_BARE_LAND; break; |
4048 | 1016 |
case ROADSIDE_GRASS: break; |
1017 |
case ROADSIDE_GRASS_ROAD_WORKS: break; |
|
1018 |
default: image -= 19; break; // Paved |
|
1019 |
} |
|
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
|
1020 |
} |
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
|
1021 |
|
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5894
diff
changeset
|
1022 |
DrawGroundSprite(image, pal); |
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
|
1023 |
|
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1024 |
/* For tram we overlay the road graphics with either tram tracks only |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1025 |
* (when there is actual road beneath the trams) or with tram tracks |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1026 |
* and some dirts which hides the road graphics */ |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1027 |
if (tram != ROAD_NONE) { |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1028 |
if (ti->tileh != SLOPE_FLAT) { |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1029 |
image = _road_sloped_sprites[ti->tileh - 1] + SPR_TRAMWAY_SLOPED_OFFSET; |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1030 |
} else { |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1031 |
image = _road_tile_sprites_1[tram] - SPR_ROAD_Y; |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1032 |
} |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1033 |
image += (road == ROAD_NONE) ? SPR_TRAMWAY_TRAM : SPR_TRAMWAY_OVERLAY; |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1034 |
DrawGroundSprite(image, pal); |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1035 |
} |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1036 |
|
9629 | 1037 |
if (road != ROAD_NONE) { |
1038 |
DisallowedRoadDirections drd = GetDisallowedRoadDirections(ti->tile); |
|
1039 |
if (drd != DRD_NONE) { |
|
1040 |
DrawRoadDetail(SPR_ONEWAY_BASE + drd - 1 + ((road == ROAD_X) ? 0 : 3), ti, 8, 8, 0); |
|
1041 |
} |
|
1042 |
} |
|
1043 |
||
3430
b283bb956a36
(svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents:
3421
diff
changeset
|
1044 |
if (HasRoadWorks(ti->tile)) { |
9574 | 1045 |
/* Road works */ |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1046 |
DrawGroundSprite((road | tram) & ROAD_X ? SPR_EXCAVATION_X : SPR_EXCAVATION_Y, PAL_NONE); |
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
|
1047 |
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
|
1048 |
} |
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
|
1049 |
|
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1050 |
if (tram != ROAD_NONE) DrawTramCatenary(ti, tram); |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1051 |
|
9574 | 1052 |
/* Return if full detail is disabled, or we are zoomed fully out. */ |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1053 |
if (!HasBit(_display_opt, DO_FULL_DETAIL) || _cur_dpi->zoom > ZOOM_LVL_DETAIL) return; |
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
|
1054 |
|
9574 | 1055 |
/* Draw extra details. */ |
4048 | 1056 |
for (drts = _road_display_table[roadside][road]; drts->image != 0; drts++) { |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1057 |
DrawRoadDetail(drts->image, ti, drts->subcoord_x, drts->subcoord_y, 0x10); |
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
|
1058 |
} |
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
|
1059 |
} |
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
|
1060 |
|
0 | 1061 |
static void DrawTile_Road(TileInfo *ti) |
1062 |
{ |
|
3793
33cdb5bf7b21
(svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents:
3792
diff
changeset
|
1063 |
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
|
1064 |
case ROAD_TILE_NORMAL: |
4081 | 1065 |
DrawRoadBits(ti); |
3060 | 1066 |
break; |
0 | 1067 |
|
3793
33cdb5bf7b21
(svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents:
3792
diff
changeset
|
1068 |
case ROAD_TILE_CROSSING: { |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5894
diff
changeset
|
1069 |
SpriteID image; |
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5894
diff
changeset
|
1070 |
SpriteID pal = PAL_NONE; |
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1071 |
Roadside roadside = GetRoadside(ti->tile); |
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
|
1072 |
|
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
1073 |
if (ti->tileh != SLOPE_FLAT) DrawFoundation(ti, FOUNDATION_LEVELED); |
0 | 1074 |
|
6498
aff910a05c6e
(svn r8935) -Codechange: unification of track type between road and rail tiles, unification of ground type between normal rail tiles and depots/waypoints and removing the need for RailTileSubType.
rubidium
parents:
6486
diff
changeset
|
1075 |
image = GetRailTypeInfo(GetRailType(ti->tile))->base_sprites.crossing; |
3060 | 1076 |
|
3272
7e556f209503
(svn r3984) Add a function to get the road axis of a level crossing
tron
parents:
3269
diff
changeset
|
1077 |
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
|
1078 |
if (IsCrossingBarred(ti->tile)) image += 2; |
3060 | 1079 |
|
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1080 |
if (AlwaysDrawUnpavedRoads(ti->tile, roadside)) { |
3060 | 1081 |
image += 8; |
1082 |
} else { |
|
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1083 |
switch (roadside) { |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5894
diff
changeset
|
1084 |
case ROADSIDE_BARREN: pal = PALETTE_TO_BARE_LAND; break; |
4048 | 1085 |
case ROADSIDE_GRASS: break; |
1086 |
default: image += 4; break; // Paved |
|
1087 |
} |
|
3060 | 1088 |
} |
1089 |
||
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5894
diff
changeset
|
1090 |
DrawGroundSprite(image, pal); |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1091 |
if (HasBit(GetRoadTypes(ti->tile), ROADTYPE_TRAM)) { |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1092 |
DrawGroundSprite(SPR_TRAMWAY_OVERLAY + (GetCrossingRoadAxis(ti->tile) ^ 1), pal); |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1093 |
DrawTramCatenary(ti, GetCrossingRoadBits(ti->tile)); |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1094 |
} |
6498
aff910a05c6e
(svn r8935) -Codechange: unification of track type between road and rail tiles, unification of ground type between normal rail tiles and depots/waypoints and removing the need for RailTileSubType.
rubidium
parents:
6486
diff
changeset
|
1095 |
if (GetRailType(ti->tile) == RAILTYPE_ELECTRIC) DrawCatenary(ti); |
3060 | 1096 |
break; |
0 | 1097 |
} |
1098 |
||
3098
4c1320da876d
(svn r3687) Complete some bits I missed whenn adding accessor functions for road types and pieces
tron
parents:
3097
diff
changeset
|
1099 |
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
|
1100 |
case ROAD_TILE_DEPOT: { |
4232
628628eaa4fc
(svn r5796) Use DrawTileSprites/DrawTileSeqStruct for road depot drawing data, too
tron
parents:
4231
diff
changeset
|
1101 |
const DrawTileSprites* dts; |
628628eaa4fc
(svn r5796) Use DrawTileSprites/DrawTileSeqStruct for road depot drawing data, too
tron
parents:
4231
diff
changeset
|
1102 |
const DrawTileSeqStruct* dtss; |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5894
diff
changeset
|
1103 |
SpriteID palette; |
0 | 1104 |
|
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
1105 |
if (ti->tileh != SLOPE_FLAT) DrawFoundation(ti, FOUNDATION_LEVELED); |
1398 | 1106 |
|
4226
3926da9dc486
(svn r5772) Road depots always have an player as owner, so remove an useless check
tron
parents:
4212
diff
changeset
|
1107 |
palette = PLAYER_SPRITE_COLOR(GetTileOwner(ti->tile)); |
0 | 1108 |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1109 |
if (HasBit(GetRoadTypes(ti->tile), ROADTYPE_TRAM)) { |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1110 |
dts = &_tram_depot[GetRoadDepotDirection(ti->tile)]; |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1111 |
} else { |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1112 |
dts = &_road_depot[GetRoadDepotDirection(ti->tile)]; |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1113 |
} |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1114 |
|
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5894
diff
changeset
|
1115 |
DrawGroundSprite(dts->ground_sprite, PAL_NONE); |
3060 | 1116 |
|
4232
628628eaa4fc
(svn r5796) Use DrawTileSprites/DrawTileSeqStruct for road depot drawing data, too
tron
parents:
4231
diff
changeset
|
1117 |
for (dtss = dts->seq; dtss->image != 0; dtss++) { |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5894
diff
changeset
|
1118 |
SpriteID image = dtss->image; |
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5894
diff
changeset
|
1119 |
SpriteID pal; |
3060 | 1120 |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1121 |
if (!IsTransparencySet(TO_BUILDINGS) && HasBit(image, PALETTE_MODIFIER_COLOR)) { |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5894
diff
changeset
|
1122 |
pal = palette; |
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5894
diff
changeset
|
1123 |
} else { |
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5894
diff
changeset
|
1124 |
pal = PAL_NONE; |
4226
3926da9dc486
(svn r5772) Road depots always have an player as owner, so remove an useless check
tron
parents:
4212
diff
changeset
|
1125 |
} |
3060 | 1126 |
|
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4048
diff
changeset
|
1127 |
AddSortableSpriteToDraw( |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5894
diff
changeset
|
1128 |
image, pal, |
4232
628628eaa4fc
(svn r5796) Use DrawTileSprites/DrawTileSeqStruct for road depot drawing data, too
tron
parents:
4231
diff
changeset
|
1129 |
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
|
1130 |
dtss->size_x, dtss->size_y, |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
1131 |
dtss->size_z, ti->z, |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1132 |
IsTransparencySet(TO_BUILDINGS) |
3060 | 1133 |
); |
1134 |
} |
|
1135 |
break; |
|
0 | 1136 |
} |
1137 |
} |
|
5573
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5212
diff
changeset
|
1138 |
DrawBridgeMiddle(ti); |
0 | 1139 |
} |
1140 |
||
9624 | 1141 |
void DrawRoadDepotSprite(int x, int y, DiagDirection dir, RoadType rt) |
0 | 1142 |
{ |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5894
diff
changeset
|
1143 |
SpriteID palette = PLAYER_SPRITE_COLOR(_local_player); |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1144 |
const DrawTileSprites* dts = (rt == ROADTYPE_TRAM) ? &_tram_depot[dir] : &_road_depot[dir]; |
4232
628628eaa4fc
(svn r5796) Use DrawTileSprites/DrawTileSeqStruct for road depot drawing data, too
tron
parents:
4231
diff
changeset
|
1145 |
const DrawTileSeqStruct* dtss; |
0 | 1146 |
|
2639 | 1147 |
x += 33; |
1148 |
y += 17; |
|
0 | 1149 |
|
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5894
diff
changeset
|
1150 |
DrawSprite(dts->ground_sprite, PAL_NONE, x, y); |
0 | 1151 |
|
4232
628628eaa4fc
(svn r5796) Use DrawTileSprites/DrawTileSeqStruct for road depot drawing data, too
tron
parents:
4231
diff
changeset
|
1152 |
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
|
1153 |
Point pt = RemapCoords(dtss->delta_x, dtss->delta_y, dtss->delta_z); |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5894
diff
changeset
|
1154 |
SpriteID image = dtss->image; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1155 |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1156 |
DrawSprite(image, HasBit(image, PALETTE_MODIFIER_COLOR) ? palette : PAL_NONE, x + pt.x, y + pt.y); |
0 | 1157 |
} |
1158 |
} |
|
1159 |
||
4231
dea6a63dd058
(svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents:
4226
diff
changeset
|
1160 |
static uint GetSlopeZ_Road(TileIndex tile, uint x, uint y) |
0 | 1161 |
{ |
4231
dea6a63dd058
(svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents:
4226
diff
changeset
|
1162 |
uint z; |
dea6a63dd058
(svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents:
4226
diff
changeset
|
1163 |
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
|
1164 |
|
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3560
diff
changeset
|
1165 |
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
|
1166 |
if (GetRoadTileType(tile) == ROAD_TILE_NORMAL) { |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
1167 |
Foundation f = GetRoadFoundation(tileh, GetAllRoadBits(tile)); |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
1168 |
z += ApplyFoundationToSlope(f, &tileh); |
4231
dea6a63dd058
(svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents:
4226
diff
changeset
|
1169 |
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
|
1170 |
} else { |
3645
86af43f87885
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3637
diff
changeset
|
1171 |
return z + TILE_HEIGHT; |
0 | 1172 |
} |
39 | 1173 |
} |
1174 |
||
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
1175 |
static Foundation GetFoundation_Road(TileIndex tile, Slope tileh) |
39 | 1176 |
{ |
3793
33cdb5bf7b21
(svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents:
3792
diff
changeset
|
1177 |
if (GetRoadTileType(tile) == ROAD_TILE_NORMAL) { |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
1178 |
return GetRoadFoundation(tileh, GetAllRoadBits(tile)); |
3286
3250f1488eb2
(svn r4000) Rewrite GetSlope{Tileh,Z}_{Road,Track} in a less confusing way
tron
parents:
3277
diff
changeset
|
1179 |
} else { |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
1180 |
return FlatteningFoundation(tileh); |
39 | 1181 |
} |
0 | 1182 |
} |
1183 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
1184 |
static void GetAcceptedCargo_Road(TileIndex tile, AcceptedCargo ac) |
0 | 1185 |
{ |
1186 |
/* not used */ |
|
1187 |
} |
|
1188 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
1189 |
static void AnimateTile_Road(TileIndex tile) |
0 | 1190 |
{ |
2639 | 1191 |
if (IsLevelCrossing(tile)) MarkTileDirtyByTile(tile); |
0 | 1192 |
} |
1193 |
||
4048 | 1194 |
|
1195 |
static const Roadside _town_road_types[][2] = { |
|
1196 |
{ ROADSIDE_GRASS, ROADSIDE_GRASS }, |
|
1197 |
{ ROADSIDE_PAVED, ROADSIDE_PAVED }, |
|
1198 |
{ ROADSIDE_PAVED, ROADSIDE_PAVED }, |
|
1199 |
{ ROADSIDE_TREES, ROADSIDE_TREES }, |
|
1200 |
{ ROADSIDE_STREET_LIGHTS, ROADSIDE_PAVED } |
|
0 | 1201 |
}; |
1202 |
||
4048 | 1203 |
static const Roadside _town_road_types_2[][2] = { |
1204 |
{ ROADSIDE_GRASS, ROADSIDE_GRASS }, |
|
1205 |
{ ROADSIDE_PAVED, ROADSIDE_PAVED }, |
|
1206 |
{ ROADSIDE_STREET_LIGHTS, ROADSIDE_PAVED }, |
|
1207 |
{ ROADSIDE_STREET_LIGHTS, ROADSIDE_PAVED }, |
|
1208 |
{ ROADSIDE_STREET_LIGHTS, ROADSIDE_PAVED } |
|
0 | 1209 |
}; |
1210 |
||
1211 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
1212 |
static void TileLoop_Road(TileIndex tile) |
0 | 1213 |
{ |
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
|
1214 |
switch (_opt.landscape) { |
9517 | 1215 |
case LT_ARCTIC: |
9505 | 1216 |
if (IsOnSnow(tile) != (GetTileZ(tile) > GetSnowLine())) { |
3430
b283bb956a36
(svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents:
3421
diff
changeset
|
1217 |
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
|
1218 |
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
|
1219 |
} |
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
|
1220 |
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
|
1221 |
|
9517 | 1222 |
case LT_TROPIC: |
3430
b283bb956a36
(svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents:
3421
diff
changeset
|
1223 |
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
|
1224 |
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
|
1225 |
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
|
1226 |
} |
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
|
1227 |
break; |
0 | 1228 |
} |
1229 |
||
3793
33cdb5bf7b21
(svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents:
3792
diff
changeset
|
1230 |
if (GetRoadTileType(tile) == ROAD_TILE_DEPOT) return; |
0 | 1231 |
|
9704 | 1232 |
const Town* t = ClosestTownFromTile(tile, (uint)-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
|
1233 |
if (!HasRoadWorks(tile)) { |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1234 |
HouseZonesBits grp = HZB_TOWN_EDGE; |
1280
b6925875de49
(svn r1784) -Fix: removed ClosestTownFromTile where possible, or replaced it
truelight
parents:
1264
diff
changeset
|
1235 |
|
0 | 1236 |
if (t != NULL) { |
1237 |
grp = GetTownRadiusGroup(t, tile); |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1238 |
|
9574 | 1239 |
/* 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
|
1240 |
if (t->road_build_months != 0 && |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1241 |
(DistanceManhattan(t->xy, tile) < 8 || grp != HZB_TOWN_EDGE) && |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1242 |
GetRoadTileType(tile) == ROAD_TILE_NORMAL && CountBits(GetAllRoadBits(tile)) > 1 ) { |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
1243 |
if (GetTileSlope(tile, NULL) == SLOPE_FLAT && EnsureNoVehicleOnGround(tile) && Chance16(1, 40)) { |
3430
b283bb956a36
(svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents:
3421
diff
changeset
|
1244 |
StartRoadWorks(tile); |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1245 |
|
541 | 1246 |
SndPlayTileFx(SND_21_JACKHAMMER, tile); |
0 | 1247 |
CreateEffectVehicleAbove( |
3421
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3418
diff
changeset
|
1248 |
TileX(tile) * TILE_SIZE + 7, |
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3418
diff
changeset
|
1249 |
TileY(tile) * TILE_SIZE + 7, |
0 | 1250 |
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
|
1251 |
EV_BULLDOZER); |
0 | 1252 |
MarkTileDirtyByTile(tile); |
1253 |
return; |
|
1254 |
} |
|
1255 |
} |
|
1256 |
} |
|
1257 |
||
1258 |
{ |
|
3430
b283bb956a36
(svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents:
3421
diff
changeset
|
1259 |
/* Adjust road ground type depending on 'grp' (grp is the distance to the center) */ |
9517 | 1260 |
const Roadside* new_rs = (_opt.landscape == LT_TOYLAND) ? _town_road_types_2[grp] : _town_road_types[grp]; |
4048 | 1261 |
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
|
1262 |
|
3430
b283bb956a36
(svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents:
3421
diff
changeset
|
1263 |
/* We have our desired type, do nothing */ |
4048 | 1264 |
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
|
1265 |
|
b283bb956a36
(svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents:
3421
diff
changeset
|
1266 |
/* We have the pre-type of the desired type, switch to the desired type */ |
4048 | 1267 |
if (cur_rs == new_rs[1]) { |
1268 |
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
|
1269 |
/* We have barren land, install the pre-type */ |
4048 | 1270 |
} else if (cur_rs == ROADSIDE_BARREN) { |
1271 |
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
|
1272 |
/* We're totally off limits, remove any installation and make barren land */ |
0 | 1273 |
} else { |
4048 | 1274 |
cur_rs = ROADSIDE_BARREN; |
0 | 1275 |
} |
4048 | 1276 |
SetRoadside(tile, cur_rs); |
0 | 1277 |
MarkTileDirtyByTile(tile); |
1278 |
} |
|
3430
b283bb956a36
(svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents:
3421
diff
changeset
|
1279 |
} 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
|
1280 |
TerminateRoadWorks(tile); |
9704 | 1281 |
|
1282 |
if (_patches.mod_road_rebuild) { |
|
1283 |
/* Generate a nicer town surface */ |
|
1284 |
const RoadBits old_rb = GetAnyRoadBits(tile, ROADTYPE_ROAD); |
|
1285 |
const RoadBits new_rb = CleanUpRoadBits(tile, old_rb); |
|
1286 |
||
1287 |
if (old_rb != new_rb) { |
|
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1288 |
RemoveRoad(tile, DC_EXEC | DC_AUTO | DC_NO_WATER, (old_rb ^ new_rb), ROADTYPE_ROAD, true); |
9704 | 1289 |
} |
1290 |
} |
|
1291 |
||
0 | 1292 |
MarkTileDirtyByTile(tile); |
1293 |
} |
|
1294 |
} |
|
1295 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
1296 |
static void ClickTile_Road(TileIndex tile) |
0 | 1297 |
{ |
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6582
diff
changeset
|
1298 |
if (GetRoadTileType(tile) == ROAD_TILE_DEPOT) ShowDepotWindow(tile, VEH_ROAD); |
0 | 1299 |
} |
1300 |
||
1301 |
static const byte _road_trackbits[16] = { |
|
1302 |
0x0, 0x0, 0x0, 0x10, 0x0, 0x2, 0x8, 0x1A, 0x0, 0x4, 0x1, 0x15, 0x20, 0x26, 0x29, 0x3F, |
|
1303 |
}; |
|
1304 |
||
9624 | 1305 |
static uint32 GetTileTrackStatus_Road(TileIndex tile, TransportType mode, uint sub_mode) |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
1306 |
{ |
9624 | 1307 |
|
3066
0d34dff23d98
(svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents:
3061
diff
changeset
|
1308 |
switch (mode) { |
0d34dff23d98
(svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents:
3061
diff
changeset
|
1309 |
case TRANSPORT_RAIL: |
0d34dff23d98
(svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents:
3061
diff
changeset
|
1310 |
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
|
1311 |
return GetCrossingRailBits(tile) * 0x101; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1312 |
|
3066
0d34dff23d98
(svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents:
3061
diff
changeset
|
1313 |
case TRANSPORT_ROAD: |
9624 | 1314 |
if ((GetRoadTypes(tile) & sub_mode) == 0) return 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
|
1315 |
switch (GetRoadTileType(tile)) { |
9624 | 1316 |
case ROAD_TILE_NORMAL: { |
1317 |
RoadType rt = (RoadType)FindFirstBit(sub_mode); |
|
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1318 |
const uint drd_to_multiplier[DRD_END] = { 0x101, 0x100, 0x1, 0x0 }; |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1319 |
uint multiplier = drd_to_multiplier[rt == ROADTYPE_TRAM ? DRD_NONE : GetDisallowedRoadDirections(tile)]; |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1320 |
return HasRoadWorks(tile) ? 0 : _road_trackbits[GetRoadBits(tile, rt)] * multiplier; |
9624 | 1321 |
} |
3066
0d34dff23d98
(svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents:
3061
diff
changeset
|
1322 |
|
3793
33cdb5bf7b21
(svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents:
3792
diff
changeset
|
1323 |
case ROAD_TILE_CROSSING: { |
4158 | 1324 |
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
|
1325 |
|
3367 | 1326 |
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
|
1327 |
return r; |
0d34dff23d98
(svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents:
3061
diff
changeset
|
1328 |
} |
0d34dff23d98
(svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents:
3061
diff
changeset
|
1329 |
|
3069
0e6aca11c3da
(svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents:
3068
diff
changeset
|
1330 |
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
|
1331 |
case ROAD_TILE_DEPOT: |
4158 | 1332 |
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
|
1333 |
} |
3066
0d34dff23d98
(svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents:
3061
diff
changeset
|
1334 |
break; |
0d34dff23d98
(svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents:
3061
diff
changeset
|
1335 |
|
0d34dff23d98
(svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents:
3061
diff
changeset
|
1336 |
default: break; |
0 | 1337 |
} |
1338 |
return 0; |
|
1339 |
} |
|
1340 |
||
1341 |
static const StringID _road_tile_strings[] = { |
|
1342 |
STR_1814_ROAD, |
|
1343 |
STR_1814_ROAD, |
|
1344 |
STR_1814_ROAD, |
|
1345 |
STR_1815_ROAD_WITH_STREETLIGHTS, |
|
1346 |
STR_1814_ROAD, |
|
1347 |
STR_1816_TREE_LINED_ROAD, |
|
1348 |
STR_1814_ROAD, |
|
1349 |
STR_1814_ROAD, |
|
1350 |
}; |
|
1351 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
1352 |
static void GetTileDesc_Road(TileIndex tile, TileDesc *td) |
0 | 1353 |
{ |
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
|
1354 |
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
|
1355 |
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
|
1356 |
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
|
1357 |
case ROAD_TILE_DEPOT: td->str = STR_1817_ROAD_VEHICLE_DEPOT; break; |
4048 | 1358 |
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
|
1359 |
} |
0 | 1360 |
} |
1361 |
||
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1362 |
/** |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1363 |
* Given the direction the road depot is pointing, this is the direction the |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1364 |
* vehicle should be travelling in in order to enter the depot. |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1365 |
*/ |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1366 |
static const byte _roadveh_enter_depot_dir[4] = { |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1367 |
TRACKDIR_X_SW, TRACKDIR_Y_NW, TRACKDIR_X_NE, TRACKDIR_Y_SE |
0 | 1368 |
}; |
1369 |
||
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
1370 |
static VehicleEnterTileStatus VehicleEnter_Road(Vehicle *v, TileIndex tile, int x, int y) |
0 | 1371 |
{ |
3793
33cdb5bf7b21
(svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents:
3792
diff
changeset
|
1372 |
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
|
1373 |
case ROAD_TILE_CROSSING: |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1374 |
if (v->type == VEH_TRAIN) { |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1375 |
/* it should be barred */ |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1376 |
assert(IsCrossingBarred(tile)); |
0 | 1377 |
} |
3060 | 1378 |
break; |
1379 |
||
3793
33cdb5bf7b21
(svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents:
3792
diff
changeset
|
1380 |
case ROAD_TILE_DEPOT: |
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6582
diff
changeset
|
1381 |
if (v->type == VEH_ROAD && |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4048
diff
changeset
|
1382 |
v->u.road.frame == 11 && |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1383 |
_roadveh_enter_depot_dir[GetRoadDepotDirection(tile)] == v->u.road.state) { |
9627 | 1384 |
v->u.road.state = RVSB_IN_DEPOT; |
1385 |
v->vehstatus |= VS_HIDDEN; |
|
1386 |
v->direction = ReverseDir(v->direction); |
|
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
1387 |
if (v->Next() == NULL) VehicleEnterDepot(v); |
9627 | 1388 |
v->tile = tile; |
1389 |
||
1390 |
InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile); |
|
6317
c73bda71ac16
(svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents:
6193
diff
changeset
|
1391 |
return VETSB_ENTERED_WORMHOLE; |
3060 | 1392 |
} |
1393 |
break; |
|
1394 |
||
1395 |
default: break; |
|
0 | 1396 |
} |
6317
c73bda71ac16
(svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents:
6193
diff
changeset
|
1397 |
return VETSB_CONTINUE; |
0 | 1398 |
} |
1399 |
||
1400 |
||
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
|
1401 |
static void ChangeTileOwner_Road(TileIndex tile, PlayerID old_player, PlayerID new_player) |
0 | 1402 |
{ |
9624 | 1403 |
if (GetRoadTileType(tile) == ROAD_TILE_DEPOT) { |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1404 |
if (GetTileOwner(tile) == old_player) { |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1405 |
if (new_player == PLAYER_SPECTATOR) { |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1406 |
DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1407 |
} else { |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1408 |
SetTileOwner(tile, new_player); |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1409 |
} |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1410 |
} |
9624 | 1411 |
return; |
0 | 1412 |
} |
1413 |
||
9624 | 1414 |
for (RoadType rt = ROADTYPE_ROAD; rt < ROADTYPE_END; rt++) { |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1415 |
if (!HasBit(GetRoadTypes(tile), rt)) continue; |
0 | 1416 |
|
9624 | 1417 |
if (GetRoadOwner(tile, rt) == old_player) { |
1418 |
SetRoadOwner(tile, rt, new_player == PLAYER_SPECTATOR ? OWNER_NONE : new_player); |
|
1419 |
} |
|
1420 |
} |
|
3060 | 1421 |
|
9624 | 1422 |
if (IsLevelCrossing(tile)) { |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1423 |
if (GetTileOwner(tile) == old_player) { |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1424 |
if (new_player == PLAYER_SPECTATOR) { |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1425 |
MakeRoadNormal(tile, GetCrossingRoadBits(tile), GetRoadTypes(tile), GetTownIndex(tile), GetRoadOwner(tile, ROADTYPE_ROAD), GetRoadOwner(tile, ROADTYPE_TRAM), GetRoadOwner(tile, ROADTYPE_HWAY)); |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1426 |
} else { |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1427 |
SetTileOwner(tile, new_player); |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1428 |
} |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1429 |
} |
0 | 1430 |
} |
1431 |
} |
|
1432 |
||
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
1433 |
static CommandCost TerraformTile_Road(TileIndex tile, uint32 flags, uint z_new, Slope tileh_new) |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
1434 |
{ |
9703
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1435 |
if (_patches.build_on_slopes && AutoslopeEnabled()) { |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1436 |
switch (GetRoadTileType(tile)) { |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1437 |
case ROAD_TILE_CROSSING: |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
1438 |
if (!IsSteepSlope(tileh_new) && (GetTileMaxZ(tile) == z_new + GetSlopeMaxZ(tileh_new)) && HasBit(VALID_LEVEL_CROSSING_SLOPES, tileh_new)) return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform); |
9703
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1439 |
break; |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1440 |
|
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1441 |
case ROAD_TILE_DEPOT: |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
1442 |
if (AutoslopeCheckForEntranceEdge(tile, z_new, tileh_new, GetRoadDepotDirection(tile))) return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform); |
9703
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1443 |
break; |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1444 |
|
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1445 |
case ROAD_TILE_NORMAL: { |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1446 |
RoadBits bits = GetAllRoadBits(tile); |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1447 |
RoadBits bits_copy = bits; |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1448 |
/* Check if the slope-road_bits combination is valid at all, i.e. it is save to call GetRoadFoundation(). */ |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1449 |
if (!CmdFailed(CheckRoadSlope(tileh_new, &bits_copy, ROAD_NONE))) { |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1450 |
/* CheckRoadSlope() sometimes changes the road_bits, if it does not agree with them. */ |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1451 |
if (bits == bits_copy) { |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1452 |
uint z_old; |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1453 |
Slope tileh_old = GetTileSlope(tile, &z_old); |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1454 |
|
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1455 |
/* Get the slope on top of the foundation */ |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1456 |
z_old += ApplyFoundationToSlope(GetRoadFoundation(tileh_old, bits), &tileh_old); |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1457 |
z_new += ApplyFoundationToSlope(GetRoadFoundation(tileh_new, bits), &tileh_new); |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1458 |
|
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1459 |
/* The surface slope must not be changed */ |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
1460 |
if ((z_old == z_new) && (tileh_old == tileh_new)) return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform); |
9703
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1461 |
} |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1462 |
} |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1463 |
break; |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1464 |
} |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1465 |
|
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1466 |
default: NOT_REACHED(); |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1467 |
} |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1468 |
} |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1469 |
|
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
1470 |
return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
1471 |
} |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
1472 |
|
0 | 1473 |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
1474 |
extern 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
|
1475 |
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
|
1476 |
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
|
1477 |
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
|
1478 |
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
|
1479 |
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
|
1480 |
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
|
1481 |
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
|
1482 |
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
|
1483 |
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
|
1484 |
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
|
1485 |
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
|
1486 |
VehicleEnter_Road, /* vehicle_enter_tile_proc */ |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
1487 |
GetFoundation_Road, /* get_foundation_proc */ |
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
1488 |
TerraformTile_Road, /* terraform_tile_proc */ |
0 | 1489 |
}; |