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