road_cmd.c
author rubidium
Tue, 09 May 2006 08:25:31 +0000
changeset 3793 33cdb5bf7b21
parent 3792 2eb8388731bf
child 3794 ac26a7b4615d
permissions -rw-r--r--
(svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
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
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     3
#include "stdafx.h"
1891
92a3b0aa0946 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1785
diff changeset
     4
#include "openttd.h"
3189
1af302c5abd0 (svn r3846) Add functions to set the type of stuff (clear, water, rail, road) under bridges
tron
parents: 3176
diff changeset
     5
#include "bridge_map.h"
3101
e2fdb8802c2f (svn r3696) Add functions to turn a tile into a normal rail tile/depot/waypoint. This is just a tiny step, the rail code needs way more love and caring
tron
parents: 3100
diff changeset
     6
#include "rail_map.h"
3144
426b825578f9 (svn r3763) Adapt to the new 'map accessors go in foo_map.h'-scheme
tron
parents: 3104
diff changeset
     7
#include "road_map.h"
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
     8
#include "table/sprites.h"
507
8aa8100b0b22 (svn r815) Include strings.h only in the files which need it.
tron
parents: 497
diff changeset
     9
#include "table/strings.h"
2163
637ec3c361f5 (svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents: 2148
diff changeset
    10
#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
    11
#include "map.h"
1209
a1ac96655b79 (svn r1713) Split off several functions which query/set information about a single tile from map.h and put them into a seperate file tile.h
tron
parents: 1095
diff changeset
    12
#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
    13
#include "town_map.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    14
#include "vehicle.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    15
#include "viewport.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    16
#include "command.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    17
#include "player.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    18
#include "town.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    19
#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
    20
#include "sound.h"
1313
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents: 1281
diff changeset
    21
#include "depot.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    22
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    23
void RoadVehEnterDepot(Vehicle *v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    24
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    25
3381
ebdcc12845c7 (svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents: 3379
diff changeset
    26
static uint CountRoadBits(RoadBits r)
ebdcc12845c7 (svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents: 3379
diff changeset
    27
{
ebdcc12845c7 (svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents: 3379
diff changeset
    28
	uint count = 0;
ebdcc12845c7 (svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents: 3379
diff changeset
    29
ebdcc12845c7 (svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents: 3379
diff changeset
    30
	if (r & ROAD_NW) ++count;
ebdcc12845c7 (svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents: 3379
diff changeset
    31
	if (r & ROAD_SW) ++count;
ebdcc12845c7 (svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents: 3379
diff changeset
    32
	if (r & ROAD_SE) ++count;
ebdcc12845c7 (svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents: 3379
diff changeset
    33
	if (r & ROAD_NE) ++count;
ebdcc12845c7 (svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents: 3379
diff changeset
    34
	return count;
ebdcc12845c7 (svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents: 3379
diff changeset
    35
}
ebdcc12845c7 (svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents: 3379
diff changeset
    36
ebdcc12845c7 (svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents: 3379
diff changeset
    37
3149
2b54fc654019 (svn r3770) Remove the _road_special_gettrackstatus hack. Egladil and me deem it unnecessary
tron
parents: 3146
diff changeset
    38
static bool CheckAllowRemoveRoad(TileIndex tile, RoadBits remove, bool* edge_road)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    39
{
3149
2b54fc654019 (svn r3770) Remove the _road_special_gettrackstatus hack. Egladil and me deem it unnecessary
tron
parents: 3146
diff changeset
    40
	RoadBits present;
2b54fc654019 (svn r3770) Remove the _road_special_gettrackstatus hack. Egladil and me deem it unnecessary
tron
parents: 3146
diff changeset
    41
	RoadBits n;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    42
	byte owner;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    43
	*edge_road = true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    44
3017
915fae59d5e0 (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents: 2989
diff changeset
    45
	if (_game_mode == GM_EDITOR) return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    46
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    47
	// Only do the special processing for actual players.
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
    48
	if (_current_player >= MAX_PLAYERS) return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    49
3560
4389ae5ad967 (svn r4435) - Fix: an assertion triggered when trying to remove a bridge with the remove-tool (r4348 surfaced this). In CmdRemoveRoad tiletype was not checked for ownership. Intorudce IsLevelCrossingTile() which checks if a tile is a crossing without knowing the type. Suggested by peter1138 and Tron.
Darkvater
parents: 3491
diff changeset
    50
	owner = IsLevelCrossingTile(tile) ? GetCrossingRoadOwner(tile) : GetTileOwner(tile);
4389ae5ad967 (svn r4435) - Fix: an assertion triggered when trying to remove a bridge with the remove-tool (r4348 surfaced this). In CmdRemoveRoad tiletype was not checked for ownership. Intorudce IsLevelCrossingTile() which checks if a tile is a crossing without knowing the type. Suggested by peter1138 and Tron.
Darkvater
parents: 3491
diff changeset
    51
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    52
	// Only do the special processing if the road is owned
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    53
	// by a town
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    54
	if (owner != OWNER_TOWN) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    55
		return owner == OWNER_NONE || CheckOwnership(owner);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    56
	}
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    60
	// Get a bitmask of which neighbouring roads has a tile
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    61
	n = 0;
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
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    68
	// If 0 or 1 bits are set in n, or if no bits that match the bits to remove,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
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;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
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
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
    76
		t = ClosestTownFromTile(tile, _patches.dist_local_authority);
aae181b00846 (svn r2142) - Fix: Game no longer crashes when you want to remove a piece of road under a bridge that belongs to the town. TODO: railcrossings store owner somewhere else, put it into _map_owner[]!
Darkvater
parents: 1398
diff changeset
    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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    86
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
    87
/** 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
    88
 * @param tile tile where to remove road from
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
    89
 * @param p1 road piece flags
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
    90
 * @param p2 unused
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    91
 */
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
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
    93
{
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
    94
	// cost for removing inner/edge -roads
aae181b00846 (svn r2142) - Fix: Game no longer crashes when you want to remove a piece of road under a bridge that belongs to the town. TODO: railcrossings store owner somewhere else, put it into _map_owner[]!
Darkvater
parents: 1398
diff changeset
    95
	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
    96
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
    97
	PlayerID owner;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    98
	Town *t;
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
    99
	/* 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
   100
	 * 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
   101
	bool edge_road;
3069
0e6aca11c3da (svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents: 3068
diff changeset
   102
	RoadBits pieces;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   103
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   104
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   105
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   106
	/* Road pieces are max 4 bitset values (NE, NW, SE, SW) */
3069
0e6aca11c3da (svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents: 3068
diff changeset
   107
	if (p1 >> 4) return CMD_ERROR;
0e6aca11c3da (svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents: 3068
diff changeset
   108
	pieces = p1;
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   109
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
	if (!IsTileType(tile, MP_STREET) && !IsTileType(tile, MP_TUNNELBRIDGE)) return CMD_ERROR;
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
   111
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
   112
	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
   113
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
   114
	if (owner == OWNER_TOWN && _game_mode != GM_EDITOR) {
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
   115
		if (IsTileType(tile, MP_TUNNELBRIDGE)) { // index of town is not saved for bridge (no space)
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
   116
			t = ClosestTownFromTile(tile, _patches.dist_local_authority);
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
		} else {
3319
7d04847e4689 (svn r4085) Add GetTown{Index,ByTile}() to get the town index resp. the town from a tile
tron
parents: 3286
diff changeset
   118
			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
   119
		}
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
   120
	} else {
1280
b6925875de49 (svn r1784) -Fix: removed ClosestTownFromTile where possible, or replaced it
truelight
parents: 1264
diff changeset
   121
		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
   122
	}
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   123
3149
2b54fc654019 (svn r3770) Remove the _road_special_gettrackstatus hack. Egladil and me deem it unnecessary
tron
parents: 3146
diff changeset
   124
	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
   125
3277
f48206e08ff0 (svn r3990) Remove another call to FindLandscapeHeight()
tron
parents: 3274
diff changeset
   126
	switch (GetTileType(tile)) {
3060
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   127
		case MP_TUNNELBRIDGE:
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   128
			if (!EnsureNoVehicleZ(tile, TilePixelHeight(tile))) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   129
3234
986c30171e92 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents: 3189
diff changeset
   130
			if (!IsBridge(tile) ||
986c30171e92 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents: 3189
diff changeset
   131
					!IsBridgeMiddle(tile) ||
986c30171e92 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents: 3189
diff changeset
   132
					!IsTransportUnderBridge(tile) ||
986c30171e92 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents: 3189
diff changeset
   133
					GetTransportTypeUnderBridge(tile) != TRANSPORT_ROAD ||
986c30171e92 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents: 3189
diff changeset
   134
					(pieces & ComplementRoadBits(GetRoadBitsUnderBridge(tile))) != 0) {
3176
c125ec95763a (svn r3812) Remove a pointless goto
tron
parents: 3167
diff changeset
   135
				return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   136
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   137
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   138
			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
   139
				ChangeTownRating(t, -road_remove_cost[(byte)edge_road], RATING_ROAD_MINIMUM);
3189
1af302c5abd0 (svn r3846) Add functions to set the type of stuff (clear, water, rail, road) under bridges
tron
parents: 3176
diff changeset
   140
				SetClearUnderBridge(tile);
3060
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   141
				MarkTileDirtyByTile(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   142
			}
3381
ebdcc12845c7 (svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents: 3379
diff changeset
   143
			return _price.remove_road * 2;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   144
3060
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   145
		case MP_STREET:
3277
f48206e08ff0 (svn r3990) Remove another call to FindLandscapeHeight()
tron
parents: 3274
diff changeset
   146
			if (!EnsureNoVehicle(tile)) return CMD_ERROR;
f48206e08ff0 (svn r3990) Remove another call to FindLandscapeHeight()
tron
parents: 3274
diff changeset
   147
3060
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   148
			// check if you're allowed to remove the street owned by a town
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   149
			// removal allowance depends on difficulty setting
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   150
			if (!CheckforTownRating(flags, t, ROAD_REMOVE)) return CMD_ERROR;
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   151
3793
33cdb5bf7b21 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3792
diff changeset
   152
			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
   153
				case ROAD_TILE_NORMAL: {
3277
f48206e08ff0 (svn r3990) Remove another call to FindLandscapeHeight()
tron
parents: 3274
diff changeset
   154
					RoadBits present = GetRoadBits(tile);
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
   155
					RoadBits c = pieces;
3060
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   156
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3560
diff changeset
   157
					if (GetTileSlope(tile, NULL) != SLOPE_FLAT &&
3277
f48206e08ff0 (svn r3990) Remove another call to FindLandscapeHeight()
tron
parents: 3274
diff changeset
   158
							(present == ROAD_Y || present == ROAD_X)) {
3060
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   159
						c |= (c & 0xC) >> 2;
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   160
						c |= (c & 0x3) << 2;
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   161
					}
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   162
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   163
					// limit the bits to delete to the existing bits.
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
   164
					c &= present;
3176
c125ec95763a (svn r3812) Remove a pointless goto
tron
parents: 3167
diff changeset
   165
					if (c == 0) return CMD_ERROR;
3060
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   166
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   167
					if (flags & DC_EXEC) {
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   168
						ChangeTownRating(t, -road_remove_cost[(byte)edge_road], RATING_ROAD_MINIMUM);
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   169
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
   170
						present ^= c;
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
   171
						if (present == 0) {
3060
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   172
							DoClearSquare(tile);
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   173
						} else {
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
   174
							SetRoadBits(tile, present);
3060
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   175
							MarkTileDirtyByTile(tile);
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   176
						}
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   177
					}
3381
ebdcc12845c7 (svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents: 3379
diff changeset
   178
					return CountRoadBits(c) * _price.remove_road;
3060
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   179
				}
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   180
3793
33cdb5bf7b21 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3792
diff changeset
   181
				case ROAD_TILE_CROSSING: {
3103
fb7f22d3bc9b (svn r3698) Add GetCrossingRailBits() and ComplementRoadBits(). Simplify the code by using them
tron
parents: 3102
diff changeset
   182
					if (pieces & ComplementRoadBits(GetCrossingRoadBits(tile))) {
3176
c125ec95763a (svn r3812) Remove a pointless goto
tron
parents: 3167
diff changeset
   183
						return CMD_ERROR;
3060
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   184
					}
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   185
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   186
					if (flags & DC_EXEC) {
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   187
						ChangeTownRating(t, -road_remove_cost[(byte)edge_road], RATING_ROAD_MINIMUM);
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   188
3242
1cefa03f0d5e (svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents: 3234
diff changeset
   189
						MakeRailNormal(tile, GetTileOwner(tile), GetCrossingRailBits(tile), GetRailTypeCrossing(tile));
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
   190
						MarkTileDirtyByTile(tile);
3060
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   191
					}
3381
ebdcc12845c7 (svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents: 3379
diff changeset
   192
					return _price.remove_road * 2;
3060
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   193
				}
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   194
3069
0e6aca11c3da (svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents: 3068
diff changeset
   195
				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
   196
				case ROAD_TILE_DEPOT:
3176
c125ec95763a (svn r3812) Remove a pointless goto
tron
parents: 3167
diff changeset
   197
					return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   198
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   199
3176
c125ec95763a (svn r3812) Remove a pointless goto
tron
parents: 3167
diff changeset
   200
		default: return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   201
	}
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   204
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
   205
static const RoadBits _valid_tileh_slopes_road[][15] = {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   206
	// set of normal ones
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   207
	{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   208
		ROAD_ALL, 0, 0,
3098
4c1320da876d (svn r3687) Complete some bits I missed whenn adding accessor functions for road types and pieces
tron
parents: 3097
diff changeset
   209
		ROAD_X,   0, 0,  // 3, 4, 5
4c1320da876d (svn r3687) Complete some bits I missed whenn adding accessor functions for road types and pieces
tron
parents: 3097
diff changeset
   210
		ROAD_Y,   0, 0,
4c1320da876d (svn r3687) Complete some bits I missed whenn adding accessor functions for road types and pieces
tron
parents: 3097
diff changeset
   211
		ROAD_Y,   0, 0,  // 9, 10, 11
4c1320da876d (svn r3687) Complete some bits I missed whenn adding accessor functions for road types and pieces
tron
parents: 3097
diff changeset
   212
		ROAD_X,   0, 0
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   213
	},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   214
	// 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
   215
	{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   216
		0,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   217
		ROAD_SW | ROAD_NW,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   218
		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
   219
		ROAD_Y  | ROAD_SW,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   220
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   221
		ROAD_SE | ROAD_NE, // 4
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   222
		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
   223
		ROAD_X  | ROAD_SE,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   224
		ROAD_ALL,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   225
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   226
		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
   227
		ROAD_X  | ROAD_NW,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   228
		ROAD_ALL,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   229
		ROAD_ALL,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   230
3098
4c1320da876d (svn r3687) Complete some bits I missed whenn adding accessor functions for road types and pieces
tron
parents: 3097
diff changeset
   231
		ROAD_Y  | ROAD_NE, // 12
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   232
		ROAD_ALL,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   233
		ROAD_ALL
13
3e7c1f74a996 (svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents: 0
diff changeset
   234
	},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   235
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   236
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   237
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3560
diff changeset
   238
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
   239
{
3381
ebdcc12845c7 (svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents: 3379
diff changeset
   240
	RoadBits road_bits;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   241
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3560
diff changeset
   242
	if (IsSteepSlope(tileh)) return CMD_ERROR;
3381
ebdcc12845c7 (svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents: 3379
diff changeset
   243
	road_bits = *pieces | existing;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   244
3381
ebdcc12845c7 (svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents: 3379
diff changeset
   245
	// no special foundation
ebdcc12845c7 (svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents: 3379
diff changeset
   246
	if ((~_valid_tileh_slopes_road[0][tileh] & road_bits) == 0) {
ebdcc12845c7 (svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents: 3379
diff changeset
   247
		// 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
   248
		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
   249
		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
   250
	}
ebdcc12845c7 (svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents: 3379
diff changeset
   251
ebdcc12845c7 (svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents: 3379
diff changeset
   252
	// foundation is used. Whole tile is leveled up
ebdcc12845c7 (svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents: 3379
diff changeset
   253
	if ((~_valid_tileh_slopes_road[1][tileh] & road_bits) == 0) {
ebdcc12845c7 (svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents: 3379
diff changeset
   254
		return existing ? 0 : _price.terraform;
ebdcc12845c7 (svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents: 3379
diff changeset
   255
	}
ebdcc12845c7 (svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents: 3379
diff changeset
   256
ebdcc12845c7 (svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents: 3379
diff changeset
   257
	// 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
   258
	if (existing == 0 && (tileh == SLOPE_W || tileh == SLOPE_S || tileh == SLOPE_E || tileh == SLOPE_N)) {
3381
ebdcc12845c7 (svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents: 3379
diff changeset
   259
		// force full pieces.
ebdcc12845c7 (svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents: 3379
diff changeset
   260
		*pieces |= (*pieces & 0xC) >> 2;
ebdcc12845c7 (svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents: 3379
diff changeset
   261
		*pieces |= (*pieces & 0x3) << 2;
ebdcc12845c7 (svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents: 3379
diff changeset
   262
		if (*pieces == ROAD_X || *pieces == ROAD_Y) return _price.terraform;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   263
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   264
	return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   265
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   266
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   267
/** 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
   268
 * @param tile tile where to build road
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   269
 * @param p1 road piece flags
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   270
 * @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
   271
 */
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
   272
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
   273
{
3381
ebdcc12845c7 (svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents: 3379
diff changeset
   274
	int32 cost = 0;
ebdcc12845c7 (svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents: 3379
diff changeset
   275
	int32 ret;
3150
025fe8cd7104 (svn r3773) Shove some semantics down ottd's throat by replacing ints and magic numbers by enums and some related changes
tron
parents: 3149
diff changeset
   276
	RoadBits existing = 0;
025fe8cd7104 (svn r3773) Shove some semantics down ottd's throat by replacing ints and magic numbers by enums and some related changes
tron
parents: 3149
diff changeset
   277
	RoadBits pieces;
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3560
diff changeset
   278
	Slope tileh;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   279
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   280
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   281
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   282
	/* 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
   283
	 * if a non-player is building the road */
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
   284
	if ((p1 >> 4) || (_current_player < MAX_PLAYERS && p2 != 0) || !IsTownIndex(p2)) return CMD_ERROR;
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
   285
	pieces = p1;
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   286
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
   287
	tileh = GetTileSlope(tile, NULL);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   288
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
   289
	switch (GetTileType(tile)) {
3060
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   290
		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
   291
			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
   292
				case ROAD_TILE_NORMAL:
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
   293
					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
   294
					if ((existing & pieces) == pieces) {
3066
0d34dff23d98 (svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents: 3061
diff changeset
   295
						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
   296
					}
3381
ebdcc12845c7 (svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents: 3379
diff changeset
   297
					if (!EnsureNoVehicle(tile)) return CMD_ERROR;
3066
0d34dff23d98 (svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents: 3061
diff changeset
   298
					break;
0d34dff23d98 (svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents: 3061
diff changeset
   299
3793
33cdb5bf7b21 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3792
diff changeset
   300
				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
   301
					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
   302
						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
   303
					}
0d34dff23d98 (svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents: 3061
diff changeset
   304
					goto do_clear;
0d34dff23d98 (svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents: 3061
diff changeset
   305
3069
0e6aca11c3da (svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents: 3068
diff changeset
   306
				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
   307
				case ROAD_TILE_DEPOT:
3066
0d34dff23d98 (svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents: 3061
diff changeset
   308
					goto do_clear;
3060
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   309
			}
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   310
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   311
3060
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   312
		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
   313
			Axis roaddir;
13
3e7c1f74a996 (svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents: 0
diff changeset
   314
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3560
diff changeset
   315
			if (IsSteepSlope(tileh)) {
3060
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   316
				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
   317
			}
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   318
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
   319
#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
   320
			/* 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
   321
			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
   322
				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
   323
			}
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
   324
#undef M
3060
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   325
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
   326
			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
   327
			switch (GetTrackBits(tile)) {
95e7bffcb3c5 (svn r3981) More work for the rail accessing functions and enums
tron
parents: 3267
diff changeset
   328
				case TRACK_BIT_X:
95e7bffcb3c5 (svn r3981) More work for the rail accessing functions and enums
tron
parents: 3267
diff changeset
   329
					if (pieces & ROAD_X) goto do_clear;
95e7bffcb3c5 (svn r3981) More work for the rail accessing functions and enums
tron
parents: 3267
diff changeset
   330
					roaddir = AXIS_Y;
95e7bffcb3c5 (svn r3981) More work for the rail accessing functions and enums
tron
parents: 3267
diff changeset
   331
					break;
95e7bffcb3c5 (svn r3981) More work for the rail accessing functions and enums
tron
parents: 3267
diff changeset
   332
95e7bffcb3c5 (svn r3981) More work for the rail accessing functions and enums
tron
parents: 3267
diff changeset
   333
				case TRACK_BIT_Y:
95e7bffcb3c5 (svn r3981) More work for the rail accessing functions and enums
tron
parents: 3267
diff changeset
   334
					if (pieces & ROAD_Y) goto do_clear;
95e7bffcb3c5 (svn r3981) More work for the rail accessing functions and enums
tron
parents: 3267
diff changeset
   335
					roaddir = AXIS_X;
95e7bffcb3c5 (svn r3981) More work for the rail accessing functions and enums
tron
parents: 3267
diff changeset
   336
					break;
95e7bffcb3c5 (svn r3981) More work for the rail accessing functions and enums
tron
parents: 3267
diff changeset
   337
95e7bffcb3c5 (svn r3981) More work for the rail accessing functions and enums
tron
parents: 3267
diff changeset
   338
				default: goto do_clear;
3060
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   339
			}
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   340
3381
ebdcc12845c7 (svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents: 3379
diff changeset
   341
			if (!EnsureNoVehicle(tile)) return CMD_ERROR;
ebdcc12845c7 (svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents: 3379
diff changeset
   342
3060
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   343
			if (flags & DC_EXEC) {
3242
1cefa03f0d5e (svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents: 3234
diff changeset
   344
				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
   345
				MarkTileDirtyByTile(tile);
3060
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   346
			}
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   347
			return _price.build_road * 2;
3017
915fae59d5e0 (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents: 2989
diff changeset
   348
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   349
3060
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   350
		case MP_TUNNELBRIDGE:
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   351
			/* check for flat land */
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3560
diff changeset
   352
			if (IsSteepSlope(tileh)) {
3060
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   353
				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
   354
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   355
3234
986c30171e92 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents: 3189
diff changeset
   356
			if (!IsBridge(tile) || !IsBridgeMiddle(tile)) goto do_clear;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   357
3060
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   358
			/* only allow roads pertendicular to bridge */
3234
986c30171e92 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents: 3189
diff changeset
   359
			if ((pieces & (GetBridgeAxis(tile) == AXIS_X ? ROAD_X : ROAD_Y)) != 0) {
986c30171e92 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents: 3189
diff changeset
   360
				goto do_clear;
986c30171e92 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents: 3189
diff changeset
   361
			}
3060
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   362
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   363
			/* check if clear land under bridge */
3234
986c30171e92 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents: 3189
diff changeset
   364
			if (IsTransportUnderBridge(tile)) {
986c30171e92 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents: 3189
diff changeset
   365
				switch (GetTransportTypeUnderBridge(tile)) {
986c30171e92 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents: 3189
diff changeset
   366
					case TRANSPORT_ROAD: return_cmd_error(STR_1007_ALREADY_BUILT);
986c30171e92 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents: 3189
diff changeset
   367
					default: return_cmd_error(STR_1008_MUST_REMOVE_RAILROAD_TRACK);
986c30171e92 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents: 3189
diff changeset
   368
				}
986c30171e92 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents: 3189
diff changeset
   369
			} else {
986c30171e92 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents: 3189
diff changeset
   370
				if (IsWaterUnderBridge(tile)) {
986c30171e92 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents: 3189
diff changeset
   371
					return_cmd_error(STR_3807_CAN_T_BUILD_ON_WATER);
986c30171e92 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents: 3189
diff changeset
   372
				}
3060
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   373
			}
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   374
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   375
			if (flags & DC_EXEC) {
3189
1af302c5abd0 (svn r3846) Add functions to set the type of stuff (clear, water, rail, road) under bridges
tron
parents: 3176
diff changeset
   376
				SetRoadUnderBridge(tile, _current_player);
1af302c5abd0 (svn r3846) Add functions to set the type of stuff (clear, water, rail, road) under bridges
tron
parents: 3176
diff changeset
   377
				MarkTileDirtyByTile(tile);
3060
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   378
			}
3381
ebdcc12845c7 (svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents: 3379
diff changeset
   379
			return _price.build_road * 2;
3060
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   380
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   381
		default:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   382
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
   383
			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
   384
			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
   385
			cost += ret;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   386
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   387
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
   388
	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
   389
	/* 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
   390
	 * 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
   391
	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
   392
		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
   393
3381
ebdcc12845c7 (svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents: 3379
diff changeset
   394
	cost += ret;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   395
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
   396
	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
   397
		// Don't put the pieces that already exist
025fe8cd7104 (svn r3773) Shove some semantics down ottd's throat by replacing ints and magic numbers by enums and some related changes
tron
parents: 3149
diff changeset
   398
		pieces &= ComplementRoadBits(existing);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   399
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   400
3381
ebdcc12845c7 (svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents: 3379
diff changeset
   401
	cost += CountRoadBits(pieces) * _price.build_road;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   402
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   403
	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
   404
		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
   405
			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
   406
		} 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
   407
			MakeRoadNormal(tile, _current_player, pieces, p2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   408
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   409
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   410
		MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   411
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   412
	return cost;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   413
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   414
3435
f299c6f48763 (svn r4265) - Fix: compile warning on VS2005 (parameter 2 different from declaration)
Darkvater
parents: 3434
diff changeset
   415
int32 DoConvertStreetRail(TileIndex tile, RailType totype, bool exec)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   416
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   417
	// not a railroad crossing?
1927
4126e0e3e884 (svn r2433) - CodeChange: unmagicify all road/train crossings with IsLevelCrossing() function (peter1138)
Darkvater
parents: 1902
diff changeset
   418
	if (!IsLevelCrossing(tile)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   419
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   420
	// not owned by me?
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   421
	if (!CheckTileOwnership(tile) || !EnsureNoVehicle(tile)) return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   422
3242
1cefa03f0d5e (svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents: 3234
diff changeset
   423
	if (GetRailTypeCrossing(tile) == totype) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   424
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   425
	if (exec) {
3242
1cefa03f0d5e (svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents: 3234
diff changeset
   426
		SetRailTypeCrossing(tile, totype);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   427
		MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   428
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   429
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   430
	return _price.build_rail >> 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   431
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   432
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   433
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   434
/** 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
   435
 * @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
   436
 * @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
   437
 * @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
   438
 * - 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
   439
 * - 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
   440
 * - 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
   441
 */
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
   442
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
   443
{
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
   444
	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
   445
	int32 cost, ret;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   446
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
   447
	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
   448
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
   449
	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
   450
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   451
	start_tile = p1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   452
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   453
	/* 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
   454
	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
   455
	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
   456
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   457
	/* 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
   458
	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
   459
		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
   460
		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
   461
		end_tile = t;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   462
		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
   463
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   464
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   465
	cost = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   466
	tile = start_tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   467
	// 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
   468
	for (;;) {
3098
4c1320da876d (svn r3687) Complete some bits I missed whenn adding accessor functions for road types and pieces
tron
parents: 3097
diff changeset
   469
		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
   470
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   471
		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
   472
		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
   473
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
   474
		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
   475
		if (CmdFailed(ret)) {
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   476
			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
   477
			_error_message = INVALID_STRING_ID;
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
   478
		} else {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   479
			cost += ret;
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
   480
		}
0
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
		if (tile == end_tile) break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   483
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   484
		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
   485
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   486
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   487
	return (cost == 0) ? CMD_ERROR : cost;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   488
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   489
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   490
/** 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
   491
 * @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
   492
 * @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
   493
 * @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
   494
 * - 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
   495
 * - 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
   496
 * - 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
   497
 */
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
   498
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
   499
{
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
   500
	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
   501
	int32 cost, ret;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   502
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
   503
	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
   504
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
   505
	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
   506
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   507
	start_tile = p1;
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
	/* 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
   510
	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
   511
	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
   512
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   513
	/* 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
   514
	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
   515
		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
   516
		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
   517
		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
   518
		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
   519
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   520
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   521
	cost = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   522
	tile = start_tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   523
	// 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
   524
	for (;;) {
3098
4c1320da876d (svn r3687) Complete some bits I missed whenn adding accessor functions for road types and pieces
tron
parents: 3097
diff changeset
   525
		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
   526
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   527
		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
   528
		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
   529
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   530
		// 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
   531
		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
   532
			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
   533
			if (!CmdFailed(ret)) cost += ret;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   534
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   535
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   536
		if (tile == end_tile) break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   537
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   538
		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
   539
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   540
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   541
	return (cost == 0) ? CMD_ERROR : cost;
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
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   544
/** 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
   545
 * @param tile tile where to build the depot
3333
41f8abe65d1e (svn r4111) Fix/Remove some stale comments
tron
parents: 3322
diff changeset
   546
 * @param p1 entrance direction (DiagDirection)
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   547
 * @param p2 unused
2085
ae9e92ffe168 (svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents: 2074
diff changeset
   548
 *
ae9e92ffe168 (svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents: 2074
diff changeset
   549
 * @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
   550
 * 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
   551
 */
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
   552
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
   553
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   554
	int32 cost;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   555
	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
   556
	Slope tileh;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   557
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   558
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   559
1785
998f4b5eec29 (svn r2289) - Fix (regression): check p1 param of road-depot building instead of unused p2 (typo). Thanks peter1138.
Darkvater
parents: 1784
diff changeset
   560
	if (p1 > 3) return CMD_ERROR; // check direction
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   561
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
   562
	if (!EnsureNoVehicle(tile)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   563
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
   564
	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
   565
	if (tileh != SLOPE_FLAT && (
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
   566
				!_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
   567
				IsSteepSlope(tileh) ||
3055
25fd76668365 (svn r3644) Don't use FindLandscapeHeightByTile() when it's overkill - often it was just a complicated way of writing GetTileSlope(tile, NULL)
tron
parents: 3017
diff changeset
   568
				!CanBuildDepotByTileh(p1, tileh)
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
   569
			)) {
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
   570
		return_cmd_error(STR_0007_FLAT_LAND_REQUIRED);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   571
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   572
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
   573
	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
   574
	if (CmdFailed(cost)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   575
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   576
	dep = AllocateDepot();
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
   577
	if (dep == NULL) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   578
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   579
	if (flags & DC_EXEC) {
2425
99e1e8430a28 (svn r2951) - Fix: [ 1259345 ] Changing engine in netgame opens train window for everyone
Darkvater
parents: 2422
diff changeset
   580
		if (IsLocalPlayer()) _last_built_road_depot_tile = tile;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   581
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   582
		dep->xy = tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   583
		dep->town_index = ClosestTownFromTile(tile, (uint)-1)->index;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   584
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
   585
		MakeRoadDepot(tile, _current_player, p1);
3100
552cf19c49cb (svn r3695) Add 2 MarkTileByTile() which I forgot in r3689 (noticed by Belugas)
tron
parents: 3099
diff changeset
   586
		MarkTileDirtyByTile(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   587
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   588
	return cost + _price.build_road_depot;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   589
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   590
1979
f4462d4e8e62 (svn r2485) Missed two uint -> TileIndex, thanks _Luca_
tron
parents: 1977
diff changeset
   591
static int32 RemoveRoadDepot(TileIndex tile, uint32 flags)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   592
{
149
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 84
diff changeset
   593
	if (!CheckTileOwnership(tile) && _current_player != OWNER_WATER)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   594
		return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   595
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   596
	if (!EnsureNoVehicle(tile)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   597
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   598
	if (flags & DC_EXEC) DoDeleteDepot(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   599
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   600
	return _price.remove_road_depot;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   601
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   602
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   603
#define M(x) (1<<(x))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   604
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
   605
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
   606
{
3793
33cdb5bf7b21 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3792
diff changeset
   607
	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
   608
		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
   609
			RoadBits b = GetRoadBits(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   610
3060
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   611
			if (!((1 << b) & (M(1)|M(2)|M(4)|M(8))) &&
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   612
					(!(flags & DC_AI_BUILDING) || !IsTileOwner(tile, OWNER_TOWN)) &&
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   613
					flags & DC_AUTO) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   614
				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
   615
			}
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
   616
			return DoCommand(tile, b, 0, flags, CMD_REMOVE_ROAD);
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   617
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   618
3793
33cdb5bf7b21 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3792
diff changeset
   619
		case ROAD_TILE_CROSSING: {
3060
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   620
			int32 ret;
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   621
3069
0e6aca11c3da (svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents: 3068
diff changeset
   622
			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
   623
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
   624
			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
   625
			if (CmdFailed(ret)) return CMD_ERROR;
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   626
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   627
			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
   628
				DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
3060
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   629
			}
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   630
			return ret;
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   631
		}
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   632
3069
0e6aca11c3da (svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents: 3068
diff changeset
   633
		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
   634
		case ROAD_TILE_DEPOT:
3060
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   635
			if (flags & DC_AUTO) {
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   636
				return_cmd_error(STR_2004_BUILDING_MUST_BE_DEMOLISHED);
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   637
			}
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   638
			return RemoveRoadDepot(tile, flags);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   639
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   640
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   641
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   642
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   643
typedef struct DrawRoadTileStruct {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   644
	uint16 image;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   645
	byte subcoord_x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   646
	byte subcoord_y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   647
} DrawRoadTileStruct;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   648
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   649
typedef struct DrawRoadSeqStruct {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   650
	uint32 image;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   651
	byte subcoord_x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   652
	byte subcoord_y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   653
	byte width;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   654
	byte height;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   655
} DrawRoadSeqStruct;
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
#include "table/road_land.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   658
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   659
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3560
diff changeset
   660
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
   661
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   662
	int i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   663
	// normal level sloped building
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
   664
	if ((~_valid_tileh_slopes_road[1][tileh] & bits) == 0) return tileh;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   665
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   666
	// inclined sloped building
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
   667
	if ((
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3560
diff changeset
   668
				(i  = 0, tileh == SLOPE_W) ||
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3560
diff changeset
   669
				(i += 2, tileh == SLOPE_S) ||
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3560
diff changeset
   670
				(i += 2, tileh == SLOPE_E) ||
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3560
diff changeset
   671
				(i += 2, tileh == SLOPE_N)
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
   672
			) && (
3098
4c1320da876d (svn r3687) Complete some bits I missed whenn adding accessor functions for road types and pieces
tron
parents: 3097
diff changeset
   673
				(     bits == ROAD_X) ||
4c1320da876d (svn r3687) Complete some bits I missed whenn adding accessor functions for road types and pieces
tron
parents: 3097
diff changeset
   674
				(i++, bits == ROAD_Y)
3017
915fae59d5e0 (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents: 2989
diff changeset
   675
			)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   676
		return i + 15;
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
   677
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   678
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   679
	return 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   680
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   681
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   682
const byte _road_sloped_sprites[14] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   683
	0,  0,  2,  0,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   684
	0,  1,  0,  0,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   685
	3,  0,  0,  0,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   686
	0,  0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   687
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   688
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
/**
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
   690
 * 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
   691
 * @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
   692
 * @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
   693
 */
3430
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
   694
static void DrawRoadBits(TileInfo* ti, RoadBits 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
   695
{
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
   696
	const DrawRoadTileStruct *drts;
14109854e818 (svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents: 2469
diff changeset
   697
	PalSpriteID image = 0;
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
   698
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3560
diff changeset
   699
	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
   700
		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
   701
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   702
		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
   703
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
		// DrawFoundation() modifies ti.
14109854e818 (svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents: 2469
diff changeset
   705
		// 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
   706
		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
   707
	}
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
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   709
	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
   710
3430
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
   711
	if (GetGroundType(ti->tile) == RGT_BARREN) image |= PALETTE_TO_BARE_LAND;
2471
14109854e818 (svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents: 2469
diff changeset
   712
3430
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
   713
	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
   714
		image += 19;
3430
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
   715
	} else if (HasPavement(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
   716
		// Pavement tiles.
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
		image -= 19;
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
	}
14109854e818 (svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents: 2469
diff changeset
   719
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
   720
	DrawGroundSprite(image);
14109854e818 (svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents: 2469
diff changeset
   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
	// Return if full detail is disabled, or we are zoomed fully out.
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   723
	if (!(_display_opt & DO_FULL_DETAIL) || _cur_dpi->zoom == 2) return;
2471
14109854e818 (svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents: 2469
diff changeset
   724
3430
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
   725
	if (HasRoadWorks(ti->tile)) {
2471
14109854e818 (svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents: 2469
diff changeset
   726
		// Road works
3098
4c1320da876d (svn r3687) Complete some bits I missed whenn adding accessor functions for road types and pieces
tron
parents: 3097
diff changeset
   727
		DrawGroundSprite(road & ROAD_X ? SPR_EXCAVATION_X : SPR_EXCAVATION_Y);
2471
14109854e818 (svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents: 2469
diff changeset
   728
		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
   729
	}
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
   730
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
   731
	// Draw extra details.
3430
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
   732
	for (drts = _road_display_table[GetGroundType(ti->tile)][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
   733
		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
   734
		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
   735
		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
   736
		if (ti->tileh != SLOPE_FLAT) z = GetSlopeZ(x, y);
3017
915fae59d5e0 (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents: 2989
diff changeset
   737
		AddSortableSpriteToDraw(drts->image, x, y, 2, 2, 0x10, z);
2471
14109854e818 (svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents: 2469
diff changeset
   738
	}
14109854e818 (svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents: 2469
diff changeset
   739
}
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
   740
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   741
static void DrawTile_Road(TileInfo *ti)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   742
{
2471
14109854e818 (svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents: 2469
diff changeset
   743
	PalSpriteID image;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   744
3793
33cdb5bf7b21 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3792
diff changeset
   745
	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
   746
		case ROAD_TILE_NORMAL:
3430
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
   747
			DrawRoadBits(ti, GetRoadBits(ti->tile));
3060
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   748
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   749
3793
33cdb5bf7b21 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3792
diff changeset
   750
		case ROAD_TILE_CROSSING: {
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3560
diff changeset
   751
			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
   752
3242
1cefa03f0d5e (svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents: 3234
diff changeset
   753
			image = GetRailTypeInfo(GetRailTypeCrossing(ti->tile))->base_sprites.crossing;
3060
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   754
3272
7e556f209503 (svn r3984) Add a function to get the road axis of a level crossing
tron
parents: 3269
diff changeset
   755
			if (GetCrossingRoadAxis(ti->tile) == AXIS_X) image++;
3060
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   756
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
   757
			if (IsCrossingBarred(ti->tile)) image += 2;
3060
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   758
3430
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
   759
			if (IsOnSnow(ti->tile)) {
3060
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   760
				image += 8;
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   761
			} else {
3430
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
   762
				if (GetGroundType(ti->tile) == RGT_BARREN) image |= PALETTE_TO_BARE_LAND;
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
   763
				if (HasPavement(ti->tile)) image += 4;
3060
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   764
			}
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   765
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   766
			DrawGroundSprite(image);
3367
3f82c99d42af (svn r4164) Use acessor functions
tron
parents: 3365
diff changeset
   767
			if (GetRailTypeCrossing(ti->tile) == RAILTYPE_ELECTRIC) DrawCatenary(ti);
3060
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   768
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   769
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   770
3098
4c1320da876d (svn r3687) Complete some bits I missed whenn adding accessor functions for road types and pieces
tron
parents: 3097
diff changeset
   771
		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
   772
		case ROAD_TILE_DEPOT: {
3060
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   773
			uint32 ormod;
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   774
			PlayerID player;
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   775
			const DrawRoadSeqStruct* drss;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   776
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3560
diff changeset
   777
			if (ti->tileh != SLOPE_FLAT) DrawFoundation(ti, ti->tileh);
1398
2299b334e660 (svn r1902) Replace some casts with proper typing
tron
parents: 1359
diff changeset
   778
3060
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   779
			ormod = PALETTE_TO_GREY;	//was this a bug/problem?
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   780
			player = GetTileOwner(ti->tile);
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   781
			if (player < MAX_PLAYERS) ormod = PLAYER_SPRITE_COLOR(player);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   782
3167
197b5ee5a831 (svn r3795) Add a function to request the orientation of a depot
tron
parents: 3150
diff changeset
   783
			drss = _road_display_datas[GetRoadDepotDirection(ti->tile)];
3060
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   784
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   785
			DrawGroundSprite(drss++->image);
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   786
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   787
			for (; drss->image != 0; drss++) {
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   788
				uint32 image = drss->image;
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
				if (image & PALETTE_MODIFIER_COLOR) image |= ormod;
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   791
				if (_display_opt & DO_TRANS_BUILDINGS) MAKE_TRANSPARENT(image);
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   792
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   793
				AddSortableSpriteToDraw(image, ti->x | drss->subcoord_x,
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   794
					ti->y | drss->subcoord_y, drss->width, drss->height, 0x14, ti->z
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   795
				);
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   796
			}
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   797
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   798
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   799
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   800
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   801
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   802
void DrawRoadDepotSprite(int x, int y, int image)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   803
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   804
	uint32 ormod;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   805
	const DrawRoadSeqStruct *dtss;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   806
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   807
	ormod = PLAYER_SPRITE_COLOR(_local_player);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   808
1398
2299b334e660 (svn r1902) Replace some casts with proper typing
tron
parents: 1359
diff changeset
   809
	dtss = _road_display_datas[image];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   810
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   811
	x += 33;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   812
	y += 17;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   813
1398
2299b334e660 (svn r1902) Replace some casts with proper typing
tron
parents: 1359
diff changeset
   814
	DrawSprite(dtss++->image, x, y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   815
2952
6a26eeda9679 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2951
diff changeset
   816
	for (; dtss->image != 0; dtss++) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   817
		Point pt = RemapCoords(dtss->subcoord_x, dtss->subcoord_y, 0);
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   818
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   819
		image = dtss->image;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   820
		if (image & PALETTE_MODIFIER_COLOR) image |= ormod;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   821
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   822
		DrawSprite(image, x + pt.x, y + pt.y);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   823
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   824
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   825
2537
d9c0df52a466 (svn r3066) Constify the parameter of GetSlopeZ_*()
tron
parents: 2535
diff changeset
   826
static uint GetSlopeZ_Road(const TileInfo* ti)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   827
{
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3560
diff changeset
   828
	Slope tileh = ti->tileh;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   829
	uint z = ti->z;
3098
4c1320da876d (svn r3687) Complete some bits I missed whenn adding accessor functions for road types and pieces
tron
parents: 3097
diff changeset
   830
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3560
diff changeset
   831
	if (tileh == SLOPE_FLAT) return z;
3793
33cdb5bf7b21 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3792
diff changeset
   832
	if (GetRoadTileType(ti->tile) == ROAD_TILE_NORMAL) {
3286
3250f1488eb2 (svn r4000) Rewrite GetSlope{Tileh,Z}_{Road,Track} in a less confusing way
tron
parents: 3277
diff changeset
   833
		uint f = GetRoadFoundation(tileh, GetRoadBits(ti->tile));
3060
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   834
3286
3250f1488eb2 (svn r4000) Rewrite GetSlope{Tileh,Z}_{Road,Track} in a less confusing way
tron
parents: 3277
diff changeset
   835
		if (f != 0) {
3645
86af43f87885 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3637
diff changeset
   836
			if (f < 15) return z + TILE_HEIGHT; // leveled foundation
3286
3250f1488eb2 (svn r4000) Rewrite GetSlope{Tileh,Z}_{Road,Track} in a less confusing way
tron
parents: 3277
diff changeset
   837
			tileh = _inclined_tileh[f - 15]; // inclined foundation
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   838
		}
3286
3250f1488eb2 (svn r4000) Rewrite GetSlope{Tileh,Z}_{Road,Track} in a less confusing way
tron
parents: 3277
diff changeset
   839
		return z + GetPartialZ(ti->x & 0xF, ti->y & 0xF, tileh);
3250f1488eb2 (svn r4000) Rewrite GetSlope{Tileh,Z}_{Road,Track} in a less confusing way
tron
parents: 3277
diff changeset
   840
	} else {
3645
86af43f87885 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3637
diff changeset
   841
		return z + TILE_HEIGHT;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   842
	}
39
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 22
diff changeset
   843
}
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 22
diff changeset
   844
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3560
diff changeset
   845
static Slope GetSlopeTileh_Road(TileIndex tile, Slope tileh)
39
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 22
diff changeset
   846
{
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3560
diff changeset
   847
	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
   848
	if (GetRoadTileType(tile) == ROAD_TILE_NORMAL) {
3418
a592d40a4d04 (svn r4242) Pass TileIndex and slope to GetSlopeTileh_*() instead of TileInfo
tron
parents: 3415
diff changeset
   849
		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
   850
3418
a592d40a4d04 (svn r4242) Pass TileIndex and slope to GetSlopeTileh_*() instead of TileInfo
tron
parents: 3415
diff changeset
   851
		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
   852
		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
   853
		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
   854
	} else {
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3560
diff changeset
   855
		return SLOPE_FLAT;
39
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 22
diff changeset
   856
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   857
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   858
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
   859
static void GetAcceptedCargo_Road(TileIndex tile, AcceptedCargo ac)
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
	/* not used */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   862
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   863
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
   864
static void AnimateTile_Road(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   865
{
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   866
	if (IsLevelCrossing(tile)) MarkTileDirtyByTile(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   867
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   868
3430
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
   869
static const RoadGroundType _town_road_types[5][2] = {
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
   870
	{RGT_GRASS,RGT_GRASS},
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
   871
	{RGT_PAVED,RGT_PAVED},
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
   872
	{RGT_PAVED,RGT_PAVED},
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
   873
	{RGT_ALLEY,RGT_ALLEY},
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
   874
	{RGT_LIGHT,RGT_PAVED},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   875
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   876
3430
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
   877
static const RoadGroundType _town_road_types_2[5][2] = {
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
   878
	{RGT_GRASS,RGT_GRASS},
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
   879
	{RGT_PAVED,RGT_PAVED},
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
   880
	{RGT_LIGHT,RGT_PAVED},
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
   881
	{RGT_LIGHT,RGT_PAVED},
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
   882
	{RGT_LIGHT,RGT_PAVED},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   883
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   884
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   885
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
   886
static void TileLoop_Road(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   887
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   888
	Town *t;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   889
	int grp;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   890
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
   891
	switch (_opt.landscape) {
915fae59d5e0 (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents: 2989
diff changeset
   892
		case LT_HILLY:
3430
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
   893
			if (IsOnSnow(tile) != (GetTileZ(tile) > _opt.snow_line)) {
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
   894
				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
   895
				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
   896
			}
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
   897
			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
   898
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
   899
		case LT_DESERT:
3430
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
   900
			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
   901
				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
   902
				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
   903
			}
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
   904
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   905
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   906
3793
33cdb5bf7b21 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3792
diff changeset
   907
	if (GetRoadTileType(tile) == ROAD_TILE_DEPOT) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   908
3430
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
   909
	if (!HasRoadWorks(tile)) {
1281
1573d0e4e7a1 (svn r1785) -Fix: space-correctness in road_cmd.c, and one wrong line from last
truelight
parents: 1280
diff changeset
   910
		t = ClosestTownFromTile(tile, (uint)-1);
1280
b6925875de49 (svn r1784) -Fix: removed ClosestTownFromTile where possible, or replaced it
truelight
parents: 1264
diff changeset
   911
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   912
		grp = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   913
		if (t != NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   914
			grp = GetTownRadiusGroup(t, tile);
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   915
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   916
			// 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
   917
			if (t->road_build_months != 0 &&
1245
768d9bc95aaa (svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents: 1214
diff changeset
   918
					!(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
   919
					GetRoadTileType(tile) == ROAD_TILE_NORMAL && (GetRoadBits(tile) == ROAD_X || GetRoadBits(tile) == ROAD_Y)) {
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3560
diff changeset
   920
				if (GetTileSlope(tile, NULL) == SLOPE_FLAT && EnsureNoVehicle(tile) && CHANCE16(1, 20)) {
3430
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
   921
					StartRoadWorks(tile);
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   922
541
e1cd34389f79 (svn r925) Use sound enums
tron
parents: 534
diff changeset
   923
					SndPlayTileFx(SND_21_JACKHAMMER, tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   924
					CreateEffectVehicleAbove(
3421
8ab76c47c72c (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3418
diff changeset
   925
						TileX(tile) * TILE_SIZE + 7,
8ab76c47c72c (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3418
diff changeset
   926
						TileY(tile) * TILE_SIZE + 7,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   927
						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
   928
						EV_BULLDOZER);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   929
					MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   930
					return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   931
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   932
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   933
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   934
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   935
		{
3430
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
   936
			/* Adjust road ground type depending on 'grp' (grp is the distance to the center) */
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
   937
			const RoadGroundType *target_rgt = (_opt.landscape == LT_CANDY) ? _town_road_types_2[grp] : _town_road_types[grp];
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
   938
			RoadGroundType rgt = GetGroundType(tile);
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   939
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 have our desired type, do nothing */
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
   941
			if (rgt == target_rgt[0]) return;
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
   942
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
   943
			/* We have the pre-type of the desired type, switch to the desired type */
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
   944
			if (rgt == target_rgt[1]) {
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
   945
				rgt = target_rgt[0];
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
   946
			/* We have barren land, install the pre-type */
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 (rgt == RGT_BARREN) {
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
   948
				rgt = target_rgt[1];
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
   949
			/* 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
   950
			} else {
3430
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
   951
				rgt = RGT_BARREN;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   952
			}
3430
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
   953
			SetGroundType(tile, rgt);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   954
			MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   955
		}
3430
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
   956
	} 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
   957
		TerminateRoadWorks(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   958
		MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   959
	}
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
void ShowRoadDepotWindow(TileIndex tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   963
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
   964
static void ClickTile_Road(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   965
{
3793
33cdb5bf7b21 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3792
diff changeset
   966
	if (GetRoadTileType(tile) == ROAD_TILE_DEPOT) ShowRoadDepotWindow(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   967
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   968
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   969
static const byte _road_trackbits[16] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   970
	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
   971
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   972
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
   973
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
   974
{
3066
0d34dff23d98 (svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents: 3061
diff changeset
   975
	switch (mode) {
0d34dff23d98 (svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents: 3061
diff changeset
   976
		case TRANSPORT_RAIL:
0d34dff23d98 (svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents: 3061
diff changeset
   977
			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
   978
			return GetCrossingRailBits(tile) * 0x101;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   979
3066
0d34dff23d98 (svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents: 3061
diff changeset
   980
		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
   981
			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
   982
				case ROAD_TILE_NORMAL:
3430
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
   983
					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
   984
3793
33cdb5bf7b21 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3792
diff changeset
   985
				case ROAD_TILE_CROSSING: {
3415
4d76e72c6ac2 (svn r4230) The road is asked for, not the rail. Undo part of r4164. (Pointed out by peter1138)
tron
parents: 3381
diff changeset
   986
					uint32 r = (GetCrossingRoadAxis(tile) == AXIS_X ? TRACK_BIT_X : TRACK_BIT_Y) * 0x101;
3272
7e556f209503 (svn r3984) Add a function to get the road axis of a level crossing
tron
parents: 3269
diff changeset
   987
3367
3f82c99d42af (svn r4164) Use acessor functions
tron
parents: 3365
diff changeset
   988
					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
   989
					return r;
0d34dff23d98 (svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents: 3061
diff changeset
   990
				}
0d34dff23d98 (svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents: 3061
diff changeset
   991
3069
0e6aca11c3da (svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents: 3068
diff changeset
   992
				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
   993
				case ROAD_TILE_DEPOT:
3066
0d34dff23d98 (svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents: 3061
diff changeset
   994
					break;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   995
			}
3066
0d34dff23d98 (svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents: 3061
diff changeset
   996
			break;
0d34dff23d98 (svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents: 3061
diff changeset
   997
0d34dff23d98 (svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents: 3061
diff changeset
   998
		default: break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   999
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1000
	return 0;
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1003
static const StringID _road_tile_strings[] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1004
	STR_1814_ROAD,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1005
	STR_1814_ROAD,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1006
	STR_1814_ROAD,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1007
	STR_1815_ROAD_WITH_STREETLIGHTS,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1008
	STR_1814_ROAD,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1009
	STR_1816_TREE_LINED_ROAD,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1010
	STR_1814_ROAD,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1011
	STR_1814_ROAD,
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
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
  1014
static void GetTileDesc_Road(TileIndex tile, TileDesc *td)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1015
{
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
  1016
	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
  1017
	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
  1018
		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
  1019
		case ROAD_TILE_DEPOT: td->str = STR_1817_ROAD_VEHICLE_DEPOT; break;
3430
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
  1020
		default: td->str = _road_tile_strings[GetGroundType(tile)]; break;
3069
0e6aca11c3da (svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents: 3068
diff changeset
  1021
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1022
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1023
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1024
static const byte _roadveh_enter_depot_unk0[4] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1025
	8, 9, 0, 1
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1026
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1027
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
  1028
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
  1029
{
3793
33cdb5bf7b21 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3792
diff changeset
  1030
	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
  1031
		case ROAD_TILE_CROSSING:
3322
fa5d46929db9 (svn r4088) -Codechange: Introduce {Unb,B}arCrossing and IsCrossingBarred to put and get the status of a level crossing
celestar
parents: 3319
diff changeset
  1032
			if (v->type == VEH_Train && !IsCrossingBarred(tile)) {
3060
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1033
				/* train crossing a road */
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1034
				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
  1035
				BarCrossing(tile);
3060
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1036
				MarkTileDirtyByTile(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1037
			}
3060
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1038
			break;
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1039
3793
33cdb5bf7b21 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3792
diff changeset
  1040
		case ROAD_TILE_DEPOT:
3060
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1041
			if (v->type == VEH_Road && v->u.road.frame == 11) {
3167
197b5ee5a831 (svn r3795) Add a function to request the orientation of a depot
tron
parents: 3150
diff changeset
  1042
				if (_roadveh_enter_depot_unk0[GetRoadDepotDirection(tile)] == v->u.road.state) {
3060
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1043
					RoadVehEnterDepot(v);
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1044
					return 4;
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1045
				}
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1046
			}
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1047
			break;
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1048
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1049
		default: break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1050
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1051
	return 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1052
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1053
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1054
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
  1055
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
  1056
{
3274
e3fd60498b38 (svn r3986) Add [GS]etCrossingRoadOwner
tron
parents: 3272
diff changeset
  1057
	if (IsLevelCrossing(tile) && GetCrossingRoadOwner(tile) == old_player) {
e3fd60498b38 (svn r3986) Add [GS]etCrossingRoadOwner
tron
parents: 3272
diff changeset
  1058
		SetCrossingRoadOwner(tile, new_player == OWNER_SPECTATOR ? OWNER_NONE : new_player);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1059
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1060
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
  1061
	if (!IsTileOwner(tile, old_player)) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1062
2502
35e279b13856 (svn r3028) s/255/OWNER_SPECTATOR/
tron
parents: 2493
diff changeset
  1063
	if (new_player != OWNER_SPECTATOR) {
1902
5d653da1abb7 (svn r2408) Introduce SetTileOwner() and use it
tron
parents: 1901
diff changeset
  1064
		SetTileOwner(tile, new_player);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1065
	}	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
  1066
		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
  1067
			case ROAD_TILE_NORMAL:
3060
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1068
				SetTileOwner(tile, OWNER_NONE);
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1069
				break;
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1070
3793
33cdb5bf7b21 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3792
diff changeset
  1071
			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
  1072
				MakeRoadNormal(tile, GetCrossingRoadOwner(tile), GetCrossingRoadBits(tile), GetTownIndex(tile));
3060
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1073
				break;
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1074
3069
0e6aca11c3da (svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents: 3068
diff changeset
  1075
			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
  1076
			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
  1077
				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
  1078
				break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1079
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1080
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1081
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1082
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1059
diff changeset
  1083
void InitializeRoad(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1084
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1085
	_last_built_road_depot_tile = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1086
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1087
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1088
const TileTypeProcs _tile_type_road_procs = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1089
	DrawTile_Road,						/* draw_tile_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1090
	GetSlopeZ_Road,						/* get_slope_z_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1091
	ClearTile_Road,						/* clear_tile_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1092
	GetAcceptedCargo_Road,		/* get_accepted_cargo_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1093
	GetTileDesc_Road,					/* get_tile_desc_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1094
	GetTileTrackStatus_Road,	/* get_tile_track_status_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1095
	ClickTile_Road,						/* click_tile_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1096
	AnimateTile_Road,					/* animate_tile_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1097
	TileLoop_Road,						/* tile_loop_clear */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1098
	ChangeTileOwner_Road,			/* change_tile_owner_clear */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1099
	NULL,											/* get_produced_cargo_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1100
	VehicleEnter_Road,				/* vehicle_enter_tile_proc */
39
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 22
diff changeset
  1101
	GetSlopeTileh_Road,				/* get_slope_tileh_proc */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1102
};