src/road_cmd.cpp
author skidd13
Mon, 19 Nov 2007 21:02:30 +0000
changeset 8424 4a488a90ccab
parent 8353 49a1d9b9d937
child 8450 dce58137301f
permissions -rw-r--r--
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
2186
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
6889
f7f6d9cb07a0 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6694
diff changeset
     3
/** @file road_cmd.cpp */
f7f6d9cb07a0 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6694
diff changeset
     4
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
#include "stdafx.h"
1891
92a3b0aa0946 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1785
diff changeset
     6
#include "openttd.h"
3189
1af302c5abd0 (svn r3846) Add functions to set the type of stuff (clear, water, rail, road) under bridges
tron
parents: 3176
diff changeset
     7
#include "bridge_map.h"
6486
4f8af35b11eb (svn r8908) -Codechange: declaration of DrawBridgeMiddle does not belong in a map accessors header.
rubidium
parents: 6460
diff changeset
     8
#include "bridge.h"
6460
b3017e083031 (svn r8876) -Fix
tron
parents: 6459
diff changeset
     9
#include "cmd_helper.h"
3101
e2fdb8802c2f (svn r3696) Add functions to turn a tile into a normal rail tile/depot/waypoint. This is just a tiny step, the rail code needs way more love and caring
tron
parents: 3100
diff changeset
    10
#include "rail_map.h"
3144
426b825578f9 (svn r3763) Adapt to the new 'map accessors go in foo_map.h'-scheme
tron
parents: 3104
diff changeset
    11
#include "road_map.h"
4232
628628eaa4fc (svn r5796) Use DrawTileSprites/DrawTileSeqStruct for road depot drawing data, too
tron
parents: 4231
diff changeset
    12
#include "sprite.h"
2008
c9d6585c96c8 (svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents: 1986
diff changeset
    13
#include "table/sprites.h"
507
8aa8100b0b22 (svn r815) Include strings.h only in the files which need it.
tron
parents: 497
diff changeset
    14
#include "table/strings.h"
7762
03721db0ac1c (svn r10587) -Codechange: move the string/dparam related stuff from variables.h to strings.h
rubidium
parents: 7719
diff changeset
    15
#include "strings.h"
2163
637ec3c361f5 (svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents: 2148
diff changeset
    16
#include "functions.h"
7353
716c6dd9322a (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 7310
diff changeset
    17
#include "window.h"
679
e959706a3e4d (svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents: 541
diff changeset
    18
#include "map.h"
6669
487ac09b95c4 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6585
diff changeset
    19
#include "landscape.h"
1209
a1ac96655b79 (svn r1713) Split off several functions which query/set information about a single tile from map.h and put them into a seperate file tile.h
tron
parents: 1095
diff changeset
    20
#include "tile.h"
3319
7d04847e4689 (svn r4085) Add GetTown{Index,ByTile}() to get the town index resp. the town from a tile
tron
parents: 3286
diff changeset
    21
#include "town_map.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    22
#include "vehicle.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    23
#include "viewport.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    24
#include "command.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    25
#include "player.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    26
#include "town.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    27
#include "gfx.h"
337
66647f97e7c0 (svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents: 241
diff changeset
    28
#include "sound.h"
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3884
diff changeset
    29
#include "yapf/yapf.h"
1313
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents: 1281
diff changeset
    30
#include "depot.h"
7037
3cd1bd7a6edb (svn r9730) -Feature: [NewGRF] Add support for miscellaneous grf feature bit 1 - paved roads on desert tiles.
maedhros
parents: 6987
diff changeset
    31
#include "newgrf.h"
7175
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
    32
#include "station_map.h"
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
    33
#include "tunnel_map.h"
7885
4eb9b01e37ff (svn r10758) -Codechange: make the depot struct use the pool item class as super class.
rubidium
parents: 7866
diff changeset
    34
#include "misc/autoptr.hpp"
8078
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
    35
#include "autoslope.h"
8345
6caa3fdb972c (svn r11399) -Feature(ette): transparency settings can now be saved and thus remembered.
belugas
parents: 8328
diff changeset
    36
#include "transparency.h"
8078
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
    37
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
    38
#define M(x) (1 << (x))
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
    39
/* Level crossings may only be built on these slopes */
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
    40
static const uint32 VALID_LEVEL_CROSSING_SLOPES = (M(SLOPE_SEN) | M(SLOPE_ENW) | M(SLOPE_NWS) | M(SLOPE_NS) | M(SLOPE_WSE) | M(SLOPE_EW) | M(SLOPE_FLAT));
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
    41
#undef M
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    42
7157
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 7122
diff changeset
    43
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
    44
{
3149
2b54fc654019 (svn r3770) Remove the _road_special_gettrackstatus hack. Egladil and me deem it unnecessary
tron
parents: 3146
diff changeset
    45
	RoadBits present;
2b54fc654019 (svn r3770) Remove the _road_special_gettrackstatus hack. Egladil and me deem it unnecessary
tron
parents: 3146
diff changeset
    46
	RoadBits n;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    47
	*edge_road = true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    48
7157
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 7122
diff changeset
    49
	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
    50
7247
78a25ab85148 (svn r9986) -Fix (r9934): flooding towns could not remove tram tracks (boekabart).
rubidium
parents: 7228
diff changeset
    51
	/* Water can always flood and towns can always remove "normal" road pieces.
78a25ab85148 (svn r9986) -Fix (r9934): flooding towns could not remove tram tracks (boekabart).
rubidium
parents: 7228
diff changeset
    52
	 * Towns are not be allowed to remove non "normal" road pieces, like tram
78a25ab85148 (svn r9986) -Fix (r9934): flooding towns could not remove tram tracks (boekabart).
rubidium
parents: 7228
diff changeset
    53
	 * tracks as that would result in trams that cannot turn. */
78a25ab85148 (svn r9986) -Fix (r9934): flooding towns could not remove tram tracks (boekabart).
rubidium
parents: 7228
diff changeset
    54
	if (_current_player == OWNER_WATER ||
78a25ab85148 (svn r9986) -Fix (r9934): flooding towns could not remove tram tracks (boekabart).
rubidium
parents: 7228
diff changeset
    55
			(rt == ROADTYPE_ROAD && !IsValidPlayer(_current_player))) return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    56
6889
f7f6d9cb07a0 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6694
diff changeset
    57
	/* Only do the special processing if the road is owned
f7f6d9cb07a0 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6694
diff changeset
    58
	 * by a town */
4849
9a3c3ae7f62f (svn r6775) -Codechange: Use some more proper types, especially Owner and PlayerID as
Darkvater
parents: 4848
diff changeset
    59
	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
    60
3017
915fae59d5e0 (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents: 2989
diff changeset
    61
	if (_cheats.magic_bulldozer.value) return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    62
6889
f7f6d9cb07a0 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6694
diff changeset
    63
	/* Get a bitmask of which neighbouring roads has a tile */
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
    64
	n = ROAD_NONE;
7157
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 7122
diff changeset
    65
	present = GetAnyRoadBits(tile, rt);
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 7122
diff changeset
    66
	if (present & ROAD_NE && GetAnyRoadBits(TILE_ADDXY(tile, -1,  0), rt) & ROAD_SW) n |= ROAD_NE;
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 7122
diff changeset
    67
	if (present & ROAD_SE && GetAnyRoadBits(TILE_ADDXY(tile,  0,  1), rt) & ROAD_NW) n |= ROAD_SE;
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 7122
diff changeset
    68
	if (present & ROAD_SW && GetAnyRoadBits(TILE_ADDXY(tile,  1,  0), rt) & ROAD_NE) n |= ROAD_SW;
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 7122
diff changeset
    69
	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
    70
6889
f7f6d9cb07a0 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6694
diff changeset
    71
	/* If 0 or 1 bits are set in n, or if no bits that match the bits to remove,
f7f6d9cb07a0 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6694
diff changeset
    72
	 * then allow it */
3149
2b54fc654019 (svn r3770) Remove the _road_special_gettrackstatus hack. Egladil and me deem it unnecessary
tron
parents: 3146
diff changeset
    73
	if ((n & (n - 1)) != 0 && (n & remove) != 0) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    74
		Town *t;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    75
		*edge_road = false;
6889
f7f6d9cb07a0 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6694
diff changeset
    76
		/* you can remove all kind of roads with extra dynamite */
3017
915fae59d5e0 (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents: 2989
diff changeset
    77
		if (_patches.extra_dynamite) return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    78
6582
5f66659ae048 (svn r9065) -Fix: possible dereference of NULL pointer.
rubidium
parents: 6574
diff changeset
    79
		t = ClosestTownFromTile(tile, (uint)-1);
1638
aae181b00846 (svn r2142) - Fix: Game no longer crashes when you want to remove a piece of road under a bridge that belongs to the town. TODO: railcrossings store owner somewhere else, put it into _map_owner[]!
Darkvater
parents: 1398
diff changeset
    80
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
    81
		SetDParam(0, t->index);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    82
		_error_message = STR_2009_LOCAL_AUTHORITY_REFUSES;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    83
		return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    84
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    85
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    86
	return true;
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
7157
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 7122
diff changeset
    89
static bool CheckAllowRemoveRoad(TileIndex tile, RoadBits remove, bool *edge_road, RoadType rt)
6442
10b44714b85d (svn r8852) -Fix (r8735): make the dynamite tool for drive through road stops as if it were removing a normal road tile (consider the local authority and such).
rubidium
parents: 6317
diff changeset
    90
{
7157
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 7122
diff changeset
    91
	return CheckAllowRemoveRoad(tile, remove, GetRoadOwner(tile, rt), edge_road, rt);
6442
10b44714b85d (svn r8852) -Fix (r8735): make the dynamite tool for drive through road stops as if it were removing a normal road tile (consider the local authority and such).
rubidium
parents: 6317
diff changeset
    92
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    93
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
    94
/** Delete a piece of road.
3491
4c8427796c64 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3435
diff changeset
    95
 * @param tile tile where to remove road from
6979
d194d25020e7 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6923
diff changeset
    96
 * @param flags operation to perform
6460
b3017e083031 (svn r8876) -Fix
tron
parents: 6459
diff changeset
    97
 * @param p1 bit 0..3 road pieces to remove (RoadBits)
7157
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 7122
diff changeset
    98
 *           bit 4..5 road type
7310
b835c3c702c1 (svn r10053) -Fix: could not clear a level-crossing tile with tram tracks.
rubidium
parents: 7264
diff changeset
    99
 *           bit    6 ignore the fact that the tram track has not been removed
b835c3c702c1 (svn r10053) -Fix: could not clear a level-crossing tile with tram tracks.
rubidium
parents: 7264
diff changeset
   100
 *                    yet when removing the road bits when not actually doing
b835c3c702c1 (svn r10053) -Fix: could not clear a level-crossing tile with tram tracks.
rubidium
parents: 7264
diff changeset
   101
 *                    it. Makes it possible to test whether the road bits can
b835c3c702c1 (svn r10053) -Fix: could not clear a level-crossing tile with tram tracks.
rubidium
parents: 7264
diff changeset
   102
 *                    be removed from a level crossing without physically
b835c3c702c1 (svn r10053) -Fix: could not clear a level-crossing tile with tram tracks.
rubidium
parents: 7264
diff changeset
   103
 *                    removing the tram bits before the test.
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   104
 * @param p2 unused
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   105
 */
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7353
diff changeset
   106
CommandCost 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
   107
{
6889
f7f6d9cb07a0 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6694
diff changeset
   108
	/* cost for removing inner/edge -roads */
1638
aae181b00846 (svn r2142) - Fix: Game no longer crashes when you want to remove a piece of road under a bridge that belongs to the town. TODO: railcrossings store owner somewhere else, put it into _map_owner[]!
Darkvater
parents: 1398
diff changeset
   109
	static const uint16 road_remove_cost[2] = {50, 18};
aae181b00846 (svn r2142) - Fix: Game no longer crashes when you want to remove a piece of road under a bridge that belongs to the town. TODO: railcrossings store owner somewhere else, put it into _map_owner[]!
Darkvater
parents: 1398
diff changeset
   110
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   111
	/* true if the roadpiece was always removeable,
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   112
	 * 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
   113
	bool edge_road;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   114
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   115
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   116
7157
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 7122
diff changeset
   117
	RoadType rt = (RoadType)GB(p1, 4, 2);
7175
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   118
	if (!IsValidRoadType(rt)) return CMD_ERROR;
2074
f23dcde246da (svn r2584) - Fix: Game no longer asserts when you use the remove-road tool on a town building or industry.
Darkvater
parents: 2049
diff changeset
   119
7719
7d381ffe9cca (svn r10502) -Fix [FS#1017]: trying to get the town from a tile that can never be associated with a town.
rubidium
parents: 7464
diff changeset
   120
	Town *t = NULL;
7175
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   121
	switch (GetTileType(tile)) {
7866
e19fda04e8d3 (svn r10733) -Codechange: change MP_STREET into MP_ROAD as we use the word "road" everywhere except in the tile type.
rubidium
parents: 7851
diff changeset
   122
		case MP_ROAD:
7719
7d381ffe9cca (svn r10502) -Fix [FS#1017]: trying to get the town from a tile that can never be associated with a town.
rubidium
parents: 7464
diff changeset
   123
			if (_game_mode != GM_EDITOR && GetRoadOwner(tile, rt) == OWNER_TOWN) t = GetTownByTile(tile);
7175
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   124
			break;
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   125
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   126
		case MP_STATION:
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   127
			if (!IsDriveThroughStopTile(tile)) return CMD_ERROR;
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   128
			break;
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   129
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   130
		case MP_TUNNELBRIDGE:
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   131
			if ((IsTunnel(tile) && GetTunnelTransportType(tile) != TRANSPORT_ROAD) ||
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   132
					(IsBridge(tile) && GetBridgeTransportType(tile) != TRANSPORT_ROAD)) return CMD_ERROR;
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   133
			break;
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   134
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   135
		default:
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   136
			return CMD_ERROR;
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   137
	}
1638
aae181b00846 (svn r2142) - Fix: Game no longer crashes when you want to remove a piece of road under a bridge that belongs to the town. TODO: railcrossings store owner somewhere else, put it into _map_owner[]!
Darkvater
parents: 1398
diff changeset
   138
6460
b3017e083031 (svn r8876) -Fix
tron
parents: 6459
diff changeset
   139
	RoadBits pieces = Extract<RoadBits, 0>(p1);
7157
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 7122
diff changeset
   140
	RoadTypes rts = GetRoadTypes(tile);
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 7122
diff changeset
   141
	/* The tile doesn't have the given road type */
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8353
diff changeset
   142
	if (!HasBit(rts, rt)) return CMD_ERROR;
6460
b3017e083031 (svn r8876) -Fix
tron
parents: 6459
diff changeset
   143
7157
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 7122
diff changeset
   144
	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
   145
6902
9da0ee122fd5 (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: 6889
diff changeset
   146
	if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
3933
a5f08e17f4a0 (svn r5070) Merged the bridge branch
celestar
parents: 3900
diff changeset
   147
6889
f7f6d9cb07a0 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6694
diff changeset
   148
	/* check if you're allowed to remove the street owned by a town
f7f6d9cb07a0 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6694
diff changeset
   149
	 * removal allowance depends on difficulty setting */
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   150
	if (!CheckforTownRating(flags, t, ROAD_REMOVE)) return CMD_ERROR;
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   151
7866
e19fda04e8d3 (svn r10733) -Codechange: change MP_STREET into MP_ROAD as we use the word "road" everywhere except in the tile type.
rubidium
parents: 7851
diff changeset
   152
	if (!IsTileType(tile, MP_ROAD)) {
7175
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   153
		/* If it's the last roadtype, just clear the whole tile */
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   154
		if (rts == RoadTypeToRoadTypes(rt)) return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   155
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7353
diff changeset
   156
		CommandCost cost;
7175
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   157
		if (IsTileType(tile, MP_TUNNELBRIDGE)) {
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   158
			TileIndex other_end = IsTunnel(tile) ? GetOtherTunnelEnd(tile) : GetOtherBridgeEnd(tile);
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   159
			/* Pay for *every* tile of the bridge or tunnel */
7446
1c4d469f986e (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 7442
diff changeset
   160
			cost.AddCost((DistanceManhattan(IsTunnel(tile) ? GetOtherTunnelEnd(tile) : GetOtherBridgeEnd(tile), tile) + 1) * _price.remove_road);
7175
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   161
			if (flags & DC_EXEC) {
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   162
				SetRoadTypes(other_end, GetRoadTypes(other_end) & ~RoadTypeToRoadTypes(rt));
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   163
				SetRoadTypes(tile, GetRoadTypes(tile) & ~RoadTypeToRoadTypes(rt));
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   164
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   165
				/* Mark tiles diry that have been repaved */
7210
508c55fdc09e (svn r9946) -Fix: more places that weren't correctly marked dirty...
rubidium
parents: 7209
diff changeset
   166
				MarkTileDirtyByTile(tile);
7175
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   167
				MarkTileDirtyByTile(other_end);
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   168
				if (IsBridge(tile)) {
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   169
					TileIndexDiff delta = TileOffsByDiagDir(GetBridgeRampDirection(tile));
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   170
7209
52241eea3899 (svn r9945) -Fix: bridges were not properly marked dirty when adding/removing roadtypes.
rubidium
parents: 7207
diff changeset
   171
					for (TileIndex t = tile + delta; t != other_end; t += delta) MarkTileDirtyByTile(t);
7175
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   172
				}
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   173
			}
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   174
		} else {
7446
1c4d469f986e (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 7442
diff changeset
   175
			cost.AddCost(_price.remove_road);
7175
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   176
			if (flags & DC_EXEC) {
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   177
				SetRoadTypes(tile, GetRoadTypes(tile) & ~RoadTypeToRoadTypes(rt));
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   178
				MarkTileDirtyByTile(tile);
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   179
			}
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   180
		}
7446
1c4d469f986e (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 7442
diff changeset
   181
		return CommandCost(cost);
7175
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   182
	}
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   183
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   184
	switch (GetRoadTileType(tile)) {
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   185
		case ROAD_TILE_NORMAL: {
7157
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 7122
diff changeset
   186
			RoadBits present = GetRoadBits(tile, rt);
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   187
			RoadBits c = pieces;
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   188
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   189
			if (HasRoadWorks(tile)) return_cmd_error(STR_ROAD_WORKS_IN_PROGRESS);
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   190
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   191
			if (GetTileSlope(tile, NULL) != SLOPE_FLAT  &&
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   192
					(present == ROAD_Y || present == ROAD_X)) {
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   193
				c |= (RoadBits)((c & 0xC) >> 2);
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   194
				c |= (RoadBits)((c & 0x3) << 2);
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   195
			}
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   196
6889
f7f6d9cb07a0 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6694
diff changeset
   197
			/* limit the bits to delete to the existing bits. */
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   198
			c &= present;
7158
ffb31324aa5e (svn r9893) -Fix (r9892): various small bugs that only act up when using something different than plain roads.
rubidium
parents: 7157
diff changeset
   199
			if (c == ROAD_NONE) return CMD_ERROR;
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   200
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   201
			if (flags & DC_EXEC) {
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   202
				ChangeTownRating(t, -road_remove_cost[(byte)edge_road], RATING_ROAD_MINIMUM);
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   203
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   204
				present ^= c;
7158
ffb31324aa5e (svn r9893) -Fix (r9892): various small bugs that only act up when using something different than plain roads.
rubidium
parents: 7157
diff changeset
   205
				if (present == ROAD_NONE) {
7157
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 7122
diff changeset
   206
					RoadTypes rts = GetRoadTypes(tile) & ComplementRoadTypes(RoadTypeToRoadTypes(rt));
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 7122
diff changeset
   207
					if (rts == ROADTYPES_NONE) {
8032
0901aabd9aef (svn r11056) -Fix [FS#1213]: road/tram tiles would not always get marked dirty properly, causing glitches for non-local players. Patch by SmatZ.
rubidium
parents: 8012
diff changeset
   208
						/* Includes MarkTileDirtyByTile() */
7157
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 7122
diff changeset
   209
						DoClearSquare(tile);
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 7122
diff changeset
   210
					} else {
7158
ffb31324aa5e (svn r9893) -Fix (r9892): various small bugs that only act up when using something different than plain roads.
rubidium
parents: 7157
diff changeset
   211
						SetRoadBits(tile, ROAD_NONE, rt);
7157
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 7122
diff changeset
   212
						SetRoadTypes(tile, rts);
8032
0901aabd9aef (svn r11056) -Fix [FS#1213]: road/tram tiles would not always get marked dirty properly, causing glitches for non-local players. Patch by SmatZ.
rubidium
parents: 8012
diff changeset
   213
						MarkTileDirtyByTile(tile);
7157
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 7122
diff changeset
   214
					}
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   215
				} else {
7260
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7257
diff changeset
   216
					/* When bits are removed, you *always* end up with something that
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7257
diff changeset
   217
					 * is not a complete straight road tile. However, trams do not have
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7257
diff changeset
   218
					 * onewayness, so they cannot remove it either. */
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7257
diff changeset
   219
					if (rt != ROADTYPE_TRAM) SetDisallowedRoadDirections(tile, DRD_NONE);
7157
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 7122
diff changeset
   220
					SetRoadBits(tile, present, rt);
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   221
					MarkTileDirtyByTile(tile);
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   222
				}
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   223
			}
8328
6909973c8359 (svn r11382) -Codechange: renamed COUNTBITS to CountBits, as it is no longer a macro (skidd13)
truelight
parents: 8315
diff changeset
   224
			return CommandCost(CountBits(c) * _price.remove_road);
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   225
		}
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   226
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   227
		case ROAD_TILE_CROSSING: {
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   228
			if (pieces & ComplementRoadBits(GetCrossingRoadBits(tile))) {
3176
c125ec95763a (svn r3812) Remove a pointless goto
tron
parents: 3167
diff changeset
   229
				return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   230
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   231
7193
e0cdd5c824dd (svn r9929) -Fix [FS#803]: fix several drawing issues.
rubidium
parents: 7187
diff changeset
   232
			/* Don't allow road to be removed from the crossing when there is tram;
e0cdd5c824dd (svn r9929) -Fix [FS#803]: fix several drawing issues.
rubidium
parents: 7187
diff changeset
   233
			 * we can't draw the crossing without trambits ;) */
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8353
diff changeset
   234
			if (rt == ROADTYPE_ROAD && HasBit(GetRoadTypes(tile), ROADTYPE_TRAM) && ((flags & DC_EXEC) || !HasBit(p1, 6))) return CMD_ERROR;
7193
e0cdd5c824dd (svn r9929) -Fix [FS#803]: fix several drawing issues.
rubidium
parents: 7187
diff changeset
   235
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   236
			if (flags & DC_EXEC) {
7157
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 7122
diff changeset
   237
				if (rt == ROADTYPE_ROAD) {
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 7122
diff changeset
   238
					ChangeTownRating(t, -road_remove_cost[(byte)edge_road], RATING_ROAD_MINIMUM);
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 7122
diff changeset
   239
				}
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   240
7157
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 7122
diff changeset
   241
				RoadTypes rts = GetRoadTypes(tile) & ComplementRoadTypes(RoadTypeToRoadTypes(rt));
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 7122
diff changeset
   242
				if (rts == ROADTYPES_NONE) {
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 7122
diff changeset
   243
					MakeRailNormal(tile, GetTileOwner(tile), GetCrossingRailBits(tile), GetRailType(tile));
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 7122
diff changeset
   244
				} else {
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 7122
diff changeset
   245
					SetRoadTypes(tile, rts);
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 7122
diff changeset
   246
				}
3060
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   247
				MarkTileDirtyByTile(tile);
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   248
				YapfNotifyTrackLayoutChange(tile, FindFirstTrack(GetTrackBits(tile)));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   249
			}
7446
1c4d469f986e (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 7442
diff changeset
   250
			return CommandCost(_price.remove_road * 2);
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   251
		}
3977
edb5b94e2094 (svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents: 3933
diff changeset
   252
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   253
		default:
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   254
		case ROAD_TILE_DEPOT:
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   255
			return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   256
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   257
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   258
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   259
3104
106ca8c3d959 (svn r3699) Replace some magic numbers for checking for a suitable slope for a level crossing by some less magic numbers
tron
parents: 3103
diff changeset
   260
static const RoadBits _valid_tileh_slopes_road[][15] = {
6889
f7f6d9cb07a0 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6694
diff changeset
   261
	/* set of normal ones */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   262
	{
8137
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   263
		ROAD_ALL,  // SLOPE_FLAT
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   264
		ROAD_NONE, // SLOPE_W
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   265
		ROAD_NONE, // SLOPE_S
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   266
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   267
		ROAD_X,    // SLOPE_SW
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   268
		ROAD_NONE, // SLOPE_E
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   269
		ROAD_NONE, // SLOPE_EW
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   270
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   271
		ROAD_Y,    // SLOPE_SE
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   272
		ROAD_NONE, // SLOPE_WSE
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   273
		ROAD_NONE, // SLOPE_N
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   274
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   275
		ROAD_Y,    // SLOPE_NW
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   276
		ROAD_NONE, // SLOPE_NS
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   277
		ROAD_NONE, // SLOPE_NE
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   278
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   279
		ROAD_X,    // SLOPE_ENW
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   280
		ROAD_NONE, // SLOPE_SEN
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   281
		ROAD_NONE  // SLOPE_ELEVATED
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   282
	},
6889
f7f6d9cb07a0 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6694
diff changeset
   283
	/* 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
   284
	{
8137
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   285
		ROAD_NONE,         // SLOPE_FLAT
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   286
		ROAD_SW | ROAD_NW, // SLOPE_W
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   287
		ROAD_SW | ROAD_SE, // SLOPE_S
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   288
8137
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   289
		ROAD_Y  | ROAD_SW, // SLOPE_SW
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   290
		ROAD_SE | ROAD_NE, // SLOPE_E
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   291
		ROAD_ALL,          // SLOPE_EW
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   292
8137
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   293
		ROAD_X  | ROAD_SE, // SLOPE_SE
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   294
		ROAD_ALL,          // SLOPE_WSE
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   295
		ROAD_NW | ROAD_NE, // SLOPE_N
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   296
8137
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   297
		ROAD_X  | ROAD_NW, // SLOPE_NW
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   298
		ROAD_ALL,          // SLOPE_NS
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   299
		ROAD_ALL,          // SLOPE_NE
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   300
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   301
		ROAD_Y  | ROAD_NE, // SLOPE_ENW
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   302
		ROAD_ALL,          // SLOPE_SEN
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   303
		ROAD_ALL           // SLOPE_ELEVATED
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   304
	},
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   305
	/* Singe bits on slopes */
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   306
	{
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   307
		ROAD_ALL,          // SLOPE_FLAT
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   308
		ROAD_NE | ROAD_SE, // SLOPE_W
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   309
		ROAD_NE | ROAD_NW, // SLOPE_S
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   310
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   311
		ROAD_NE,           // SLOPE_SW
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   312
		ROAD_NW | ROAD_SW, // SLOPE_E
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   313
		ROAD_ALL,          // SLOPE_EW
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   314
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   315
		ROAD_NW,           // SLOPE_SE
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   316
		ROAD_ALL,          // SLOPE_WSE
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   317
		ROAD_SE | ROAD_SW, // SLOPE_N
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   318
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   319
		ROAD_SE,           // SLOPE_NW
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   320
		ROAD_ALL,          // SLOPE_NS
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   321
		ROAD_ALL,          // SLOPE_NE
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   322
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   323
		ROAD_SW,           // SLOPE_ENW
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   324
		ROAD_ALL,          // SLOPE_SEN
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   325
		ROAD_ALL,          // SLOPE_ELEVATED
13
3e7c1f74a996 (svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents: 0
diff changeset
   326
	},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   327
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   328
8137
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   329
/**
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   330
 * Calculate the costs for roads on slopes
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   331
 *  Aside modify the RoadBits to fit on the slopes
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   332
 *
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   333
 * @note The RoadBits are modified too!
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   334
 * @param tileh The current slope
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   335
 * @param pieces The RoadBits we want to add
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   336
 * @param existing The existent RoadBits
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   337
 * @return The costs for these RoadBits on this slope
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   338
 */
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7353
diff changeset
   339
static CommandCost CheckRoadSlope(Slope tileh, RoadBits* pieces, RoadBits existing)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   340
{
4246
14a8849c32df (svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents: 4232
diff changeset
   341
	if (IsSteepSlope(tileh)) {
8137
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   342
		/* Force straight roads. */
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   343
		*pieces |= MirrorRoadBits(*pieces);
7828
b78d1fab57da (svn r10695) -Fix [FS#1079]: building single pieces of road over tramtrack or vice versa on slopes did not work as expected.
rubidium
parents: 7762
diff changeset
   344
8137
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   345
		if (existing == ROAD_NONE || existing == *pieces) {
4246
14a8849c32df (svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents: 4232
diff changeset
   346
			if (*pieces == ROAD_X || *pieces == ROAD_Y) return _price.terraform;
14a8849c32df (svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents: 4232
diff changeset
   347
		}
14a8849c32df (svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents: 4232
diff changeset
   348
		return CMD_ERROR;
14a8849c32df (svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents: 4232
diff changeset
   349
	}
8137
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   350
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   351
	RoadBits road_bits = *pieces | existing;
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   352
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   353
	/* Single bits on slopes.
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   354
	 * We check for the roads that need at least 2 bits */
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   355
	if (_patches.build_on_slopes && !_is_old_ai_player &&
8328
6909973c8359 (svn r11382) -Codechange: renamed COUNTBITS to CountBits, as it is no longer a macro (skidd13)
truelight
parents: 8315
diff changeset
   356
			existing == ROAD_NONE && CountBits(*pieces) == 1 &&
8137
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   357
			(_valid_tileh_slopes_road[2][tileh] & *pieces) == ROAD_NONE) {
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   358
		return CommandCost(_price.terraform);
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   359
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   360
6889
f7f6d9cb07a0 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6694
diff changeset
   361
	/* no special foundation */
8137
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   362
	if ((~_valid_tileh_slopes_road[0][tileh] & road_bits) == ROAD_NONE) {
6889
f7f6d9cb07a0 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6694
diff changeset
   363
		/* force that all bits are set when we have slopes */
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3560
diff changeset
   364
		if (tileh != SLOPE_FLAT) *pieces |= _valid_tileh_slopes_road[0][tileh];
7446
1c4d469f986e (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 7442
diff changeset
   365
		return CommandCost(); // no extra cost
3381
ebdcc12845c7 (svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents: 3379
diff changeset
   366
	}
ebdcc12845c7 (svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents: 3379
diff changeset
   367
6889
f7f6d9cb07a0 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6694
diff changeset
   368
	/* foundation is used. Whole tile is leveled up */
8137
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   369
	if ((~_valid_tileh_slopes_road[1][tileh] & road_bits) == ROAD_NONE) {
8259
127e5d73637d (svn r11312) -Codechange: implement a overflow safe integer and use that for money and don't misuses CommandCost to have a overflow safe integer. Based on a patch by Noldo.
rubidium
parents: 8254
diff changeset
   370
		return CommandCost(existing != ROAD_NONE ? (Money)0 : _price.terraform);
3381
ebdcc12845c7 (svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents: 3379
diff changeset
   371
	}
ebdcc12845c7 (svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents: 3379
diff changeset
   372
8137
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   373
	/* Force straight roads. */
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   374
	*pieces |= MirrorRoadBits(*pieces);
7828
b78d1fab57da (svn r10695) -Fix [FS#1079]: building single pieces of road over tramtrack or vice versa on slopes did not work as expected.
rubidium
parents: 7762
diff changeset
   375
6889
f7f6d9cb07a0 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6694
diff changeset
   376
	/* partly leveled up tile, only if there's no road on that tile */
8137
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
   377
	if ((existing == ROAD_NONE || existing == *pieces) && (tileh == SLOPE_W || tileh == SLOPE_S || tileh == SLOPE_E || tileh == SLOPE_N)) {
3381
ebdcc12845c7 (svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents: 3379
diff changeset
   378
		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
   379
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   380
	return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   381
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   382
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   383
/** Build a piece of road.
3491
4c8427796c64 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3435
diff changeset
   384
 * @param tile tile where to build road
6979
d194d25020e7 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6923
diff changeset
   385
 * @param flags operation to perform
6460
b3017e083031 (svn r8876) -Fix
tron
parents: 6459
diff changeset
   386
 * @param p1 bit 0..3 road pieces to build (RoadBits)
7157
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 7122
diff changeset
   387
 *           bit 4..5 road type
7260
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7257
diff changeset
   388
 *           bit 6..7 disallowed directions to toggle
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   389
 * @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
   390
 */
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7353
diff changeset
   391
CommandCost 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
   392
{
7446
1c4d469f986e (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 7442
diff changeset
   393
	CommandCost cost;
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7353
diff changeset
   394
	CommandCost ret;
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   395
	RoadBits existing = ROAD_NONE;
7211
2e9a89c80c8d (svn r9947) -Fix [FS#807]: don't check whether roadbits may be built when they are already built for another type.
rubidium
parents: 7210
diff changeset
   396
	RoadBits all_bits = ROAD_NONE;
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3560
diff changeset
   397
	Slope tileh;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   398
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   399
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   400
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   401
	/* Road pieces are max 4 bitset values (NE, NW, SE, SW) and town can only be non-zero
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   402
	 * if a non-player is building the road */
6460
b3017e083031 (svn r8876) -Fix
tron
parents: 6459
diff changeset
   403
	if ((IsValidPlayer(_current_player) && p2 != 0) || (_current_player == OWNER_TOWN && !IsValidTownID(p2))) return CMD_ERROR;
b3017e083031 (svn r8876) -Fix
tron
parents: 6459
diff changeset
   404
b3017e083031 (svn r8876) -Fix
tron
parents: 6459
diff changeset
   405
	RoadBits pieces = Extract<RoadBits, 0>(p1);
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   406
7157
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 7122
diff changeset
   407
	RoadType rt = (RoadType)GB(p1, 4, 2);
8353
49a1d9b9d937 (svn r11407) -Fix: do not allow building of tram-tracks when they are not available (SmatZ)
truelight
parents: 8345
diff changeset
   408
	if (!IsValidRoadType(rt) || !ValParamRoadType(rt)) return CMD_ERROR;
7157
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 7122
diff changeset
   409
7260
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7257
diff changeset
   410
	DisallowedRoadDirections toggle_drd = (DisallowedRoadDirections)GB(p1, 6, 2);
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7257
diff changeset
   411
3434
21094a78dcdb (svn r4263) -Codechange: Road building no longer uses FindLandscapeHeight. Last occurence of FindLandscapeTile in the tile-specific functions gone. Thanks to Tron for doing lots of work in this direction
celestar
parents: 3430
diff changeset
   412
	tileh = GetTileSlope(tile, NULL);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   413
3434
21094a78dcdb (svn r4263) -Codechange: Road building no longer uses FindLandscapeHeight. Last occurence of FindLandscapeTile in the tile-specific functions gone. Thanks to Tron for doing lots of work in this direction
celestar
parents: 3430
diff changeset
   414
	switch (GetTileType(tile)) {
7866
e19fda04e8d3 (svn r10733) -Codechange: change MP_STREET into MP_ROAD as we use the word "road" everywhere except in the tile type.
rubidium
parents: 7851
diff changeset
   415
		case MP_ROAD:
3793
33cdb5bf7b21 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3792
diff changeset
   416
			switch (GetRoadTileType(tile)) {
7260
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7257
diff changeset
   417
				case ROAD_TILE_NORMAL: {
4046
566de0b02064 (svn r5315) -Fix: Prohibit altering a road tile while road works are in progress
tron
parents: 4000
diff changeset
   418
					if (HasRoadWorks(tile)) return_cmd_error(STR_ROAD_WORKS_IN_PROGRESS);
7252
9a5ca22a83c8 (svn r9991) -Fix: one could build road when trams were driving on the tile and vice versa.
rubidium
parents: 7247
diff changeset
   419
					if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
9a5ca22a83c8 (svn r9991) -Fix: one could build road when trams were driving on the tile and vice versa.
rubidium
parents: 7247
diff changeset
   420
7215
ef3e4b2bc075 (svn r9951) -Fix: slope check was incomplete when building road over tram track (and vice-versa)
glx
parents: 7213
diff changeset
   421
					all_bits = GetAllRoadBits(tile);
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8353
diff changeset
   422
					if (!HasBit(GetRoadTypes(tile), rt)) break;
4046
566de0b02064 (svn r5315) -Fix: Prohibit altering a road tile while road works are in progress
tron
parents: 4000
diff changeset
   423
7157
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 7122
diff changeset
   424
					existing = GetRoadBits(tile, rt);
7260
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7257
diff changeset
   425
					RoadBits merged = existing | pieces;
7264
6e0199b059b9 (svn r10004) -Fix: trams can always intersect/have junctions on one way roads (because they only work for busses and lorries).
rubidium
parents: 7260
diff changeset
   426
					bool crossing = (merged != ROAD_X && merged != ROAD_Y);
6e0199b059b9 (svn r10004) -Fix: trams can always intersect/have junctions on one way roads (because they only work for busses and lorries).
rubidium
parents: 7260
diff changeset
   427
					if (rt != ROADTYPE_TRAM && (GetDisallowedRoadDirections(tile) != DRD_NONE || toggle_drd != DRD_NONE) && crossing) {
7260
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7257
diff changeset
   428
						/* Junctions cannot be one-way */
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7257
diff changeset
   429
						return_cmd_error(STR_ERR_ONEWAY_ROADS_CAN_T_HAVE_JUNCTION);
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7257
diff changeset
   430
					}
3150
025fe8cd7104 (svn r3773) Shove some semantics down ottd's throat by replacing ints and magic numbers by enums and some related changes
tron
parents: 3149
diff changeset
   431
					if ((existing & pieces) == pieces) {
7260
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7257
diff changeset
   432
						/* We only want to set the (dis)allowed road directions */
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7257
diff changeset
   433
						if (toggle_drd != DRD_NONE && rt != ROADTYPE_TRAM && GetRoadOwner(tile, ROADTYPE_ROAD) == _current_player) {
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7257
diff changeset
   434
							if (crossing) return_cmd_error(STR_ERR_ONEWAY_ROADS_CAN_T_HAVE_JUNCTION);
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7257
diff changeset
   435
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7257
diff changeset
   436
							/* Ignore half built tiles */
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7257
diff changeset
   437
							if (flags & DC_EXEC && rt != ROADTYPE_TRAM && (existing == ROAD_X || existing == ROAD_Y)) {
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7257
diff changeset
   438
								SetDisallowedRoadDirections(tile, GetDisallowedRoadDirections(tile) ^ toggle_drd);
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7257
diff changeset
   439
								MarkTileDirtyByTile(tile);
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7257
diff changeset
   440
							}
7446
1c4d469f986e (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 7442
diff changeset
   441
							return CommandCost();
7260
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7257
diff changeset
   442
						}
3066
0d34dff23d98 (svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents: 3061
diff changeset
   443
						return_cmd_error(STR_1007_ALREADY_BUILT);
0d34dff23d98 (svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents: 3061
diff changeset
   444
					}
7260
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7257
diff changeset
   445
				} break;
3066
0d34dff23d98 (svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents: 3061
diff changeset
   446
3793
33cdb5bf7b21 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3792
diff changeset
   447
				case ROAD_TILE_CROSSING:
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8353
diff changeset
   448
					if (HasBit(GetRoadTypes(tile), rt)) return_cmd_error(STR_1007_ALREADY_BUILT);
7211
2e9a89c80c8d (svn r9947) -Fix [FS#807]: don't check whether roadbits may be built when they are already built for another type.
rubidium
parents: 7210
diff changeset
   449
					all_bits = GetCrossingRoadBits(tile);
2e9a89c80c8d (svn r9947) -Fix [FS#807]: don't check whether roadbits may be built when they are already built for another type.
rubidium
parents: 7210
diff changeset
   450
					if (pieces & ComplementRoadBits(all_bits)) goto do_clear;
7157
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 7122
diff changeset
   451
					break;
3066
0d34dff23d98 (svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents: 3061
diff changeset
   452
3069
0e6aca11c3da (svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents: 3068
diff changeset
   453
				default:
3793
33cdb5bf7b21 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3792
diff changeset
   454
				case ROAD_TILE_DEPOT:
3066
0d34dff23d98 (svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents: 3061
diff changeset
   455
					goto do_clear;
3060
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   456
			}
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   457
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   458
3060
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   459
		case MP_RAILWAY: {
3099
374e275300e3 (svn r3689) Add functions to turn a tile into either a normal road tile, a level crossing or a road depot
tron
parents: 3098
diff changeset
   460
			Axis roaddir;
13
3e7c1f74a996 (svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents: 0
diff changeset
   461
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3560
diff changeset
   462
			if (IsSteepSlope(tileh)) {
3060
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   463
				return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   464
			}
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   465
3104
106ca8c3d959 (svn r3699) Replace some magic numbers for checking for a suitable slope for a level crossing by some less magic numbers
tron
parents: 3103
diff changeset
   466
			/* Level crossings may only be built on these slopes */
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8353
diff changeset
   467
			if (!HasBit(VALID_LEVEL_CROSSING_SLOPES, tileh)) {
3060
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   468
				return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   469
			}
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   470
3792
2eb8388731bf (svn r4788) - Codechange: RAILTYPE_{NORMAL,ELECTRIC,...} and RAIL_TYPE_{NORMAL,SIGNAL,...} have nearly the same name, rename RAIL_TYPE_* to RAIL_TILE_* of extra clarity
rubidium
parents: 3673
diff changeset
   471
			if (GetRailTileType(tile) != RAIL_TILE_NORMAL) goto do_clear;
3269
95e7bffcb3c5 (svn r3981) More work for the rail accessing functions and enums
tron
parents: 3267
diff changeset
   472
			switch (GetTrackBits(tile)) {
95e7bffcb3c5 (svn r3981) More work for the rail accessing functions and enums
tron
parents: 3267
diff changeset
   473
				case TRACK_BIT_X:
95e7bffcb3c5 (svn r3981) More work for the rail accessing functions and enums
tron
parents: 3267
diff changeset
   474
					if (pieces & ROAD_X) goto do_clear;
95e7bffcb3c5 (svn r3981) More work for the rail accessing functions and enums
tron
parents: 3267
diff changeset
   475
					roaddir = AXIS_Y;
95e7bffcb3c5 (svn r3981) More work for the rail accessing functions and enums
tron
parents: 3267
diff changeset
   476
					break;
95e7bffcb3c5 (svn r3981) More work for the rail accessing functions and enums
tron
parents: 3267
diff changeset
   477
95e7bffcb3c5 (svn r3981) More work for the rail accessing functions and enums
tron
parents: 3267
diff changeset
   478
				case TRACK_BIT_Y:
95e7bffcb3c5 (svn r3981) More work for the rail accessing functions and enums
tron
parents: 3267
diff changeset
   479
					if (pieces & ROAD_Y) goto do_clear;
95e7bffcb3c5 (svn r3981) More work for the rail accessing functions and enums
tron
parents: 3267
diff changeset
   480
					roaddir = AXIS_X;
95e7bffcb3c5 (svn r3981) More work for the rail accessing functions and enums
tron
parents: 3267
diff changeset
   481
					break;
95e7bffcb3c5 (svn r3981) More work for the rail accessing functions and enums
tron
parents: 3267
diff changeset
   482
95e7bffcb3c5 (svn r3981) More work for the rail accessing functions and enums
tron
parents: 3267
diff changeset
   483
				default: goto do_clear;
3060
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   484
			}
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   485
6902
9da0ee122fd5 (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: 6889
diff changeset
   486
			if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
3381
ebdcc12845c7 (svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents: 3379
diff changeset
   487
3060
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   488
			if (flags & DC_EXEC) {
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   489
				YapfNotifyTrackLayoutChange(tile, FindFirstTrack(GetTrackBits(tile)));
7193
e0cdd5c824dd (svn r9929) -Fix [FS#803]: fix several drawing issues.
rubidium
parents: 7187
diff changeset
   490
				/* Always add road to the roadtypes (can't draw without it) */
e0cdd5c824dd (svn r9929) -Fix [FS#803]: fix several drawing issues.
rubidium
parents: 7187
diff changeset
   491
				MakeRoadCrossing(tile, _current_player, _current_player, _current_player, GetTileOwner(tile), roaddir, GetRailType(tile), RoadTypeToRoadTypes(rt) | ROADTYPES_ROAD, p2);
3100
552cf19c49cb (svn r3695) Add 2 MarkTileByTile() which I forgot in r3689 (noticed by Belugas)
tron
parents: 3099
diff changeset
   492
				MarkTileDirtyByTile(tile);
3060
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   493
			}
7446
1c4d469f986e (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 7442
diff changeset
   494
			return CommandCost(_price.build_road * (rt == ROADTYPE_ROAD ? 2 : 4));
3017
915fae59d5e0 (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents: 2989
diff changeset
   495
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   496
7175
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   497
		case MP_STATION:
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   498
			if (!IsDriveThroughStopTile(tile)) return CMD_ERROR;
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8353
diff changeset
   499
			if (HasBit(GetRoadTypes(tile), rt)) return_cmd_error(STR_1007_ALREADY_BUILT);
7257
18c8b085008d (svn r9996) -Fix: be more strict when building/upgrading roads and/or road stops.
rubidium
parents: 7252
diff changeset
   500
			/* Don't allow "upgrading" the roadstop when vehicles are already driving on it */
18c8b085008d (svn r9996) -Fix: be more strict when building/upgrading roads and/or road stops.
rubidium
parents: 7252
diff changeset
   501
			if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
7175
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   502
			break;
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   503
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   504
		case MP_TUNNELBRIDGE:
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   505
			if ((IsTunnel(tile) && GetTunnelTransportType(tile) != TRANSPORT_ROAD) ||
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   506
					(IsBridge(tile) && GetBridgeTransportType(tile) != TRANSPORT_ROAD)) return CMD_ERROR;
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8353
diff changeset
   507
			if (HasBit(GetRoadTypes(tile), rt)) return_cmd_error(STR_1007_ALREADY_BUILT);
7257
18c8b085008d (svn r9996) -Fix: be more strict when building/upgrading roads and/or road stops.
rubidium
parents: 7252
diff changeset
   508
			/* Don't allow "upgrading" the bridge/tunnel when vehicles are already driving on it */
18c8b085008d (svn r9996) -Fix: be more strict when building/upgrading roads and/or road stops.
rubidium
parents: 7252
diff changeset
   509
			if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
7175
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   510
			break;
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   511
3060
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   512
		default:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   513
do_clear:;
3491
4c8427796c64 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3435
diff changeset
   514
			ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
3381
ebdcc12845c7 (svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents: 3379
diff changeset
   515
			if (CmdFailed(ret)) return ret;
7446
1c4d469f986e (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 7442
diff changeset
   516
			cost.AddCost(ret);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   517
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   518
7212
1922cfdc28b8 (svn r9948) -Fix (r9947): building illegal roads on slopes. Why do 'fixes' always have the tendancy to backfire?
rubidium
parents: 7211
diff changeset
   519
	if (all_bits != pieces) {
7211
2e9a89c80c8d (svn r9947) -Fix [FS#807]: don't check whether roadbits may be built when they are already built for another type.
rubidium
parents: 7210
diff changeset
   520
		/* Check the foundation/slopes when adding road/tram bits */
2e9a89c80c8d (svn r9947) -Fix [FS#807]: don't check whether roadbits may be built when they are already built for another type.
rubidium
parents: 7210
diff changeset
   521
		ret = CheckRoadSlope(tileh, &pieces, all_bits | existing);
2e9a89c80c8d (svn r9947) -Fix [FS#807]: don't check whether roadbits may be built when they are already built for another type.
rubidium
parents: 7210
diff changeset
   522
		/* Return an error if we need to build a foundation (ret != 0) but the
2e9a89c80c8d (svn r9947) -Fix [FS#807]: don't check whether roadbits may be built when they are already built for another type.
rubidium
parents: 7210
diff changeset
   523
		 * current patch-setting is turned off (or stupid AI@work) */
7446
1c4d469f986e (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 7442
diff changeset
   524
		if (CmdFailed(ret) || (ret.GetCost() != 0 && (!_patches.build_on_slopes || _is_old_ai_player))) {
7211
2e9a89c80c8d (svn r9947) -Fix [FS#807]: don't check whether roadbits may be built when they are already built for another type.
rubidium
parents: 7210
diff changeset
   525
			return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
2e9a89c80c8d (svn r9947) -Fix [FS#807]: don't check whether roadbits may be built when they are already built for another type.
rubidium
parents: 7210
diff changeset
   526
		}
7446
1c4d469f986e (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 7442
diff changeset
   527
		cost.AddCost(ret);
7211
2e9a89c80c8d (svn r9947) -Fix [FS#807]: don't check whether roadbits may be built when they are already built for another type.
rubidium
parents: 7210
diff changeset
   528
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   529
7866
e19fda04e8d3 (svn r10733) -Codechange: change MP_STREET into MP_ROAD as we use the word "road" everywhere except in the tile type.
rubidium
parents: 7851
diff changeset
   530
	if (IsTileType(tile, MP_ROAD)) {
6889
f7f6d9cb07a0 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6694
diff changeset
   531
		/* Don't put the pieces that already exist */
3150
025fe8cd7104 (svn r3773) Shove some semantics down ottd's throat by replacing ints and magic numbers by enums and some related changes
tron
parents: 3149
diff changeset
   532
		pieces &= ComplementRoadBits(existing);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   533
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   534
8328
6909973c8359 (svn r11382) -Codechange: renamed COUNTBITS to CountBits, as it is no longer a macro (skidd13)
truelight
parents: 8315
diff changeset
   535
	cost.AddCost(CountBits(pieces) * _price.build_road);
7175
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   536
	if (IsTileType(tile, MP_TUNNELBRIDGE)) {
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   537
		/* Pay for *every* tile of the bridge or tunnel */
7446
1c4d469f986e (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 7442
diff changeset
   538
		cost.MultiplyCost(DistanceManhattan(IsTunnel(tile) ? GetOtherTunnelEnd(tile) : GetOtherBridgeEnd(tile), tile));
7175
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   539
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   540
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   541
	if (flags & DC_EXEC) {
7175
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   542
		switch (GetTileType(tile)) {
7866
e19fda04e8d3 (svn r10733) -Codechange: change MP_STREET into MP_ROAD as we use the word "road" everywhere except in the tile type.
rubidium
parents: 7851
diff changeset
   543
			case MP_ROAD: {
7175
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   544
				RoadTileType rtt = GetRoadTileType(tile);
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   545
				if (existing == ROAD_NONE || rtt == ROAD_TILE_CROSSING) {
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   546
					SetRoadTypes(tile, GetRoadTypes(tile) | RoadTypeToRoadTypes(rt));
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   547
					SetRoadOwner(tile, rt, _current_player);
7464
1ea676d8eb7d (svn r10224) -Fix [FS#891]: the town road belongs to didn't get set properly when a town builds road over tram bits.
rubidium
parents: 7461
diff changeset
   548
					if (_current_player == OWNER_TOWN && rt == ROADTYPE_ROAD) SetTownIndex(tile, p2);
7175
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   549
				}
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   550
				if (rtt != ROAD_TILE_CROSSING) SetRoadBits(tile, existing | pieces, rt);
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   551
			} break;
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   552
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   553
			case MP_TUNNELBRIDGE: {
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   554
				TileIndex other_end = IsTunnel(tile) ? GetOtherTunnelEnd(tile) : GetOtherBridgeEnd(tile);
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   555
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   556
				SetRoadTypes(other_end, GetRoadTypes(other_end) | RoadTypeToRoadTypes(rt));
7157
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 7122
diff changeset
   557
				SetRoadTypes(tile, GetRoadTypes(tile) | RoadTypeToRoadTypes(rt));
7175
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   558
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   559
				/* Mark tiles diry that have been repaved */
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   560
				MarkTileDirtyByTile(other_end);
7210
508c55fdc09e (svn r9946) -Fix: more places that weren't correctly marked dirty...
rubidium
parents: 7209
diff changeset
   561
				MarkTileDirtyByTile(tile);
7175
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   562
				if (IsBridge(tile)) {
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   563
					TileIndexDiff delta = TileOffsByDiagDir(GetBridgeRampDirection(tile));
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   564
7209
52241eea3899 (svn r9945) -Fix: bridges were not properly marked dirty when adding/removing roadtypes.
rubidium
parents: 7207
diff changeset
   565
					for (TileIndex t = tile + delta; t != other_end; t += delta) MarkTileDirtyByTile(t);
7175
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   566
				}
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   567
			} break;
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   568
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   569
			case MP_STATION:
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   570
				SetRoadTypes(tile, GetRoadTypes(tile) | RoadTypeToRoadTypes(rt));
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   571
				break;
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   572
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   573
			default:
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   574
				MakeRoadNormal(tile, pieces, RoadTypeToRoadTypes(rt), p2, _current_player, _current_player, _current_player);
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   575
				break;
0
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
7866
e19fda04e8d3 (svn r10733) -Codechange: change MP_STREET into MP_ROAD as we use the word "road" everywhere except in the tile type.
rubidium
parents: 7851
diff changeset
   578
		if (rt != ROADTYPE_TRAM && IsTileType(tile, MP_ROAD) && GetRoadTileType(tile) == ROAD_TILE_NORMAL) {
7260
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7257
diff changeset
   579
			existing |= pieces;
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7257
diff changeset
   580
			SetDisallowedRoadDirections(tile, (existing == ROAD_X || existing == ROAD_Y) ?
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7257
diff changeset
   581
					GetDisallowedRoadDirections(tile) ^ toggle_drd : DRD_NONE);
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7257
diff changeset
   582
		}
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7257
diff changeset
   583
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   584
		MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   585
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   586
	return cost;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   587
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   588
6694
a10a42eefd52 (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: 6683
diff changeset
   589
/**
a10a42eefd52 (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: 6683
diff changeset
   590
 * Switches the rail type on a level crossing.
a10a42eefd52 (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: 6683
diff changeset
   591
 * @param tile        The tile on which the railtype is to be convert.
a10a42eefd52 (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: 6683
diff changeset
   592
 * @param totype      The railtype we want to convert to
a10a42eefd52 (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: 6683
diff changeset
   593
 * @param exec        Switches between test and execute mode
a10a42eefd52 (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: 6683
diff changeset
   594
 * @return            The cost and state of the operation
a10a42eefd52 (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: 6683
diff changeset
   595
 * @retval CMD_ERROR  An error occured during the operation.
a10a42eefd52 (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: 6683
diff changeset
   596
 */
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7353
diff changeset
   597
CommandCost DoConvertStreetRail(TileIndex tile, RailType totype, bool exec)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   598
{
6889
f7f6d9cb07a0 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6694
diff changeset
   599
	/* not a railroad crossing? */
1927
4126e0e3e884 (svn r2433) - CodeChange: unmagicify all road/train crossings with IsLevelCrossing() function (peter1138)
Darkvater
parents: 1902
diff changeset
   600
	if (!IsLevelCrossing(tile)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   601
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   602
	if (exec) {
6498
aff910a05c6e (svn r8935) -Codechange: unification of track type between road and rail tiles, unification of ground type between normal rail tiles and depots/waypoints and removing the need for RailTileSubType.
rubidium
parents: 6486
diff changeset
   603
		SetRailType(tile, totype);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   604
		MarkTileDirtyByTile(tile);
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   605
		YapfNotifyTrackLayoutChange(tile, FindFirstTrack(GetCrossingRailBits(tile)));
8035
a0200ced6d9f (svn r11059) -Fix [FS#1182]: inconsistency between Rail<->ElRail conversions of different kinds of rail containing tiles (normal rail, stations, depots, etc). Patch by SmatZ.
rubidium
parents: 8032
diff changeset
   606
		VehicleFromPos(tile, &tile, UpdateTrainPowerProc);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   607
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   608
8226
c66a40c8e9bf (svn r11265) -Feature: Make more advanced rail types more expensive to build.
maedhros
parents: 8171
diff changeset
   609
	return CommandCost(RailBuildCost(totype) / 2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   610
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   611
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   612
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   613
/** Build a long piece of road.
3491
4c8427796c64 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3435
diff changeset
   614
 * @param end_tile end tile of drag
6979
d194d25020e7 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6923
diff changeset
   615
 * @param flags operation to perform
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   616
 * @param p1 start tile of drag
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   617
 * @param p2 various bitstuffed elements
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   618
 * - p2 = (bit 0) - start tile starts in the 2nd half of tile (p2 & 1)
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   619
 * - p2 = (bit 1) - end tile starts in the 2nd half of tile (p2 & 2)
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   620
 * - p2 = (bit 2) - direction: 0 = along x-axis, 1 = along y-axis (p2 & 4)
7158
ffb31324aa5e (svn r9893) -Fix (r9892): various small bugs that only act up when using something different than plain roads.
rubidium
parents: 7157
diff changeset
   621
 * - p2 = (bit 3 + 4) - road type
7260
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7257
diff changeset
   622
 * - p2 = (bit 5) - set road direction
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   623
 */
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7353
diff changeset
   624
CommandCost 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
   625
{
3491
4c8427796c64 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3435
diff changeset
   626
	TileIndex start_tile, tile;
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7353
diff changeset
   627
	CommandCost cost, ret;
7206
e7aad1699f9a (svn r9942) -Fix [FS#804]: crash when upgrading both ends of a bridge.
rubidium
parents: 7198
diff changeset
   628
	bool had_bridge = false;
7924
7ceb46058085 (svn r10833) -Fix [FS#1115]: assertion (different cost between test and execution) of overbuilding road tunnels with tram tracks (and vice versa) when the dragged area contains both ends of the tunnel.
rubidium
parents: 7885
diff changeset
   629
	bool had_tunnel = false;
7260
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7257
diff changeset
   630
	bool had_success = false;
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7257
diff changeset
   631
	DisallowedRoadDirections drd = DRD_NORTHBOUND;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   632
889
7f8630bfea41 (svn r1375) -Fix: [1050990] Buying trains sometimes accounted for incorrectly. Was the result of the cost getting reset in a recursive call of docommand. That is fixed. In addition all cost-commands are typed explicitely. Please do not forget to do so or your costs will be credited to construction if you are unlucky.
darkvater
parents: 817
diff changeset
   633
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
7f8630bfea41 (svn r1375) -Fix: [1050990] Buying trains sometimes accounted for incorrectly. Was the result of the cost getting reset in a recursive call of docommand. That is fixed. In addition all cost-commands are typed explicitely. Please do not forget to do so or your costs will be credited to construction if you are unlucky.
darkvater
parents: 817
diff changeset
   634
2934
3b7eef9871f8 (svn r3490) -Fix: A bunch (10) of off-by-one errors when checking if a TileIndex points to a tile on the map
tron
parents: 2916
diff changeset
   635
	if (p1 >= MapSize()) return CMD_ERROR;
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   636
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   637
	start_tile = p1;
7158
ffb31324aa5e (svn r9893) -Fix (r9892): various small bugs that only act up when using something different than plain roads.
rubidium
parents: 7157
diff changeset
   638
	RoadType rt = (RoadType)GB(p2, 3, 2);
8353
49a1d9b9d937 (svn r11407) -Fix: do not allow building of tram-tracks when they are not available (SmatZ)
truelight
parents: 8345
diff changeset
   639
	if (!IsValidRoadType(rt) || !ValParamRoadType(rt)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   640
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   641
	/* Only drag in X or Y direction dictated by the direction variable */
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8353
diff changeset
   642
	if (!HasBit(p2, 2) && TileY(start_tile) != TileY(end_tile)) return CMD_ERROR; // x-axis
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8353
diff changeset
   643
	if (HasBit(p2, 2)  && TileX(start_tile) != TileX(end_tile)) return CMD_ERROR; // y-axis
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   644
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   645
	/* Swap start and ending tile, also the half-tile drag var (bit 0 and 1) */
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8353
diff changeset
   646
	if (start_tile > end_tile || (start_tile == end_tile && HasBit(p2, 0))) {
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   647
		TileIndex t = start_tile;
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   648
		start_tile = end_tile;
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   649
		end_tile = t;
6987
b0f13039bda2 (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6979
diff changeset
   650
		p2 ^= IS_INT_INSIDE(p2 & 3, 1, 3) ? 3 : 0;
7260
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7257
diff changeset
   651
		drd = DRD_SOUTHBOUND;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   652
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   653
7260
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7257
diff changeset
   654
	/* On the X-axis, we have to swap the initial bits, so they
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7257
diff changeset
   655
	 * will be interpreted correctly in the GTTS. Futhermore
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7257
diff changeset
   656
	 * when you just 'click' on one tile to build them. */
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8353
diff changeset
   657
	if (HasBit(p2, 2) == (start_tile == end_tile && HasBit(p2, 0) == HasBit(p2, 1))) drd ^= DRD_BOTH;
7260
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7257
diff changeset
   658
	/* No disallowed direction bits have to be toggled */
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8353
diff changeset
   659
	if (!HasBit(p2, 5)) drd = DRD_NONE;
7260
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7257
diff changeset
   660
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   661
	tile = start_tile;
6889
f7f6d9cb07a0 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6694
diff changeset
   662
	/* Start tile is the small number. */
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   663
	for (;;) {
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8353
diff changeset
   664
		RoadBits bits = HasBit(p2, 2) ? ROAD_Y : ROAD_X;
3098
4c1320da876d (svn r3687) Complete some bits I missed whenn adding accessor functions for road types and pieces
tron
parents: 3097
diff changeset
   665
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8353
diff changeset
   666
		if (tile == end_tile && !HasBit(p2, 1)) bits &= ROAD_NW | ROAD_NE;
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8353
diff changeset
   667
		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
   668
7260
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7257
diff changeset
   669
		ret = DoCommand(tile, drd << 6 | rt << 4 | bits, 0, flags, CMD_BUILD_ROAD);
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   670
		if (CmdFailed(ret)) {
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   671
			if (_error_message != STR_1007_ALREADY_BUILT) return CMD_ERROR;
3671
6d3a34989d05 (svn r4586) - Codechange: Recursive commands that rely on _error_message to handle success/failure can fail if a recursive call fails but doesn't set the error message, thus resulting in an old, possibly erroneous being used (see FS#130 prior to r4585). Now properly reset the global variable _error_message in these cases.
Darkvater
parents: 3670
diff changeset
   672
			_error_message = INVALID_STRING_ID;
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
   673
		} else {
7260
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7257
diff changeset
   674
			had_success = true;
7924
7ceb46058085 (svn r10833) -Fix [FS#1115]: assertion (different cost between test and execution) of overbuilding road tunnels with tram tracks (and vice versa) when the dragged area contains both ends of the tunnel.
rubidium
parents: 7885
diff changeset
   675
			/* Only pay for the upgrade on one side of the bridges and tunnels */
7ceb46058085 (svn r10833) -Fix [FS#1115]: assertion (different cost between test and execution) of overbuilding road tunnels with tram tracks (and vice versa) when the dragged area contains both ends of the tunnel.
rubidium
parents: 7885
diff changeset
   676
			if (IsTileType(tile, MP_TUNNELBRIDGE)) {
7ceb46058085 (svn r10833) -Fix [FS#1115]: assertion (different cost between test and execution) of overbuilding road tunnels with tram tracks (and vice versa) when the dragged area contains both ends of the tunnel.
rubidium
parents: 7885
diff changeset
   677
				if (IsBridge(tile)) {
7ceb46058085 (svn r10833) -Fix [FS#1115]: assertion (different cost between test and execution) of overbuilding road tunnels with tram tracks (and vice versa) when the dragged area contains both ends of the tunnel.
rubidium
parents: 7885
diff changeset
   678
					if ((!had_bridge || GetBridgeRampDirection(tile) == DIAGDIR_SE || GetBridgeRampDirection(tile) == DIAGDIR_SW)) {
7ceb46058085 (svn r10833) -Fix [FS#1115]: assertion (different cost between test and execution) of overbuilding road tunnels with tram tracks (and vice versa) when the dragged area contains both ends of the tunnel.
rubidium
parents: 7885
diff changeset
   679
						cost.AddCost(ret);
7ceb46058085 (svn r10833) -Fix [FS#1115]: assertion (different cost between test and execution) of overbuilding road tunnels with tram tracks (and vice versa) when the dragged area contains both ends of the tunnel.
rubidium
parents: 7885
diff changeset
   680
					}
7ceb46058085 (svn r10833) -Fix [FS#1115]: assertion (different cost between test and execution) of overbuilding road tunnels with tram tracks (and vice versa) when the dragged area contains both ends of the tunnel.
rubidium
parents: 7885
diff changeset
   681
					had_bridge = true;
7ceb46058085 (svn r10833) -Fix [FS#1115]: assertion (different cost between test and execution) of overbuilding road tunnels with tram tracks (and vice versa) when the dragged area contains both ends of the tunnel.
rubidium
parents: 7885
diff changeset
   682
				} else {
7ceb46058085 (svn r10833) -Fix [FS#1115]: assertion (different cost between test and execution) of overbuilding road tunnels with tram tracks (and vice versa) when the dragged area contains both ends of the tunnel.
rubidium
parents: 7885
diff changeset
   683
					if ((!had_tunnel || GetTunnelDirection(tile) == DIAGDIR_SE || GetTunnelDirection(tile) == DIAGDIR_SW)) {
7ceb46058085 (svn r10833) -Fix [FS#1115]: assertion (different cost between test and execution) of overbuilding road tunnels with tram tracks (and vice versa) when the dragged area contains both ends of the tunnel.
rubidium
parents: 7885
diff changeset
   684
						cost.AddCost(ret);
7ceb46058085 (svn r10833) -Fix [FS#1115]: assertion (different cost between test and execution) of overbuilding road tunnels with tram tracks (and vice versa) when the dragged area contains both ends of the tunnel.
rubidium
parents: 7885
diff changeset
   685
					}
7ceb46058085 (svn r10833) -Fix [FS#1115]: assertion (different cost between test and execution) of overbuilding road tunnels with tram tracks (and vice versa) when the dragged area contains both ends of the tunnel.
rubidium
parents: 7885
diff changeset
   686
					had_tunnel = true;
7206
e7aad1699f9a (svn r9942) -Fix [FS#804]: crash when upgrading both ends of a bridge.
rubidium
parents: 7198
diff changeset
   687
				}
e7aad1699f9a (svn r9942) -Fix [FS#804]: crash when upgrading both ends of a bridge.
rubidium
parents: 7198
diff changeset
   688
			} else {
7446
1c4d469f986e (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 7442
diff changeset
   689
				cost.AddCost(ret);
7206
e7aad1699f9a (svn r9942) -Fix [FS#804]: crash when upgrading both ends of a bridge.
rubidium
parents: 7198
diff changeset
   690
			}
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
   691
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   692
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   693
		if (tile == end_tile) break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   694
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8353
diff changeset
   695
		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
   696
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   697
7260
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7257
diff changeset
   698
	return !had_success ? CMD_ERROR : cost;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   699
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   700
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   701
/** Remove a long piece of road.
3491
4c8427796c64 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3435
diff changeset
   702
 * @param end_tile end tile of drag
6979
d194d25020e7 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6923
diff changeset
   703
 * @param flags operation to perform
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   704
 * @param p1 start tile of drag
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   705
 * @param p2 various bitstuffed elements
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   706
 * - p2 = (bit 0) - start tile starts in the 2nd half of tile (p2 & 1)
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   707
 * - p2 = (bit 1) - end tile starts in the 2nd half of tile (p2 & 2)
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   708
 * - p2 = (bit 2) - direction: 0 = along x-axis, 1 = along y-axis (p2 & 4)
7158
ffb31324aa5e (svn r9893) -Fix (r9892): various small bugs that only act up when using something different than plain roads.
rubidium
parents: 7157
diff changeset
   709
 * - p2 = (bit 3 + 4) - road type
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   710
 */
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7353
diff changeset
   711
CommandCost 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
   712
{
3491
4c8427796c64 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3435
diff changeset
   713
	TileIndex start_tile, tile;
7938
ee704bc1c5d3 (svn r10890) -Fix [FS#1125]: removing road with the road removal tool would also work with a negative bank account, making the bank account even more negative than it was.
rubidium
parents: 7924
diff changeset
   714
	CommandCost cost, ret, money;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   715
889
7f8630bfea41 (svn r1375) -Fix: [1050990] Buying trains sometimes accounted for incorrectly. Was the result of the cost getting reset in a recursive call of docommand. That is fixed. In addition all cost-commands are typed explicitely. Please do not forget to do so or your costs will be credited to construction if you are unlucky.
darkvater
parents: 817
diff changeset
   716
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
7f8630bfea41 (svn r1375) -Fix: [1050990] Buying trains sometimes accounted for incorrectly. Was the result of the cost getting reset in a recursive call of docommand. That is fixed. In addition all cost-commands are typed explicitely. Please do not forget to do so or your costs will be credited to construction if you are unlucky.
darkvater
parents: 817
diff changeset
   717
2934
3b7eef9871f8 (svn r3490) -Fix: A bunch (10) of off-by-one errors when checking if a TileIndex points to a tile on the map
tron
parents: 2916
diff changeset
   718
	if (p1 >= MapSize()) return CMD_ERROR;
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   719
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   720
	start_tile = p1;
7158
ffb31324aa5e (svn r9893) -Fix (r9892): various small bugs that only act up when using something different than plain roads.
rubidium
parents: 7157
diff changeset
   721
	RoadType rt = (RoadType)GB(p2, 3, 2);
ffb31324aa5e (svn r9893) -Fix (r9892): various small bugs that only act up when using something different than plain roads.
rubidium
parents: 7157
diff changeset
   722
	if (!IsValidRoadType(rt)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   723
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   724
	/* Only drag in X or Y direction dictated by the direction variable */
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8353
diff changeset
   725
	if (!HasBit(p2, 2) && TileY(start_tile) != TileY(end_tile)) return CMD_ERROR; // x-axis
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8353
diff changeset
   726
	if (HasBit(p2, 2)  && TileX(start_tile) != TileX(end_tile)) return CMD_ERROR; // y-axis
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   727
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   728
	/* Swap start and ending tile, also the half-tile drag var (bit 0 and 1) */
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8353
diff changeset
   729
	if (start_tile > end_tile || (start_tile == end_tile && HasBit(p2, 0))) {
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   730
		TileIndex t = start_tile;
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   731
		start_tile = end_tile;
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   732
		end_tile = t;
3017
915fae59d5e0 (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents: 2989
diff changeset
   733
		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
   734
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   735
7938
ee704bc1c5d3 (svn r10890) -Fix [FS#1125]: removing road with the road removal tool would also work with a negative bank account, making the bank account even more negative than it was.
rubidium
parents: 7924
diff changeset
   736
	money.AddCost(GetAvailableMoneyForCommand());
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   737
	tile = start_tile;
6889
f7f6d9cb07a0 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6694
diff changeset
   738
	/* Start tile is the small number. */
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   739
	for (;;) {
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8353
diff changeset
   740
		RoadBits bits = HasBit(p2, 2) ? ROAD_Y : ROAD_X;
3098
4c1320da876d (svn r3687) Complete some bits I missed whenn adding accessor functions for road types and pieces
tron
parents: 3097
diff changeset
   741
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8353
diff changeset
   742
		if (tile == end_tile && !HasBit(p2, 1)) bits &= ROAD_NW | ROAD_NE;
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8353
diff changeset
   743
		if (tile == start_tile && HasBit(p2, 0)) bits &= ROAD_SE | ROAD_SW;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   744
6889
f7f6d9cb07a0 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6694
diff changeset
   745
		/* try to remove the halves. */
3098
4c1320da876d (svn r3687) Complete some bits I missed whenn adding accessor functions for road types and pieces
tron
parents: 3097
diff changeset
   746
		if (bits != 0) {
7938
ee704bc1c5d3 (svn r10890) -Fix [FS#1125]: removing road with the road removal tool would also work with a negative bank account, making the bank account even more negative than it was.
rubidium
parents: 7924
diff changeset
   747
			ret = DoCommand(tile, rt << 4 | bits, 0, flags & ~DC_EXEC, CMD_REMOVE_ROAD);
ee704bc1c5d3 (svn r10890) -Fix [FS#1125]: removing road with the road removal tool would also work with a negative bank account, making the bank account even more negative than it was.
rubidium
parents: 7924
diff changeset
   748
			if (CmdSucceeded(ret)) {
ee704bc1c5d3 (svn r10890) -Fix [FS#1125]: removing road with the road removal tool would also work with a negative bank account, making the bank account even more negative than it was.
rubidium
parents: 7924
diff changeset
   749
				if (flags & DC_EXEC) {
ee704bc1c5d3 (svn r10890) -Fix [FS#1125]: removing road with the road removal tool would also work with a negative bank account, making the bank account even more negative than it was.
rubidium
parents: 7924
diff changeset
   750
					money.AddCost(-ret.GetCost());
ee704bc1c5d3 (svn r10890) -Fix [FS#1125]: removing road with the road removal tool would also work with a negative bank account, making the bank account even more negative than it was.
rubidium
parents: 7924
diff changeset
   751
					if (money.GetCost() < 0) {
ee704bc1c5d3 (svn r10890) -Fix [FS#1125]: removing road with the road removal tool would also work with a negative bank account, making the bank account even more negative than it was.
rubidium
parents: 7924
diff changeset
   752
						_additional_cash_required = DoCommand(end_tile, start_tile, p2, flags & ~DC_EXEC, CMD_REMOVE_LONG_ROAD).GetCost();
ee704bc1c5d3 (svn r10890) -Fix [FS#1125]: removing road with the road removal tool would also work with a negative bank account, making the bank account even more negative than it was.
rubidium
parents: 7924
diff changeset
   753
						return cost;
ee704bc1c5d3 (svn r10890) -Fix [FS#1125]: removing road with the road removal tool would also work with a negative bank account, making the bank account even more negative than it was.
rubidium
parents: 7924
diff changeset
   754
					}
ee704bc1c5d3 (svn r10890) -Fix [FS#1125]: removing road with the road removal tool would also work with a negative bank account, making the bank account even more negative than it was.
rubidium
parents: 7924
diff changeset
   755
					DoCommand(tile, rt << 4 | bits, 0, flags, CMD_REMOVE_ROAD);
ee704bc1c5d3 (svn r10890) -Fix [FS#1125]: removing road with the road removal tool would also work with a negative bank account, making the bank account even more negative than it was.
rubidium
parents: 7924
diff changeset
   756
				}
ee704bc1c5d3 (svn r10890) -Fix [FS#1125]: removing road with the road removal tool would also work with a negative bank account, making the bank account even more negative than it was.
rubidium
parents: 7924
diff changeset
   757
				cost.AddCost(ret);
ee704bc1c5d3 (svn r10890) -Fix [FS#1125]: removing road with the road removal tool would also work with a negative bank account, making the bank account even more negative than it was.
rubidium
parents: 7924
diff changeset
   758
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   759
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   760
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   761
		if (tile == end_tile) break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   762
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8353
diff changeset
   763
		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
   764
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   765
7446
1c4d469f986e (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 7442
diff changeset
   766
	return (cost.GetCost() == 0) ? CMD_ERROR : cost;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   767
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   768
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   769
/** Build a road depot.
3491
4c8427796c64 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3435
diff changeset
   770
 * @param tile tile where to build the depot
6979
d194d25020e7 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6923
diff changeset
   771
 * @param flags operation to perform
6460
b3017e083031 (svn r8876) -Fix
tron
parents: 6459
diff changeset
   772
 * @param p1 bit 0..1 entrance direction (DiagDirection)
7158
ffb31324aa5e (svn r9893) -Fix (r9892): various small bugs that only act up when using something different than plain roads.
rubidium
parents: 7157
diff changeset
   773
 *           bit 2..3 road type
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   774
 * @param p2 unused
2085
ae9e92ffe168 (svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents: 2074
diff changeset
   775
 *
ae9e92ffe168 (svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents: 2074
diff changeset
   776
 * @todo When checking for the tile slope,
ae9e92ffe168 (svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents: 2074
diff changeset
   777
 * distingush between "Flat land required" and "land sloped in wrong direction"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   778
 */
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7353
diff changeset
   779
CommandCost 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
   780
{
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7353
diff changeset
   781
	CommandCost cost;
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3560
diff changeset
   782
	Slope tileh;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   783
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   784
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   785
6460
b3017e083031 (svn r8876) -Fix
tron
parents: 6459
diff changeset
   786
	DiagDirection dir = Extract<DiagDirection, 0>(p1);
7158
ffb31324aa5e (svn r9893) -Fix (r9892): various small bugs that only act up when using something different than plain roads.
rubidium
parents: 7157
diff changeset
   787
	RoadType rt = (RoadType)GB(p1, 2, 2);
ffb31324aa5e (svn r9893) -Fix (r9892): various small bugs that only act up when using something different than plain roads.
rubidium
parents: 7157
diff changeset
   788
8353
49a1d9b9d937 (svn r11407) -Fix: do not allow building of tram-tracks when they are not available (SmatZ)
truelight
parents: 8345
diff changeset
   789
	if (!IsValidRoadType(rt) || !ValParamRoadType(rt)) return CMD_ERROR;
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   790
3055
25fd76668365 (svn r3644) Don't use FindLandscapeHeightByTile() when it's overkill - often it was just a complicated way of writing GetTileSlope(tile, NULL)
tron
parents: 3017
diff changeset
   791
	tileh = GetTileSlope(tile, NULL);
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3560
diff changeset
   792
	if (tileh != SLOPE_FLAT && (
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
   793
				!_patches.build_on_slopes ||
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3560
diff changeset
   794
				IsSteepSlope(tileh) ||
6460
b3017e083031 (svn r8876) -Fix
tron
parents: 6459
diff changeset
   795
				!CanBuildDepotByTileh(dir, tileh)
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
   796
			)) {
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
   797
		return_cmd_error(STR_0007_FLAT_LAND_REQUIRED);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   798
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   799
3491
4c8427796c64 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3435
diff changeset
   800
	cost = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   801
	if (CmdFailed(cost)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   802
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   803
	if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST);
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   804
7885
4eb9b01e37ff (svn r10758) -Codechange: make the depot struct use the pool item class as super class.
rubidium
parents: 7866
diff changeset
   805
	Depot *dep = new Depot(tile);
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
   806
	if (dep == NULL) return CMD_ERROR;
7885
4eb9b01e37ff (svn r10758) -Codechange: make the depot struct use the pool item class as super class.
rubidium
parents: 7866
diff changeset
   807
	AutoPtrT<Depot> d_auto_delete = dep;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   808
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   809
	if (flags & DC_EXEC) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   810
		dep->town_index = ClosestTownFromTile(tile, (uint)-1)->index;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   811
7157
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 7122
diff changeset
   812
		MakeRoadDepot(tile, _current_player, dir, rt);
3100
552cf19c49cb (svn r3695) Add 2 MarkTileByTile() which I forgot in r3689 (noticed by Belugas)
tron
parents: 3099
diff changeset
   813
		MarkTileDirtyByTile(tile);
7885
4eb9b01e37ff (svn r10758) -Codechange: make the depot struct use the pool item class as super class.
rubidium
parents: 7866
diff changeset
   814
		d_auto_delete.Detach();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   815
	}
7446
1c4d469f986e (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 7442
diff changeset
   816
	return cost.AddCost(_price.build_road_depot);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   817
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   818
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7353
diff changeset
   819
static CommandCost RemoveRoadDepot(TileIndex tile, uint32 flags)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   820
{
149
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 84
diff changeset
   821
	if (!CheckTileOwnership(tile) && _current_player != OWNER_WATER)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   822
		return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   823
8254
5de2bbd26163 (svn r11303) -Fix: EnsureNoVehicle and EnsureNoVehicleOnGround were both used to check whether there was no vehicle on the ground, except that the former didn't take care of aircraft shadows. So now we only use EnsureNoVehicleOnGround.
rubidium
parents: 8226
diff changeset
   824
	if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   825
7885
4eb9b01e37ff (svn r10758) -Codechange: make the depot struct use the pool item class as super class.
rubidium
parents: 7866
diff changeset
   826
	if (flags & DC_EXEC) {
4eb9b01e37ff (svn r10758) -Codechange: make the depot struct use the pool item class as super class.
rubidium
parents: 7866
diff changeset
   827
		DoClearSquare(tile);
4eb9b01e37ff (svn r10758) -Codechange: make the depot struct use the pool item class as super class.
rubidium
parents: 7866
diff changeset
   828
		delete GetDepotByTile(tile);
4eb9b01e37ff (svn r10758) -Codechange: make the depot struct use the pool item class as super class.
rubidium
parents: 7866
diff changeset
   829
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   830
7446
1c4d469f986e (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 7442
diff changeset
   831
	return CommandCost(_price.remove_road_depot);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   832
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   833
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7353
diff changeset
   834
static CommandCost ClearTile_Road(TileIndex tile, byte flags)
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
   835
{
3793
33cdb5bf7b21 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3792
diff changeset
   836
	switch (GetRoadTileType(tile)) {
33cdb5bf7b21 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3792
diff changeset
   837
		case ROAD_TILE_NORMAL: {
7157
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 7122
diff changeset
   838
			RoadBits b = GetAllRoadBits(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   839
5888
3117320a611b (svn r8096) -Codechange: Invert the check if you are allowed to clear a road tile so there are not so many negations (too confusing) and added some comments to further clarify what happens.
Darkvater
parents: 5838
diff changeset
   840
			/* Clear the road if only one piece is on the tile OR the AI tries
3117320a611b (svn r8096) -Codechange: Invert the check if you are allowed to clear a road tile so there are not so many negations (too confusing) and added some comments to further clarify what happens.
Darkvater
parents: 5838
diff changeset
   841
			 * to clear town road OR we are not using the DC_AUTO flag */
8328
6909973c8359 (svn r11382) -Codechange: renamed COUNTBITS to CountBits, as it is no longer a macro (skidd13)
truelight
parents: 8315
diff changeset
   842
			if ((CountBits(b) == 1 && GetRoadBits(tile, ROADTYPE_TRAM) == ROAD_NONE) ||
5888
3117320a611b (svn r8096) -Codechange: Invert the check if you are allowed to clear a road tile so there are not so many negations (too confusing) and added some comments to further clarify what happens.
Darkvater
parents: 5838
diff changeset
   843
			    ((flags & DC_AI_BUILDING) && IsTileOwner(tile, OWNER_TOWN)) ||
3117320a611b (svn r8096) -Codechange: Invert the check if you are allowed to clear a road tile so there are not so many negations (too confusing) and added some comments to further clarify what happens.
Darkvater
parents: 5838
diff changeset
   844
			    !(flags & DC_AUTO)
3117320a611b (svn r8096) -Codechange: Invert the check if you are allowed to clear a road tile so there are not so many negations (too confusing) and added some comments to further clarify what happens.
Darkvater
parents: 5838
diff changeset
   845
				) {
7175
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   846
				RoadTypes rts = GetRoadTypes(tile);
7446
1c4d469f986e (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 7442
diff changeset
   847
				CommandCost ret;
7175
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   848
				for (RoadType rt = ROADTYPE_ROAD; rt < ROADTYPE_END; rt++) {
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8353
diff changeset
   849
					if (HasBit(rts, rt)) {
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7353
diff changeset
   850
						CommandCost tmp_ret = DoCommand(tile, rt << 4 | GetRoadBits(tile, rt), 0, flags, CMD_REMOVE_ROAD);
7175
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   851
						if (CmdFailed(tmp_ret)) return tmp_ret;
7446
1c4d469f986e (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 7442
diff changeset
   852
						ret.AddCost(tmp_ret);
7175
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   853
					}
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   854
				}
5afb72652b6d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 7162
diff changeset
   855
				return ret;
3060
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   856
			}
5888
3117320a611b (svn r8096) -Codechange: Invert the check if you are allowed to clear a road tile so there are not so many negations (too confusing) and added some comments to further clarify what happens.
Darkvater
parents: 5838
diff changeset
   857
			return_cmd_error(STR_1801_MUST_REMOVE_ROAD_FIRST);
5894
eb5ff472c10f (svn r8102) -Cleanup: Remove unreachable code (r8096), useless cast
Darkvater
parents: 5888
diff changeset
   858
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   859
3793
33cdb5bf7b21 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3792
diff changeset
   860
		case ROAD_TILE_CROSSING: {
7310
b835c3c702c1 (svn r10053) -Fix: could not clear a level-crossing tile with tram tracks.
rubidium
parents: 7264
diff changeset
   861
			RoadTypes rts = GetRoadTypes(tile);
7446
1c4d469f986e (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 7442
diff changeset
   862
			CommandCost ret;
3060
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   863
3069
0e6aca11c3da (svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents: 3068
diff changeset
   864
			if (flags & DC_AUTO) return_cmd_error(STR_1801_MUST_REMOVE_ROAD_FIRST);
3060
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   865
7310
b835c3c702c1 (svn r10053) -Fix: could not clear a level-crossing tile with tram tracks.
rubidium
parents: 7264
diff changeset
   866
			/* Must iterate over the roadtypes in a reverse manner because
b835c3c702c1 (svn r10053) -Fix: could not clear a level-crossing tile with tram tracks.
rubidium
parents: 7264
diff changeset
   867
			 * tram tracks must be removed before the road bits. */
b835c3c702c1 (svn r10053) -Fix: could not clear a level-crossing tile with tram tracks.
rubidium
parents: 7264
diff changeset
   868
			for (RoadType rt = ROADTYPE_HWAY; rt >= ROADTYPE_ROAD; rt--) {
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8353
diff changeset
   869
				if (HasBit(rts, rt)) {
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7353
diff changeset
   870
					CommandCost tmp_ret = DoCommand(tile, 1 << 6 | rt << 4 | GetCrossingRoadBits(tile), 0, flags, CMD_REMOVE_ROAD);
7310
b835c3c702c1 (svn r10053) -Fix: could not clear a level-crossing tile with tram tracks.
rubidium
parents: 7264
diff changeset
   871
					if (CmdFailed(tmp_ret)) return tmp_ret;
7446
1c4d469f986e (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 7442
diff changeset
   872
					ret.AddCost(tmp_ret);
7310
b835c3c702c1 (svn r10053) -Fix: could not clear a level-crossing tile with tram tracks.
rubidium
parents: 7264
diff changeset
   873
				}
b835c3c702c1 (svn r10053) -Fix: could not clear a level-crossing tile with tram tracks.
rubidium
parents: 7264
diff changeset
   874
			}
3060
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   875
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   876
			if (flags & DC_EXEC) {
3491
4c8427796c64 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3435
diff changeset
   877
				DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
3060
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   878
			}
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   879
			return ret;
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   880
		}
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   881
3069
0e6aca11c3da (svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents: 3068
diff changeset
   882
		default:
3793
33cdb5bf7b21 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3792
diff changeset
   883
		case ROAD_TILE_DEPOT:
3060
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   884
			if (flags & DC_AUTO) {
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   885
				return_cmd_error(STR_2004_BUILDING_MUST_BE_DEMOLISHED);
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   886
			}
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   887
			return RemoveRoadDepot(tile, flags);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   888
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   889
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   890
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   891
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6498
diff changeset
   892
struct DrawRoadTileStruct {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   893
	uint16 image;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   894
	byte subcoord_x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   895
	byte subcoord_y;
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6498
diff changeset
   896
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   897
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   898
#include "table/road_land.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   899
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   900
7831
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7829
diff changeset
   901
Foundation GetRoadFoundation(Slope tileh, RoadBits bits)
2548
97ada3bd2702 (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2544
diff changeset
   902
{
7831
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7829
diff changeset
   903
	if (!IsSteepSlope(tileh)) {
7851
a8b46108eee8 (svn r10718) -Fix (r10698): when having a road corner on a slope removing the road bit perpendicular on the slope made the foundation disappear.
rubidium
parents: 7831
diff changeset
   904
		if ((~_valid_tileh_slopes_road[0][tileh] & bits) == 0) {
a8b46108eee8 (svn r10718) -Fix (r10698): when having a road corner on a slope removing the road bit perpendicular on the slope made the foundation disappear.
rubidium
parents: 7831
diff changeset
   905
			/* As one can remove a single road piece when in a corner on a foundation as
a8b46108eee8 (svn r10718) -Fix (r10698): when having a road corner on a slope removing the road bit perpendicular on the slope made the foundation disappear.
rubidium
parents: 7831
diff changeset
   906
			 * it is on a sloped piece of landscape, one creates a state that cannot be
a8b46108eee8 (svn r10718) -Fix (r10698): when having a road corner on a slope removing the road bit perpendicular on the slope made the foundation disappear.
rubidium
parents: 7831
diff changeset
   907
			 * created directly, but the state itself is still perfectly drawable.
a8b46108eee8 (svn r10718) -Fix (r10698): when having a road corner on a slope removing the road bit perpendicular on the slope made the foundation disappear.
rubidium
parents: 7831
diff changeset
   908
			 * However, as we do not want this to be build directly, we need to check
a8b46108eee8 (svn r10718) -Fix (r10698): when having a road corner on a slope removing the road bit perpendicular on the slope made the foundation disappear.
rubidium
parents: 7831
diff changeset
   909
			 * for that situation in here. */
8328
6909973c8359 (svn r11382) -Codechange: renamed COUNTBITS to CountBits, as it is no longer a macro (skidd13)
truelight
parents: 8315
diff changeset
   910
			return (tileh != 0 && CountBits(bits) == 1) ? FOUNDATION_LEVELED : FOUNDATION_NONE;
7851
a8b46108eee8 (svn r10718) -Fix (r10698): when having a road corner on a slope removing the road bit perpendicular on the slope made the foundation disappear.
rubidium
parents: 7831
diff changeset
   911
		}
7831
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7829
diff changeset
   912
		if ((~_valid_tileh_slopes_road[1][tileh] & bits) == 0) return FOUNDATION_LEVELED;
4246
14a8849c32df (svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents: 4232
diff changeset
   913
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   914
7831
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7829
diff changeset
   915
	return (bits == ROAD_X ? FOUNDATION_INCLINED_X : FOUNDATION_INCLINED_Y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   916
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   917
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   918
const byte _road_sloped_sprites[14] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   919
	0,  0,  2,  0,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   920
	0,  1,  0,  0,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   921
	3,  0,  0,  0,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   922
	0,  0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   923
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   924
2471
14109854e818 (svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents: 2469
diff changeset
   925
/**
7037
3cd1bd7a6edb (svn r9730) -Feature: [NewGRF] Add support for miscellaneous grf feature bit 1 - paved roads on desert tiles.
maedhros
parents: 6987
diff changeset
   926
 * Whether to draw unpaved roads regardless of the town zone.
3cd1bd7a6edb (svn r9730) -Feature: [NewGRF] Add support for miscellaneous grf feature bit 1 - paved roads on desert tiles.
maedhros
parents: 6987
diff changeset
   927
 * By default, OpenTTD always draws roads as unpaved if they are on a desert
3cd1bd7a6edb (svn r9730) -Feature: [NewGRF] Add support for miscellaneous grf feature bit 1 - paved roads on desert tiles.
maedhros
parents: 6987
diff changeset
   928
 * tile or above the snowline. Newgrf files, however, can set a bit that allows
3cd1bd7a6edb (svn r9730) -Feature: [NewGRF] Add support for miscellaneous grf feature bit 1 - paved roads on desert tiles.
maedhros
parents: 6987
diff changeset
   929
 * paved roads to be built on desert tiles as they would be on grassy tiles.
3cd1bd7a6edb (svn r9730) -Feature: [NewGRF] Add support for miscellaneous grf feature bit 1 - paved roads on desert tiles.
maedhros
parents: 6987
diff changeset
   930
 *
3cd1bd7a6edb (svn r9730) -Feature: [NewGRF] Add support for miscellaneous grf feature bit 1 - paved roads on desert tiles.
maedhros
parents: 6987
diff changeset
   931
 * @param tile The tile the road is on
3cd1bd7a6edb (svn r9730) -Feature: [NewGRF] Add support for miscellaneous grf feature bit 1 - paved roads on desert tiles.
maedhros
parents: 6987
diff changeset
   932
 * @param roadside What sort of road this is
3cd1bd7a6edb (svn r9730) -Feature: [NewGRF] Add support for miscellaneous grf feature bit 1 - paved roads on desert tiles.
maedhros
parents: 6987
diff changeset
   933
 * @return True if the road should be drawn unpaved regardless of the roadside.
3cd1bd7a6edb (svn r9730) -Feature: [NewGRF] Add support for miscellaneous grf feature bit 1 - paved roads on desert tiles.
maedhros
parents: 6987
diff changeset
   934
 */
3cd1bd7a6edb (svn r9730) -Feature: [NewGRF] Add support for miscellaneous grf feature bit 1 - paved roads on desert tiles.
maedhros
parents: 6987
diff changeset
   935
static bool AlwaysDrawUnpavedRoads(TileIndex tile, Roadside roadside)
3cd1bd7a6edb (svn r9730) -Feature: [NewGRF] Add support for miscellaneous grf feature bit 1 - paved roads on desert tiles.
maedhros
parents: 6987
diff changeset
   936
{
3cd1bd7a6edb (svn r9730) -Feature: [NewGRF] Add support for miscellaneous grf feature bit 1 - paved roads on desert tiles.
maedhros
parents: 6987
diff changeset
   937
	return (IsOnSnow(tile) &&
3cd1bd7a6edb (svn r9730) -Feature: [NewGRF] Add support for miscellaneous grf feature bit 1 - paved roads on desert tiles.
maedhros
parents: 6987
diff changeset
   938
			!(_opt.landscape == LT_TROPIC && HasGrfMiscBit(GMB_DESERT_PAVED_ROADS) &&
3cd1bd7a6edb (svn r9730) -Feature: [NewGRF] Add support for miscellaneous grf feature bit 1 - paved roads on desert tiles.
maedhros
parents: 6987
diff changeset
   939
				roadside != ROADSIDE_BARREN && roadside != ROADSIDE_GRASS && roadside != ROADSIDE_GRASS_ROAD_WORKS));
3cd1bd7a6edb (svn r9730) -Feature: [NewGRF] Add support for miscellaneous grf feature bit 1 - paved roads on desert tiles.
maedhros
parents: 6987
diff changeset
   940
}
3cd1bd7a6edb (svn r9730) -Feature: [NewGRF] Add support for miscellaneous grf feature bit 1 - paved roads on desert tiles.
maedhros
parents: 6987
diff changeset
   941
3cd1bd7a6edb (svn r9730) -Feature: [NewGRF] Add support for miscellaneous grf feature bit 1 - paved roads on desert tiles.
maedhros
parents: 6987
diff changeset
   942
/**
7187
f7dc3204d457 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 7185
diff changeset
   943
 * Draws the catenary for the given tile
f7dc3204d457 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 7185
diff changeset
   944
 * @param ti   information about the tile (slopes, height etc)
f7dc3204d457 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 7185
diff changeset
   945
 * @param tram the roadbits for the tram
f7dc3204d457 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 7185
diff changeset
   946
 */
f7dc3204d457 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 7185
diff changeset
   947
void DrawTramCatenary(TileInfo *ti, RoadBits tram)
f7dc3204d457 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 7185
diff changeset
   948
{
f7dc3204d457 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 7185
diff changeset
   949
	/* Don't draw the catenary under a low bridge */
8345
6caa3fdb972c (svn r11399) -Feature(ette): transparency settings can now be saved and thus remembered.
belugas
parents: 8328
diff changeset
   950
	if (MayHaveBridgeAbove(ti->tile) && IsBridgeAbove(ti->tile) && !IsTransparencySet(TO_BUILDINGS)) {
7187
f7dc3204d457 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 7185
diff changeset
   951
		uint height = GetBridgeHeight(GetNorthernBridgeEnd(ti->tile));
f7dc3204d457 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 7185
diff changeset
   952
7195
6edfafb988be (svn r9931) -Fix: some glitches with catenary and bridges.
rubidium
parents: 7193
diff changeset
   953
		if (height <= GetTileMaxZ(ti->tile) + TILE_HEIGHT) return;
7187
f7dc3204d457 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 7185
diff changeset
   954
	}
f7dc3204d457 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 7185
diff changeset
   955
f7dc3204d457 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 7185
diff changeset
   956
	SpriteID front;
f7dc3204d457 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 7185
diff changeset
   957
	SpriteID back;
f7dc3204d457 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 7185
diff changeset
   958
f7dc3204d457 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 7185
diff changeset
   959
	if (ti->tileh != SLOPE_FLAT) {
f7dc3204d457 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 7185
diff changeset
   960
		back  = SPR_TRAMWAY_BACK_WIRES_SLOPED  + _road_sloped_sprites[ti->tileh - 1];
f7dc3204d457 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 7185
diff changeset
   961
		front = SPR_TRAMWAY_FRONT_WIRES_SLOPED + _road_sloped_sprites[ti->tileh - 1];
f7dc3204d457 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 7185
diff changeset
   962
	} else {
f7dc3204d457 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 7185
diff changeset
   963
		back  = SPR_TRAMWAY_BASE + _road_backpole_sprites_1[tram];
f7dc3204d457 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 7185
diff changeset
   964
		front = SPR_TRAMWAY_BASE + _road_frontwire_sprites_1[tram];
f7dc3204d457 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 7185
diff changeset
   965
	}
f7dc3204d457 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 7185
diff changeset
   966
8345
6caa3fdb972c (svn r11399) -Feature(ette): transparency settings can now be saved and thus remembered.
belugas
parents: 8328
diff changeset
   967
	AddSortableSpriteToDraw(back,  PAL_NONE, ti->x, ti->y, 16, 16, TILE_HEIGHT + BB_HEIGHT_UNDER_BRIDGE, ti->z, IsTransparencySet(TO_BUILDINGS));
6caa3fdb972c (svn r11399) -Feature(ette): transparency settings can now be saved and thus remembered.
belugas
parents: 8328
diff changeset
   968
	AddSortableSpriteToDraw(front, PAL_NONE, ti->x, ti->y, 16, 16, TILE_HEIGHT + BB_HEIGHT_UNDER_BRIDGE, ti->z, IsTransparencySet(TO_BUILDINGS));
7187
f7dc3204d457 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 7185
diff changeset
   969
}
f7dc3204d457 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 7185
diff changeset
   970
f7dc3204d457 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 7185
diff changeset
   971
/**
7260
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7257
diff changeset
   972
 * Draws details on/around the road
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7257
diff changeset
   973
 * @param img the sprite to draw
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7257
diff changeset
   974
 * @param ti  the tile to draw on
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7257
diff changeset
   975
 * @param dx  the offset from the top of the BB of the tile
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7257
diff changeset
   976
 * @param dy  the offset from the top of the BB of the tile
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7257
diff changeset
   977
 * @param h   the height of the sprite to draw
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7257
diff changeset
   978
 */
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7257
diff changeset
   979
static void DrawRoadDetail(SpriteID img, TileInfo *ti, int dx, int dy, int h)
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7257
diff changeset
   980
{
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7257
diff changeset
   981
	int x = ti->x | dx;
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7257
diff changeset
   982
	int y = ti->y | dy;
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7257
diff changeset
   983
	byte z = ti->z;
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7257
diff changeset
   984
	if (ti->tileh != SLOPE_FLAT) z = GetSlopeZ(x, y);
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7257
diff changeset
   985
	AddSortableSpriteToDraw(img, PAL_NONE, x, y, 2, 2, h, z);
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7257
diff changeset
   986
}
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7257
diff changeset
   987
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7257
diff changeset
   988
/**
2471
14109854e818 (svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents: 2469
diff changeset
   989
 * Draw ground sprite and road pieces
14109854e818 (svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents: 2469
diff changeset
   990
 * @param ti TileInfo
14109854e818 (svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents: 2469
diff changeset
   991
 */
4081
8d4111a68f72 (svn r5396) - Remove two fixed parameters
tron
parents: 4077
diff changeset
   992
static void DrawRoadBits(TileInfo* ti)
2471
14109854e818 (svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents: 2469
diff changeset
   993
{
7157
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 7122
diff changeset
   994
	RoadBits road = GetRoadBits(ti->tile, ROADTYPE_ROAD);
7187
f7dc3204d457 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 7185
diff changeset
   995
	RoadBits tram = GetRoadBits(ti->tile, ROADTYPE_TRAM);
f7dc3204d457 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 7185
diff changeset
   996
2471
14109854e818 (svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents: 2469
diff changeset
   997
	const DrawRoadTileStruct *drts;
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5894
diff changeset
   998
	SpriteID image = 0;
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5894
diff changeset
   999
	SpriteID pal = PAL_NONE;
4048
e773f441eb4f (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1000
	Roadside roadside;
2471
14109854e818 (svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents: 2469
diff changeset
  1001
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3560
diff changeset
  1002
	if (ti->tileh != SLOPE_FLAT) {
7831
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7829
diff changeset
  1003
		DrawFoundation(ti, GetRoadFoundation(ti->tileh, road | tram));
2471
14109854e818 (svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents: 2469
diff changeset
  1004
6889
f7f6d9cb07a0 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6694
diff changeset
  1005
		/* DrawFoundation() modifies ti.
f7f6d9cb07a0 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6694
diff changeset
  1006
		 * Default sloped sprites.. */
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3560
diff changeset
  1007
		if (ti->tileh != SLOPE_FLAT) image = _road_sloped_sprites[ti->tileh - 1] + 0x53F;
2471
14109854e818 (svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents: 2469
diff changeset
  1008
	}
14109854e818 (svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents: 2469
diff changeset
  1009
7187
f7dc3204d457 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 7185
diff changeset
  1010
	if (image == 0) image = _road_tile_sprites_1[road != ROAD_NONE ? road : tram];
2471
14109854e818 (svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents: 2469
diff changeset
  1011
4048
e773f441eb4f (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1012
	roadside = GetRoadside(ti->tile);
2471
14109854e818 (svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents: 2469
diff changeset
  1013
7037
3cd1bd7a6edb (svn r9730) -Feature: [NewGRF] Add support for miscellaneous grf feature bit 1 - paved roads on desert tiles.
maedhros
parents: 6987
diff changeset
  1014
	if (AlwaysDrawUnpavedRoads(ti->tile, roadside)) {
2471
14109854e818 (svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents: 2469
diff changeset
  1015
		image += 19;
4048
e773f441eb4f (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1016
	} else {
e773f441eb4f (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1017
		switch (roadside) {
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5894
diff changeset
  1018
			case ROADSIDE_BARREN:           pal = PALETTE_TO_BARE_LAND; break;
4048
e773f441eb4f (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1019
			case ROADSIDE_GRASS:            break;
e773f441eb4f (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1020
			case ROADSIDE_GRASS_ROAD_WORKS: break;
e773f441eb4f (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1021
			default:                        image -= 19; break; // Paved
e773f441eb4f (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1022
		}
2471
14109854e818 (svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents: 2469
diff changeset
  1023
	}
14109854e818 (svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents: 2469
diff changeset
  1024
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5894
diff changeset
  1025
	DrawGroundSprite(image, pal);
2471
14109854e818 (svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents: 2469
diff changeset
  1026
7187
f7dc3204d457 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 7185
diff changeset
  1027
	/* For tram we overlay the road graphics with either tram tracks only
f7dc3204d457 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 7185
diff changeset
  1028
	 * (when there is actual road beneath the trams) or with tram tracks
f7dc3204d457 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 7185
diff changeset
  1029
	 * and some dirts which hides the road graphics */
f7dc3204d457 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 7185
diff changeset
  1030
	if (tram != ROAD_NONE) {
f7dc3204d457 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 7185
diff changeset
  1031
		if (ti->tileh != SLOPE_FLAT) {
f7dc3204d457 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 7185
diff changeset
  1032
			image = _road_sloped_sprites[ti->tileh - 1] + SPR_TRAMWAY_SLOPED_OFFSET;
f7dc3204d457 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 7185
diff changeset
  1033
		} else {
f7dc3204d457 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 7185
diff changeset
  1034
			image = _road_tile_sprites_1[tram] - SPR_ROAD_Y;
f7dc3204d457 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 7185
diff changeset
  1035
		}
f7dc3204d457 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 7185
diff changeset
  1036
		image += (road == ROAD_NONE) ? SPR_TRAMWAY_TRAM : SPR_TRAMWAY_OVERLAY;
f7dc3204d457 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 7185
diff changeset
  1037
		DrawGroundSprite(image, pal);
f7dc3204d457 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 7185
diff changeset
  1038
	}
f7dc3204d457 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 7185
diff changeset
  1039
7461
f9c5dc7f2476 (svn r10221) -Fix: the one way sprites weren't drawn in the correct order, so they could remove the tramtrack in some cases.
rubidium
parents: 7446
diff changeset
  1040
	if (road != ROAD_NONE) {
f9c5dc7f2476 (svn r10221) -Fix: the one way sprites weren't drawn in the correct order, so they could remove the tramtrack in some cases.
rubidium
parents: 7446
diff changeset
  1041
		DisallowedRoadDirections drd = GetDisallowedRoadDirections(ti->tile);
f9c5dc7f2476 (svn r10221) -Fix: the one way sprites weren't drawn in the correct order, so they could remove the tramtrack in some cases.
rubidium
parents: 7446
diff changeset
  1042
		if (drd != DRD_NONE) {
f9c5dc7f2476 (svn r10221) -Fix: the one way sprites weren't drawn in the correct order, so they could remove the tramtrack in some cases.
rubidium
parents: 7446
diff changeset
  1043
			DrawRoadDetail(SPR_ONEWAY_BASE + drd - 1 + ((road == ROAD_X) ? 0 : 3), ti, 8, 8, 0);
f9c5dc7f2476 (svn r10221) -Fix: the one way sprites weren't drawn in the correct order, so they could remove the tramtrack in some cases.
rubidium
parents: 7446
diff changeset
  1044
		}
f9c5dc7f2476 (svn r10221) -Fix: the one way sprites weren't drawn in the correct order, so they could remove the tramtrack in some cases.
rubidium
parents: 7446
diff changeset
  1045
	}
f9c5dc7f2476 (svn r10221) -Fix: the one way sprites weren't drawn in the correct order, so they could remove the tramtrack in some cases.
rubidium
parents: 7446
diff changeset
  1046
3430
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
  1047
	if (HasRoadWorks(ti->tile)) {
6889
f7f6d9cb07a0 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6694
diff changeset
  1048
		/* Road works */
7187
f7dc3204d457 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 7185
diff changeset
  1049
		DrawGroundSprite((road | tram) & ROAD_X ? SPR_EXCAVATION_X : SPR_EXCAVATION_Y, PAL_NONE);
2471
14109854e818 (svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents: 2469
diff changeset
  1050
		return;
14109854e818 (svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents: 2469
diff changeset
  1051
	}
14109854e818 (svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents: 2469
diff changeset
  1052
7187
f7dc3204d457 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 7185
diff changeset
  1053
	if (tram != ROAD_NONE) DrawTramCatenary(ti, tram);
f7dc3204d457 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 7185
diff changeset
  1054
6889
f7f6d9cb07a0 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6694
diff changeset
  1055
	/* Return if full detail is disabled, or we are zoomed fully out. */
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8353
diff changeset
  1056
	if (!HasBit(_display_opt, DO_FULL_DETAIL) || _cur_dpi->zoom > ZOOM_LVL_DETAIL) return;
5148
00b593a6bae5 (svn r7240) -Fix: Always display the excavation of roadworks even when fully zoomed out (they are quite noticable) or "full details" are off (they are part of the game mechanics)
tron
parents: 5116
diff changeset
  1057
6889
f7f6d9cb07a0 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6694
diff changeset
  1058
	/* Draw extra details. */
4048
e773f441eb4f (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1059
	for (drts = _road_display_table[roadside][road]; drts->image != 0; drts++) {
7260
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7257
diff changeset
  1060
		DrawRoadDetail(drts->image, ti, drts->subcoord_x, drts->subcoord_y, 0x10);
2471
14109854e818 (svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents: 2469
diff changeset
  1061
	}
14109854e818 (svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents: 2469
diff changeset
  1062
}
14109854e818 (svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents: 2469
diff changeset
  1063
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1064
static void DrawTile_Road(TileInfo *ti)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1065
{
3793
33cdb5bf7b21 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3792
diff changeset
  1066
	switch (GetRoadTileType(ti->tile)) {
33cdb5bf7b21 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3792
diff changeset
  1067
		case ROAD_TILE_NORMAL:
4081
8d4111a68f72 (svn r5396) - Remove two fixed parameters
tron
parents: 4077
diff changeset
  1068
			DrawRoadBits(ti);
3060
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1069
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1070
3793
33cdb5bf7b21 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3792
diff changeset
  1071
		case ROAD_TILE_CROSSING: {
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5894
diff changeset
  1072
			SpriteID image;
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5894
diff changeset
  1073
			SpriteID pal = PAL_NONE;
7037
3cd1bd7a6edb (svn r9730) -Feature: [NewGRF] Add support for miscellaneous grf feature bit 1 - paved roads on desert tiles.
maedhros
parents: 6987
diff changeset
  1074
			Roadside roadside = GetRoadside(ti->tile);
4000
bab1ebc37da0 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3977
diff changeset
  1075
7831
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7829
diff changeset
  1076
			if (ti->tileh != SLOPE_FLAT) DrawFoundation(ti, FOUNDATION_LEVELED);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1077
6498
aff910a05c6e (svn r8935) -Codechange: unification of track type between road and rail tiles, unification of ground type between normal rail tiles and depots/waypoints and removing the need for RailTileSubType.
rubidium
parents: 6486
diff changeset
  1078
			image = GetRailTypeInfo(GetRailType(ti->tile))->base_sprites.crossing;
3060
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1079
3272
7e556f209503 (svn r3984) Add a function to get the road axis of a level crossing
tron
parents: 3269
diff changeset
  1080
			if (GetCrossingRoadAxis(ti->tile) == AXIS_X) image++;
3322
fa5d46929db9 (svn r4088) -Codechange: Introduce {Unb,B}arCrossing and IsCrossingBarred to put and get the status of a level crossing
celestar
parents: 3319
diff changeset
  1081
			if (IsCrossingBarred(ti->tile)) image += 2;
3060
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1082
7037
3cd1bd7a6edb (svn r9730) -Feature: [NewGRF] Add support for miscellaneous grf feature bit 1 - paved roads on desert tiles.
maedhros
parents: 6987
diff changeset
  1083
			if (AlwaysDrawUnpavedRoads(ti->tile, roadside)) {
3060
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1084
				image += 8;
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1085
			} else {
7037
3cd1bd7a6edb (svn r9730) -Feature: [NewGRF] Add support for miscellaneous grf feature bit 1 - paved roads on desert tiles.
maedhros
parents: 6987
diff changeset
  1086
				switch (roadside) {
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5894
diff changeset
  1087
					case ROADSIDE_BARREN: pal = PALETTE_TO_BARE_LAND; break;
4048
e773f441eb4f (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1088
					case ROADSIDE_GRASS:  break;
e773f441eb4f (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1089
					default:              image += 4; break; // Paved
e773f441eb4f (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1090
				}
3060
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1091
			}
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1092
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5894
diff changeset
  1093
			DrawGroundSprite(image, pal);
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8353
diff changeset
  1094
			if (HasBit(GetRoadTypes(ti->tile), ROADTYPE_TRAM)) {
7193
e0cdd5c824dd (svn r9929) -Fix [FS#803]: fix several drawing issues.
rubidium
parents: 7187
diff changeset
  1095
				DrawGroundSprite(SPR_TRAMWAY_OVERLAY + (GetCrossingRoadAxis(ti->tile) ^ 1), pal);
e0cdd5c824dd (svn r9929) -Fix [FS#803]: fix several drawing issues.
rubidium
parents: 7187
diff changeset
  1096
				DrawTramCatenary(ti, GetCrossingRoadBits(ti->tile));
e0cdd5c824dd (svn r9929) -Fix [FS#803]: fix several drawing issues.
rubidium
parents: 7187
diff changeset
  1097
			}
6498
aff910a05c6e (svn r8935) -Codechange: unification of track type between road and rail tiles, unification of ground type between normal rail tiles and depots/waypoints and removing the need for RailTileSubType.
rubidium
parents: 6486
diff changeset
  1098
			if (GetRailType(ti->tile) == RAILTYPE_ELECTRIC) DrawCatenary(ti);
3060
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1099
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1100
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1101
3098
4c1320da876d (svn r3687) Complete some bits I missed whenn adding accessor functions for road types and pieces
tron
parents: 3097
diff changeset
  1102
		default:
3793
33cdb5bf7b21 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3792
diff changeset
  1103
		case ROAD_TILE_DEPOT: {
4232
628628eaa4fc (svn r5796) Use DrawTileSprites/DrawTileSeqStruct for road depot drawing data, too
tron
parents: 4231
diff changeset
  1104
			const DrawTileSprites* dts;
628628eaa4fc (svn r5796) Use DrawTileSprites/DrawTileSeqStruct for road depot drawing data, too
tron
parents: 4231
diff changeset
  1105
			const DrawTileSeqStruct* dtss;
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5894
diff changeset
  1106
			SpriteID palette;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1107
7831
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7829
diff changeset
  1108
			if (ti->tileh != SLOPE_FLAT) DrawFoundation(ti, FOUNDATION_LEVELED);
1398
2299b334e660 (svn r1902) Replace some casts with proper typing
tron
parents: 1359
diff changeset
  1109
4226
3926da9dc486 (svn r5772) Road depots always have an player as owner, so remove an useless check
tron
parents: 4212
diff changeset
  1110
			palette = PLAYER_SPRITE_COLOR(GetTileOwner(ti->tile));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1111
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8353
diff changeset
  1112
			if (HasBit(GetRoadTypes(ti->tile), ROADTYPE_TRAM)) {
7187
f7dc3204d457 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 7185
diff changeset
  1113
				dts =  &_tram_depot[GetRoadDepotDirection(ti->tile)];
f7dc3204d457 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 7185
diff changeset
  1114
			} else {
f7dc3204d457 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 7185
diff changeset
  1115
				dts =  &_road_depot[GetRoadDepotDirection(ti->tile)];
f7dc3204d457 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 7185
diff changeset
  1116
			}
f7dc3204d457 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 7185
diff changeset
  1117
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5894
diff changeset
  1118
			DrawGroundSprite(dts->ground_sprite, PAL_NONE);
3060
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1119
4232
628628eaa4fc (svn r5796) Use DrawTileSprites/DrawTileSeqStruct for road depot drawing data, too
tron
parents: 4231
diff changeset
  1120
			for (dtss = dts->seq; dtss->image != 0; dtss++) {
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5894
diff changeset
  1121
				SpriteID image = dtss->image;
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5894
diff changeset
  1122
				SpriteID pal;
3060
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1123
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8353
diff changeset
  1124
				if (!IsTransparencySet(TO_BUILDINGS) && HasBit(image, PALETTE_MODIFIER_COLOR)) {
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5894
diff changeset
  1125
					pal = palette;
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5894
diff changeset
  1126
				} else {
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5894
diff changeset
  1127
					pal = PAL_NONE;
4226
3926da9dc486 (svn r5772) Road depots always have an player as owner, so remove an useless check
tron
parents: 4212
diff changeset
  1128
				}
3060
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1129
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4048
diff changeset
  1130
				AddSortableSpriteToDraw(
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5894
diff changeset
  1131
					image, pal,
4232
628628eaa4fc (svn r5796) Use DrawTileSprites/DrawTileSeqStruct for road depot drawing data, too
tron
parents: 4231
diff changeset
  1132
					ti->x + dtss->delta_x, ti->y + dtss->delta_y,
628628eaa4fc (svn r5796) Use DrawTileSprites/DrawTileSeqStruct for road depot drawing data, too
tron
parents: 4231
diff changeset
  1133
					dtss->size_x, dtss->size_y,
7829
88883899c9e6 (svn r10696) -Codechange: remove duplication of the "make sprite transparent" code.
rubidium
parents: 7828
diff changeset
  1134
					dtss->size_z, ti->z,
8345
6caa3fdb972c (svn r11399) -Feature(ette): transparency settings can now be saved and thus remembered.
belugas
parents: 8328
diff changeset
  1135
					IsTransparencySet(TO_BUILDINGS)
3060
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1136
				);
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1137
			}
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1138
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1139
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1140
	}
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
  1141
	DrawBridgeMiddle(ti);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1142
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1143
7162
b769c2b45103 (svn r9897) -Codechange: prepare the toolbar for more road types.
rubidium
parents: 7158
diff changeset
  1144
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
  1145
{
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5894
diff changeset
  1146
	SpriteID palette = PLAYER_SPRITE_COLOR(_local_player);
7187
f7dc3204d457 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 7185
diff changeset
  1147
	const DrawTileSprites* dts = (rt == ROADTYPE_TRAM) ? &_tram_depot[dir] : &_road_depot[dir];
4232
628628eaa4fc (svn r5796) Use DrawTileSprites/DrawTileSeqStruct for road depot drawing data, too
tron
parents: 4231
diff changeset
  1148
	const DrawTileSeqStruct* dtss;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1149
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2549
diff changeset
  1150
	x += 33;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2549
diff changeset
  1151
	y += 17;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1152
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5894
diff changeset
  1153
	DrawSprite(dts->ground_sprite, PAL_NONE, x, y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1154
4232
628628eaa4fc (svn r5796) Use DrawTileSprites/DrawTileSeqStruct for road depot drawing data, too
tron
parents: 4231
diff changeset
  1155
	for (dtss = dts->seq; dtss->image != 0; dtss++) {
628628eaa4fc (svn r5796) Use DrawTileSprites/DrawTileSeqStruct for road depot drawing data, too
tron
parents: 4231
diff changeset
  1156
		Point pt = RemapCoords(dtss->delta_x, dtss->delta_y, dtss->delta_z);
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5894
diff changeset
  1157
		SpriteID image = dtss->image;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1158
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8353
diff changeset
  1159
		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
  1160
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1161
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1162
4231
dea6a63dd058 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4226
diff changeset
  1163
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
  1164
{
4231
dea6a63dd058 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4226
diff changeset
  1165
	uint z;
dea6a63dd058 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4226
diff changeset
  1166
	Slope tileh = GetTileSlope(tile, &z);
3098
4c1320da876d (svn r3687) Complete some bits I missed whenn adding accessor functions for road types and pieces
tron
parents: 3097
diff changeset
  1167
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3560
diff changeset
  1168
	if (tileh == SLOPE_FLAT) return z;
4231
dea6a63dd058 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4226
diff changeset
  1169
	if (GetRoadTileType(tile) == ROAD_TILE_NORMAL) {
7831
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7829
diff changeset
  1170
		Foundation f = GetRoadFoundation(tileh, GetAllRoadBits(tile));
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7829
diff changeset
  1171
		z += ApplyFoundationToSlope(f, &tileh);
4231
dea6a63dd058 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4226
diff changeset
  1172
		return z + GetPartialZ(x & 0xF, y & 0xF, tileh);
3286
3250f1488eb2 (svn r4000) Rewrite GetSlope{Tileh,Z}_{Road,Track} in a less confusing way
tron
parents: 3277
diff changeset
  1173
	} else {
3645
86af43f87885 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3637
diff changeset
  1174
		return z + TILE_HEIGHT;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1175
	}
39
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 22
diff changeset
  1176
}
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 22
diff changeset
  1177
7831
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7829
diff changeset
  1178
static Foundation GetFoundation_Road(TileIndex tile, Slope tileh)
39
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 22
diff changeset
  1179
{
3793
33cdb5bf7b21 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3792
diff changeset
  1180
	if (GetRoadTileType(tile) == ROAD_TILE_NORMAL) {
7831
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7829
diff changeset
  1181
		return GetRoadFoundation(tileh, GetAllRoadBits(tile));
3286
3250f1488eb2 (svn r4000) Rewrite GetSlope{Tileh,Z}_{Road,Track} in a less confusing way
tron
parents: 3277
diff changeset
  1182
	} else {
7831
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7829
diff changeset
  1183
		return FlatteningFoundation(tileh);
39
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 22
diff changeset
  1184
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1185
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1186
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
  1187
static void GetAcceptedCargo_Road(TileIndex tile, AcceptedCargo ac)
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
	/* not used */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1190
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1191
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
  1192
static void AnimateTile_Road(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1193
{
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2549
diff changeset
  1194
	if (IsLevelCrossing(tile)) MarkTileDirtyByTile(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1195
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1196
4048
e773f441eb4f (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1197
e773f441eb4f (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1198
static const Roadside _town_road_types[][2] = {
e773f441eb4f (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1199
	{ ROADSIDE_GRASS,         ROADSIDE_GRASS },
e773f441eb4f (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1200
	{ ROADSIDE_PAVED,         ROADSIDE_PAVED },
e773f441eb4f (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1201
	{ ROADSIDE_PAVED,         ROADSIDE_PAVED },
e773f441eb4f (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1202
	{ ROADSIDE_TREES,         ROADSIDE_TREES },
e773f441eb4f (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1203
	{ ROADSIDE_STREET_LIGHTS, ROADSIDE_PAVED }
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1204
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1205
4048
e773f441eb4f (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1206
static const Roadside _town_road_types_2[][2] = {
e773f441eb4f (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1207
	{ ROADSIDE_GRASS,         ROADSIDE_GRASS },
e773f441eb4f (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1208
	{ ROADSIDE_PAVED,         ROADSIDE_PAVED },
e773f441eb4f (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1209
	{ ROADSIDE_STREET_LIGHTS, ROADSIDE_PAVED },
e773f441eb4f (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1210
	{ ROADSIDE_STREET_LIGHTS, ROADSIDE_PAVED },
e773f441eb4f (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1211
	{ ROADSIDE_STREET_LIGHTS, ROADSIDE_PAVED }
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1212
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1213
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1214
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
  1215
static void TileLoop_Road(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1216
{
3017
915fae59d5e0 (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents: 2989
diff changeset
  1217
	switch (_opt.landscape) {
6683
7ec558346172 (svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents: 6669
diff changeset
  1218
		case LT_ARCTIC:
6669
487ac09b95c4 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6585
diff changeset
  1219
			if (IsOnSnow(tile) != (GetTileZ(tile) > GetSnowLine())) {
3430
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
  1220
				ToggleSnow(tile);
3017
915fae59d5e0 (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents: 2989
diff changeset
  1221
				MarkTileDirtyByTile(tile);
915fae59d5e0 (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents: 2989
diff changeset
  1222
			}
915fae59d5e0 (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents: 2989
diff changeset
  1223
			break;
915fae59d5e0 (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents: 2989
diff changeset
  1224
6683
7ec558346172 (svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents: 6669
diff changeset
  1225
		case LT_TROPIC:
3430
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
  1226
			if (GetTropicZone(tile) == TROPICZONE_DESERT && !IsOnDesert(tile)) {
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
  1227
				ToggleDesert(tile);
3017
915fae59d5e0 (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents: 2989
diff changeset
  1228
				MarkTileDirtyByTile(tile);
915fae59d5e0 (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents: 2989
diff changeset
  1229
			}
915fae59d5e0 (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents: 2989
diff changeset
  1230
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1231
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1232
3793
33cdb5bf7b21 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3792
diff changeset
  1233
	if (GetRoadTileType(tile) == ROAD_TILE_DEPOT) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1234
8137
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
  1235
	const Town* t = ClosestTownFromTile(tile, (uint)-1);
3430
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
  1236
	if (!HasRoadWorks(tile)) {
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4048
diff changeset
  1237
		int grp = 0;
1280
b6925875de49 (svn r1784) -Fix: removed ClosestTownFromTile where possible, or replaced it
truelight
parents: 1264
diff changeset
  1238
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1239
		if (t != NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1240
			grp = GetTownRadiusGroup(t, tile);
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1241
6889
f7f6d9cb07a0 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6694
diff changeset
  1242
			/* 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
  1243
			if (t->road_build_months != 0 &&
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4048
diff changeset
  1244
					(DistanceManhattan(t->xy, tile) < 8 || grp != 0) &&
8328
6909973c8359 (svn r11382) -Codechange: renamed COUNTBITS to CountBits, as it is no longer a macro (skidd13)
truelight
parents: 8315
diff changeset
  1245
					GetRoadTileType(tile) == ROAD_TILE_NORMAL && CountBits(GetAllRoadBits(tile)) > 1 ) {
8137
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
  1246
				if (GetTileSlope(tile, NULL) == SLOPE_FLAT && EnsureNoVehicleOnGround(tile) && CHANCE16(1, 40)) {
3430
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
  1247
					StartRoadWorks(tile);
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1248
541
e1cd34389f79 (svn r925) Use sound enums
tron
parents: 534
diff changeset
  1249
					SndPlayTileFx(SND_21_JACKHAMMER, tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1250
					CreateEffectVehicleAbove(
3421
8ab76c47c72c (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3418
diff changeset
  1251
						TileX(tile) * TILE_SIZE + 7,
8ab76c47c72c (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3418
diff changeset
  1252
						TileY(tile) * TILE_SIZE + 7,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1253
						0,
1359
8ba976aed634 (svn r1863) Give the effect vehicle type enums more descriptive names and use the enum as parameter type for CreateEffectVehicle*()
tron
parents: 1327
diff changeset
  1254
						EV_BULLDOZER);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1255
					MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1256
					return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1257
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1258
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1259
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1260
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1261
		{
3430
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
  1262
			/* Adjust road ground type depending on 'grp' (grp is the distance to the center) */
6683
7ec558346172 (svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents: 6669
diff changeset
  1263
			const Roadside* new_rs = (_opt.landscape == LT_TOYLAND) ? _town_road_types_2[grp] : _town_road_types[grp];
4048
e773f441eb4f (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1264
			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
  1265
3430
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
  1266
			/* We have our desired type, do nothing */
4048
e773f441eb4f (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1267
			if (cur_rs == new_rs[0]) return;
3430
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
  1268
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
  1269
			/* We have the pre-type of the desired type, switch to the desired type */
4048
e773f441eb4f (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1270
			if (cur_rs == new_rs[1]) {
e773f441eb4f (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1271
				cur_rs = new_rs[0];
3430
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
  1272
			/* We have barren land, install the pre-type */
4048
e773f441eb4f (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1273
			} else if (cur_rs == ROADSIDE_BARREN) {
e773f441eb4f (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1274
				cur_rs = new_rs[1];
3430
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
  1275
			/* 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
  1276
			} else {
4048
e773f441eb4f (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1277
				cur_rs = ROADSIDE_BARREN;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1278
			}
4048
e773f441eb4f (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1279
			SetRoadside(tile, cur_rs);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1280
			MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1281
		}
3430
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
  1282
	} else if (IncreaseRoadWorksCounter(tile)) {
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
  1283
		TerminateRoadWorks(tile);
8137
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
  1284
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
  1285
		if (_patches.mod_road_rebuild) {
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
  1286
			/* Generate a nicer town surface */
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
  1287
			const RoadBits old_rb = GetAnyRoadBits(tile, ROADTYPE_ROAD);
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
  1288
			const RoadBits new_rb = CleanUpRoadBits(tile, old_rb);
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
  1289
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
  1290
			if (old_rb != new_rb) {
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
  1291
				DoCommand(tile, (old_rb ^ new_rb), t->index, DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_REMOVE_ROAD);
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
  1292
			}
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
  1293
		}
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8097
diff changeset
  1294
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1295
		MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1296
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1297
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1298
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
  1299
static void ClickTile_Road(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1300
{
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6582
diff changeset
  1301
	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
  1302
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1303
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1304
static const byte _road_trackbits[16] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1305
	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
  1306
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1307
7179
3e123c2b7c93 (svn r9914) -Codechange: prepare GTTS and the pathfinders to handle multiple road types on a single tile.
rubidium
parents: 7175
diff changeset
  1308
static uint32 GetTileTrackStatus_Road(TileIndex tile, TransportType mode, uint sub_mode)
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
  1309
{
7157
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 7122
diff changeset
  1310
3066
0d34dff23d98 (svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents: 3061
diff changeset
  1311
	switch (mode) {
0d34dff23d98 (svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents: 3061
diff changeset
  1312
		case TRANSPORT_RAIL:
0d34dff23d98 (svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents: 3061
diff changeset
  1313
			if (!IsLevelCrossing(tile)) return 0;
3267
591027d10884 (svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents: 3242
diff changeset
  1314
			return GetCrossingRailBits(tile) * 0x101;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1315
3066
0d34dff23d98 (svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents: 3061
diff changeset
  1316
		case TRANSPORT_ROAD:
7179
3e123c2b7c93 (svn r9914) -Codechange: prepare GTTS and the pathfinders to handle multiple road types on a single tile.
rubidium
parents: 7175
diff changeset
  1317
			if ((GetRoadTypes(tile) & sub_mode) == 0) return 0;
3793
33cdb5bf7b21 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3792
diff changeset
  1318
			switch (GetRoadTileType(tile)) {
7179
3e123c2b7c93 (svn r9914) -Codechange: prepare GTTS and the pathfinders to handle multiple road types on a single tile.
rubidium
parents: 7175
diff changeset
  1319
				case ROAD_TILE_NORMAL: {
3e123c2b7c93 (svn r9914) -Codechange: prepare GTTS and the pathfinders to handle multiple road types on a single tile.
rubidium
parents: 7175
diff changeset
  1320
					RoadType rt = (RoadType)FindFirstBit(sub_mode);
7260
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7257
diff changeset
  1321
					const uint drd_to_multiplier[DRD_END] = { 0x101, 0x100, 0x1, 0x0 };
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7257
diff changeset
  1322
					uint multiplier = drd_to_multiplier[rt == ROADTYPE_TRAM ? DRD_NONE : GetDisallowedRoadDirections(tile)];
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7257
diff changeset
  1323
					return HasRoadWorks(tile) ? 0 : _road_trackbits[GetRoadBits(tile, rt)] * multiplier;
7179
3e123c2b7c93 (svn r9914) -Codechange: prepare GTTS and the pathfinders to handle multiple road types on a single tile.
rubidium
parents: 7175
diff changeset
  1324
				}
3066
0d34dff23d98 (svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents: 3061
diff changeset
  1325
3793
33cdb5bf7b21 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3792
diff changeset
  1326
				case ROAD_TILE_CROSSING: {
4158
a8f7265a6fd0 (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4081
diff changeset
  1327
					uint32 r = AxisToTrackBits(GetCrossingRoadAxis(tile)) * 0x101;
3272
7e556f209503 (svn r3984) Add a function to get the road axis of a level crossing
tron
parents: 3269
diff changeset
  1328
3367
3f82c99d42af (svn r4164) Use acessor functions
tron
parents: 3365
diff changeset
  1329
					if (IsCrossingBarred(tile)) r *= 0x10001;
3066
0d34dff23d98 (svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents: 3061
diff changeset
  1330
					return r;
0d34dff23d98 (svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents: 3061
diff changeset
  1331
				}
0d34dff23d98 (svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents: 3061
diff changeset
  1332
3069
0e6aca11c3da (svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents: 3068
diff changeset
  1333
				default:
3793
33cdb5bf7b21 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3792
diff changeset
  1334
				case ROAD_TILE_DEPOT:
4158
a8f7265a6fd0 (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4081
diff changeset
  1335
					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
  1336
			}
3066
0d34dff23d98 (svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents: 3061
diff changeset
  1337
			break;
0d34dff23d98 (svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents: 3061
diff changeset
  1338
0d34dff23d98 (svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents: 3061
diff changeset
  1339
		default: break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1340
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1341
	return 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1342
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1343
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1344
static const StringID _road_tile_strings[] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1345
	STR_1814_ROAD,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1346
	STR_1814_ROAD,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1347
	STR_1814_ROAD,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1348
	STR_1815_ROAD_WITH_STREETLIGHTS,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1349
	STR_1814_ROAD,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1350
	STR_1816_TREE_LINED_ROAD,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1351
	STR_1814_ROAD,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1352
	STR_1814_ROAD,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1353
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1354
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
  1355
static void GetTileDesc_Road(TileIndex tile, TileDesc *td)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1356
{
1901
fb05044cf5c3 (svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents: 1891
diff changeset
  1357
	td->owner = GetTileOwner(tile);
3793
33cdb5bf7b21 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3792
diff changeset
  1358
	switch (GetRoadTileType(tile)) {
33cdb5bf7b21 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3792
diff changeset
  1359
		case ROAD_TILE_CROSSING: td->str = STR_1818_ROAD_RAIL_LEVEL_CROSSING; break;
33cdb5bf7b21 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3792
diff changeset
  1360
		case ROAD_TILE_DEPOT: td->str = STR_1817_ROAD_VEHICLE_DEPOT; break;
4048
e773f441eb4f (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1361
		default: td->str = _road_tile_strings[GetRoadside(tile)]; break;
3069
0e6aca11c3da (svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents: 3068
diff changeset
  1362
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1363
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1364
7219
e5b7a61ea70f (svn r9955) -Codechange: Make _roadveh_enter_depot_unk0 slightly less mysterious.
maedhros
parents: 7215
diff changeset
  1365
/**
e5b7a61ea70f (svn r9955) -Codechange: Make _roadveh_enter_depot_unk0 slightly less mysterious.
maedhros
parents: 7215
diff changeset
  1366
 * Given the direction the road depot is pointing, this is the direction the
e5b7a61ea70f (svn r9955) -Codechange: Make _roadveh_enter_depot_unk0 slightly less mysterious.
maedhros
parents: 7215
diff changeset
  1367
 * vehicle should be travelling in in order to enter the depot.
e5b7a61ea70f (svn r9955) -Codechange: Make _roadveh_enter_depot_unk0 slightly less mysterious.
maedhros
parents: 7215
diff changeset
  1368
 */
e5b7a61ea70f (svn r9955) -Codechange: Make _roadveh_enter_depot_unk0 slightly less mysterious.
maedhros
parents: 7215
diff changeset
  1369
static const byte _roadveh_enter_depot_dir[4] = {
e5b7a61ea70f (svn r9955) -Codechange: Make _roadveh_enter_depot_unk0 slightly less mysterious.
maedhros
parents: 7215
diff changeset
  1370
	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
  1371
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1372
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
  1373
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
  1374
{
3793
33cdb5bf7b21 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3792
diff changeset
  1375
	switch (GetRoadTileType(tile)) {
33cdb5bf7b21 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3792
diff changeset
  1376
		case ROAD_TILE_CROSSING:
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6582
diff changeset
  1377
			if (v->type == VEH_TRAIN && !IsCrossingBarred(tile)) {
3060
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1378
				/* train crossing a road */
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1379
				SndPlayVehicleFx(SND_0E_LEVEL_CROSSING, v);
3322
fa5d46929db9 (svn r4088) -Codechange: Introduce {Unb,B}arCrossing and IsCrossingBarred to put and get the status of a level crossing
celestar
parents: 3319
diff changeset
  1380
				BarCrossing(tile);
3060
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1381
				MarkTileDirtyByTile(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1382
			}
3060
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1383
			break;
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1384
3793
33cdb5bf7b21 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3792
diff changeset
  1385
		case ROAD_TILE_DEPOT:
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6582
diff changeset
  1386
			if (v->type == VEH_ROAD &&
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4048
diff changeset
  1387
					v->u.road.frame == 11 &&
7219
e5b7a61ea70f (svn r9955) -Codechange: Make _roadveh_enter_depot_unk0 slightly less mysterious.
maedhros
parents: 7215
diff changeset
  1388
					_roadveh_enter_depot_dir[GetRoadDepotDirection(tile)] == v->u.road.state) {
7353
716c6dd9322a (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 7310
diff changeset
  1389
				v->u.road.state = RVSB_IN_DEPOT;
716c6dd9322a (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 7310
diff changeset
  1390
				v->vehstatus |= VS_HIDDEN;
716c6dd9322a (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 7310
diff changeset
  1391
				v->direction = ReverseDir(v->direction);
7988
6075538f6111 (svn r11003) -Codechange: replace Vehicle->next to Vehicle->Next() and Vehicle->SetNext() so we can trap instances that change a next pointer and (in the future) update the first/previous pointers based on that.
rubidium
parents: 7938
diff changeset
  1392
				if (v->Next() == NULL) VehicleEnterDepot(v);
7353
716c6dd9322a (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 7310
diff changeset
  1393
				v->tile = tile;
716c6dd9322a (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 7310
diff changeset
  1394
716c6dd9322a (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 7310
diff changeset
  1395
				InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile);
6317
c73bda71ac16 (svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents: 6193
diff changeset
  1396
				return VETSB_ENTERED_WORMHOLE;
3060
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1397
			}
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1398
			break;
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1399
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1400
		default: break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1401
	}
6317
c73bda71ac16 (svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents: 6193
diff changeset
  1402
	return VETSB_CONTINUE;
0
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
2436
177cb6a8339f (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents: 2425
diff changeset
  1406
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
  1407
{
7157
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 7122
diff changeset
  1408
	if (GetRoadTileType(tile) == ROAD_TILE_DEPOT) {
7213
9e17eef904cb (svn r9949) -Fix: (road) depots got deowned on bankrupts.
rubidium
parents: 7212
diff changeset
  1409
		if (GetTileOwner(tile) == old_player) {
9e17eef904cb (svn r9949) -Fix: (road) depots got deowned on bankrupts.
rubidium
parents: 7212
diff changeset
  1410
			if (new_player == PLAYER_SPECTATOR) {
9e17eef904cb (svn r9949) -Fix: (road) depots got deowned on bankrupts.
rubidium
parents: 7212
diff changeset
  1411
				DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
9e17eef904cb (svn r9949) -Fix: (road) depots got deowned on bankrupts.
rubidium
parents: 7212
diff changeset
  1412
			} else {
9e17eef904cb (svn r9949) -Fix: (road) depots got deowned on bankrupts.
rubidium
parents: 7212
diff changeset
  1413
				SetTileOwner(tile, new_player);
9e17eef904cb (svn r9949) -Fix: (road) depots got deowned on bankrupts.
rubidium
parents: 7212
diff changeset
  1414
			}
7185
1fbb1d9d34d1 (svn r9921) -Fix (r9892): ownership wasn't properly propagated on owner changes.
rubidium
parents: 7179
diff changeset
  1415
		}
7157
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 7122
diff changeset
  1416
		return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1417
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1418
7157
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 7122
diff changeset
  1419
	for (RoadType rt = ROADTYPE_ROAD; rt < ROADTYPE_END; rt++) {
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8353
diff changeset
  1420
		if (!HasBit(GetRoadTypes(tile), rt)) continue;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1421
7157
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 7122
diff changeset
  1422
		if (GetRoadOwner(tile, rt) == old_player) {
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 7122
diff changeset
  1423
			SetRoadOwner(tile, rt, new_player == PLAYER_SPECTATOR ? OWNER_NONE : new_player);
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 7122
diff changeset
  1424
		}
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 7122
diff changeset
  1425
	}
3060
187ddce152fe (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1426
7157
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 7122
diff changeset
  1427
	if (IsLevelCrossing(tile)) {
7185
1fbb1d9d34d1 (svn r9921) -Fix (r9892): ownership wasn't properly propagated on owner changes.
rubidium
parents: 7179
diff changeset
  1428
		if (GetTileOwner(tile) == old_player) {
1fbb1d9d34d1 (svn r9921) -Fix (r9892): ownership wasn't properly propagated on owner changes.
rubidium
parents: 7179
diff changeset
  1429
			if (new_player == PLAYER_SPECTATOR) {
1fbb1d9d34d1 (svn r9921) -Fix (r9892): ownership wasn't properly propagated on owner changes.
rubidium
parents: 7179
diff changeset
  1430
				MakeRoadNormal(tile, GetCrossingRoadBits(tile), GetRoadTypes(tile), GetTownIndex(tile), GetRoadOwner(tile, ROADTYPE_ROAD), GetRoadOwner(tile, ROADTYPE_TRAM), GetRoadOwner(tile, ROADTYPE_HWAY));
1fbb1d9d34d1 (svn r9921) -Fix (r9892): ownership wasn't properly propagated on owner changes.
rubidium
parents: 7179
diff changeset
  1431
			} else {
1fbb1d9d34d1 (svn r9921) -Fix (r9892): ownership wasn't properly propagated on owner changes.
rubidium
parents: 7179
diff changeset
  1432
				SetTileOwner(tile, new_player);
1fbb1d9d34d1 (svn r9921) -Fix (r9892): ownership wasn't properly propagated on owner changes.
rubidium
parents: 7179
diff changeset
  1433
			}
1fbb1d9d34d1 (svn r9921) -Fix (r9892): ownership wasn't properly propagated on owner changes.
rubidium
parents: 7179
diff changeset
  1434
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1435
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1436
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1437
7990
70039e33e893 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7988
diff changeset
  1438
static CommandCost TerraformTile_Road(TileIndex tile, uint32 flags, uint z_new, Slope tileh_new)
70039e33e893 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7988
diff changeset
  1439
{
8078
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  1440
	if (_patches.build_on_slopes && AutoslopeEnabled()) {
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  1441
		switch (GetRoadTileType(tile)) {
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  1442
			case ROAD_TILE_CROSSING:
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8353
diff changeset
  1443
				if (!IsSteepSlope(tileh_new) && (GetTileMaxZ(tile) == z_new + GetSlopeMaxZ(tileh_new)) && HasBit(VALID_LEVEL_CROSSING_SLOPES, tileh_new)) return _price.terraform;
8078
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  1444
				break;
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  1445
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  1446
			case ROAD_TILE_DEPOT:
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  1447
				if (AutoslopeCheckForEntranceEdge(tile, z_new, tileh_new, GetRoadDepotDirection(tile))) return _price.terraform;
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  1448
				break;
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  1449
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  1450
			case ROAD_TILE_NORMAL: {
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  1451
				RoadBits bits = GetAllRoadBits(tile);
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  1452
				RoadBits bits_copy = bits;
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  1453
				/* Check if the slope-road_bits combination is valid at all, i.e. it is save to call GetRoadFoundation(). */
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  1454
				if (!CmdFailed(CheckRoadSlope(tileh_new, &bits_copy, ROAD_NONE))) {
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  1455
					/* CheckRoadSlope() sometimes changes the road_bits, if it does not agree with them. */
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  1456
					if (bits == bits_copy) {
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  1457
						uint z_old;
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  1458
						Slope tileh_old = GetTileSlope(tile, &z_old);
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  1459
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  1460
						/* Get the slope on top of the foundation */
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  1461
						z_old += ApplyFoundationToSlope(GetRoadFoundation(tileh_old, bits), &tileh_old);
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  1462
						z_new += ApplyFoundationToSlope(GetRoadFoundation(tileh_new, bits), &tileh_new);
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  1463
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  1464
						/* The surface slope must not be changed */
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  1465
						if ((z_old == z_new) && (tileh_old == tileh_new)) return _price.terraform;
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  1466
					}
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  1467
				}
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  1468
				break;
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  1469
			}
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  1470
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  1471
			default: NOT_REACHED();
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  1472
		}
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  1473
	}
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  1474
7990
70039e33e893 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7988
diff changeset
  1475
	return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
70039e33e893 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7988
diff changeset
  1476
}
70039e33e893 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7988
diff changeset
  1477
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1478
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
  1479
extern const TileTypeProcs _tile_type_road_procs = {
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4246
diff changeset
  1480
	DrawTile_Road,           /* draw_tile_proc */
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4246
diff changeset
  1481
	GetSlopeZ_Road,          /* get_slope_z_proc */
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4246
diff changeset
  1482
	ClearTile_Road,          /* clear_tile_proc */
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4246
diff changeset
  1483
	GetAcceptedCargo_Road,   /* get_accepted_cargo_proc */
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4246
diff changeset
  1484
	GetTileDesc_Road,        /* get_tile_desc_proc */
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4246
diff changeset
  1485
	GetTileTrackStatus_Road, /* get_tile_track_status_proc */
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4246
diff changeset
  1486
	ClickTile_Road,          /* click_tile_proc */
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4246
diff changeset
  1487
	AnimateTile_Road,        /* animate_tile_proc */
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4246
diff changeset
  1488
	TileLoop_Road,           /* tile_loop_clear */
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4246
diff changeset
  1489
	ChangeTileOwner_Road,    /* change_tile_owner_clear */
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4246
diff changeset
  1490
	NULL,                    /* get_produced_cargo_proc */
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4246
diff changeset
  1491
	VehicleEnter_Road,       /* vehicle_enter_tile_proc */
7831
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7829
diff changeset
  1492
	GetFoundation_Road,      /* get_foundation_proc */
7990
70039e33e893 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7988
diff changeset
  1493
	TerraformTile_Road,      /* terraform_tile_proc */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1494
};