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