src/road_cmd.cpp
author rubidium
Thu, 07 Jun 2007 08:58:21 +0000
changeset 6814 46c7d033c926
parent 6768 379e38fcab7e
child 6857 60130753e595
permissions -rw-r--r--
(svn r10053) -Fix: could not clear a level-crossing tile with tram tracks.
2186
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
6393
e1e4939d19b5 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6368
diff changeset
     3
/** @file road_cmd.cpp */
e1e4939d19b5 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6368
diff changeset
     4
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
#include "stdafx.h"
1891
862800791170 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1785
diff changeset
     6
#include "openttd.h"
3189
bf047128dee7 (svn r3846) Add functions to set the type of stuff (clear, water, rail, road) under bridges
tron
parents: 3176
diff changeset
     7
#include "bridge_map.h"
6160
fa42299e967e (svn r8908) -Codechange: declaration of DrawBridgeMiddle does not belong in a map accessors header.
rubidium
parents: 6134
diff changeset
     8
#include "bridge.h"
6134
871305fd9ab7 (svn r8876) -Fix
tron
parents: 6133
diff changeset
     9
#include "cmd_helper.h"
3101
a44fdf9faef1 (svn r3696) Add functions to turn a tile into a normal rail tile/depot/waypoint. This is just a tiny step, the rail code needs way more love and caring
tron
parents: 3100
diff changeset
    10
#include "rail_map.h"
3144
33e42feae531 (svn r3763) Adapt to the new 'map accessors go in foo_map.h'-scheme
tron
parents: 3104
diff changeset
    11
#include "road_map.h"
4232
136a11474264 (svn r5796) Use DrawTileSprites/DrawTileSeqStruct for road depot drawing data, too
tron
parents: 4231
diff changeset
    12
#include "sprite.h"
2008
cdb444f6d43c (svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents: 1986
diff changeset
    13
#include "table/sprites.h"
507
04b5403aaf6b (svn r815) Include strings.h only in the files which need it.
tron
parents: 497
diff changeset
    14
#include "table/strings.h"
2163
b17b313113a0 (svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents: 2148
diff changeset
    15
#include "functions.h"
679
04ca2cd69420 (svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents: 541
diff changeset
    16
#include "map.h"
6343
76d17f784c13 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6259
diff changeset
    17
#include "landscape.h"
1209
2e00193652b2 (svn r1713) Split off several functions which query/set information about a single tile from map.h and put them into a seperate file tile.h
tron
parents: 1095
diff changeset
    18
#include "tile.h"
3319
16c0f06829a5 (svn r4085) Add GetTown{Index,ByTile}() to get the town index resp. the town from a tile
tron
parents: 3286
diff changeset
    19
#include "town_map.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    20
#include "vehicle.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    21
#include "viewport.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    22
#include "command.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    23
#include "player.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    24
#include "town.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    25
#include "gfx.h"
337
cbe0c766c947 (svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents: 241
diff changeset
    26
#include "sound.h"
3900
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3884
diff changeset
    27
#include "yapf/yapf.h"
1313
f1013ec3d318 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents: 1281
diff changeset
    28
#include "depot.h"
6541
dfa5165a5ab7 (svn r9730) -Feature: [NewGRF] Add support for miscellaneous grf feature bit 1 - paved roads on desert tiles.
maedhros
parents: 6491
diff changeset
    29
#include "newgrf.h"
6679
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
    30
#include "station_map.h"
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
    31
#include "tunnel_map.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    32
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    33
3381
91ee7484deff (svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents: 3379
diff changeset
    34
static uint CountRoadBits(RoadBits r)
91ee7484deff (svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents: 3379
diff changeset
    35
{
91ee7484deff (svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents: 3379
diff changeset
    36
	uint count = 0;
91ee7484deff (svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents: 3379
diff changeset
    37
91ee7484deff (svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents: 3379
diff changeset
    38
	if (r & ROAD_NW) ++count;
91ee7484deff (svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents: 3379
diff changeset
    39
	if (r & ROAD_SW) ++count;
91ee7484deff (svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents: 3379
diff changeset
    40
	if (r & ROAD_SE) ++count;
91ee7484deff (svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents: 3379
diff changeset
    41
	if (r & ROAD_NE) ++count;
91ee7484deff (svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents: 3379
diff changeset
    42
	return count;
91ee7484deff (svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents: 3379
diff changeset
    43
}
91ee7484deff (svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents: 3379
diff changeset
    44
91ee7484deff (svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents: 3379
diff changeset
    45
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
    46
bool CheckAllowRemoveRoad(TileIndex tile, RoadBits remove, Owner owner, bool *edge_road, RoadType rt)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    47
{
3149
9685221d33fa (svn r3770) Remove the _road_special_gettrackstatus hack. Egladil and me deem it unnecessary
tron
parents: 3146
diff changeset
    48
	RoadBits present;
9685221d33fa (svn r3770) Remove the _road_special_gettrackstatus hack. Egladil and me deem it unnecessary
tron
parents: 3146
diff changeset
    49
	RoadBits n;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    50
	*edge_road = true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    51
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
    52
	if (_game_mode == GM_EDITOR || remove == ROAD_NONE) return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    53
6751
a7f281b2a89a (svn r9986) -Fix (r9934): flooding towns could not remove tram tracks (boekabart).
rubidium
parents: 6732
diff changeset
    54
	/* Water can always flood and towns can always remove "normal" road pieces.
a7f281b2a89a (svn r9986) -Fix (r9934): flooding towns could not remove tram tracks (boekabart).
rubidium
parents: 6732
diff changeset
    55
	 * Towns are not be allowed to remove non "normal" road pieces, like tram
a7f281b2a89a (svn r9986) -Fix (r9934): flooding towns could not remove tram tracks (boekabart).
rubidium
parents: 6732
diff changeset
    56
	 * tracks as that would result in trams that cannot turn. */
a7f281b2a89a (svn r9986) -Fix (r9934): flooding towns could not remove tram tracks (boekabart).
rubidium
parents: 6732
diff changeset
    57
	if (_current_player == OWNER_WATER ||
a7f281b2a89a (svn r9986) -Fix (r9934): flooding towns could not remove tram tracks (boekabart).
rubidium
parents: 6732
diff changeset
    58
			(rt == ROADTYPE_ROAD && !IsValidPlayer(_current_player))) return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    59
6393
e1e4939d19b5 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6368
diff changeset
    60
	/* Only do the special processing if the road is owned
e1e4939d19b5 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6368
diff changeset
    61
	 * by a town */
4849
1c6f21eb97f2 (svn r6775) -Codechange: Use some more proper types, especially Owner and PlayerID as
Darkvater
parents: 4848
diff changeset
    62
	if (owner != OWNER_TOWN) return (owner == OWNER_NONE) || CheckOwnership(owner);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    63
3017
a75caf4efa2d (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
    64
	if (_cheats.magic_bulldozer.value) return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    65
6393
e1e4939d19b5 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6368
diff changeset
    66
	/* Get a bitmask of which neighbouring roads has a tile */
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
    67
	n = ROAD_NONE;
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
    68
	present = GetAnyRoadBits(tile, rt);
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
    69
	if (present & ROAD_NE && GetAnyRoadBits(TILE_ADDXY(tile, -1,  0), rt) & ROAD_SW) n |= ROAD_NE;
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
    70
	if (present & ROAD_SE && GetAnyRoadBits(TILE_ADDXY(tile,  0,  1), rt) & ROAD_NW) n |= ROAD_SE;
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
    71
	if (present & ROAD_SW && GetAnyRoadBits(TILE_ADDXY(tile,  1,  0), rt) & ROAD_NE) n |= ROAD_SW;
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
    72
	if (present & ROAD_NW && GetAnyRoadBits(TILE_ADDXY(tile,  0, -1), rt) & ROAD_SE) n |= ROAD_NW;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
    73
6393
e1e4939d19b5 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6368
diff changeset
    74
	/* If 0 or 1 bits are set in n, or if no bits that match the bits to remove,
e1e4939d19b5 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6368
diff changeset
    75
	 * then allow it */
3149
9685221d33fa (svn r3770) Remove the _road_special_gettrackstatus hack. Egladil and me deem it unnecessary
tron
parents: 3146
diff changeset
    76
	if ((n & (n - 1)) != 0 && (n & remove) != 0) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    77
		Town *t;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    78
		*edge_road = false;
6393
e1e4939d19b5 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6368
diff changeset
    79
		/* you can remove all kind of roads with extra dynamite */
3017
a75caf4efa2d (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
    80
		if (_patches.extra_dynamite) return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    81
6256
24e274c0ae42 (svn r9065) -Fix: possible dereference of NULL pointer.
rubidium
parents: 6248
diff changeset
    82
		t = ClosestTownFromTile(tile, (uint)-1);
1638
4779658c2d03 (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
    83
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
    84
		SetDParam(0, t->index);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    85
		_error_message = STR_2009_LOCAL_AUTHORITY_REFUSES;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    86
		return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    87
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    88
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    89
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    90
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    91
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
    92
static bool CheckAllowRemoveRoad(TileIndex tile, RoadBits remove, bool *edge_road, RoadType rt)
6116
0a63874accb6 (svn r8852) -Fix (r8735): make the dynamite tool for drive through road stops as if it were removing a normal road tile (consider the local authority and such).
rubidium
parents: 5991
diff changeset
    93
{
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
    94
	return CheckAllowRemoveRoad(tile, remove, GetRoadOwner(tile, rt), edge_road, rt);
6116
0a63874accb6 (svn r8852) -Fix (r8735): make the dynamite tool for drive through road stops as if it were removing a normal road tile (consider the local authority and such).
rubidium
parents: 5991
diff changeset
    95
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    96
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
    97
/** Delete a piece of road.
3491
35d747bb5e82 (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
    98
 * @param tile tile where to remove road from
6483
ae78fc3c6b20 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6427
diff changeset
    99
 * @param flags operation to perform
6134
871305fd9ab7 (svn r8876) -Fix
tron
parents: 6133
diff changeset
   100
 * @param p1 bit 0..3 road pieces to remove (RoadBits)
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
   101
 *           bit 4..5 road type
6814
46c7d033c926 (svn r10053) -Fix: could not clear a level-crossing tile with tram tracks.
rubidium
parents: 6768
diff changeset
   102
 *           bit    6 ignore the fact that the tram track has not been removed
46c7d033c926 (svn r10053) -Fix: could not clear a level-crossing tile with tram tracks.
rubidium
parents: 6768
diff changeset
   103
 *                    yet when removing the road bits when not actually doing
46c7d033c926 (svn r10053) -Fix: could not clear a level-crossing tile with tram tracks.
rubidium
parents: 6768
diff changeset
   104
 *                    it. Makes it possible to test whether the road bits can
46c7d033c926 (svn r10053) -Fix: could not clear a level-crossing tile with tram tracks.
rubidium
parents: 6768
diff changeset
   105
 *                    be removed from a level crossing without physically
46c7d033c926 (svn r10053) -Fix: could not clear a level-crossing tile with tram tracks.
rubidium
parents: 6768
diff changeset
   106
 *                    removing the tram bits before the test.
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   107
 * @param p2 unused
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   108
 */
3491
35d747bb5e82 (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
   109
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
   110
{
6393
e1e4939d19b5 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6368
diff changeset
   111
	/* cost for removing inner/edge -roads */
1638
4779658c2d03 (svn r2142) - Fix: Game no longer crashes when you want to remove a piece of road under a bridge that belongs to the town. TODO: railcrossings store owner somewhere else, put it into _map_owner[]!
Darkvater
parents: 1398
diff changeset
   112
	static const uint16 road_remove_cost[2] = {50, 18};
4779658c2d03 (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
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   114
	Town *t;
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   115
	/* true if the roadpiece was always removeable,
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   116
	 * 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
   117
	bool edge_road;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   118
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   119
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   120
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
   121
	RoadType rt = (RoadType)GB(p1, 4, 2);
6679
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   122
	if (!IsValidRoadType(rt)) return CMD_ERROR;
2074
089fab08189c (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
   123
6679
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   124
	Owner owner;
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   125
	switch (GetTileType(tile)) {
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   126
		case MP_STREET:
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   127
			owner = GetRoadOwner(tile, rt);
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   128
			break;
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   129
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   130
		case MP_STATION:
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   131
			if (!IsDriveThroughStopTile(tile)) return CMD_ERROR;
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   132
			owner = GetTileOwner(tile);
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   133
			break;
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   134
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   135
		case MP_TUNNELBRIDGE:
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   136
			if ((IsTunnel(tile) && GetTunnelTransportType(tile) != TRANSPORT_ROAD) ||
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   137
					(IsBridge(tile) && GetBridgeTransportType(tile) != TRANSPORT_ROAD)) return CMD_ERROR;
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   138
			owner = GetTileOwner(tile);
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   139
			break;
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   140
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   141
		default:
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   142
			return CMD_ERROR;
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   143
	}
1638
4779658c2d03 (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
   144
4779658c2d03 (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
   145
	if (owner == OWNER_TOWN && _game_mode != GM_EDITOR) {
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   146
		t = GetTownByTile(tile);
3017
a75caf4efa2d (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
   147
	} else {
1280
33a251c30758 (svn r1784) -Fix: removed ClosestTownFromTile where possible, or replaced it
truelight
parents: 1264
diff changeset
   148
		t = NULL;
3017
a75caf4efa2d (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
   149
	}
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   150
6134
871305fd9ab7 (svn r8876) -Fix
tron
parents: 6133
diff changeset
   151
	RoadBits pieces = Extract<RoadBits, 0>(p1);
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
   152
	RoadTypes rts = GetRoadTypes(tile);
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
   153
	/* The tile doesn't have the given road type */
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
   154
	if (!HASBIT(rts, rt)) return CMD_ERROR;
6134
871305fd9ab7 (svn r8876) -Fix
tron
parents: 6133
diff changeset
   155
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
   156
	if (!CheckAllowRemoveRoad(tile, pieces, &edge_road, rt)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   157
6406
8ccf18e94c67 (svn r9542) -Fix(FS# 712): When checking if a vehicle is on a given tile, and you are working on the ground tile, do not take aircrafts into account, as they do not pose any danger for the construction/destruction/conversion itself. Z stuff, in other words
belugas
parents: 6393
diff changeset
   158
	if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
3933
231ae3c419f4 (svn r5070) Merged the bridge branch
celestar
parents: 3900
diff changeset
   159
6393
e1e4939d19b5 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6368
diff changeset
   160
	/* check if you're allowed to remove the street owned by a town
e1e4939d19b5 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6368
diff changeset
   161
	 * removal allowance depends on difficulty setting */
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   162
	if (!CheckforTownRating(flags, t, ROAD_REMOVE)) return CMD_ERROR;
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   163
6679
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   164
	if (!IsTileType(tile, MP_STREET)) {
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   165
		/* If it's the last roadtype, just clear the whole tile */
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   166
		if (rts == RoadTypeToRoadTypes(rt)) return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   167
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   168
		int32 cost;
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   169
		if (IsTileType(tile, MP_TUNNELBRIDGE)) {
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   170
			TileIndex other_end = IsTunnel(tile) ? GetOtherTunnelEnd(tile) : GetOtherBridgeEnd(tile);
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   171
			/* Pay for *every* tile of the bridge or tunnel */
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   172
			cost = (DistanceManhattan(IsTunnel(tile) ? GetOtherTunnelEnd(tile) : GetOtherBridgeEnd(tile), tile) + 1) * _price.remove_road;
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   173
			if (flags & DC_EXEC) {
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   174
				SetRoadTypes(other_end, GetRoadTypes(other_end) & ~RoadTypeToRoadTypes(rt));
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   175
				SetRoadTypes(tile, GetRoadTypes(tile) & ~RoadTypeToRoadTypes(rt));
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   176
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   177
				/* Mark tiles diry that have been repaved */
6714
f8edec66a9c4 (svn r9946) -Fix: more places that weren't correctly marked dirty...
rubidium
parents: 6713
diff changeset
   178
				MarkTileDirtyByTile(tile);
6679
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   179
				MarkTileDirtyByTile(other_end);
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   180
				if (IsBridge(tile)) {
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   181
					TileIndexDiff delta = TileOffsByDiagDir(GetBridgeRampDirection(tile));
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   182
6713
7962b523ecd6 (svn r9945) -Fix: bridges were not properly marked dirty when adding/removing roadtypes.
rubidium
parents: 6711
diff changeset
   183
					for (TileIndex t = tile + delta; t != other_end; t += delta) MarkTileDirtyByTile(t);
6679
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   184
				}
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   185
			}
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   186
		} else {
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   187
			cost = _price.remove_road;
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   188
			if (flags & DC_EXEC) {
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   189
				SetRoadTypes(tile, GetRoadTypes(tile) & ~RoadTypeToRoadTypes(rt));
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   190
				MarkTileDirtyByTile(tile);
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   191
			}
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   192
		}
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   193
		return cost;
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   194
	}
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   195
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   196
	switch (GetRoadTileType(tile)) {
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   197
		case ROAD_TILE_NORMAL: {
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
   198
			RoadBits present = GetRoadBits(tile, rt);
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   199
			RoadBits c = pieces;
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   200
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   201
			if (HasRoadWorks(tile)) return_cmd_error(STR_ROAD_WORKS_IN_PROGRESS);
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   202
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   203
			if (GetTileSlope(tile, NULL) != SLOPE_FLAT  &&
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   204
					(present == ROAD_Y || present == ROAD_X)) {
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   205
				c |= (RoadBits)((c & 0xC) >> 2);
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   206
				c |= (RoadBits)((c & 0x3) << 2);
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   207
			}
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   208
6393
e1e4939d19b5 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6368
diff changeset
   209
			/* limit the bits to delete to the existing bits. */
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   210
			c &= present;
6662
ea30b3497d9a (svn r9893) -Fix (r9892): various small bugs that only act up when using something different than plain roads.
rubidium
parents: 6661
diff changeset
   211
			if (c == ROAD_NONE) return CMD_ERROR;
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   212
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   213
			if (flags & DC_EXEC) {
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   214
				ChangeTownRating(t, -road_remove_cost[(byte)edge_road], RATING_ROAD_MINIMUM);
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   215
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   216
				present ^= c;
6662
ea30b3497d9a (svn r9893) -Fix (r9892): various small bugs that only act up when using something different than plain roads.
rubidium
parents: 6661
diff changeset
   217
				if (present == ROAD_NONE) {
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
   218
					RoadTypes rts = GetRoadTypes(tile) & ComplementRoadTypes(RoadTypeToRoadTypes(rt));
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
   219
					if (rts == ROADTYPES_NONE) {
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
   220
						DoClearSquare(tile);
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
   221
					} else {
6662
ea30b3497d9a (svn r9893) -Fix (r9892): various small bugs that only act up when using something different than plain roads.
rubidium
parents: 6661
diff changeset
   222
						SetRoadBits(tile, ROAD_NONE, rt);
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
   223
						SetRoadTypes(tile, rts);
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
   224
					}
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   225
				} else {
6764
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   226
					/* When bits are removed, you *always* end up with something that
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   227
					 * is not a complete straight road tile. However, trams do not have
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   228
					 * onewayness, so they cannot remove it either. */
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   229
					if (rt != ROADTYPE_TRAM) SetDisallowedRoadDirections(tile, DRD_NONE);
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
   230
					SetRoadBits(tile, present, rt);
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   231
					MarkTileDirtyByTile(tile);
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   232
				}
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   233
			}
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   234
			return CountRoadBits(c) * _price.remove_road;
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   235
		}
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   236
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   237
		case ROAD_TILE_CROSSING: {
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   238
			if (pieces & ComplementRoadBits(GetCrossingRoadBits(tile))) {
3176
3975f96c40f8 (svn r3812) Remove a pointless goto
tron
parents: 3167
diff changeset
   239
				return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   240
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   241
6697
dde1f5dced50 (svn r9929) -Fix [FS#803]: fix several drawing issues.
rubidium
parents: 6691
diff changeset
   242
			/* Don't allow road to be removed from the crossing when there is tram;
dde1f5dced50 (svn r9929) -Fix [FS#803]: fix several drawing issues.
rubidium
parents: 6691
diff changeset
   243
			 * we can't draw the crossing without trambits ;) */
6814
46c7d033c926 (svn r10053) -Fix: could not clear a level-crossing tile with tram tracks.
rubidium
parents: 6768
diff changeset
   244
			if (rt == ROADTYPE_ROAD && HASBIT(GetRoadTypes(tile), ROADTYPE_TRAM) && ((flags & DC_EXEC) || !HASBIT(p1, 6))) return CMD_ERROR;
6697
dde1f5dced50 (svn r9929) -Fix [FS#803]: fix several drawing issues.
rubidium
parents: 6691
diff changeset
   245
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   246
			if (flags & DC_EXEC) {
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
   247
				if (rt == ROADTYPE_ROAD) {
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
   248
					ChangeTownRating(t, -road_remove_cost[(byte)edge_road], RATING_ROAD_MINIMUM);
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
   249
				}
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   250
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
   251
				RoadTypes rts = GetRoadTypes(tile) & ComplementRoadTypes(RoadTypeToRoadTypes(rt));
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
   252
				if (rts == ROADTYPES_NONE) {
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
   253
					MakeRailNormal(tile, GetTileOwner(tile), GetCrossingRailBits(tile), GetRailType(tile));
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
   254
				} else {
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
   255
					SetRoadTypes(tile, rts);
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
   256
				}
3060
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   257
				MarkTileDirtyByTile(tile);
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   258
				YapfNotifyTrackLayoutChange(tile, FindFirstTrack(GetTrackBits(tile)));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   259
			}
3381
91ee7484deff (svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents: 3379
diff changeset
   260
			return _price.remove_road * 2;
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   261
		}
3977
513433ebd092 (svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents: 3933
diff changeset
   262
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   263
		default:
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   264
		case ROAD_TILE_DEPOT:
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   265
			return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   266
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   267
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   268
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   269
3104
c039f8a65ba0 (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
   270
static const RoadBits _valid_tileh_slopes_road[][15] = {
6393
e1e4939d19b5 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6368
diff changeset
   271
	/* set of normal ones */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   272
	{
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   273
		ROAD_ALL, ROAD_NONE, ROAD_NONE,
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   274
		ROAD_X,   ROAD_NONE, ROAD_NONE,  // 3, 4, 5
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   275
		ROAD_Y,   ROAD_NONE, ROAD_NONE,
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   276
		ROAD_Y,   ROAD_NONE, ROAD_NONE,  // 9, 10, 11
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   277
		ROAD_X,   ROAD_NONE, ROAD_NONE
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   278
	},
6393
e1e4939d19b5 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6368
diff changeset
   279
	/* 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
   280
	{
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   281
		ROAD_NONE,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   282
		ROAD_SW | ROAD_NW,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   283
		ROAD_SW | ROAD_SE,
3098
aed45c5c1e11 (svn r3687) Complete some bits I missed whenn adding accessor functions for road types and pieces
tron
parents: 3097
diff changeset
   284
		ROAD_Y  | ROAD_SW,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   285
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   286
		ROAD_SE | ROAD_NE, // 4
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   287
		ROAD_ALL,
3098
aed45c5c1e11 (svn r3687) Complete some bits I missed whenn adding accessor functions for road types and pieces
tron
parents: 3097
diff changeset
   288
		ROAD_X  | ROAD_SE,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   289
		ROAD_ALL,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   290
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   291
		ROAD_NW | ROAD_NE, // 8
3098
aed45c5c1e11 (svn r3687) Complete some bits I missed whenn adding accessor functions for road types and pieces
tron
parents: 3097
diff changeset
   292
		ROAD_X  | ROAD_NW,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   293
		ROAD_ALL,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   294
		ROAD_ALL,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   295
3098
aed45c5c1e11 (svn r3687) Complete some bits I missed whenn adding accessor functions for road types and pieces
tron
parents: 3097
diff changeset
   296
		ROAD_Y  | ROAD_NE, // 12
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   297
		ROAD_ALL,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   298
		ROAD_ALL
13
3e7c1f74a996 (svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents: 0
diff changeset
   299
	},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   300
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   301
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   302
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3560
diff changeset
   303
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
   304
{
3381
91ee7484deff (svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents: 3379
diff changeset
   305
	RoadBits road_bits;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   306
4246
6dcc0e44a367 (svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents: 4232
diff changeset
   307
	if (IsSteepSlope(tileh)) {
6dcc0e44a367 (svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents: 4232
diff changeset
   308
		if (existing == 0) {
6393
e1e4939d19b5 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6368
diff changeset
   309
			/* force full pieces. */
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   310
			*pieces |= (RoadBits)((*pieces & 0xC) >> 2);
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   311
			*pieces |= (RoadBits)((*pieces & 0x3) << 2);
4246
6dcc0e44a367 (svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents: 4232
diff changeset
   312
			if (*pieces == ROAD_X || *pieces == ROAD_Y) return _price.terraform;
6dcc0e44a367 (svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents: 4232
diff changeset
   313
		}
6dcc0e44a367 (svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents: 4232
diff changeset
   314
		return CMD_ERROR;
6dcc0e44a367 (svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents: 4232
diff changeset
   315
	}
3381
91ee7484deff (svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents: 3379
diff changeset
   316
	road_bits = *pieces | existing;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   317
6393
e1e4939d19b5 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6368
diff changeset
   318
	/* no special foundation */
3381
91ee7484deff (svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents: 3379
diff changeset
   319
	if ((~_valid_tileh_slopes_road[0][tileh] & road_bits) == 0) {
6393
e1e4939d19b5 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6368
diff changeset
   320
		/* force that all bits are set when we have slopes */
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3560
diff changeset
   321
		if (tileh != SLOPE_FLAT) *pieces |= _valid_tileh_slopes_road[0][tileh];
3381
91ee7484deff (svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents: 3379
diff changeset
   322
		return 0; // no extra cost
91ee7484deff (svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents: 3379
diff changeset
   323
	}
91ee7484deff (svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents: 3379
diff changeset
   324
6393
e1e4939d19b5 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6368
diff changeset
   325
	/* foundation is used. Whole tile is leveled up */
3381
91ee7484deff (svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents: 3379
diff changeset
   326
	if ((~_valid_tileh_slopes_road[1][tileh] & road_bits) == 0) {
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4048
diff changeset
   327
		return existing != 0 ? 0 : _price.terraform;
3381
91ee7484deff (svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents: 3379
diff changeset
   328
	}
91ee7484deff (svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents: 3379
diff changeset
   329
6393
e1e4939d19b5 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6368
diff changeset
   330
	/* partly leveled up tile, only if there's no road on that tile */
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3560
diff changeset
   331
	if (existing == 0 && (tileh == SLOPE_W || tileh == SLOPE_S || tileh == SLOPE_E || tileh == SLOPE_N)) {
6393
e1e4939d19b5 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6368
diff changeset
   332
		/* force full pieces. */
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   333
		*pieces |= (RoadBits)((*pieces & 0xC) >> 2);
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   334
		*pieces |= (RoadBits)((*pieces & 0x3) << 2);
3381
91ee7484deff (svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents: 3379
diff changeset
   335
		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
   336
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   337
	return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   338
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   339
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   340
/** Build a piece of road.
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3435
diff changeset
   341
 * @param tile tile where to build road
6483
ae78fc3c6b20 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6427
diff changeset
   342
 * @param flags operation to perform
6134
871305fd9ab7 (svn r8876) -Fix
tron
parents: 6133
diff changeset
   343
 * @param p1 bit 0..3 road pieces to build (RoadBits)
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
   344
 *           bit 4..5 road type
6764
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   345
 *           bit 6..7 disallowed directions to toggle
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   346
 * @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
   347
 */
3491
35d747bb5e82 (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
   348
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
   349
{
3381
91ee7484deff (svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents: 3379
diff changeset
   350
	int32 cost = 0;
91ee7484deff (svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents: 3379
diff changeset
   351
	int32 ret;
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   352
	RoadBits existing = ROAD_NONE;
6715
b5c030551158 (svn r9947) -Fix [FS#807]: don't check whether roadbits may be built when they are already built for another type.
rubidium
parents: 6714
diff changeset
   353
	RoadBits all_bits = ROAD_NONE;
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3560
diff changeset
   354
	Slope tileh;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   355
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   356
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   357
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   358
	/* Road pieces are max 4 bitset values (NE, NW, SE, SW) and town can only be non-zero
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   359
	 * if a non-player is building the road */
6134
871305fd9ab7 (svn r8876) -Fix
tron
parents: 6133
diff changeset
   360
	if ((IsValidPlayer(_current_player) && p2 != 0) || (_current_player == OWNER_TOWN && !IsValidTownID(p2))) return CMD_ERROR;
871305fd9ab7 (svn r8876) -Fix
tron
parents: 6133
diff changeset
   361
871305fd9ab7 (svn r8876) -Fix
tron
parents: 6133
diff changeset
   362
	RoadBits pieces = Extract<RoadBits, 0>(p1);
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   363
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
   364
	RoadType rt = (RoadType)GB(p1, 4, 2);
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
   365
	if (!IsValidRoadType(rt)) return CMD_ERROR;
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
   366
6764
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   367
	DisallowedRoadDirections toggle_drd = (DisallowedRoadDirections)GB(p1, 6, 2);
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   368
3434
0ada2e311826 (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
   369
	tileh = GetTileSlope(tile, NULL);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   370
3434
0ada2e311826 (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
   371
	switch (GetTileType(tile)) {
3060
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   372
		case MP_STREET:
3793
7fe24e10ea63 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3792
diff changeset
   373
			switch (GetRoadTileType(tile)) {
6764
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   374
				case ROAD_TILE_NORMAL: {
4046
5538f3a43418 (svn r5315) -Fix: Prohibit altering a road tile while road works are in progress
tron
parents: 4000
diff changeset
   375
					if (HasRoadWorks(tile)) return_cmd_error(STR_ROAD_WORKS_IN_PROGRESS);
6756
44f714e247ba (svn r9991) -Fix: one could build road when trams were driving on the tile and vice versa.
rubidium
parents: 6751
diff changeset
   376
					if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
44f714e247ba (svn r9991) -Fix: one could build road when trams were driving on the tile and vice versa.
rubidium
parents: 6751
diff changeset
   377
6719
70e750141e56 (svn r9951) -Fix: slope check was incomplete when building road over tram track (and vice-versa)
glx
parents: 6717
diff changeset
   378
					all_bits = GetAllRoadBits(tile);
6662
ea30b3497d9a (svn r9893) -Fix (r9892): various small bugs that only act up when using something different than plain roads.
rubidium
parents: 6661
diff changeset
   379
					if (!HASBIT(GetRoadTypes(tile), rt)) break;
4046
5538f3a43418 (svn r5315) -Fix: Prohibit altering a road tile while road works are in progress
tron
parents: 4000
diff changeset
   380
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
   381
					existing = GetRoadBits(tile, rt);
6764
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   382
					RoadBits merged = existing | pieces;
6768
379e38fcab7e (svn r10004) -Fix: trams can always intersect/have junctions on one way roads (because they only work for busses and lorries).
rubidium
parents: 6764
diff changeset
   383
					bool crossing = (merged != ROAD_X && merged != ROAD_Y);
379e38fcab7e (svn r10004) -Fix: trams can always intersect/have junctions on one way roads (because they only work for busses and lorries).
rubidium
parents: 6764
diff changeset
   384
					if (rt != ROADTYPE_TRAM && (GetDisallowedRoadDirections(tile) != DRD_NONE || toggle_drd != DRD_NONE) && crossing) {
6764
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   385
						/* Junctions cannot be one-way */
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   386
						return_cmd_error(STR_ERR_ONEWAY_ROADS_CAN_T_HAVE_JUNCTION);
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   387
					}
3150
729951cb5448 (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
   388
					if ((existing & pieces) == pieces) {
6764
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   389
						/* We only want to set the (dis)allowed road directions */
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   390
						if (toggle_drd != DRD_NONE && rt != ROADTYPE_TRAM && GetRoadOwner(tile, ROADTYPE_ROAD) == _current_player) {
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   391
							if (crossing) return_cmd_error(STR_ERR_ONEWAY_ROADS_CAN_T_HAVE_JUNCTION);
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   392
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   393
							/* Ignore half built tiles */
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   394
							if (flags & DC_EXEC && rt != ROADTYPE_TRAM && (existing == ROAD_X || existing == ROAD_Y)) {
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   395
								SetDisallowedRoadDirections(tile, GetDisallowedRoadDirections(tile) ^ toggle_drd);
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   396
								MarkTileDirtyByTile(tile);
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   397
							}
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   398
							return 0;
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   399
						}
3066
26c43ab051b8 (svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents: 3061
diff changeset
   400
						return_cmd_error(STR_1007_ALREADY_BUILT);
26c43ab051b8 (svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents: 3061
diff changeset
   401
					}
6764
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   402
				} break;
3066
26c43ab051b8 (svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents: 3061
diff changeset
   403
3793
7fe24e10ea63 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3792
diff changeset
   404
				case ROAD_TILE_CROSSING:
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
   405
					if (HASBIT(GetRoadTypes(tile), rt)) return_cmd_error(STR_1007_ALREADY_BUILT);
6715
b5c030551158 (svn r9947) -Fix [FS#807]: don't check whether roadbits may be built when they are already built for another type.
rubidium
parents: 6714
diff changeset
   406
					all_bits = GetCrossingRoadBits(tile);
b5c030551158 (svn r9947) -Fix [FS#807]: don't check whether roadbits may be built when they are already built for another type.
rubidium
parents: 6714
diff changeset
   407
					if (pieces & ComplementRoadBits(all_bits)) goto do_clear;
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
   408
					break;
3066
26c43ab051b8 (svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents: 3061
diff changeset
   409
3069
9a1fd047b595 (svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents: 3068
diff changeset
   410
				default:
3793
7fe24e10ea63 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3792
diff changeset
   411
				case ROAD_TILE_DEPOT:
3066
26c43ab051b8 (svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents: 3061
diff changeset
   412
					goto do_clear;
3060
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   413
			}
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   414
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   415
3060
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   416
		case MP_RAILWAY: {
3099
571719b2cee3 (svn r3689) Add functions to turn a tile into either a normal road tile, a level crossing or a road depot
tron
parents: 3098
diff changeset
   417
			Axis roaddir;
13
3e7c1f74a996 (svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents: 0
diff changeset
   418
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3560
diff changeset
   419
			if (IsSteepSlope(tileh)) {
3060
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   420
				return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   421
			}
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   422
3104
c039f8a65ba0 (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
   423
#define M(x) (1 << (x))
c039f8a65ba0 (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
   424
			/* Level crossings may only be built on these slopes */
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3560
diff changeset
   425
			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
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   426
				return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   427
			}
3104
c039f8a65ba0 (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
   428
#undef M
3060
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   429
3792
67c865c9315c (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
   430
			if (GetRailTileType(tile) != RAIL_TILE_NORMAL) goto do_clear;
3269
62fb247bf94b (svn r3981) More work for the rail accessing functions and enums
tron
parents: 3267
diff changeset
   431
			switch (GetTrackBits(tile)) {
62fb247bf94b (svn r3981) More work for the rail accessing functions and enums
tron
parents: 3267
diff changeset
   432
				case TRACK_BIT_X:
62fb247bf94b (svn r3981) More work for the rail accessing functions and enums
tron
parents: 3267
diff changeset
   433
					if (pieces & ROAD_X) goto do_clear;
62fb247bf94b (svn r3981) More work for the rail accessing functions and enums
tron
parents: 3267
diff changeset
   434
					roaddir = AXIS_Y;
62fb247bf94b (svn r3981) More work for the rail accessing functions and enums
tron
parents: 3267
diff changeset
   435
					break;
62fb247bf94b (svn r3981) More work for the rail accessing functions and enums
tron
parents: 3267
diff changeset
   436
62fb247bf94b (svn r3981) More work for the rail accessing functions and enums
tron
parents: 3267
diff changeset
   437
				case TRACK_BIT_Y:
62fb247bf94b (svn r3981) More work for the rail accessing functions and enums
tron
parents: 3267
diff changeset
   438
					if (pieces & ROAD_Y) goto do_clear;
62fb247bf94b (svn r3981) More work for the rail accessing functions and enums
tron
parents: 3267
diff changeset
   439
					roaddir = AXIS_X;
62fb247bf94b (svn r3981) More work for the rail accessing functions and enums
tron
parents: 3267
diff changeset
   440
					break;
62fb247bf94b (svn r3981) More work for the rail accessing functions and enums
tron
parents: 3267
diff changeset
   441
62fb247bf94b (svn r3981) More work for the rail accessing functions and enums
tron
parents: 3267
diff changeset
   442
				default: goto do_clear;
3060
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   443
			}
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   444
6406
8ccf18e94c67 (svn r9542) -Fix(FS# 712): When checking if a vehicle is on a given tile, and you are working on the ground tile, do not take aircrafts into account, as they do not pose any danger for the construction/destruction/conversion itself. Z stuff, in other words
belugas
parents: 6393
diff changeset
   445
			if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
3381
91ee7484deff (svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents: 3379
diff changeset
   446
3060
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   447
			if (flags & DC_EXEC) {
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   448
				YapfNotifyTrackLayoutChange(tile, FindFirstTrack(GetTrackBits(tile)));
6697
dde1f5dced50 (svn r9929) -Fix [FS#803]: fix several drawing issues.
rubidium
parents: 6691
diff changeset
   449
				/* Always add road to the roadtypes (can't draw without it) */
dde1f5dced50 (svn r9929) -Fix [FS#803]: fix several drawing issues.
rubidium
parents: 6691
diff changeset
   450
				MakeRoadCrossing(tile, _current_player, _current_player, _current_player, GetTileOwner(tile), roaddir, GetRailType(tile), RoadTypeToRoadTypes(rt) | ROADTYPES_ROAD, p2);
3100
a6706067501d (svn r3695) Add 2 MarkTileByTile() which I forgot in r3689 (noticed by Belugas)
tron
parents: 3099
diff changeset
   451
				MarkTileDirtyByTile(tile);
3060
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   452
			}
6697
dde1f5dced50 (svn r9929) -Fix [FS#803]: fix several drawing issues.
rubidium
parents: 6691
diff changeset
   453
			return _price.build_road * (rt == ROADTYPE_ROAD ? 2 : 4);
3017
a75caf4efa2d (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
   454
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   455
6679
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   456
		case MP_STATION:
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   457
			if (!IsDriveThroughStopTile(tile)) return CMD_ERROR;
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   458
			if (HASBIT(GetRoadTypes(tile), rt)) return_cmd_error(STR_1007_ALREADY_BUILT);
6761
43c0425f9290 (svn r9996) -Fix: be more strict when building/upgrading roads and/or road stops.
rubidium
parents: 6756
diff changeset
   459
			/* Don't allow "upgrading" the roadstop when vehicles are already driving on it */
43c0425f9290 (svn r9996) -Fix: be more strict when building/upgrading roads and/or road stops.
rubidium
parents: 6756
diff changeset
   460
			if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
6679
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   461
			break;
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   462
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   463
		case MP_TUNNELBRIDGE:
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   464
			if ((IsTunnel(tile) && GetTunnelTransportType(tile) != TRANSPORT_ROAD) ||
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   465
					(IsBridge(tile) && GetBridgeTransportType(tile) != TRANSPORT_ROAD)) return CMD_ERROR;
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   466
			if (HASBIT(GetRoadTypes(tile), rt)) return_cmd_error(STR_1007_ALREADY_BUILT);
6761
43c0425f9290 (svn r9996) -Fix: be more strict when building/upgrading roads and/or road stops.
rubidium
parents: 6756
diff changeset
   467
			/* Don't allow "upgrading" the bridge/tunnel when vehicles are already driving on it */
43c0425f9290 (svn r9996) -Fix: be more strict when building/upgrading roads and/or road stops.
rubidium
parents: 6756
diff changeset
   468
			if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
6679
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   469
			break;
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   470
3060
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   471
		default:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   472
do_clear:;
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3435
diff changeset
   473
			ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
3381
91ee7484deff (svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents: 3379
diff changeset
   474
			if (CmdFailed(ret)) return ret;
91ee7484deff (svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents: 3379
diff changeset
   475
			cost += ret;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   476
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   477
6716
ef761cad5326 (svn r9948) -Fix (r9947): building illegal roads on slopes. Why do 'fixes' always have the tendancy to backfire?
rubidium
parents: 6715
diff changeset
   478
	if (all_bits != pieces) {
6715
b5c030551158 (svn r9947) -Fix [FS#807]: don't check whether roadbits may be built when they are already built for another type.
rubidium
parents: 6714
diff changeset
   479
		/* Check the foundation/slopes when adding road/tram bits */
b5c030551158 (svn r9947) -Fix [FS#807]: don't check whether roadbits may be built when they are already built for another type.
rubidium
parents: 6714
diff changeset
   480
		ret = CheckRoadSlope(tileh, &pieces, all_bits | existing);
b5c030551158 (svn r9947) -Fix [FS#807]: don't check whether roadbits may be built when they are already built for another type.
rubidium
parents: 6714
diff changeset
   481
		/* Return an error if we need to build a foundation (ret != 0) but the
b5c030551158 (svn r9947) -Fix [FS#807]: don't check whether roadbits may be built when they are already built for another type.
rubidium
parents: 6714
diff changeset
   482
		 * current patch-setting is turned off (or stupid AI@work) */
b5c030551158 (svn r9947) -Fix [FS#807]: don't check whether roadbits may be built when they are already built for another type.
rubidium
parents: 6714
diff changeset
   483
		if (CmdFailed(ret) || (ret != 0 && (!_patches.build_on_slopes || _is_old_ai_player))) {
b5c030551158 (svn r9947) -Fix [FS#807]: don't check whether roadbits may be built when they are already built for another type.
rubidium
parents: 6714
diff changeset
   484
			return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
b5c030551158 (svn r9947) -Fix [FS#807]: don't check whether roadbits may be built when they are already built for another type.
rubidium
parents: 6714
diff changeset
   485
		}
b5c030551158 (svn r9947) -Fix [FS#807]: don't check whether roadbits may be built when they are already built for another type.
rubidium
parents: 6714
diff changeset
   486
		cost += ret;
b5c030551158 (svn r9947) -Fix [FS#807]: don't check whether roadbits may be built when they are already built for another type.
rubidium
parents: 6714
diff changeset
   487
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   488
3434
0ada2e311826 (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
   489
	if (IsTileType(tile, MP_STREET)) {
6393
e1e4939d19b5 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6368
diff changeset
   490
		/* Don't put the pieces that already exist */
3150
729951cb5448 (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
   491
		pieces &= ComplementRoadBits(existing);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   492
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   493
3381
91ee7484deff (svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents: 3379
diff changeset
   494
	cost += CountRoadBits(pieces) * _price.build_road;
6679
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   495
	if (IsTileType(tile, MP_TUNNELBRIDGE)) {
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   496
		/* Pay for *every* tile of the bridge or tunnel */
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   497
		cost *= DistanceManhattan(IsTunnel(tile) ? GetOtherTunnelEnd(tile) : GetOtherBridgeEnd(tile), tile);
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   498
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   499
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   500
	if (flags & DC_EXEC) {
6679
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   501
		switch (GetTileType(tile)) {
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   502
			case MP_STREET: {
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   503
				RoadTileType rtt = GetRoadTileType(tile);
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   504
				if (existing == ROAD_NONE || rtt == ROAD_TILE_CROSSING) {
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   505
					SetRoadTypes(tile, GetRoadTypes(tile) | RoadTypeToRoadTypes(rt));
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   506
					SetRoadOwner(tile, rt, _current_player);
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   507
				}
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   508
				if (rtt != ROAD_TILE_CROSSING) SetRoadBits(tile, existing | pieces, rt);
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   509
			} break;
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   510
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   511
			case MP_TUNNELBRIDGE: {
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   512
				TileIndex other_end = IsTunnel(tile) ? GetOtherTunnelEnd(tile) : GetOtherBridgeEnd(tile);
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   513
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   514
				SetRoadTypes(other_end, GetRoadTypes(other_end) | RoadTypeToRoadTypes(rt));
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
   515
				SetRoadTypes(tile, GetRoadTypes(tile) | RoadTypeToRoadTypes(rt));
6679
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   516
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   517
				/* Mark tiles diry that have been repaved */
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   518
				MarkTileDirtyByTile(other_end);
6714
f8edec66a9c4 (svn r9946) -Fix: more places that weren't correctly marked dirty...
rubidium
parents: 6713
diff changeset
   519
				MarkTileDirtyByTile(tile);
6679
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   520
				if (IsBridge(tile)) {
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   521
					TileIndexDiff delta = TileOffsByDiagDir(GetBridgeRampDirection(tile));
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   522
6713
7962b523ecd6 (svn r9945) -Fix: bridges were not properly marked dirty when adding/removing roadtypes.
rubidium
parents: 6711
diff changeset
   523
					for (TileIndex t = tile + delta; t != other_end; t += delta) MarkTileDirtyByTile(t);
6679
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   524
				}
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   525
			} break;
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   526
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   527
			case MP_STATION:
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   528
				SetRoadTypes(tile, GetRoadTypes(tile) | RoadTypeToRoadTypes(rt));
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   529
				break;
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   530
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   531
			default:
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   532
				MakeRoadNormal(tile, pieces, RoadTypeToRoadTypes(rt), p2, _current_player, _current_player, _current_player);
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   533
				break;
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
6764
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   536
		if (rt != ROADTYPE_TRAM && IsTileType(tile, MP_STREET) && GetRoadTileType(tile) == ROAD_TILE_NORMAL) {
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   537
			existing |= pieces;
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   538
			SetDisallowedRoadDirections(tile, (existing == ROAD_X || existing == ROAD_Y) ?
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   539
					GetDisallowedRoadDirections(tile) ^ toggle_drd : DRD_NONE);
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   540
		}
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   541
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   542
		MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   543
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   544
	return cost;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   545
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   546
6368
c58210a58402 (svn r9425) -Codechange/Fix (FS#689): Housekeeping in the convert rail functions: Changed the order of error checks to generate more meaningful error messages, added some doxygen comments and replaced bitshifting by proper mathematical operations
celestar
parents: 6357
diff changeset
   547
/**
c58210a58402 (svn r9425) -Codechange/Fix (FS#689): Housekeeping in the convert rail functions: Changed the order of error checks to generate more meaningful error messages, added some doxygen comments and replaced bitshifting by proper mathematical operations
celestar
parents: 6357
diff changeset
   548
 * Switches the rail type on a level crossing.
c58210a58402 (svn r9425) -Codechange/Fix (FS#689): Housekeeping in the convert rail functions: Changed the order of error checks to generate more meaningful error messages, added some doxygen comments and replaced bitshifting by proper mathematical operations
celestar
parents: 6357
diff changeset
   549
 * @param tile        The tile on which the railtype is to be convert.
c58210a58402 (svn r9425) -Codechange/Fix (FS#689): Housekeeping in the convert rail functions: Changed the order of error checks to generate more meaningful error messages, added some doxygen comments and replaced bitshifting by proper mathematical operations
celestar
parents: 6357
diff changeset
   550
 * @param totype      The railtype we want to convert to
c58210a58402 (svn r9425) -Codechange/Fix (FS#689): Housekeeping in the convert rail functions: Changed the order of error checks to generate more meaningful error messages, added some doxygen comments and replaced bitshifting by proper mathematical operations
celestar
parents: 6357
diff changeset
   551
 * @param exec        Switches between test and execute mode
c58210a58402 (svn r9425) -Codechange/Fix (FS#689): Housekeeping in the convert rail functions: Changed the order of error checks to generate more meaningful error messages, added some doxygen comments and replaced bitshifting by proper mathematical operations
celestar
parents: 6357
diff changeset
   552
 * @return            The cost and state of the operation
c58210a58402 (svn r9425) -Codechange/Fix (FS#689): Housekeeping in the convert rail functions: Changed the order of error checks to generate more meaningful error messages, added some doxygen comments and replaced bitshifting by proper mathematical operations
celestar
parents: 6357
diff changeset
   553
 * @retval CMD_ERROR  An error occured during the operation.
c58210a58402 (svn r9425) -Codechange/Fix (FS#689): Housekeeping in the convert rail functions: Changed the order of error checks to generate more meaningful error messages, added some doxygen comments and replaced bitshifting by proper mathematical operations
celestar
parents: 6357
diff changeset
   554
 */
3435
dfba5b1c7c2d (svn r4265) - Fix: compile warning on VS2005 (parameter 2 different from declaration)
Darkvater
parents: 3434
diff changeset
   555
int32 DoConvertStreetRail(TileIndex tile, RailType totype, bool exec)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   556
{
6393
e1e4939d19b5 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6368
diff changeset
   557
	/* not a railroad crossing? */
1927
1181e7652e2f (svn r2433) - CodeChange: unmagicify all road/train crossings with IsLevelCrossing() function (peter1138)
Darkvater
parents: 1902
diff changeset
   558
	if (!IsLevelCrossing(tile)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   559
6393
e1e4939d19b5 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6368
diff changeset
   560
	/* not owned by me? */
6406
8ccf18e94c67 (svn r9542) -Fix(FS# 712): When checking if a vehicle is on a given tile, and you are working on the ground tile, do not take aircrafts into account, as they do not pose any danger for the construction/destruction/conversion itself. Z stuff, in other words
belugas
parents: 6393
diff changeset
   561
	if (!CheckTileOwnership(tile) || !EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   562
6172
e6d7a5b3d63f (svn r8935) -Codechange: unification of track type between road and rail tiles, unification of ground type between normal rail tiles and depots/waypoints and removing the need for RailTileSubType.
rubidium
parents: 6160
diff changeset
   563
	if (GetRailType(tile) == totype) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   564
6393
e1e4939d19b5 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6368
diff changeset
   565
	/* 'hidden' elrails can't be downgraded to normal rail when elrails are disabled */
6172
e6d7a5b3d63f (svn r8935) -Codechange: unification of track type between road and rail tiles, unification of ground type between normal rail tiles and depots/waypoints and removing the need for RailTileSubType.
rubidium
parents: 6160
diff changeset
   566
	if (_patches.disable_elrails && totype == RAILTYPE_RAIL && GetRailType(tile) == RAILTYPE_ELECTRIC) return CMD_ERROR;
5116
3c0c3da214ca (svn r7195) -Feature: [FS#297, optional elrails] New patches/vehicles option 'disable electrified railways'.
KUDr
parents: 5009
diff changeset
   567
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   568
	if (exec) {
6172
e6d7a5b3d63f (svn r8935) -Codechange: unification of track type between road and rail tiles, unification of ground type between normal rail tiles and depots/waypoints and removing the need for RailTileSubType.
rubidium
parents: 6160
diff changeset
   569
		SetRailType(tile, totype);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   570
		MarkTileDirtyByTile(tile);
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   571
		YapfNotifyTrackLayoutChange(tile, FindFirstTrack(GetCrossingRailBits(tile)));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   572
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   573
6368
c58210a58402 (svn r9425) -Codechange/Fix (FS#689): Housekeeping in the convert rail functions: Changed the order of error checks to generate more meaningful error messages, added some doxygen comments and replaced bitshifting by proper mathematical operations
celestar
parents: 6357
diff changeset
   574
	return _price.build_rail / 2;
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   577
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   578
/** Build a long piece of road.
3491
35d747bb5e82 (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
   579
 * @param end_tile end tile of drag
6483
ae78fc3c6b20 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6427
diff changeset
   580
 * @param flags operation to perform
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   581
 * @param p1 start tile of drag
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   582
 * @param p2 various bitstuffed elements
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   583
 * - p2 = (bit 0) - start tile starts in the 2nd half of tile (p2 & 1)
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   584
 * - p2 = (bit 1) - end tile starts in the 2nd half of tile (p2 & 2)
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   585
 * - p2 = (bit 2) - direction: 0 = along x-axis, 1 = along y-axis (p2 & 4)
6662
ea30b3497d9a (svn r9893) -Fix (r9892): various small bugs that only act up when using something different than plain roads.
rubidium
parents: 6661
diff changeset
   586
 * - p2 = (bit 3 + 4) - road type
6764
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   587
 * - p2 = (bit 5) - set road direction
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   588
 */
3491
35d747bb5e82 (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
   589
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
   590
{
3491
35d747bb5e82 (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
   591
	TileIndex start_tile, tile;
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   592
	int32 cost, ret;
6710
fd3ade8bf17a (svn r9942) -Fix [FS#804]: crash when upgrading both ends of a bridge.
rubidium
parents: 6702
diff changeset
   593
	bool had_bridge = false;
6764
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   594
	bool had_success = false;
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   595
	DisallowedRoadDirections drd = DRD_NORTHBOUND;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   596
889
64d2f7d5f02b (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
   597
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
64d2f7d5f02b (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
   598
2934
3f29a7212713 (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
   599
	if (p1 >= MapSize()) return CMD_ERROR;
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   600
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   601
	start_tile = p1;
6662
ea30b3497d9a (svn r9893) -Fix (r9892): various small bugs that only act up when using something different than plain roads.
rubidium
parents: 6661
diff changeset
   602
	RoadType rt = (RoadType)GB(p2, 3, 2);
ea30b3497d9a (svn r9893) -Fix (r9892): various small bugs that only act up when using something different than plain roads.
rubidium
parents: 6661
diff changeset
   603
	if (!IsValidRoadType(rt)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   604
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   605
	/* Only drag in X or Y direction dictated by the direction variable */
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   606
	if (!HASBIT(p2, 2) && TileY(start_tile) != TileY(end_tile)) return CMD_ERROR; // x-axis
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   607
	if (HASBIT(p2, 2)  && TileX(start_tile) != TileX(end_tile)) return CMD_ERROR; // y-axis
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   608
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   609
	/* Swap start and ending tile, also the half-tile drag var (bit 0 and 1) */
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   610
	if (start_tile > end_tile || (start_tile == end_tile && HASBIT(p2, 0))) {
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   611
		TileIndex t = start_tile;
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   612
		start_tile = end_tile;
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   613
		end_tile = t;
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6483
diff changeset
   614
		p2 ^= IS_INT_INSIDE(p2 & 3, 1, 3) ? 3 : 0;
6764
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   615
		drd = DRD_SOUTHBOUND;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   616
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   617
6764
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   618
	/* On the X-axis, we have to swap the initial bits, so they
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   619
	 * will be interpreted correctly in the GTTS. Futhermore
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   620
	 * when you just 'click' on one tile to build them. */
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   621
	if (HASBIT(p2, 2) == (start_tile == end_tile)) drd ^= DRD_BOTH;
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   622
	/* No disallowed direction bits have to be toggled */
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   623
	if (!HASBIT(p2, 5)) drd = DRD_NONE;
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   624
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   625
	cost = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   626
	tile = start_tile;
6393
e1e4939d19b5 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6368
diff changeset
   627
	/* Start tile is the small number. */
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   628
	for (;;) {
3098
aed45c5c1e11 (svn r3687) Complete some bits I missed whenn adding accessor functions for road types and pieces
tron
parents: 3097
diff changeset
   629
		RoadBits bits = HASBIT(p2, 2) ? ROAD_Y : ROAD_X;
aed45c5c1e11 (svn r3687) Complete some bits I missed whenn adding accessor functions for road types and pieces
tron
parents: 3097
diff changeset
   630
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   631
		if (tile == end_tile && !HASBIT(p2, 1)) bits &= ROAD_NW | ROAD_NE;
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   632
		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
   633
6764
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   634
		ret = DoCommand(tile, drd << 6 | rt << 4 | bits, 0, flags, CMD_BUILD_ROAD);
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   635
		if (CmdFailed(ret)) {
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   636
			if (_error_message != STR_1007_ALREADY_BUILT) return CMD_ERROR;
3671
5b6a80e29dd6 (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
   637
			_error_message = INVALID_STRING_ID;
2549
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
   638
		} else {
6764
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   639
			had_success = true;
6710
fd3ade8bf17a (svn r9942) -Fix [FS#804]: crash when upgrading both ends of a bridge.
rubidium
parents: 6702
diff changeset
   640
			/* Only pay for the upgrade on one side of the bridge */
fd3ade8bf17a (svn r9942) -Fix [FS#804]: crash when upgrading both ends of a bridge.
rubidium
parents: 6702
diff changeset
   641
			if (IsBridgeTile(tile)) {
fd3ade8bf17a (svn r9942) -Fix [FS#804]: crash when upgrading both ends of a bridge.
rubidium
parents: 6702
diff changeset
   642
				if ((!had_bridge || GetBridgeRampDirection(tile) == DIAGDIR_SE || GetBridgeRampDirection(tile) == DIAGDIR_SW)) {
fd3ade8bf17a (svn r9942) -Fix [FS#804]: crash when upgrading both ends of a bridge.
rubidium
parents: 6702
diff changeset
   643
					cost += ret;
fd3ade8bf17a (svn r9942) -Fix [FS#804]: crash when upgrading both ends of a bridge.
rubidium
parents: 6702
diff changeset
   644
				}
fd3ade8bf17a (svn r9942) -Fix [FS#804]: crash when upgrading both ends of a bridge.
rubidium
parents: 6702
diff changeset
   645
				had_bridge = true;
fd3ade8bf17a (svn r9942) -Fix [FS#804]: crash when upgrading both ends of a bridge.
rubidium
parents: 6702
diff changeset
   646
			} else {
fd3ade8bf17a (svn r9942) -Fix [FS#804]: crash when upgrading both ends of a bridge.
rubidium
parents: 6702
diff changeset
   647
				cost += ret;
fd3ade8bf17a (svn r9942) -Fix [FS#804]: crash when upgrading both ends of a bridge.
rubidium
parents: 6702
diff changeset
   648
			}
2549
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
   649
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   650
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   651
		if (tile == end_tile) break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   652
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   653
		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
   654
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   655
6764
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   656
	return !had_success ? CMD_ERROR : cost;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   657
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   658
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   659
/** Remove a long piece of road.
3491
35d747bb5e82 (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
   660
 * @param end_tile end tile of drag
6483
ae78fc3c6b20 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6427
diff changeset
   661
 * @param flags operation to perform
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   662
 * @param p1 start tile of drag
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   663
 * @param p2 various bitstuffed elements
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   664
 * - p2 = (bit 0) - start tile starts in the 2nd half of tile (p2 & 1)
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   665
 * - p2 = (bit 1) - end tile starts in the 2nd half of tile (p2 & 2)
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   666
 * - p2 = (bit 2) - direction: 0 = along x-axis, 1 = along y-axis (p2 & 4)
6662
ea30b3497d9a (svn r9893) -Fix (r9892): various small bugs that only act up when using something different than plain roads.
rubidium
parents: 6661
diff changeset
   667
 * - p2 = (bit 3 + 4) - road type
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   668
 */
3491
35d747bb5e82 (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
   669
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
   670
{
3491
35d747bb5e82 (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
   671
	TileIndex start_tile, tile;
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   672
	int32 cost, ret;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   673
889
64d2f7d5f02b (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
   674
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
64d2f7d5f02b (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
   675
2934
3f29a7212713 (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
   676
	if (p1 >= MapSize()) return CMD_ERROR;
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   677
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   678
	start_tile = p1;
6662
ea30b3497d9a (svn r9893) -Fix (r9892): various small bugs that only act up when using something different than plain roads.
rubidium
parents: 6661
diff changeset
   679
	RoadType rt = (RoadType)GB(p2, 3, 2);
ea30b3497d9a (svn r9893) -Fix (r9892): various small bugs that only act up when using something different than plain roads.
rubidium
parents: 6661
diff changeset
   680
	if (!IsValidRoadType(rt)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   681
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   682
	/* Only drag in X or Y direction dictated by the direction variable */
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   683
	if (!HASBIT(p2, 2) && TileY(start_tile) != TileY(end_tile)) return CMD_ERROR; // x-axis
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   684
	if (HASBIT(p2, 2)  && TileX(start_tile) != TileX(end_tile)) return CMD_ERROR; // y-axis
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   685
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   686
	/* Swap start and ending tile, also the half-tile drag var (bit 0 and 1) */
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   687
	if (start_tile > end_tile || (start_tile == end_tile && HASBIT(p2, 0))) {
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   688
		TileIndex t = start_tile;
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   689
		start_tile = end_tile;
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   690
		end_tile = t;
3017
a75caf4efa2d (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
   691
		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
   692
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   693
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   694
	cost = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   695
	tile = start_tile;
6393
e1e4939d19b5 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6368
diff changeset
   696
	/* Start tile is the small number. */
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   697
	for (;;) {
3098
aed45c5c1e11 (svn r3687) Complete some bits I missed whenn adding accessor functions for road types and pieces
tron
parents: 3097
diff changeset
   698
		RoadBits bits = HASBIT(p2, 2) ? ROAD_Y : ROAD_X;
aed45c5c1e11 (svn r3687) Complete some bits I missed whenn adding accessor functions for road types and pieces
tron
parents: 3097
diff changeset
   699
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   700
		if (tile == end_tile && !HASBIT(p2, 1)) bits &= ROAD_NW | ROAD_NE;
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   701
		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
   702
6393
e1e4939d19b5 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6368
diff changeset
   703
		/* try to remove the halves. */
3098
aed45c5c1e11 (svn r3687) Complete some bits I missed whenn adding accessor functions for road types and pieces
tron
parents: 3097
diff changeset
   704
		if (bits != 0) {
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
   705
			ret = DoCommand(tile, rt << 4 | bits, 0, flags, CMD_REMOVE_ROAD);
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   706
			if (!CmdFailed(ret)) cost += ret;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   707
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   708
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   709
		if (tile == end_tile) break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   710
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   711
		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
   712
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   713
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   714
	return (cost == 0) ? CMD_ERROR : cost;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   715
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   716
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   717
/** Build a road depot.
3491
35d747bb5e82 (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
   718
 * @param tile tile where to build the depot
6483
ae78fc3c6b20 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6427
diff changeset
   719
 * @param flags operation to perform
6134
871305fd9ab7 (svn r8876) -Fix
tron
parents: 6133
diff changeset
   720
 * @param p1 bit 0..1 entrance direction (DiagDirection)
6662
ea30b3497d9a (svn r9893) -Fix (r9892): various small bugs that only act up when using something different than plain roads.
rubidium
parents: 6661
diff changeset
   721
 *           bit 2..3 road type
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   722
 * @param p2 unused
2085
876f20a0e843 (svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents: 2074
diff changeset
   723
 *
876f20a0e843 (svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents: 2074
diff changeset
   724
 * @todo When checking for the tile slope,
876f20a0e843 (svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents: 2074
diff changeset
   725
 * 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
   726
 */
3491
35d747bb5e82 (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
   727
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
   728
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   729
	int32 cost;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   730
	Depot *dep;
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3560
diff changeset
   731
	Slope tileh;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   732
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   733
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   734
6134
871305fd9ab7 (svn r8876) -Fix
tron
parents: 6133
diff changeset
   735
	DiagDirection dir = Extract<DiagDirection, 0>(p1);
6662
ea30b3497d9a (svn r9893) -Fix (r9892): various small bugs that only act up when using something different than plain roads.
rubidium
parents: 6661
diff changeset
   736
	RoadType rt = (RoadType)GB(p1, 2, 2);
ea30b3497d9a (svn r9893) -Fix (r9892): various small bugs that only act up when using something different than plain roads.
rubidium
parents: 6661
diff changeset
   737
ea30b3497d9a (svn r9893) -Fix (r9892): various small bugs that only act up when using something different than plain roads.
rubidium
parents: 6661
diff changeset
   738
	if (!IsValidRoadType(rt)) return CMD_ERROR;
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   739
3055
ed20cba49858 (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
   740
	tileh = GetTileSlope(tile, NULL);
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3560
diff changeset
   741
	if (tileh != SLOPE_FLAT && (
2549
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
   742
				!_patches.build_on_slopes ||
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3560
diff changeset
   743
				IsSteepSlope(tileh) ||
6134
871305fd9ab7 (svn r8876) -Fix
tron
parents: 6133
diff changeset
   744
				!CanBuildDepotByTileh(dir, tileh)
2549
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
   745
			)) {
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
   746
		return_cmd_error(STR_0007_FLAT_LAND_REQUIRED);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   747
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   748
3491
35d747bb5e82 (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
   749
	cost = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   750
	if (CmdFailed(cost)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   751
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   752
	if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST);
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   753
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   754
	dep = AllocateDepot();
2549
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
   755
	if (dep == NULL) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   756
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   757
	if (flags & DC_EXEC) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   758
		dep->xy = tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   759
		dep->town_index = ClosestTownFromTile(tile, (uint)-1)->index;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   760
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
   761
		MakeRoadDepot(tile, _current_player, dir, rt);
3100
a6706067501d (svn r3695) Add 2 MarkTileByTile() which I forgot in r3689 (noticed by Belugas)
tron
parents: 3099
diff changeset
   762
		MarkTileDirtyByTile(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   763
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   764
	return cost + _price.build_road_depot;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   765
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   766
1979
82d8bcc16ce2 (svn r2485) Missed two uint -> TileIndex, thanks _Luca_
tron
parents: 1977
diff changeset
   767
static int32 RemoveRoadDepot(TileIndex tile, uint32 flags)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   768
{
149
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 84
diff changeset
   769
	if (!CheckTileOwnership(tile) && _current_player != OWNER_WATER)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   770
		return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   771
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   772
	if (!EnsureNoVehicle(tile)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   773
4388
c8a66d26e146 (svn r6141) -Codechange: introduced DepotID and used it as much as possible
truelight
parents: 4352
diff changeset
   774
	if (flags & DC_EXEC) DeleteDepot(GetDepotByTile(tile));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   775
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   776
	return _price.remove_road_depot;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   777
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   778
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
   779
static int32 ClearTile_Road(TileIndex tile, byte flags)
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
   780
{
3793
7fe24e10ea63 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3792
diff changeset
   781
	switch (GetRoadTileType(tile)) {
7fe24e10ea63 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3792
diff changeset
   782
		case ROAD_TILE_NORMAL: {
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
   783
			RoadBits b = GetAllRoadBits(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   784
5637
aa922e570f9a (svn r8096) -Codechange: Invert the check if you are allowed to clear a road tile so there are not so many negations (too confusing) and added some comments to further clarify what happens.
Darkvater
parents: 5587
diff changeset
   785
#define M(x) (1 << (x))
aa922e570f9a (svn r8096) -Codechange: Invert the check if you are allowed to clear a road tile so there are not so many negations (too confusing) and added some comments to further clarify what happens.
Darkvater
parents: 5587
diff changeset
   786
			/* Clear the road if only one piece is on the tile OR the AI tries
aa922e570f9a (svn r8096) -Codechange: Invert the check if you are allowed to clear a road tile so there are not so many negations (too confusing) and added some comments to further clarify what happens.
Darkvater
parents: 5587
diff changeset
   787
			 * to clear town road OR we are not using the DC_AUTO flag */
aa922e570f9a (svn r8096) -Codechange: Invert the check if you are allowed to clear a road tile so there are not so many negations (too confusing) and added some comments to further clarify what happens.
Darkvater
parents: 5587
diff changeset
   788
			if ((M(b) & (M(ROAD_NW) | M(ROAD_SW) | M(ROAD_SE) | M(ROAD_NE))) ||
aa922e570f9a (svn r8096) -Codechange: Invert the check if you are allowed to clear a road tile so there are not so many negations (too confusing) and added some comments to further clarify what happens.
Darkvater
parents: 5587
diff changeset
   789
			    ((flags & DC_AI_BUILDING) && IsTileOwner(tile, OWNER_TOWN)) ||
aa922e570f9a (svn r8096) -Codechange: Invert the check if you are allowed to clear a road tile so there are not so many negations (too confusing) and added some comments to further clarify what happens.
Darkvater
parents: 5587
diff changeset
   790
			    !(flags & DC_AUTO)
aa922e570f9a (svn r8096) -Codechange: Invert the check if you are allowed to clear a road tile so there are not so many negations (too confusing) and added some comments to further clarify what happens.
Darkvater
parents: 5587
diff changeset
   791
				) {
6679
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   792
				RoadTypes rts = GetRoadTypes(tile);
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   793
				int32 ret = 0;
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   794
				for (RoadType rt = ROADTYPE_ROAD; rt < ROADTYPE_END; rt++) {
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   795
					if (HASBIT(rts, rt)) {
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   796
						int32 tmp_ret = DoCommand(tile, rt << 4 | GetRoadBits(tile, rt), 0, flags, CMD_REMOVE_ROAD);
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   797
						if (CmdFailed(tmp_ret)) return tmp_ret;
6732
d1c81dee3e89 (svn r9964) -Fix: removing of road should not be free of charge.
rubidium
parents: 6723
diff changeset
   798
						ret += tmp_ret;
6679
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   799
					}
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   800
				}
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   801
				return ret;
3060
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   802
			}
5637
aa922e570f9a (svn r8096) -Codechange: Invert the check if you are allowed to clear a road tile so there are not so many negations (too confusing) and added some comments to further clarify what happens.
Darkvater
parents: 5587
diff changeset
   803
			return_cmd_error(STR_1801_MUST_REMOVE_ROAD_FIRST);
5643
b373887faf8b (svn r8102) -Cleanup: Remove unreachable code (r8096), useless cast
Darkvater
parents: 5637
diff changeset
   804
		}
5637
aa922e570f9a (svn r8096) -Codechange: Invert the check if you are allowed to clear a road tile so there are not so many negations (too confusing) and added some comments to further clarify what happens.
Darkvater
parents: 5587
diff changeset
   805
#undef M
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   806
3793
7fe24e10ea63 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3792
diff changeset
   807
		case ROAD_TILE_CROSSING: {
6814
46c7d033c926 (svn r10053) -Fix: could not clear a level-crossing tile with tram tracks.
rubidium
parents: 6768
diff changeset
   808
			RoadTypes rts = GetRoadTypes(tile);
46c7d033c926 (svn r10053) -Fix: could not clear a level-crossing tile with tram tracks.
rubidium
parents: 6768
diff changeset
   809
			int32 ret = 0;
3060
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   810
3069
9a1fd047b595 (svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents: 3068
diff changeset
   811
			if (flags & DC_AUTO) return_cmd_error(STR_1801_MUST_REMOVE_ROAD_FIRST);
3060
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   812
6814
46c7d033c926 (svn r10053) -Fix: could not clear a level-crossing tile with tram tracks.
rubidium
parents: 6768
diff changeset
   813
			/* Must iterate over the roadtypes in a reverse manner because
46c7d033c926 (svn r10053) -Fix: could not clear a level-crossing tile with tram tracks.
rubidium
parents: 6768
diff changeset
   814
			 * tram tracks must be removed before the road bits. */
46c7d033c926 (svn r10053) -Fix: could not clear a level-crossing tile with tram tracks.
rubidium
parents: 6768
diff changeset
   815
			for (RoadType rt = ROADTYPE_HWAY; rt >= ROADTYPE_ROAD; rt--) {
46c7d033c926 (svn r10053) -Fix: could not clear a level-crossing tile with tram tracks.
rubidium
parents: 6768
diff changeset
   816
				if (HASBIT(rts, rt)) {
46c7d033c926 (svn r10053) -Fix: could not clear a level-crossing tile with tram tracks.
rubidium
parents: 6768
diff changeset
   817
					int32 tmp_ret = DoCommand(tile, 1 << 6 | rt << 4 | GetCrossingRoadBits(tile), 0, flags, CMD_REMOVE_ROAD);
46c7d033c926 (svn r10053) -Fix: could not clear a level-crossing tile with tram tracks.
rubidium
parents: 6768
diff changeset
   818
					if (CmdFailed(tmp_ret)) return tmp_ret;
46c7d033c926 (svn r10053) -Fix: could not clear a level-crossing tile with tram tracks.
rubidium
parents: 6768
diff changeset
   819
					ret += tmp_ret;
46c7d033c926 (svn r10053) -Fix: could not clear a level-crossing tile with tram tracks.
rubidium
parents: 6768
diff changeset
   820
				}
46c7d033c926 (svn r10053) -Fix: could not clear a level-crossing tile with tram tracks.
rubidium
parents: 6768
diff changeset
   821
			}
3060
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   822
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   823
			if (flags & DC_EXEC) {
3491
35d747bb5e82 (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
   824
				DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
3060
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   825
			}
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   826
			return ret;
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   827
		}
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   828
3069
9a1fd047b595 (svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents: 3068
diff changeset
   829
		default:
3793
7fe24e10ea63 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3792
diff changeset
   830
		case ROAD_TILE_DEPOT:
3060
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   831
			if (flags & DC_AUTO) {
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   832
				return_cmd_error(STR_2004_BUILDING_MUST_BE_DEMOLISHED);
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   833
			}
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   834
			return RemoveRoadDepot(tile, flags);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   835
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   836
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   837
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   838
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6172
diff changeset
   839
struct DrawRoadTileStruct {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   840
	uint16 image;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   841
	byte subcoord_x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   842
	byte subcoord_y;
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6172
diff changeset
   843
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   844
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   845
#include "table/road_land.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   846
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   847
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3560
diff changeset
   848
uint GetRoadFoundation(Slope tileh, RoadBits bits)
2548
49c8a096033f (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2544
diff changeset
   849
{
3878
ef06782573c0 (svn r4927) Replace 3 big ifs (which regard foundations) by a bit less confusing code
tron
parents: 3794
diff changeset
   850
	uint i;
ef06782573c0 (svn r4927) Replace 3 big ifs (which regard foundations) by a bit less confusing code
tron
parents: 3794
diff changeset
   851
6393
e1e4939d19b5 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6368
diff changeset
   852
	/* normal level sloped building */
4246
6dcc0e44a367 (svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents: 4232
diff changeset
   853
	if (!IsSteepSlope(tileh) &&
6dcc0e44a367 (svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents: 4232
diff changeset
   854
			(~_valid_tileh_slopes_road[1][tileh] & bits) == 0) {
6dcc0e44a367 (svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents: 4232
diff changeset
   855
		return tileh;
6dcc0e44a367 (svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents: 4232
diff changeset
   856
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   857
6393
e1e4939d19b5 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6368
diff changeset
   858
	/* inclined sloped building */
3878
ef06782573c0 (svn r4927) Replace 3 big ifs (which regard foundations) by a bit less confusing code
tron
parents: 3794
diff changeset
   859
	switch (bits) {
ef06782573c0 (svn r4927) Replace 3 big ifs (which regard foundations) by a bit less confusing code
tron
parents: 3794
diff changeset
   860
		case ROAD_X: i = 0; break;
ef06782573c0 (svn r4927) Replace 3 big ifs (which regard foundations) by a bit less confusing code
tron
parents: 3794
diff changeset
   861
		case ROAD_Y: i = 1; break;
ef06782573c0 (svn r4927) Replace 3 big ifs (which regard foundations) by a bit less confusing code
tron
parents: 3794
diff changeset
   862
		default:     return 0;
3017
a75caf4efa2d (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
   863
	}
3878
ef06782573c0 (svn r4927) Replace 3 big ifs (which regard foundations) by a bit less confusing code
tron
parents: 3794
diff changeset
   864
	switch (tileh) {
4246
6dcc0e44a367 (svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents: 4232
diff changeset
   865
		case SLOPE_W:
6dcc0e44a367 (svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents: 4232
diff changeset
   866
		case SLOPE_STEEP_W: i += 0; break;
6dcc0e44a367 (svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents: 4232
diff changeset
   867
		case SLOPE_S:
6dcc0e44a367 (svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents: 4232
diff changeset
   868
		case SLOPE_STEEP_S: i += 2; break;
6dcc0e44a367 (svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents: 4232
diff changeset
   869
		case SLOPE_E:
6dcc0e44a367 (svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents: 4232
diff changeset
   870
		case SLOPE_STEEP_E: i += 4; break;
6dcc0e44a367 (svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents: 4232
diff changeset
   871
		case SLOPE_N:
6dcc0e44a367 (svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents: 4232
diff changeset
   872
		case SLOPE_STEEP_N: i += 6; break;
6dcc0e44a367 (svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents: 4232
diff changeset
   873
		default: return 0;
3878
ef06782573c0 (svn r4927) Replace 3 big ifs (which regard foundations) by a bit less confusing code
tron
parents: 3794
diff changeset
   874
	}
ef06782573c0 (svn r4927) Replace 3 big ifs (which regard foundations) by a bit less confusing code
tron
parents: 3794
diff changeset
   875
	return i + 15;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   876
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   877
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   878
const byte _road_sloped_sprites[14] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   879
	0,  0,  2,  0,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   880
	0,  1,  0,  0,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   881
	3,  0,  0,  0,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   882
	0,  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
2471
5935596f14a8 (svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents: 2469
diff changeset
   885
/**
6541
dfa5165a5ab7 (svn r9730) -Feature: [NewGRF] Add support for miscellaneous grf feature bit 1 - paved roads on desert tiles.
maedhros
parents: 6491
diff changeset
   886
 * Whether to draw unpaved roads regardless of the town zone.
dfa5165a5ab7 (svn r9730) -Feature: [NewGRF] Add support for miscellaneous grf feature bit 1 - paved roads on desert tiles.
maedhros
parents: 6491
diff changeset
   887
 * By default, OpenTTD always draws roads as unpaved if they are on a desert
dfa5165a5ab7 (svn r9730) -Feature: [NewGRF] Add support for miscellaneous grf feature bit 1 - paved roads on desert tiles.
maedhros
parents: 6491
diff changeset
   888
 * tile or above the snowline. Newgrf files, however, can set a bit that allows
dfa5165a5ab7 (svn r9730) -Feature: [NewGRF] Add support for miscellaneous grf feature bit 1 - paved roads on desert tiles.
maedhros
parents: 6491
diff changeset
   889
 * paved roads to be built on desert tiles as they would be on grassy tiles.
dfa5165a5ab7 (svn r9730) -Feature: [NewGRF] Add support for miscellaneous grf feature bit 1 - paved roads on desert tiles.
maedhros
parents: 6491
diff changeset
   890
 *
dfa5165a5ab7 (svn r9730) -Feature: [NewGRF] Add support for miscellaneous grf feature bit 1 - paved roads on desert tiles.
maedhros
parents: 6491
diff changeset
   891
 * @param tile The tile the road is on
dfa5165a5ab7 (svn r9730) -Feature: [NewGRF] Add support for miscellaneous grf feature bit 1 - paved roads on desert tiles.
maedhros
parents: 6491
diff changeset
   892
 * @param roadside What sort of road this is
dfa5165a5ab7 (svn r9730) -Feature: [NewGRF] Add support for miscellaneous grf feature bit 1 - paved roads on desert tiles.
maedhros
parents: 6491
diff changeset
   893
 * @return True if the road should be drawn unpaved regardless of the roadside.
dfa5165a5ab7 (svn r9730) -Feature: [NewGRF] Add support for miscellaneous grf feature bit 1 - paved roads on desert tiles.
maedhros
parents: 6491
diff changeset
   894
 */
dfa5165a5ab7 (svn r9730) -Feature: [NewGRF] Add support for miscellaneous grf feature bit 1 - paved roads on desert tiles.
maedhros
parents: 6491
diff changeset
   895
static bool AlwaysDrawUnpavedRoads(TileIndex tile, Roadside roadside)
dfa5165a5ab7 (svn r9730) -Feature: [NewGRF] Add support for miscellaneous grf feature bit 1 - paved roads on desert tiles.
maedhros
parents: 6491
diff changeset
   896
{
dfa5165a5ab7 (svn r9730) -Feature: [NewGRF] Add support for miscellaneous grf feature bit 1 - paved roads on desert tiles.
maedhros
parents: 6491
diff changeset
   897
	return (IsOnSnow(tile) &&
dfa5165a5ab7 (svn r9730) -Feature: [NewGRF] Add support for miscellaneous grf feature bit 1 - paved roads on desert tiles.
maedhros
parents: 6491
diff changeset
   898
			!(_opt.landscape == LT_TROPIC && HasGrfMiscBit(GMB_DESERT_PAVED_ROADS) &&
dfa5165a5ab7 (svn r9730) -Feature: [NewGRF] Add support for miscellaneous grf feature bit 1 - paved roads on desert tiles.
maedhros
parents: 6491
diff changeset
   899
				roadside != ROADSIDE_BARREN && roadside != ROADSIDE_GRASS && roadside != ROADSIDE_GRASS_ROAD_WORKS));
dfa5165a5ab7 (svn r9730) -Feature: [NewGRF] Add support for miscellaneous grf feature bit 1 - paved roads on desert tiles.
maedhros
parents: 6491
diff changeset
   900
}
dfa5165a5ab7 (svn r9730) -Feature: [NewGRF] Add support for miscellaneous grf feature bit 1 - paved roads on desert tiles.
maedhros
parents: 6491
diff changeset
   901
dfa5165a5ab7 (svn r9730) -Feature: [NewGRF] Add support for miscellaneous grf feature bit 1 - paved roads on desert tiles.
maedhros
parents: 6491
diff changeset
   902
/**
6691
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
   903
 * Draws the catenary for the given tile
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
   904
 * @param ti   information about the tile (slopes, height etc)
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
   905
 * @param tram the roadbits for the tram
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
   906
 */
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
   907
void DrawTramCatenary(TileInfo *ti, RoadBits tram)
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
   908
{
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
   909
	/* Don't draw the catenary under a low bridge */
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
   910
	if (MayHaveBridgeAbove(ti->tile) && IsBridgeAbove(ti->tile) && !HASBIT(_transparent_opt, TO_BUILDINGS)) {
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
   911
		uint height = GetBridgeHeight(GetNorthernBridgeEnd(ti->tile));
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
   912
6699
d2f35126c1a6 (svn r9931) -Fix: some glitches with catenary and bridges.
rubidium
parents: 6697
diff changeset
   913
		if (height <= GetTileMaxZ(ti->tile) + TILE_HEIGHT) return;
6691
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
   914
	}
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
   915
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
   916
	SpriteID front;
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
   917
	SpriteID back;
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
   918
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
   919
	if (ti->tileh != SLOPE_FLAT) {
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
   920
		back  = SPR_TRAMWAY_BACK_WIRES_SLOPED  + _road_sloped_sprites[ti->tileh - 1];
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
   921
		front = SPR_TRAMWAY_FRONT_WIRES_SLOPED + _road_sloped_sprites[ti->tileh - 1];
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
   922
	} else {
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
   923
		back  = SPR_TRAMWAY_BASE + _road_backpole_sprites_1[tram];
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
   924
		front = SPR_TRAMWAY_BASE + _road_frontwire_sprites_1[tram];
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
   925
	}
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
   926
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
   927
	SpriteID pal = PAL_NONE;
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
   928
	if (HASBIT(_transparent_opt, TO_BUILDINGS)) {
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
   929
		SETBIT(front, PALETTE_MODIFIER_TRANSPARENT);
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
   930
		SETBIT(back,  PALETTE_MODIFIER_TRANSPARENT);
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
   931
		pal = PALETTE_TO_TRANSPARENT;
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
   932
	}
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
   933
6699
d2f35126c1a6 (svn r9931) -Fix: some glitches with catenary and bridges.
rubidium
parents: 6697
diff changeset
   934
	AddSortableSpriteToDraw(back,  pal, ti->x, ti->y, 16, 16, 0x1F, ti->z);
d2f35126c1a6 (svn r9931) -Fix: some glitches with catenary and bridges.
rubidium
parents: 6697
diff changeset
   935
	AddSortableSpriteToDraw(front, pal, ti->x, ti->y, 16, 16, 0x1F, ti->z);
6691
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
   936
}
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
   937
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
   938
/**
6764
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   939
 * Draws details on/around the road
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   940
 * @param img the sprite to draw
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   941
 * @param ti  the tile to draw on
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   942
 * @param dx  the offset from the top of the BB of the tile
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   943
 * @param dy  the offset from the top of the BB of the tile
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   944
 * @param h   the height of the sprite to draw
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   945
 */
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   946
static void DrawRoadDetail(SpriteID img, TileInfo *ti, int dx, int dy, int h)
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   947
{
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   948
	int x = ti->x | dx;
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   949
	int y = ti->y | dy;
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   950
	byte z = ti->z;
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   951
	if (ti->tileh != SLOPE_FLAT) z = GetSlopeZ(x, y);
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   952
	AddSortableSpriteToDraw(img, PAL_NONE, x, y, 2, 2, h, z);
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   953
}
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   954
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   955
/**
2471
5935596f14a8 (svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents: 2469
diff changeset
   956
 * Draw ground sprite and road pieces
5935596f14a8 (svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents: 2469
diff changeset
   957
 * @param ti TileInfo
5935596f14a8 (svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents: 2469
diff changeset
   958
 */
4081
46f02386923e (svn r5396) - Remove two fixed parameters
tron
parents: 4077
diff changeset
   959
static void DrawRoadBits(TileInfo* ti)
2471
5935596f14a8 (svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents: 2469
diff changeset
   960
{
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
   961
	RoadBits road = GetRoadBits(ti->tile, ROADTYPE_ROAD);
6691
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
   962
	RoadBits tram = GetRoadBits(ti->tile, ROADTYPE_TRAM);
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
   963
2471
5935596f14a8 (svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents: 2469
diff changeset
   964
	const DrawRoadTileStruct *drts;
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5643
diff changeset
   965
	SpriteID image = 0;
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5643
diff changeset
   966
	SpriteID pal = PAL_NONE;
4048
5d653b47d349 (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
   967
	Roadside roadside;
2471
5935596f14a8 (svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents: 2469
diff changeset
   968
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3560
diff changeset
   969
	if (ti->tileh != SLOPE_FLAT) {
6691
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
   970
		int foundation = GetRoadFoundation(ti->tileh, road | tram);
2471
5935596f14a8 (svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents: 2469
diff changeset
   971
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   972
		if (foundation != 0) DrawFoundation(ti, foundation);
2471
5935596f14a8 (svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents: 2469
diff changeset
   973
6393
e1e4939d19b5 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6368
diff changeset
   974
		/* DrawFoundation() modifies ti.
e1e4939d19b5 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6368
diff changeset
   975
		 * Default sloped sprites.. */
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3560
diff changeset
   976
		if (ti->tileh != SLOPE_FLAT) image = _road_sloped_sprites[ti->tileh - 1] + 0x53F;
2471
5935596f14a8 (svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents: 2469
diff changeset
   977
	}
5935596f14a8 (svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents: 2469
diff changeset
   978
6691
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
   979
	if (image == 0) image = _road_tile_sprites_1[road != ROAD_NONE ? road : tram];
2471
5935596f14a8 (svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents: 2469
diff changeset
   980
4048
5d653b47d349 (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
   981
	roadside = GetRoadside(ti->tile);
2471
5935596f14a8 (svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents: 2469
diff changeset
   982
6541
dfa5165a5ab7 (svn r9730) -Feature: [NewGRF] Add support for miscellaneous grf feature bit 1 - paved roads on desert tiles.
maedhros
parents: 6491
diff changeset
   983
	if (AlwaysDrawUnpavedRoads(ti->tile, roadside)) {
2471
5935596f14a8 (svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents: 2469
diff changeset
   984
		image += 19;
4048
5d653b47d349 (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
   985
	} else {
5d653b47d349 (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
   986
		switch (roadside) {
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5643
diff changeset
   987
			case ROADSIDE_BARREN:           pal = PALETTE_TO_BARE_LAND; break;
4048
5d653b47d349 (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
   988
			case ROADSIDE_GRASS:            break;
5d653b47d349 (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
   989
			case ROADSIDE_GRASS_ROAD_WORKS: break;
5d653b47d349 (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
   990
			default:                        image -= 19; break; // Paved
5d653b47d349 (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
   991
		}
2471
5935596f14a8 (svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents: 2469
diff changeset
   992
	}
5935596f14a8 (svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents: 2469
diff changeset
   993
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5643
diff changeset
   994
	DrawGroundSprite(image, pal);
2471
5935596f14a8 (svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents: 2469
diff changeset
   995
6764
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   996
	if (road != ROAD_NONE) {
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   997
		DisallowedRoadDirections drd = GetDisallowedRoadDirections(ti->tile);
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   998
		if (drd != DRD_NONE) {
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   999
			DrawRoadDetail(SPR_ONEWAY_BASE + drd - 1 + ((road == ROAD_X) ? 0 : 3), ti, 8, 8, 0);
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
  1000
		}
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
  1001
	}
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
  1002
6691
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
  1003
	/* For tram we overlay the road graphics with either tram tracks only
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
  1004
	 * (when there is actual road beneath the trams) or with tram tracks
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
  1005
	 * and some dirts which hides the road graphics */
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
  1006
	if (tram != ROAD_NONE) {
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
  1007
		if (ti->tileh != SLOPE_FLAT) {
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
  1008
			image = _road_sloped_sprites[ti->tileh - 1] + SPR_TRAMWAY_SLOPED_OFFSET;
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
  1009
		} else {
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
  1010
			image = _road_tile_sprites_1[tram] - SPR_ROAD_Y;
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
  1011
		}
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
  1012
		image += (road == ROAD_NONE) ? SPR_TRAMWAY_TRAM : SPR_TRAMWAY_OVERLAY;
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
  1013
		DrawGroundSprite(image, pal);
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
  1014
	}
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
  1015
3430
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
  1016
	if (HasRoadWorks(ti->tile)) {
6393
e1e4939d19b5 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6368
diff changeset
  1017
		/* Road works */
6691
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
  1018
		DrawGroundSprite((road | tram) & ROAD_X ? SPR_EXCAVATION_X : SPR_EXCAVATION_Y, PAL_NONE);
2471
5935596f14a8 (svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents: 2469
diff changeset
  1019
		return;
5935596f14a8 (svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents: 2469
diff changeset
  1020
	}
5935596f14a8 (svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents: 2469
diff changeset
  1021
6691
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
  1022
	if (tram != ROAD_NONE) DrawTramCatenary(ti, tram);
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
  1023
6393
e1e4939d19b5 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6368
diff changeset
  1024
	/* Return if full detail is disabled, or we are zoomed fully out. */
6626
207875b9069a (svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents: 6624
diff changeset
  1025
	if (!HASBIT(_display_opt, DO_FULL_DETAIL) || _cur_dpi->zoom > ZOOM_LVL_DETAIL) return;
5148
3641479afb1d (svn r7240) -Fix: Always display the excavation of roadworks even when fully zoomed out (they are quite noticable) or "full details" are off (they are part of the game mechanics)
tron
parents: 5116
diff changeset
  1026
6393
e1e4939d19b5 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6368
diff changeset
  1027
	/* Draw extra details. */
4048
5d653b47d349 (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1028
	for (drts = _road_display_table[roadside][road]; drts->image != 0; drts++) {
6764
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
  1029
		DrawRoadDetail(drts->image, ti, drts->subcoord_x, drts->subcoord_y, 0x10);
2471
5935596f14a8 (svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents: 2469
diff changeset
  1030
	}
5935596f14a8 (svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents: 2469
diff changeset
  1031
}
5935596f14a8 (svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents: 2469
diff changeset
  1032
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1033
static void DrawTile_Road(TileInfo *ti)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1034
{
3793
7fe24e10ea63 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3792
diff changeset
  1035
	switch (GetRoadTileType(ti->tile)) {
7fe24e10ea63 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3792
diff changeset
  1036
		case ROAD_TILE_NORMAL:
4081
46f02386923e (svn r5396) - Remove two fixed parameters
tron
parents: 4077
diff changeset
  1037
			DrawRoadBits(ti);
3060
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1038
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1039
3793
7fe24e10ea63 (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_CROSSING: {
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5643
diff changeset
  1041
			SpriteID image;
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5643
diff changeset
  1042
			SpriteID pal = PAL_NONE;
6541
dfa5165a5ab7 (svn r9730) -Feature: [NewGRF] Add support for miscellaneous grf feature bit 1 - paved roads on desert tiles.
maedhros
parents: 6491
diff changeset
  1043
			Roadside roadside = GetRoadside(ti->tile);
4000
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3977
diff changeset
  1044
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3560
diff changeset
  1045
			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
  1046
6172
e6d7a5b3d63f (svn r8935) -Codechange: unification of track type between road and rail tiles, unification of ground type between normal rail tiles and depots/waypoints and removing the need for RailTileSubType.
rubidium
parents: 6160
diff changeset
  1047
			image = GetRailTypeInfo(GetRailType(ti->tile))->base_sprites.crossing;
3060
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1048
3272
b3e2d8e19937 (svn r3984) Add a function to get the road axis of a level crossing
tron
parents: 3269
diff changeset
  1049
			if (GetCrossingRoadAxis(ti->tile) == AXIS_X) image++;
3322
41b4d25b126d (svn r4088) -Codechange: Introduce {Unb,B}arCrossing and IsCrossingBarred to put and get the status of a level crossing
celestar
parents: 3319
diff changeset
  1050
			if (IsCrossingBarred(ti->tile)) image += 2;
3060
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1051
6541
dfa5165a5ab7 (svn r9730) -Feature: [NewGRF] Add support for miscellaneous grf feature bit 1 - paved roads on desert tiles.
maedhros
parents: 6491
diff changeset
  1052
			if (AlwaysDrawUnpavedRoads(ti->tile, roadside)) {
3060
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1053
				image += 8;
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1054
			} else {
6541
dfa5165a5ab7 (svn r9730) -Feature: [NewGRF] Add support for miscellaneous grf feature bit 1 - paved roads on desert tiles.
maedhros
parents: 6491
diff changeset
  1055
				switch (roadside) {
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5643
diff changeset
  1056
					case ROADSIDE_BARREN: pal = PALETTE_TO_BARE_LAND; break;
4048
5d653b47d349 (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1057
					case ROADSIDE_GRASS:  break;
5d653b47d349 (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1058
					default:              image += 4; break; // Paved
5d653b47d349 (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1059
				}
3060
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1060
			}
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1061
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5643
diff changeset
  1062
			DrawGroundSprite(image, pal);
6697
dde1f5dced50 (svn r9929) -Fix [FS#803]: fix several drawing issues.
rubidium
parents: 6691
diff changeset
  1063
			if (HASBIT(GetRoadTypes(ti->tile), ROADTYPE_TRAM)) {
dde1f5dced50 (svn r9929) -Fix [FS#803]: fix several drawing issues.
rubidium
parents: 6691
diff changeset
  1064
				DrawGroundSprite(SPR_TRAMWAY_OVERLAY + (GetCrossingRoadAxis(ti->tile) ^ 1), pal);
dde1f5dced50 (svn r9929) -Fix [FS#803]: fix several drawing issues.
rubidium
parents: 6691
diff changeset
  1065
				DrawTramCatenary(ti, GetCrossingRoadBits(ti->tile));
dde1f5dced50 (svn r9929) -Fix [FS#803]: fix several drawing issues.
rubidium
parents: 6691
diff changeset
  1066
			}
6172
e6d7a5b3d63f (svn r8935) -Codechange: unification of track type between road and rail tiles, unification of ground type between normal rail tiles and depots/waypoints and removing the need for RailTileSubType.
rubidium
parents: 6160
diff changeset
  1067
			if (GetRailType(ti->tile) == RAILTYPE_ELECTRIC) DrawCatenary(ti);
3060
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1068
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1069
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1070
3098
aed45c5c1e11 (svn r3687) Complete some bits I missed whenn adding accessor functions for road types and pieces
tron
parents: 3097
diff changeset
  1071
		default:
3793
7fe24e10ea63 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3792
diff changeset
  1072
		case ROAD_TILE_DEPOT: {
4232
136a11474264 (svn r5796) Use DrawTileSprites/DrawTileSeqStruct for road depot drawing data, too
tron
parents: 4231
diff changeset
  1073
			const DrawTileSprites* dts;
136a11474264 (svn r5796) Use DrawTileSprites/DrawTileSeqStruct for road depot drawing data, too
tron
parents: 4231
diff changeset
  1074
			const DrawTileSeqStruct* dtss;
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5643
diff changeset
  1075
			SpriteID palette;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1076
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3560
diff changeset
  1077
			if (ti->tileh != SLOPE_FLAT) DrawFoundation(ti, ti->tileh);
1398
3c5c97aba203 (svn r1902) Replace some casts with proper typing
tron
parents: 1359
diff changeset
  1078
4226
10d7608f4c6c (svn r5772) Road depots always have an player as owner, so remove an useless check
tron
parents: 4212
diff changeset
  1079
			palette = PLAYER_SPRITE_COLOR(GetTileOwner(ti->tile));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1080
6691
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
  1081
			if (HASBIT(GetRoadTypes(ti->tile), ROADTYPE_TRAM)) {
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
  1082
				dts =  &_tram_depot[GetRoadDepotDirection(ti->tile)];
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
  1083
			} else {
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
  1084
				dts =  &_road_depot[GetRoadDepotDirection(ti->tile)];
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
  1085
			}
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
  1086
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5643
diff changeset
  1087
			DrawGroundSprite(dts->ground_sprite, PAL_NONE);
3060
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1088
4232
136a11474264 (svn r5796) Use DrawTileSprites/DrawTileSeqStruct for road depot drawing data, too
tron
parents: 4231
diff changeset
  1089
			for (dtss = dts->seq; dtss->image != 0; dtss++) {
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5643
diff changeset
  1090
				SpriteID image = dtss->image;
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5643
diff changeset
  1091
				SpriteID pal;
3060
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1092
6427
7dc1012757d8 (svn r9563) -Feature: Add more finer control to transparency options, including a new toolbar, accessible from the map menu or Ctrl X. Patch by Wolf01.
peter1138
parents: 6406
diff changeset
  1093
				if (HASBIT(_transparent_opt, TO_BUILDINGS)) {
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5643
diff changeset
  1094
					SETBIT(image, PALETTE_MODIFIER_TRANSPARENT);
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5643
diff changeset
  1095
					pal = PALETTE_TO_TRANSPARENT;
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5643
diff changeset
  1096
				} else if (HASBIT(image, PALETTE_MODIFIER_COLOR)) {
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5643
diff changeset
  1097
					pal = palette;
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5643
diff changeset
  1098
				} else {
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5643
diff changeset
  1099
					pal = PAL_NONE;
4226
10d7608f4c6c (svn r5772) Road depots always have an player as owner, so remove an useless check
tron
parents: 4212
diff changeset
  1100
				}
3060
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1101
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4048
diff changeset
  1102
				AddSortableSpriteToDraw(
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5643
diff changeset
  1103
					image, pal,
4232
136a11474264 (svn r5796) Use DrawTileSprites/DrawTileSeqStruct for road depot drawing data, too
tron
parents: 4231
diff changeset
  1104
					ti->x + dtss->delta_x, ti->y + dtss->delta_y,
136a11474264 (svn r5796) Use DrawTileSprites/DrawTileSeqStruct for road depot drawing data, too
tron
parents: 4231
diff changeset
  1105
					dtss->size_x, dtss->size_y,
136a11474264 (svn r5796) Use DrawTileSprites/DrawTileSeqStruct for road depot drawing data, too
tron
parents: 4231
diff changeset
  1106
					dtss->size_z, ti->z
3060
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1107
				);
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1108
			}
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1109
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1110
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1111
	}
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
  1112
	DrawBridgeMiddle(ti);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1113
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1114
6666
41ceafa4c85e (svn r9897) -Codechange: prepare the toolbar for more road types.
rubidium
parents: 6662
diff changeset
  1115
void DrawRoadDepotSprite(int x, int y, DiagDirection dir, RoadType rt)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1116
{
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5643
diff changeset
  1117
	SpriteID palette = PLAYER_SPRITE_COLOR(_local_player);
6691
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
  1118
	const DrawTileSprites* dts = (rt == ROADTYPE_TRAM) ? &_tram_depot[dir] : &_road_depot[dir];
4232
136a11474264 (svn r5796) Use DrawTileSprites/DrawTileSeqStruct for road depot drawing data, too
tron
parents: 4231
diff changeset
  1119
	const DrawTileSeqStruct* dtss;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1120
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2549
diff changeset
  1121
	x += 33;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2549
diff changeset
  1122
	y += 17;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1123
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5643
diff changeset
  1124
	DrawSprite(dts->ground_sprite, PAL_NONE, x, y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1125
4232
136a11474264 (svn r5796) Use DrawTileSprites/DrawTileSeqStruct for road depot drawing data, too
tron
parents: 4231
diff changeset
  1126
	for (dtss = dts->seq; dtss->image != 0; dtss++) {
136a11474264 (svn r5796) Use DrawTileSprites/DrawTileSeqStruct for road depot drawing data, too
tron
parents: 4231
diff changeset
  1127
		Point pt = RemapCoords(dtss->delta_x, dtss->delta_y, dtss->delta_z);
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5643
diff changeset
  1128
		SpriteID image = dtss->image;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1129
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5643
diff changeset
  1130
		DrawSprite(image, HASBIT(image, PALETTE_MODIFIER_COLOR) ? palette : PAL_NONE, x + pt.x, y + pt.y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1131
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1132
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1133
4231
2823b3643862 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4226
diff changeset
  1134
static uint GetSlopeZ_Road(TileIndex tile, uint x, uint y)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1135
{
4231
2823b3643862 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4226
diff changeset
  1136
	uint z;
2823b3643862 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4226
diff changeset
  1137
	Slope tileh = GetTileSlope(tile, &z);
3098
aed45c5c1e11 (svn r3687) Complete some bits I missed whenn adding accessor functions for road types and pieces
tron
parents: 3097
diff changeset
  1138
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3560
diff changeset
  1139
	if (tileh == SLOPE_FLAT) return z;
4231
2823b3643862 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4226
diff changeset
  1140
	if (GetRoadTileType(tile) == ROAD_TILE_NORMAL) {
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
  1141
		uint f = GetRoadFoundation(tileh, GetAllRoadBits(tile));
3060
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1142
3286
5177aab0ec21 (svn r4000) Rewrite GetSlope{Tileh,Z}_{Road,Track} in a less confusing way
tron
parents: 3277
diff changeset
  1143
		if (f != 0) {
4246
6dcc0e44a367 (svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents: 4232
diff changeset
  1144
			if (IsSteepSlope(tileh)) {
6dcc0e44a367 (svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents: 4232
diff changeset
  1145
				z += TILE_HEIGHT;
6dcc0e44a367 (svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents: 4232
diff changeset
  1146
			} else if (f < 15) {
6dcc0e44a367 (svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents: 4232
diff changeset
  1147
				return z + TILE_HEIGHT; // leveled foundation
6dcc0e44a367 (svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents: 4232
diff changeset
  1148
			}
3286
5177aab0ec21 (svn r4000) Rewrite GetSlope{Tileh,Z}_{Road,Track} in a less confusing way
tron
parents: 3277
diff changeset
  1149
			tileh = _inclined_tileh[f - 15]; // inclined foundation
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1150
		}
4231
2823b3643862 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4226
diff changeset
  1151
		return z + GetPartialZ(x & 0xF, y & 0xF, tileh);
3286
5177aab0ec21 (svn r4000) Rewrite GetSlope{Tileh,Z}_{Road,Track} in a less confusing way
tron
parents: 3277
diff changeset
  1152
	} else {
3645
7f950533d510 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3637
diff changeset
  1153
		return z + TILE_HEIGHT;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1154
	}
39
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 22
diff changeset
  1155
}
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 22
diff changeset
  1156
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3560
diff changeset
  1157
static Slope GetSlopeTileh_Road(TileIndex tile, Slope tileh)
39
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 22
diff changeset
  1158
{
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3560
diff changeset
  1159
	if (tileh == SLOPE_FLAT) return SLOPE_FLAT;
3793
7fe24e10ea63 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3792
diff changeset
  1160
	if (GetRoadTileType(tile) == ROAD_TILE_NORMAL) {
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
  1161
		uint f = GetRoadFoundation(tileh, GetAllRoadBits(tile));
3098
aed45c5c1e11 (svn r3687) Complete some bits I missed whenn adding accessor functions for road types and pieces
tron
parents: 3097
diff changeset
  1162
3418
ec9003ebf933 (svn r4242) Pass TileIndex and slope to GetSlopeTileh_*() instead of TileInfo
tron
parents: 3415
diff changeset
  1163
		if (f == 0) return tileh;
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3560
diff changeset
  1164
		if (f < 15) return SLOPE_FLAT; // leveled foundation
3286
5177aab0ec21 (svn r4000) Rewrite GetSlope{Tileh,Z}_{Road,Track} in a less confusing way
tron
parents: 3277
diff changeset
  1165
		return _inclined_tileh[f - 15]; // inclined foundation
5177aab0ec21 (svn r4000) Rewrite GetSlope{Tileh,Z}_{Road,Track} in a less confusing way
tron
parents: 3277
diff changeset
  1166
	} else {
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3560
diff changeset
  1167
		return SLOPE_FLAT;
39
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 22
diff changeset
  1168
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1169
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1170
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
  1171
static void GetAcceptedCargo_Road(TileIndex tile, AcceptedCargo ac)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1172
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1173
	/* not used */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1174
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1175
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
  1176
static void AnimateTile_Road(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1177
{
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2549
diff changeset
  1178
	if (IsLevelCrossing(tile)) MarkTileDirtyByTile(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1179
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1180
4048
5d653b47d349 (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1181
5d653b47d349 (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1182
static const Roadside _town_road_types[][2] = {
5d653b47d349 (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1183
	{ ROADSIDE_GRASS,         ROADSIDE_GRASS },
5d653b47d349 (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1184
	{ ROADSIDE_PAVED,         ROADSIDE_PAVED },
5d653b47d349 (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1185
	{ ROADSIDE_PAVED,         ROADSIDE_PAVED },
5d653b47d349 (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1186
	{ ROADSIDE_TREES,         ROADSIDE_TREES },
5d653b47d349 (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1187
	{ ROADSIDE_STREET_LIGHTS, ROADSIDE_PAVED }
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1188
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1189
4048
5d653b47d349 (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1190
static const Roadside _town_road_types_2[][2] = {
5d653b47d349 (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1191
	{ ROADSIDE_GRASS,         ROADSIDE_GRASS },
5d653b47d349 (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1192
	{ ROADSIDE_PAVED,         ROADSIDE_PAVED },
5d653b47d349 (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1193
	{ ROADSIDE_STREET_LIGHTS, ROADSIDE_PAVED },
5d653b47d349 (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1194
	{ ROADSIDE_STREET_LIGHTS, ROADSIDE_PAVED },
5d653b47d349 (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1195
	{ ROADSIDE_STREET_LIGHTS, ROADSIDE_PAVED }
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1196
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1197
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1198
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
  1199
static void TileLoop_Road(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1200
{
3017
a75caf4efa2d (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
  1201
	switch (_opt.landscape) {
6357
f0f5e7d1713c (svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents: 6343
diff changeset
  1202
		case LT_ARCTIC:
6343
76d17f784c13 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6259
diff changeset
  1203
			if (IsOnSnow(tile) != (GetTileZ(tile) > GetSnowLine())) {
3430
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
  1204
				ToggleSnow(tile);
3017
a75caf4efa2d (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
  1205
				MarkTileDirtyByTile(tile);
a75caf4efa2d (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
  1206
			}
a75caf4efa2d (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
  1207
			break;
a75caf4efa2d (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
  1208
6357
f0f5e7d1713c (svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents: 6343
diff changeset
  1209
		case LT_TROPIC:
3430
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
  1210
			if (GetTropicZone(tile) == TROPICZONE_DESERT && !IsOnDesert(tile)) {
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
  1211
				ToggleDesert(tile);
3017
a75caf4efa2d (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
  1212
				MarkTileDirtyByTile(tile);
a75caf4efa2d (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
  1213
			}
a75caf4efa2d (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents: 2989
diff changeset
  1214
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1215
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1216
3793
7fe24e10ea63 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3792
diff changeset
  1217
	if (GetRoadTileType(tile) == ROAD_TILE_DEPOT) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1218
3430
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
  1219
	if (!HasRoadWorks(tile)) {
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4048
diff changeset
  1220
		const Town* t = ClosestTownFromTile(tile, (uint)-1);
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4048
diff changeset
  1221
		int grp = 0;
1280
33a251c30758 (svn r1784) -Fix: removed ClosestTownFromTile where possible, or replaced it
truelight
parents: 1264
diff changeset
  1222
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1223
		if (t != NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1224
			grp = GetTownRadiusGroup(t, tile);
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1225
6393
e1e4939d19b5 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6368
diff changeset
  1226
			/* 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
  1227
			if (t->road_build_months != 0 &&
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4048
diff changeset
  1228
					(DistanceManhattan(t->xy, tile) < 8 || grp != 0) &&
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
  1229
					GetRoadTileType(tile) == ROAD_TILE_NORMAL && (GetAllRoadBits(tile) == ROAD_X || GetAllRoadBits(tile) == ROAD_Y)) {
6406
8ccf18e94c67 (svn r9542) -Fix(FS# 712): When checking if a vehicle is on a given tile, and you are working on the ground tile, do not take aircrafts into account, as they do not pose any danger for the construction/destruction/conversion itself. Z stuff, in other words
belugas
parents: 6393
diff changeset
  1230
				if (GetTileSlope(tile, NULL) == SLOPE_FLAT && EnsureNoVehicleOnGround(tile) && CHANCE16(1, 20)) {
3430
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
  1231
					StartRoadWorks(tile);
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1232
541
625227bb2a3d (svn r925) Use sound enums
tron
parents: 534
diff changeset
  1233
					SndPlayTileFx(SND_21_JACKHAMMER, tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1234
					CreateEffectVehicleAbove(
3421
7968a4b5ff0a (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3418
diff changeset
  1235
						TileX(tile) * TILE_SIZE + 7,
7968a4b5ff0a (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3418
diff changeset
  1236
						TileY(tile) * TILE_SIZE + 7,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1237
						0,
1359
52782e5cf7c9 (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
  1238
						EV_BULLDOZER);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1239
					MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1240
					return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1241
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1242
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1243
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1244
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1245
		{
3430
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
  1246
			/* Adjust road ground type depending on 'grp' (grp is the distance to the center) */
6357
f0f5e7d1713c (svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents: 6343
diff changeset
  1247
			const Roadside* new_rs = (_opt.landscape == LT_TOYLAND) ? _town_road_types_2[grp] : _town_road_types[grp];
4048
5d653b47d349 (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1248
			Roadside cur_rs = GetRoadside(tile);
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1249
3430
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
  1250
			/* We have our desired type, do nothing */
4048
5d653b47d349 (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1251
			if (cur_rs == new_rs[0]) return;
3430
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
  1252
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
  1253
			/* We have the pre-type of the desired type, switch to the desired type */
4048
5d653b47d349 (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1254
			if (cur_rs == new_rs[1]) {
5d653b47d349 (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1255
				cur_rs = new_rs[0];
3430
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
  1256
			/* We have barren land, install the pre-type */
4048
5d653b47d349 (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1257
			} else if (cur_rs == ROADSIDE_BARREN) {
5d653b47d349 (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1258
				cur_rs = new_rs[1];
3430
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
  1259
			/* 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
  1260
			} else {
4048
5d653b47d349 (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1261
				cur_rs = ROADSIDE_BARREN;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1262
			}
4048
5d653b47d349 (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1263
			SetRoadside(tile, cur_rs);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1264
			MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1265
		}
3430
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
  1266
	} else if (IncreaseRoadWorksCounter(tile)) {
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
  1267
		TerminateRoadWorks(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1268
		MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1269
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1270
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1271
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
  1272
static void ClickTile_Road(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1273
{
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6256
diff changeset
  1274
	if (GetRoadTileType(tile) == ROAD_TILE_DEPOT) ShowDepotWindow(tile, VEH_ROAD);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1275
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1276
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1277
static const byte _road_trackbits[16] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1278
	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
  1279
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1280
6683
b88ae30866ce (svn r9914) -Codechange: prepare GTTS and the pathfinders to handle multiple road types on a single tile.
rubidium
parents: 6679
diff changeset
  1281
static uint32 GetTileTrackStatus_Road(TileIndex tile, TransportType mode, uint sub_mode)
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
  1282
{
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
  1283
3066
26c43ab051b8 (svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents: 3061
diff changeset
  1284
	switch (mode) {
26c43ab051b8 (svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents: 3061
diff changeset
  1285
		case TRANSPORT_RAIL:
26c43ab051b8 (svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents: 3061
diff changeset
  1286
			if (!IsLevelCrossing(tile)) return 0;
3267
feff95208a9f (svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents: 3242
diff changeset
  1287
			return GetCrossingRailBits(tile) * 0x101;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1288
3066
26c43ab051b8 (svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents: 3061
diff changeset
  1289
		case TRANSPORT_ROAD:
6683
b88ae30866ce (svn r9914) -Codechange: prepare GTTS and the pathfinders to handle multiple road types on a single tile.
rubidium
parents: 6679
diff changeset
  1290
			if ((GetRoadTypes(tile) & sub_mode) == 0) return 0;
3793
7fe24e10ea63 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3792
diff changeset
  1291
			switch (GetRoadTileType(tile)) {
6683
b88ae30866ce (svn r9914) -Codechange: prepare GTTS and the pathfinders to handle multiple road types on a single tile.
rubidium
parents: 6679
diff changeset
  1292
				case ROAD_TILE_NORMAL: {
b88ae30866ce (svn r9914) -Codechange: prepare GTTS and the pathfinders to handle multiple road types on a single tile.
rubidium
parents: 6679
diff changeset
  1293
					RoadType rt = (RoadType)FindFirstBit(sub_mode);
6764
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
  1294
					const uint drd_to_multiplier[DRD_END] = { 0x101, 0x100, 0x1, 0x0 };
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
  1295
					uint multiplier = drd_to_multiplier[rt == ROADTYPE_TRAM ? DRD_NONE : GetDisallowedRoadDirections(tile)];
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
  1296
					return HasRoadWorks(tile) ? 0 : _road_trackbits[GetRoadBits(tile, rt)] * multiplier;
6683
b88ae30866ce (svn r9914) -Codechange: prepare GTTS and the pathfinders to handle multiple road types on a single tile.
rubidium
parents: 6679
diff changeset
  1297
				}
3066
26c43ab051b8 (svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents: 3061
diff changeset
  1298
3793
7fe24e10ea63 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3792
diff changeset
  1299
				case ROAD_TILE_CROSSING: {
4158
91ff9bb84ced (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4081
diff changeset
  1300
					uint32 r = AxisToTrackBits(GetCrossingRoadAxis(tile)) * 0x101;
3272
b3e2d8e19937 (svn r3984) Add a function to get the road axis of a level crossing
tron
parents: 3269
diff changeset
  1301
3367
a995838e8d85 (svn r4164) Use acessor functions
tron
parents: 3365
diff changeset
  1302
					if (IsCrossingBarred(tile)) r *= 0x10001;
3066
26c43ab051b8 (svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents: 3061
diff changeset
  1303
					return r;
26c43ab051b8 (svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents: 3061
diff changeset
  1304
				}
26c43ab051b8 (svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents: 3061
diff changeset
  1305
3069
9a1fd047b595 (svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents: 3068
diff changeset
  1306
				default:
3793
7fe24e10ea63 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3792
diff changeset
  1307
				case ROAD_TILE_DEPOT:
4158
91ff9bb84ced (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4081
diff changeset
  1308
					return AxisToTrackBits(DiagDirToAxis(GetRoadDepotDirection(tile))) * 0x101;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1309
			}
3066
26c43ab051b8 (svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents: 3061
diff changeset
  1310
			break;
26c43ab051b8 (svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents: 3061
diff changeset
  1311
26c43ab051b8 (svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents: 3061
diff changeset
  1312
		default: break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1313
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1314
	return 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1315
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1316
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1317
static const StringID _road_tile_strings[] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1318
	STR_1814_ROAD,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1319
	STR_1814_ROAD,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1320
	STR_1814_ROAD,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1321
	STR_1815_ROAD_WITH_STREETLIGHTS,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1322
	STR_1814_ROAD,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1323
	STR_1816_TREE_LINED_ROAD,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1324
	STR_1814_ROAD,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1325
	STR_1814_ROAD,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1326
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1327
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
  1328
static void GetTileDesc_Road(TileIndex tile, TileDesc *td)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1329
{
1901
03bf9bf99319 (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
  1330
	td->owner = GetTileOwner(tile);
3793
7fe24e10ea63 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3792
diff changeset
  1331
	switch (GetRoadTileType(tile)) {
7fe24e10ea63 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3792
diff changeset
  1332
		case ROAD_TILE_CROSSING: td->str = STR_1818_ROAD_RAIL_LEVEL_CROSSING; break;
7fe24e10ea63 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3792
diff changeset
  1333
		case ROAD_TILE_DEPOT: td->str = STR_1817_ROAD_VEHICLE_DEPOT; break;
4048
5d653b47d349 (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1334
		default: td->str = _road_tile_strings[GetRoadside(tile)]; break;
3069
9a1fd047b595 (svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents: 3068
diff changeset
  1335
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1336
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1337
6723
89182b2f015a (svn r9955) -Codechange: Make _roadveh_enter_depot_unk0 slightly less mysterious.
maedhros
parents: 6719
diff changeset
  1338
/**
89182b2f015a (svn r9955) -Codechange: Make _roadveh_enter_depot_unk0 slightly less mysterious.
maedhros
parents: 6719
diff changeset
  1339
 * Given the direction the road depot is pointing, this is the direction the
89182b2f015a (svn r9955) -Codechange: Make _roadveh_enter_depot_unk0 slightly less mysterious.
maedhros
parents: 6719
diff changeset
  1340
 * vehicle should be travelling in in order to enter the depot.
89182b2f015a (svn r9955) -Codechange: Make _roadveh_enter_depot_unk0 slightly less mysterious.
maedhros
parents: 6719
diff changeset
  1341
 */
89182b2f015a (svn r9955) -Codechange: Make _roadveh_enter_depot_unk0 slightly less mysterious.
maedhros
parents: 6719
diff changeset
  1342
static const byte _roadveh_enter_depot_dir[4] = {
89182b2f015a (svn r9955) -Codechange: Make _roadveh_enter_depot_unk0 slightly less mysterious.
maedhros
parents: 6719
diff changeset
  1343
	TRACKDIR_X_SW, TRACKDIR_Y_NW, TRACKDIR_X_NE, TRACKDIR_Y_SE
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1344
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1345
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
  1346
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
  1347
{
3793
7fe24e10ea63 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3792
diff changeset
  1348
	switch (GetRoadTileType(tile)) {
7fe24e10ea63 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3792
diff changeset
  1349
		case ROAD_TILE_CROSSING:
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6256
diff changeset
  1350
			if (v->type == VEH_TRAIN && !IsCrossingBarred(tile)) {
3060
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1351
				/* train crossing a road */
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1352
				SndPlayVehicleFx(SND_0E_LEVEL_CROSSING, v);
3322
41b4d25b126d (svn r4088) -Codechange: Introduce {Unb,B}arCrossing and IsCrossingBarred to put and get the status of a level crossing
celestar
parents: 3319
diff changeset
  1353
				BarCrossing(tile);
3060
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1354
				MarkTileDirtyByTile(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1355
			}
3060
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1356
			break;
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1357
3793
7fe24e10ea63 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3792
diff changeset
  1358
		case ROAD_TILE_DEPOT:
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6256
diff changeset
  1359
			if (v->type == VEH_ROAD &&
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4048
diff changeset
  1360
					v->u.road.frame == 11 &&
6723
89182b2f015a (svn r9955) -Codechange: Make _roadveh_enter_depot_unk0 slightly less mysterious.
maedhros
parents: 6719
diff changeset
  1361
					_roadveh_enter_depot_dir[GetRoadDepotDirection(tile)] == v->u.road.state) {
4725
40cccaaa042c (svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents: 4638
diff changeset
  1362
				VehicleEnterDepot(v);
5991
ec2eebfe86de (svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents: 5942
diff changeset
  1363
				return VETSB_ENTERED_WORMHOLE;
3060
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1364
			}
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1365
			break;
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1366
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1367
		default: break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1368
	}
5991
ec2eebfe86de (svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents: 5942
diff changeset
  1369
	return VETSB_CONTINUE;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1370
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1371
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1372
2436
7d5df545bd5d (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents: 2425
diff changeset
  1373
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
  1374
{
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
  1375
	if (GetRoadTileType(tile) == ROAD_TILE_DEPOT) {
6717
804853737caa (svn r9949) -Fix: (road) depots got deowned on bankrupts.
rubidium
parents: 6716
diff changeset
  1376
		if (GetTileOwner(tile) == old_player) {
804853737caa (svn r9949) -Fix: (road) depots got deowned on bankrupts.
rubidium
parents: 6716
diff changeset
  1377
			if (new_player == PLAYER_SPECTATOR) {
804853737caa (svn r9949) -Fix: (road) depots got deowned on bankrupts.
rubidium
parents: 6716
diff changeset
  1378
				DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
804853737caa (svn r9949) -Fix: (road) depots got deowned on bankrupts.
rubidium
parents: 6716
diff changeset
  1379
			} else {
804853737caa (svn r9949) -Fix: (road) depots got deowned on bankrupts.
rubidium
parents: 6716
diff changeset
  1380
				SetTileOwner(tile, new_player);
804853737caa (svn r9949) -Fix: (road) depots got deowned on bankrupts.
rubidium
parents: 6716
diff changeset
  1381
			}
6689
84811200d69c (svn r9921) -Fix (r9892): ownership wasn't properly propagated on owner changes.
rubidium
parents: 6683
diff changeset
  1382
		}
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
  1383
		return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1384
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1385
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
  1386
	for (RoadType rt = ROADTYPE_ROAD; rt < ROADTYPE_END; rt++) {
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
  1387
		if (!HASBIT(GetRoadTypes(tile), rt)) continue;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1388
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
  1389
		if (GetRoadOwner(tile, rt) == old_player) {
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
  1390
			SetRoadOwner(tile, rt, new_player == PLAYER_SPECTATOR ? OWNER_NONE : new_player);
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
  1391
		}
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
  1392
	}
3060
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1393
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
  1394
	if (IsLevelCrossing(tile)) {
6689
84811200d69c (svn r9921) -Fix (r9892): ownership wasn't properly propagated on owner changes.
rubidium
parents: 6683
diff changeset
  1395
		if (GetTileOwner(tile) == old_player) {
84811200d69c (svn r9921) -Fix (r9892): ownership wasn't properly propagated on owner changes.
rubidium
parents: 6683
diff changeset
  1396
			if (new_player == PLAYER_SPECTATOR) {
84811200d69c (svn r9921) -Fix (r9892): ownership wasn't properly propagated on owner changes.
rubidium
parents: 6683
diff changeset
  1397
				MakeRoadNormal(tile, GetCrossingRoadBits(tile), GetRoadTypes(tile), GetTownIndex(tile), GetRoadOwner(tile, ROADTYPE_ROAD), GetRoadOwner(tile, ROADTYPE_TRAM), GetRoadOwner(tile, ROADTYPE_HWAY));
84811200d69c (svn r9921) -Fix (r9892): ownership wasn't properly propagated on owner changes.
rubidium
parents: 6683
diff changeset
  1398
			} else {
84811200d69c (svn r9921) -Fix (r9892): ownership wasn't properly propagated on owner changes.
rubidium
parents: 6683
diff changeset
  1399
				SetTileOwner(tile, new_player);
84811200d69c (svn r9921) -Fix (r9892): ownership wasn't properly propagated on owner changes.
rubidium
parents: 6683
diff changeset
  1400
			}
84811200d69c (svn r9921) -Fix (r9892): ownership wasn't properly propagated on owner changes.
rubidium
parents: 6683
diff changeset
  1401
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1402
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1403
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1404
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1405
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
  1406
extern const TileTypeProcs _tile_type_road_procs = {
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4246
diff changeset
  1407
	DrawTile_Road,           /* draw_tile_proc */
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4246
diff changeset
  1408
	GetSlopeZ_Road,          /* get_slope_z_proc */
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4246
diff changeset
  1409
	ClearTile_Road,          /* clear_tile_proc */
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4246
diff changeset
  1410
	GetAcceptedCargo_Road,   /* get_accepted_cargo_proc */
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4246
diff changeset
  1411
	GetTileDesc_Road,        /* get_tile_desc_proc */
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4246
diff changeset
  1412
	GetTileTrackStatus_Road, /* get_tile_track_status_proc */
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4246
diff changeset
  1413
	ClickTile_Road,          /* click_tile_proc */
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4246
diff changeset
  1414
	AnimateTile_Road,        /* animate_tile_proc */
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4246
diff changeset
  1415
	TileLoop_Road,           /* tile_loop_clear */
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4246
diff changeset
  1416
	ChangeTileOwner_Road,    /* change_tile_owner_clear */
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4246
diff changeset
  1417
	NULL,                    /* get_produced_cargo_proc */
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4246
diff changeset
  1418
	VehicleEnter_Road,       /* vehicle_enter_tile_proc */
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4246
diff changeset
  1419
	GetSlopeTileh_Road,      /* get_slope_tileh_proc */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1420
};