src/road_cmd.cpp
author peter1138
Sun, 03 Aug 2008 17:35:08 +0000
changeset 9834 7474149531c1
parent 9789 b753e2d50d99
child 10017 c0eb11a864d7
permissions -rw-r--r--
(svn r13977) -Codechange: Let ResizeWindowForWidget() handle hidden (zero height or zero width) widgets.
2186
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
9111
48ce04029fe4 (svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents: 9067
diff changeset
     3
/** @file road_cmd.cpp Commands related to road tiles. */
6393
e1e4939d19b5 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6368
diff changeset
     4
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
#include "stdafx.h"
1891
862800791170 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1785
diff changeset
     6
#include "openttd.h"
3189
bf047128dee7 (svn r3846) Add functions to set the type of stuff (clear, water, rail, road) under bridges
tron
parents: 3176
diff changeset
     7
#include "bridge_map.h"
6160
fa42299e967e (svn r8908) -Codechange: declaration of DrawBridgeMiddle does not belong in a map accessors header.
rubidium
parents: 6134
diff changeset
     8
#include "bridge.h"
6134
871305fd9ab7 (svn r8876) -Fix
tron
parents: 6133
diff changeset
     9
#include "cmd_helper.h"
3101
a44fdf9faef1 (svn r3696) Add functions to turn a tile into a normal rail tile/depot/waypoint. This is just a tiny step, the rail code needs way more love and caring
tron
parents: 3100
diff changeset
    10
#include "rail_map.h"
3144
33e42feae531 (svn r3763) Adapt to the new 'map accessors go in foo_map.h'-scheme
tron
parents: 3104
diff changeset
    11
#include "road_map.h"
8102
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents: 8096
diff changeset
    12
#include "road_internal.h"
4232
136a11474264 (svn r5796) Use DrawTileSprites/DrawTileSeqStruct for road depot drawing data, too
tron
parents: 4231
diff changeset
    13
#include "sprite.h"
8119
52b48108425a (svn r11680) -Codechange: refactor more out of openttd.h and functions.h.
rubidium
parents: 8116
diff changeset
    14
#include "tile_cmd.h"
6343
76d17f784c13 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6259
diff changeset
    15
#include "landscape.h"
3319
16c0f06829a5 (svn r4085) Add GetTown{Index,ByTile}() to get the town index resp. the town from a tile
tron
parents: 3286
diff changeset
    16
#include "town_map.h"
8224
c5a64d87cc54 (svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents: 8211
diff changeset
    17
#include "viewport_func.h"
8116
8da76dcb3287 (svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents: 8114
diff changeset
    18
#include "command_func.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    19
#include "town.h"
3900
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3884
diff changeset
    20
#include "yapf/yapf.h"
8962
1b263c69799d (svn r12754) -Codechange: split depot.h into depot_map.h, depot_func.h and depot_base.h and remove quite a lot of unneeded (before this) includes of depot.h.
rubidium
parents: 8912
diff changeset
    21
#include "depot_base.h"
1b263c69799d (svn r12754) -Codechange: split depot.h into depot_map.h, depot_func.h and depot_base.h and remove quite a lot of unneeded (before this) includes of depot.h.
rubidium
parents: 8912
diff changeset
    22
#include "depot_func.h"
6541
dfa5165a5ab7 (svn r9730) -Feature: [NewGRF] Add support for miscellaneous grf feature bit 1 - paved roads on desert tiles.
maedhros
parents: 6491
diff changeset
    23
#include "newgrf.h"
6679
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
    24
#include "station_map.h"
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
    25
#include "tunnel_map.h"
8211
29a8510dfd62 (svn r11774) -Change: do not include variables.h in a header when it is not needed.
rubidium
parents: 8197
diff changeset
    26
#include "variables.h"
7582
80c8517b08d1 (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: 7539
diff changeset
    27
#include "autoslope.h"
7849
0a1c0af2c96c (svn r11399) -Feature(ette): transparency settings can now be saved and thus remembered.
belugas
parents: 7832
diff changeset
    28
#include "transparency.h"
8083
ad22eade501f (svn r11644) -Codechange: merge some functions from tunnel_map.h and bridge_map.h into tunnelbridge_map.h
smatz
parents: 8081
diff changeset
    29
#include "tunnelbridge_map.h"
8106
e6790dd9e750 (svn r11667) -Codechange: split window.h into a header that defines some 'global' window related types, on that defined 'global' window functions and one that defines functions and types only used by *_gui.cpps.
rubidium
parents: 8102
diff changeset
    30
#include "window_func.h"
8114
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents: 8108
diff changeset
    31
#include "strings_func.h"
8144
65cec0877b78 (svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium
parents: 8139
diff changeset
    32
#include "vehicle_func.h"
65cec0877b78 (svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium
parents: 8139
diff changeset
    33
#include "vehicle_base.h"
8157
1505def01945 (svn r11719) -Codechange: split sound.h in a header with types and one with functions.
rubidium
parents: 8144
diff changeset
    34
#include "sound_func.h"
8342
bf710180e7ce (svn r11908) -Fix: update crossing when merging a company, when building a crossing and after loading older savegame
smatz
parents: 8308
diff changeset
    35
#include "road_func.h"
8398
1e181e2e4e15 (svn r11968) -Codechange: remove redundant FindLengthOfTunnel(), use GetTunnelBridgeLength() and/or GetOtherTunnelEnd() instead
smatz
parents: 8390
diff changeset
    36
#include "tunnelbridge.h"
8965
29a591456a2f (svn r12757) -Codechange: move all cheat related stuff from all over the place to a single location.
rubidium
parents: 8962
diff changeset
    37
#include "cheat_func.h"
9006
7666e7b47088 (svn r12801) -Codechange: remove the dependency of function.h in town_map.h
rubidium
parents: 8965
diff changeset
    38
#include "functions.h"
9009
6684576ef32b (svn r12804) -Codechange: move the effect vehicle handling out of vehicle.cpp
rubidium
parents: 9006
diff changeset
    39
#include "effectvehicle_func.h"
9154
2c042b567165 (svn r13016) -Codechange: unify the detection if rail catenary should be drawn
smatz
parents: 9111
diff changeset
    40
#include "elrail_func.h"
9038
38f0f10f8cca (svn r12857) -Fix [FS#1948]: remove the last uses of AutoPtr in the station code.
rubidium
parents: 9036
diff changeset
    41
#include "oldpool_func.h"
8083
ad22eade501f (svn r11644) -Codechange: merge some functions from tunnel_map.h and bridge_map.h into tunnelbridge_map.h
smatz
parents: 8081
diff changeset
    42
8264
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8254
diff changeset
    43
#include "table/sprites.h"
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8254
diff changeset
    44
#include "table/strings.h"
7582
80c8517b08d1 (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: 7539
diff changeset
    45
9298
c758dcefb1f2 (svn r13166) -Codechange: CmdSetRoadDriveSide belongs in road_cmd.cpp, not settings_gui.cpp.
rubidium
parents: 9224
diff changeset
    46
c758dcefb1f2 (svn r13166) -Codechange: CmdSetRoadDriveSide belongs in road_cmd.cpp, not settings_gui.cpp.
rubidium
parents: 9224
diff changeset
    47
bool RoadVehiclesAreBuilt()
c758dcefb1f2 (svn r13166) -Codechange: CmdSetRoadDriveSide belongs in road_cmd.cpp, not settings_gui.cpp.
rubidium
parents: 9224
diff changeset
    48
{
c758dcefb1f2 (svn r13166) -Codechange: CmdSetRoadDriveSide belongs in road_cmd.cpp, not settings_gui.cpp.
rubidium
parents: 9224
diff changeset
    49
	const Vehicle* v;
c758dcefb1f2 (svn r13166) -Codechange: CmdSetRoadDriveSide belongs in road_cmd.cpp, not settings_gui.cpp.
rubidium
parents: 9224
diff changeset
    50
c758dcefb1f2 (svn r13166) -Codechange: CmdSetRoadDriveSide belongs in road_cmd.cpp, not settings_gui.cpp.
rubidium
parents: 9224
diff changeset
    51
	FOR_ALL_VEHICLES(v) {
c758dcefb1f2 (svn r13166) -Codechange: CmdSetRoadDriveSide belongs in road_cmd.cpp, not settings_gui.cpp.
rubidium
parents: 9224
diff changeset
    52
		if (v->type == VEH_ROAD) return true;
c758dcefb1f2 (svn r13166) -Codechange: CmdSetRoadDriveSide belongs in road_cmd.cpp, not settings_gui.cpp.
rubidium
parents: 9224
diff changeset
    53
	}
c758dcefb1f2 (svn r13166) -Codechange: CmdSetRoadDriveSide belongs in road_cmd.cpp, not settings_gui.cpp.
rubidium
parents: 9224
diff changeset
    54
	return false;
c758dcefb1f2 (svn r13166) -Codechange: CmdSetRoadDriveSide belongs in road_cmd.cpp, not settings_gui.cpp.
rubidium
parents: 9224
diff changeset
    55
}
c758dcefb1f2 (svn r13166) -Codechange: CmdSetRoadDriveSide belongs in road_cmd.cpp, not settings_gui.cpp.
rubidium
parents: 9224
diff changeset
    56
c758dcefb1f2 (svn r13166) -Codechange: CmdSetRoadDriveSide belongs in road_cmd.cpp, not settings_gui.cpp.
rubidium
parents: 9224
diff changeset
    57
/**
c758dcefb1f2 (svn r13166) -Codechange: CmdSetRoadDriveSide belongs in road_cmd.cpp, not settings_gui.cpp.
rubidium
parents: 9224
diff changeset
    58
 * Change the side of the road vehicles drive on (server only).
c758dcefb1f2 (svn r13166) -Codechange: CmdSetRoadDriveSide belongs in road_cmd.cpp, not settings_gui.cpp.
rubidium
parents: 9224
diff changeset
    59
 * @param tile unused
c758dcefb1f2 (svn r13166) -Codechange: CmdSetRoadDriveSide belongs in road_cmd.cpp, not settings_gui.cpp.
rubidium
parents: 9224
diff changeset
    60
 * @param flags operation to perform
c758dcefb1f2 (svn r13166) -Codechange: CmdSetRoadDriveSide belongs in road_cmd.cpp, not settings_gui.cpp.
rubidium
parents: 9224
diff changeset
    61
 * @param p1 the side of the road; 0 = left side and 1 = right side
c758dcefb1f2 (svn r13166) -Codechange: CmdSetRoadDriveSide belongs in road_cmd.cpp, not settings_gui.cpp.
rubidium
parents: 9224
diff changeset
    62
 * @param p2 unused
c758dcefb1f2 (svn r13166) -Codechange: CmdSetRoadDriveSide belongs in road_cmd.cpp, not settings_gui.cpp.
rubidium
parents: 9224
diff changeset
    63
 */
c758dcefb1f2 (svn r13166) -Codechange: CmdSetRoadDriveSide belongs in road_cmd.cpp, not settings_gui.cpp.
rubidium
parents: 9224
diff changeset
    64
CommandCost CmdSetRoadDriveSide(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
c758dcefb1f2 (svn r13166) -Codechange: CmdSetRoadDriveSide belongs in road_cmd.cpp, not settings_gui.cpp.
rubidium
parents: 9224
diff changeset
    65
{
c758dcefb1f2 (svn r13166) -Codechange: CmdSetRoadDriveSide belongs in road_cmd.cpp, not settings_gui.cpp.
rubidium
parents: 9224
diff changeset
    66
	/* Check boundaries and you can only change this if NO vehicles have been built yet,
c758dcefb1f2 (svn r13166) -Codechange: CmdSetRoadDriveSide belongs in road_cmd.cpp, not settings_gui.cpp.
rubidium
parents: 9224
diff changeset
    67
	 * except in the intro-menu where of course it's always possible to do so. */
c758dcefb1f2 (svn r13166) -Codechange: CmdSetRoadDriveSide belongs in road_cmd.cpp, not settings_gui.cpp.
rubidium
parents: 9224
diff changeset
    68
	if (p1 > 1 || (_game_mode != GM_MENU && RoadVehiclesAreBuilt())) return CMD_ERROR;
c758dcefb1f2 (svn r13166) -Codechange: CmdSetRoadDriveSide belongs in road_cmd.cpp, not settings_gui.cpp.
rubidium
parents: 9224
diff changeset
    69
c758dcefb1f2 (svn r13166) -Codechange: CmdSetRoadDriveSide belongs in road_cmd.cpp, not settings_gui.cpp.
rubidium
parents: 9224
diff changeset
    70
	if (flags & DC_EXEC) {
9346
bfd803297888 (svn r13242) -Codechange: remove _opt_ptr.
rubidium
parents: 9342
diff changeset
    71
		if (_game_mode == GM_MENU) {
9461
94946c6cebf2 (svn r13379) -Fix (r13255): drive side can't be changed in intro
glx
parents: 9413
diff changeset
    72
			_settings_newgame.vehicle.road_side = p1;
9346
bfd803297888 (svn r13242) -Codechange: remove _opt_ptr.
rubidium
parents: 9342
diff changeset
    73
		} else {
9413
7042a8ec3fa8 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 9358
diff changeset
    74
			_settings_game.vehicle.road_side = p1;
9346
bfd803297888 (svn r13242) -Codechange: remove _opt_ptr.
rubidium
parents: 9342
diff changeset
    75
		}
9298
c758dcefb1f2 (svn r13166) -Codechange: CmdSetRoadDriveSide belongs in road_cmd.cpp, not settings_gui.cpp.
rubidium
parents: 9224
diff changeset
    76
		InvalidateWindow(WC_GAME_OPTIONS, 0);
c758dcefb1f2 (svn r13166) -Codechange: CmdSetRoadDriveSide belongs in road_cmd.cpp, not settings_gui.cpp.
rubidium
parents: 9224
diff changeset
    77
	}
c758dcefb1f2 (svn r13166) -Codechange: CmdSetRoadDriveSide belongs in road_cmd.cpp, not settings_gui.cpp.
rubidium
parents: 9224
diff changeset
    78
	return CommandCost();
c758dcefb1f2 (svn r13166) -Codechange: CmdSetRoadDriveSide belongs in road_cmd.cpp, not settings_gui.cpp.
rubidium
parents: 9224
diff changeset
    79
}
c758dcefb1f2 (svn r13166) -Codechange: CmdSetRoadDriveSide belongs in road_cmd.cpp, not settings_gui.cpp.
rubidium
parents: 9224
diff changeset
    80
7582
80c8517b08d1 (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: 7539
diff changeset
    81
#define M(x) (1 << (x))
80c8517b08d1 (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: 7539
diff changeset
    82
/* Level crossings may only be built on these slopes */
80c8517b08d1 (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: 7539
diff changeset
    83
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));
80c8517b08d1 (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: 7539
diff changeset
    84
#undef M
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    85
8744
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
    86
/* Invalid RoadBits on slopes  */
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
    87
static const RoadBits _invalid_tileh_slopes_road[2][15] = {
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
    88
	/* The inverse of the mixable RoadBits on a leveled slope */
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
    89
	{
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
    90
		ROAD_NONE,         // SLOPE_FLAT
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
    91
		ROAD_NE | ROAD_SE, // SLOPE_W
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
    92
		ROAD_NE | ROAD_NW, // SLOPE_S
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
    93
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
    94
		ROAD_NE,           // SLOPE_SW
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
    95
		ROAD_NW | ROAD_SW, // SLOPE_E
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
    96
		ROAD_NONE,         // SLOPE_EW
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
    97
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
    98
		ROAD_NW,           // SLOPE_SE
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
    99
		ROAD_NONE,         // SLOPE_WSE
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   100
		ROAD_SE | ROAD_SW, // SLOPE_N
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   101
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   102
		ROAD_SE,           // SLOPE_NW
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   103
		ROAD_NONE,         // SLOPE_NS
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   104
		ROAD_NONE,         // SLOPE_ENW
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   105
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   106
		ROAD_SW,           // SLOPE_NE
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   107
		ROAD_NONE,         // SLOPE_SEN
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   108
		ROAD_NONE          // SLOPE_NWS
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   109
	},
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   110
	/* The inverse of the allowed straight roads on a slope
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   111
	 * (with and without a foundation). */
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   112
	{
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   113
		ROAD_NONE, // SLOPE_FLAT
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   114
		ROAD_NONE, // SLOPE_W    Foundation
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   115
		ROAD_NONE, // SLOPE_S    Foundation
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   116
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   117
		ROAD_Y,    // SLOPE_SW
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   118
		ROAD_NONE, // SLOPE_E    Foundation
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   119
		ROAD_ALL,  // SLOPE_EW
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   120
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   121
		ROAD_X,    // SLOPE_SE
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   122
		ROAD_ALL,  // SLOPE_WSE
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   123
		ROAD_NONE, // SLOPE_N    Foundation
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   124
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   125
		ROAD_X,    // SLOPE_NW
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   126
		ROAD_ALL,  // SLOPE_NS
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   127
		ROAD_ALL,  // SLOPE_ENW
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   128
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   129
		ROAD_Y,    // SLOPE_NE
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   130
		ROAD_ALL,  // SLOPE_SEN
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   131
		ROAD_ALL   // SLOPE_NW
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   132
	}
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   133
};
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   134
8384
d46e5338da92 (svn r11953) -Fix (r11172): do not allow modifying roadbits when other roadtypes would need different foundation
smatz
parents: 8344
diff changeset
   135
Foundation GetRoadFoundation(Slope tileh, RoadBits bits);
d46e5338da92 (svn r11953) -Fix (r11172): do not allow modifying roadbits when other roadtypes would need different foundation
smatz
parents: 8344
diff changeset
   136
9342
6daf441eee26 (svn r13234) -Fix: Check/affect town rating when removing/bulldozing town-owned road under drivethrough stops.
frosch
parents: 9341
diff changeset
   137
/**
6daf441eee26 (svn r13234) -Fix: Check/affect town rating when removing/bulldozing town-owned road under drivethrough stops.
frosch
parents: 9341
diff changeset
   138
 * Is it allowed to remove the given road bits from the given tile?
6daf441eee26 (svn r13234) -Fix: Check/affect town rating when removing/bulldozing town-owned road under drivethrough stops.
frosch
parents: 9341
diff changeset
   139
 * @param tile      the tile to remove the road from
6daf441eee26 (svn r13234) -Fix: Check/affect town rating when removing/bulldozing town-owned road under drivethrough stops.
frosch
parents: 9341
diff changeset
   140
 * @param remove    the roadbits that are going to be removed
6daf441eee26 (svn r13234) -Fix: Check/affect town rating when removing/bulldozing town-owned road under drivethrough stops.
frosch
parents: 9341
diff changeset
   141
 * @param owner     the actual owner of the roadbits of the tile
6daf441eee26 (svn r13234) -Fix: Check/affect town rating when removing/bulldozing town-owned road under drivethrough stops.
frosch
parents: 9341
diff changeset
   142
 * @param rt        the road type to remove the bits from
6daf441eee26 (svn r13234) -Fix: Check/affect town rating when removing/bulldozing town-owned road under drivethrough stops.
frosch
parents: 9341
diff changeset
   143
 * @param flags     command flags
6daf441eee26 (svn r13234) -Fix: Check/affect town rating when removing/bulldozing town-owned road under drivethrough stops.
frosch
parents: 9341
diff changeset
   144
 * @param town_check Shall the town rating checked/affected
6daf441eee26 (svn r13234) -Fix: Check/affect town rating when removing/bulldozing town-owned road under drivethrough stops.
frosch
parents: 9341
diff changeset
   145
 * @return true when it is allowed to remove the road bits
6daf441eee26 (svn r13234) -Fix: Check/affect town rating when removing/bulldozing town-owned road under drivethrough stops.
frosch
parents: 9341
diff changeset
   146
 */
6daf441eee26 (svn r13234) -Fix: Check/affect town rating when removing/bulldozing town-owned road under drivethrough stops.
frosch
parents: 9341
diff changeset
   147
bool CheckAllowRemoveRoad(TileIndex tile, RoadBits remove, Owner owner, RoadType rt, uint32 flags, bool town_check)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   148
{
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
   149
	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
   150
6751
a7f281b2a89a (svn r9986) -Fix (r9934): flooding towns could not remove tram tracks (boekabart).
rubidium
parents: 6732
diff changeset
   151
	/* Water can always flood and towns can always remove "normal" road pieces.
a7f281b2a89a (svn r9986) -Fix (r9934): flooding towns could not remove tram tracks (boekabart).
rubidium
parents: 6732
diff changeset
   152
	 * Towns are not be allowed to remove non "normal" road pieces, like tram
a7f281b2a89a (svn r9986) -Fix (r9934): flooding towns could not remove tram tracks (boekabart).
rubidium
parents: 6732
diff changeset
   153
	 * tracks as that would result in trams that cannot turn. */
a7f281b2a89a (svn r9986) -Fix (r9934): flooding towns could not remove tram tracks (boekabart).
rubidium
parents: 6732
diff changeset
   154
	if (_current_player == OWNER_WATER ||
9652
0405e98d8e96 (svn r13719) -Codechange: rename IsValidPlayer to IsValidPlayerID in line with all other structs/classes that are in a pool.
rubidium
parents: 9583
diff changeset
   155
			(rt == ROADTYPE_ROAD && !IsValidPlayerID(_current_player))) return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   156
6393
e1e4939d19b5 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6368
diff changeset
   157
	/* Only do the special processing if the road is owned
e1e4939d19b5 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6368
diff changeset
   158
	 * by a town */
4849
1c6f21eb97f2 (svn r6775) -Codechange: Use some more proper types, especially Owner and PlayerID as
Darkvater
parents: 4848
diff changeset
   159
	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
   160
9342
6daf441eee26 (svn r13234) -Fix: Check/affect town rating when removing/bulldozing town-owned road under drivethrough stops.
frosch
parents: 9341
diff changeset
   161
	if (!town_check) return true;
6daf441eee26 (svn r13234) -Fix: Check/affect town rating when removing/bulldozing town-owned road under drivethrough stops.
frosch
parents: 9341
diff changeset
   162
3017
a75caf4efa2d (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents: 2989
diff changeset
   163
	if (_cheats.magic_bulldozer.value) return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   164
9342
6daf441eee26 (svn r13234) -Fix: Check/affect town rating when removing/bulldozing town-owned road under drivethrough stops.
frosch
parents: 9341
diff changeset
   165
	Town *t = ClosestTownFromTile(tile, UINT_MAX);
6daf441eee26 (svn r13234) -Fix: Check/affect town rating when removing/bulldozing town-owned road under drivethrough stops.
frosch
parents: 9341
diff changeset
   166
	if (t == NULL) return true;
6daf441eee26 (svn r13234) -Fix: Check/affect town rating when removing/bulldozing town-owned road under drivethrough stops.
frosch
parents: 9341
diff changeset
   167
6daf441eee26 (svn r13234) -Fix: Check/affect town rating when removing/bulldozing town-owned road under drivethrough stops.
frosch
parents: 9341
diff changeset
   168
	/* check if you're allowed to remove the street owned by a town
6daf441eee26 (svn r13234) -Fix: Check/affect town rating when removing/bulldozing town-owned road under drivethrough stops.
frosch
parents: 9341
diff changeset
   169
	 * removal allowance depends on difficulty setting */
6daf441eee26 (svn r13234) -Fix: Check/affect town rating when removing/bulldozing town-owned road under drivethrough stops.
frosch
parents: 9341
diff changeset
   170
	if (!CheckforTownRating(flags, t, ROAD_REMOVE)) return false;
6daf441eee26 (svn r13234) -Fix: Check/affect town rating when removing/bulldozing town-owned road under drivethrough stops.
frosch
parents: 9341
diff changeset
   171
6393
e1e4939d19b5 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6368
diff changeset
   172
	/* Get a bitmask of which neighbouring roads has a tile */
8734
cf2c240d2e1b (svn r12419) -Cleanup: of the internal road-piece building and removing.
skidd13
parents: 8732
diff changeset
   173
	RoadBits n = ROAD_NONE;
cf2c240d2e1b (svn r12419) -Cleanup: of the internal road-piece building and removing.
skidd13
parents: 8732
diff changeset
   174
	RoadBits present = GetAnyRoadBits(tile, rt);
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
   175
	if (present & ROAD_NE && GetAnyRoadBits(TILE_ADDXY(tile, -1,  0), rt) & ROAD_SW) n |= ROAD_NE;
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
   176
	if (present & ROAD_SE && GetAnyRoadBits(TILE_ADDXY(tile,  0,  1), rt) & ROAD_NW) n |= ROAD_SE;
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
   177
	if (present & ROAD_SW && GetAnyRoadBits(TILE_ADDXY(tile,  1,  0), rt) & ROAD_NE) n |= ROAD_SW;
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
   178
	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
   179
9342
6daf441eee26 (svn r13234) -Fix: Check/affect town rating when removing/bulldozing town-owned road under drivethrough stops.
frosch
parents: 9341
diff changeset
   180
	int rating_decrease = RATING_ROAD_DOWN_STEP_EDGE;
6393
e1e4939d19b5 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6368
diff changeset
   181
	/* If 0 or 1 bits are set in n, or if no bits that match the bits to remove,
e1e4939d19b5 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6368
diff changeset
   182
	 * then allow it */
8734
cf2c240d2e1b (svn r12419) -Cleanup: of the internal road-piece building and removing.
skidd13
parents: 8732
diff changeset
   183
	if (KillFirstBit(n) != ROAD_NONE && (n & remove) != ROAD_NONE) {
6393
e1e4939d19b5 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6368
diff changeset
   184
		/* you can remove all kind of roads with extra dynamite */
9413
7042a8ec3fa8 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 9358
diff changeset
   185
		if (!_settings_game.construction.extra_dynamite) {
9342
6daf441eee26 (svn r13234) -Fix: Check/affect town rating when removing/bulldozing town-owned road under drivethrough stops.
frosch
parents: 9341
diff changeset
   186
			SetDParam(0, t->index);
6daf441eee26 (svn r13234) -Fix: Check/affect town rating when removing/bulldozing town-owned road under drivethrough stops.
frosch
parents: 9341
diff changeset
   187
			_error_message = STR_2009_LOCAL_AUTHORITY_REFUSES;
6daf441eee26 (svn r13234) -Fix: Check/affect town rating when removing/bulldozing town-owned road under drivethrough stops.
frosch
parents: 9341
diff changeset
   188
			return false;
6daf441eee26 (svn r13234) -Fix: Check/affect town rating when removing/bulldozing town-owned road under drivethrough stops.
frosch
parents: 9341
diff changeset
   189
		}
6daf441eee26 (svn r13234) -Fix: Check/affect town rating when removing/bulldozing town-owned road under drivethrough stops.
frosch
parents: 9341
diff changeset
   190
		rating_decrease = RATING_ROAD_DOWN_STEP_INNER;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   191
	}
9342
6daf441eee26 (svn r13234) -Fix: Check/affect town rating when removing/bulldozing town-owned road under drivethrough stops.
frosch
parents: 9341
diff changeset
   192
	ChangeTownRating(t, rating_decrease, RATING_ROAD_MINIMUM);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   193
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   194
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   195
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   196
8428
fb88a9033b48 (svn r11998) -Fix [FS#1692](r10053): possible remote assert by setting bit 6 of p1 for CMD_REMOVE_ROAD
smatz
parents: 8413
diff changeset
   197
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   198
/** Delete a piece of road.
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3435
diff changeset
   199
 * @param tile tile where to remove road from
6483
ae78fc3c6b20 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6427
diff changeset
   200
 * @param flags operation to perform
8428
fb88a9033b48 (svn r11998) -Fix [FS#1692](r10053): possible remote assert by setting bit 6 of p1 for CMD_REMOVE_ROAD
smatz
parents: 8413
diff changeset
   201
 * @param pieces roadbits to remove
fb88a9033b48 (svn r11998) -Fix [FS#1692](r10053): possible remote assert by setting bit 6 of p1 for CMD_REMOVE_ROAD
smatz
parents: 8413
diff changeset
   202
 * @param rt roadtype to remove
fb88a9033b48 (svn r11998) -Fix [FS#1692](r10053): possible remote assert by setting bit 6 of p1 for CMD_REMOVE_ROAD
smatz
parents: 8413
diff changeset
   203
 * @param crossing_check should we check if there is a tram track when we are removing road from crossing?
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   204
 */
8912
f8cb564a6109 (svn r12682) -Fix [FS#1920]: removing road pieces from a town gave you twice the intended penalty.
rubidium
parents: 8859
diff changeset
   205
static CommandCost RemoveRoad(TileIndex tile, uint32 flags, RoadBits pieces, RoadType rt, bool crossing_check, bool town_check = true)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   206
{
9341
bd60c3b2d1e0 (svn r13233) -Fix: Replace some (incorrect) evaluations of TileOwner by RoadOwner.
frosch
parents: 9322
diff changeset
   207
	RoadTypes rts = GetRoadTypes(tile);
bd60c3b2d1e0 (svn r13233) -Fix: Replace some (incorrect) evaluations of TileOwner by RoadOwner.
frosch
parents: 9322
diff changeset
   208
	/* The tile doesn't have the given road type */
bd60c3b2d1e0 (svn r13233) -Fix: Replace some (incorrect) evaluations of TileOwner by RoadOwner.
frosch
parents: 9322
diff changeset
   209
	if (!HasBit(rts, rt)) return CMD_ERROR;
bd60c3b2d1e0 (svn r13233) -Fix: Replace some (incorrect) evaluations of TileOwner by RoadOwner.
frosch
parents: 9322
diff changeset
   210
9342
6daf441eee26 (svn r13234) -Fix: Check/affect town rating when removing/bulldozing town-owned road under drivethrough stops.
frosch
parents: 9341
diff changeset
   211
	bool town_road_under_stop = false;
6daf441eee26 (svn r13234) -Fix: Check/affect town rating when removing/bulldozing town-owned road under drivethrough stops.
frosch
parents: 9341
diff changeset
   212
6679
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   213
	switch (GetTileType(tile)) {
7370
41adc721b1fa (svn r10733) -Codechange: change MP_STREET into MP_ROAD as we use the word "road" everywhere except in the tile type.
rubidium
parents: 7355
diff changeset
   214
		case MP_ROAD:
8075
acd9b1120d9d (svn r11636) -Fix: it was possible to build/remove road/tram in tunnel/bridge when there was vehicle in it
smatz
parents: 8043
diff changeset
   215
			if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
6679
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   216
			break;
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   217
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   218
		case MP_STATION:
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   219
			if (!IsDriveThroughStopTile(tile)) return CMD_ERROR;
9342
6daf441eee26 (svn r13234) -Fix: Check/affect town rating when removing/bulldozing town-owned road under drivethrough stops.
frosch
parents: 9341
diff changeset
   220
			if (rt == ROADTYPE_ROAD) town_road_under_stop = GetStopBuiltOnTownRoad(tile);
8075
acd9b1120d9d (svn r11636) -Fix: it was possible to build/remove road/tram in tunnel/bridge when there was vehicle in it
smatz
parents: 8043
diff changeset
   221
			if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
6679
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   222
			break;
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   223
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   224
		case MP_TUNNELBRIDGE:
8390
f88f515e6557 (svn r11960) -Cleanup: simplify some IsTunnel(Tile) / IsBridge(Tile) conditions
smatz
parents: 8384
diff changeset
   225
			if (GetTunnelBridgeTransportType(tile) != TRANSPORT_ROAD) return CMD_ERROR;
f88f515e6557 (svn r11960) -Cleanup: simplify some IsTunnel(Tile) / IsBridge(Tile) conditions
smatz
parents: 8384
diff changeset
   226
			if (GetVehicleTunnelBridge(tile, GetOtherTunnelBridgeEnd(tile)) != NULL) return CMD_ERROR;
f88f515e6557 (svn r11960) -Cleanup: simplify some IsTunnel(Tile) / IsBridge(Tile) conditions
smatz
parents: 8384
diff changeset
   227
			break;
6679
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   228
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   229
		default:
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   230
			return CMD_ERROR;
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   231
	}
1638
4779658c2d03 (svn r2142) - Fix: Game no longer crashes when you want to remove a piece of road under a bridge that belongs to the town. TODO: railcrossings store owner somewhere else, put it into _map_owner[]!
Darkvater
parents: 1398
diff changeset
   232
9342
6daf441eee26 (svn r13234) -Fix: Check/affect town rating when removing/bulldozing town-owned road under drivethrough stops.
frosch
parents: 9341
diff changeset
   233
	if (!CheckAllowRemoveRoad(tile, pieces, town_road_under_stop ? OWNER_TOWN : GetRoadOwner(tile, rt), rt, flags, town_check)) return CMD_ERROR;
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   234
7370
41adc721b1fa (svn r10733) -Codechange: change MP_STREET into MP_ROAD as we use the word "road" everywhere except in the tile type.
rubidium
parents: 7355
diff changeset
   235
	if (!IsTileType(tile, MP_ROAD)) {
6679
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   236
		/* If it's the last roadtype, just clear the whole tile */
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   237
		if (rts == RoadTypeToRoadTypes(rt)) return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   238
8230
64f28fe2d5c8 (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8224
diff changeset
   239
		CommandCost cost(EXPENSES_CONSTRUCTION);
6679
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   240
		if (IsTileType(tile, MP_TUNNELBRIDGE)) {
8197
3af783256580 (svn r11760) -Codechange: unify the way how other end of a tunnel/bridge is determined at some places
smatz
parents: 8187
diff changeset
   241
			TileIndex other_end = GetOtherTunnelBridgeEnd(tile);
6679
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   242
			/* Pay for *every* tile of the bridge or tunnel */
8398
1e181e2e4e15 (svn r11968) -Codechange: remove redundant FindLengthOfTunnel(), use GetTunnelBridgeLength() and/or GetOtherTunnelEnd() instead
smatz
parents: 8390
diff changeset
   243
			cost.AddCost((GetTunnelBridgeLength(other_end, tile) + 2) * _price.remove_road);
6679
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   244
			if (flags & DC_EXEC) {
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   245
				SetRoadTypes(other_end, GetRoadTypes(other_end) & ~RoadTypeToRoadTypes(rt));
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   246
				SetRoadTypes(tile, GetRoadTypes(tile) & ~RoadTypeToRoadTypes(rt));
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   247
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   248
				/* Mark tiles diry that have been repaved */
6714
f8edec66a9c4 (svn r9946) -Fix: more places that weren't correctly marked dirty...
rubidium
parents: 6713
diff changeset
   249
				MarkTileDirtyByTile(tile);
6679
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   250
				MarkTileDirtyByTile(other_end);
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   251
				if (IsBridge(tile)) {
8083
ad22eade501f (svn r11644) -Codechange: merge some functions from tunnel_map.h and bridge_map.h into tunnelbridge_map.h
smatz
parents: 8081
diff changeset
   252
					TileIndexDiff delta = TileOffsByDiagDir(GetTunnelBridgeDirection(tile));
6679
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   253
6713
7962b523ecd6 (svn r9945) -Fix: bridges were not properly marked dirty when adding/removing roadtypes.
rubidium
parents: 6711
diff changeset
   254
					for (TileIndex t = tile + delta; t != other_end; t += delta) MarkTileDirtyByTile(t);
6679
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   255
				}
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   256
			}
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   257
		} else {
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6946
diff changeset
   258
			cost.AddCost(_price.remove_road);
6679
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   259
			if (flags & DC_EXEC) {
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   260
				SetRoadTypes(tile, GetRoadTypes(tile) & ~RoadTypeToRoadTypes(rt));
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   261
				MarkTileDirtyByTile(tile);
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   262
			}
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   263
		}
8230
64f28fe2d5c8 (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8224
diff changeset
   264
		return cost;
6679
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   265
	}
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   266
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   267
	switch (GetRoadTileType(tile)) {
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   268
		case ROAD_TILE_NORMAL: {
8744
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   269
			const Slope tileh = GetTileSlope(tile, NULL);
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
   270
			RoadBits present = GetRoadBits(tile, rt);
8744
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   271
			const RoadBits other = GetOtherRoadBits(tile, rt);
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   272
			const Foundation f = GetRoadFoundation(tileh, present);
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   273
9067
5cd9fa28b860 (svn r12919) -Fix [FS#1965]: flood road tiles even when there are road works in progress
smatz
parents: 9038
diff changeset
   274
			if (HasRoadWorks(tile) && _current_player != OWNER_WATER) return_cmd_error(STR_ROAD_WORKS_IN_PROGRESS);
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   275
8744
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   276
			/* Autocomplete to a straight road
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   277
			 * @li on steep slopes
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   278
			 * @li if the bits of the other roadtypes result in another foundation
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   279
			 * @li if build on slopes is disabled */
8747
d6c53cb184f3 (svn r12443) -Add: OpenTTDs version to openttd.cfg, just so we do not need to keep to ask people for their version number because it's likely they give you the wrong answer anyway.
rubidium
parents: 8746
diff changeset
   280
			if (IsSteepSlope(tileh) || (IsStraightRoad(other) &&
d6c53cb184f3 (svn r12443) -Add: OpenTTDs version to openttd.cfg, just so we do not need to keep to ask people for their version number because it's likely they give you the wrong answer anyway.
rubidium
parents: 8746
diff changeset
   281
					(other & _invalid_tileh_slopes_road[0][tileh & SLOPE_ELEVATED]) != ROAD_NONE) ||
9413
7042a8ec3fa8 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 9358
diff changeset
   282
					(tileh != SLOPE_FLAT && !_settings_game.construction.build_on_slopes)) {
8734
cf2c240d2e1b (svn r12419) -Cleanup: of the internal road-piece building and removing.
skidd13
parents: 8732
diff changeset
   283
				pieces |= MirrorRoadBits(pieces);
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   284
			}
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   285
6393
e1e4939d19b5 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6368
diff changeset
   286
			/* limit the bits to delete to the existing bits. */
8734
cf2c240d2e1b (svn r12419) -Cleanup: of the internal road-piece building and removing.
skidd13
parents: 8732
diff changeset
   287
			pieces &= present;
cf2c240d2e1b (svn r12419) -Cleanup: of the internal road-piece building and removing.
skidd13
parents: 8732
diff changeset
   288
			if (pieces == ROAD_NONE) return CMD_ERROR;
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   289
8744
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   290
			/* Now set present what it will be after the remove */
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   291
			present ^= pieces;
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   292
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   293
			/* Check for invalid RoadBit combinations on slopes */
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   294
			if (tileh != SLOPE_FLAT && present != ROAD_NONE &&
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   295
					(present & _invalid_tileh_slopes_road[0][tileh & SLOPE_ELEVATED]) == present) {
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   296
				return CMD_ERROR;
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   297
			}
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   298
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   299
			if (flags & DC_EXEC) {
9067
5cd9fa28b860 (svn r12919) -Fix [FS#1965]: flood road tiles even when there are road works in progress
smatz
parents: 9038
diff changeset
   300
				if (HasRoadWorks(tile)) {
5cd9fa28b860 (svn r12919) -Fix [FS#1965]: flood road tiles even when there are road works in progress
smatz
parents: 9038
diff changeset
   301
					/* flooding tile with road works, don't forget to remove the effect vehicle too */
5cd9fa28b860 (svn r12919) -Fix [FS#1965]: flood road tiles even when there are road works in progress
smatz
parents: 9038
diff changeset
   302
					assert(_current_player == OWNER_WATER);
5cd9fa28b860 (svn r12919) -Fix [FS#1965]: flood road tiles even when there are road works in progress
smatz
parents: 9038
diff changeset
   303
					Vehicle *v;
5cd9fa28b860 (svn r12919) -Fix [FS#1965]: flood road tiles even when there are road works in progress
smatz
parents: 9038
diff changeset
   304
					FOR_ALL_VEHICLES(v) {
5cd9fa28b860 (svn r12919) -Fix [FS#1965]: flood road tiles even when there are road works in progress
smatz
parents: 9038
diff changeset
   305
						if (v->type == VEH_EFFECT && TileVirtXY(v->x_pos, v->y_pos) == tile) {
5cd9fa28b860 (svn r12919) -Fix [FS#1965]: flood road tiles even when there are road works in progress
smatz
parents: 9038
diff changeset
   306
							delete v;
5cd9fa28b860 (svn r12919) -Fix [FS#1965]: flood road tiles even when there are road works in progress
smatz
parents: 9038
diff changeset
   307
						}
5cd9fa28b860 (svn r12919) -Fix [FS#1965]: flood road tiles even when there are road works in progress
smatz
parents: 9038
diff changeset
   308
					}
5cd9fa28b860 (svn r12919) -Fix [FS#1965]: flood road tiles even when there are road works in progress
smatz
parents: 9038
diff changeset
   309
				}
6662
ea30b3497d9a (svn r9893) -Fix (r9892): various small bugs that only act up when using something different than plain roads.
rubidium
parents: 6661
diff changeset
   310
				if (present == ROAD_NONE) {
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
   311
					RoadTypes rts = GetRoadTypes(tile) & ComplementRoadTypes(RoadTypeToRoadTypes(rt));
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
   312
					if (rts == ROADTYPES_NONE) {
7536
e9509b41fb11 (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: 7516
diff changeset
   313
						/* Includes MarkTileDirtyByTile() */
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
   314
						DoClearSquare(tile);
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
   315
					} else {
6662
ea30b3497d9a (svn r9893) -Fix (r9892): various small bugs that only act up when using something different than plain roads.
rubidium
parents: 6661
diff changeset
   316
						SetRoadBits(tile, ROAD_NONE, rt);
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
   317
						SetRoadTypes(tile, rts);
7536
e9509b41fb11 (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: 7516
diff changeset
   318
						MarkTileDirtyByTile(tile);
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
   319
					}
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   320
				} else {
6764
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   321
					/* When bits are removed, you *always* end up with something that
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   322
					 * is not a complete straight road tile. However, trams do not have
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   323
					 * onewayness, so they cannot remove it either. */
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   324
					if (rt != ROADTYPE_TRAM) SetDisallowedRoadDirections(tile, DRD_NONE);
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
   325
					SetRoadBits(tile, present, rt);
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   326
					MarkTileDirtyByTile(tile);
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   327
				}
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   328
			}
8744
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   329
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   330
			/* If we change the foundation we have to pay for it. */
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   331
			return CommandCost(EXPENSES_CONSTRUCTION, CountBits(pieces) * _price.remove_road +
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   332
					((GetRoadFoundation(tileh, present) != f) ? _price.terraform : (Money)0));
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   333
		}
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   334
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   335
		case ROAD_TILE_CROSSING: {
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   336
			if (pieces & ComplementRoadBits(GetCrossingRoadBits(tile))) {
3176
3975f96c40f8 (svn r3812) Remove a pointless goto
tron
parents: 3167
diff changeset
   337
				return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   338
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   339
6697
dde1f5dced50 (svn r9929) -Fix [FS#803]: fix several drawing issues.
rubidium
parents: 6691
diff changeset
   340
			/* Don't allow road to be removed from the crossing when there is tram;
dde1f5dced50 (svn r9929) -Fix [FS#803]: fix several drawing issues.
rubidium
parents: 6691
diff changeset
   341
			 * we can't draw the crossing without trambits ;) */
8563
13b1a41e46f1 (svn r12141) -Codechange: Introduce IsNormalRoad[Tile](), IsRoadDepot[Tile]() and HasTileRoadType(); and use them.
frosch
parents: 8560
diff changeset
   342
			if (rt == ROADTYPE_ROAD && HasTileRoadType(tile, ROADTYPE_TRAM) && (flags & DC_EXEC || crossing_check)) return CMD_ERROR;
6697
dde1f5dced50 (svn r9929) -Fix [FS#803]: fix several drawing issues.
rubidium
parents: 6691
diff changeset
   343
8187
ebae31fc6f0b (svn r11750) -Revert (r11749): commited too much
glx
parents: 8186
diff changeset
   344
			if (flags & DC_EXEC) {
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
   345
				RoadTypes rts = GetRoadTypes(tile) & ComplementRoadTypes(RoadTypeToRoadTypes(rt));
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
   346
				if (rts == ROADTYPES_NONE) {
9789
b753e2d50d99 (svn r13931) -Codechange [YAPP]: Retain the reservation state when building/removing waypoints or level crossings. (michi_cc)
rubidium
parents: 9785
diff changeset
   347
					TrackBits tracks = GetCrossingRailBits(tile);
b753e2d50d99 (svn r13931) -Codechange [YAPP]: Retain the reservation state when building/removing waypoints or level crossings. (michi_cc)
rubidium
parents: 9785
diff changeset
   348
					bool reserved = GetCrossingReservation(tile);
b753e2d50d99 (svn r13931) -Codechange [YAPP]: Retain the reservation state when building/removing waypoints or level crossings. (michi_cc)
rubidium
parents: 9785
diff changeset
   349
					MakeRailNormal(tile, GetTileOwner(tile), tracks, GetRailType(tile));
b753e2d50d99 (svn r13931) -Codechange [YAPP]: Retain the reservation state when building/removing waypoints or level crossings. (michi_cc)
rubidium
parents: 9785
diff changeset
   350
					if (reserved) SetTrackReservation(tile, tracks);
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
   351
				} else {
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
   352
					SetRoadTypes(tile, rts);
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
   353
				}
3060
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   354
				MarkTileDirtyByTile(tile);
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   355
				YapfNotifyTrackLayoutChange(tile, FindFirstTrack(GetTrackBits(tile)));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   356
			}
8230
64f28fe2d5c8 (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8224
diff changeset
   357
			return CommandCost(EXPENSES_CONSTRUCTION, _price.remove_road * 2);
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   358
		}
3977
513433ebd092 (svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents: 3933
diff changeset
   359
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   360
		default:
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   361
		case ROAD_TILE_DEPOT:
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   362
			return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   363
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   364
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   365
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   366
8428
fb88a9033b48 (svn r11998) -Fix [FS#1692](r10053): possible remote assert by setting bit 6 of p1 for CMD_REMOVE_ROAD
smatz
parents: 8413
diff changeset
   367
/** Delete a piece of road.
fb88a9033b48 (svn r11998) -Fix [FS#1692](r10053): possible remote assert by setting bit 6 of p1 for CMD_REMOVE_ROAD
smatz
parents: 8413
diff changeset
   368
 * @param tile tile where to remove road from
fb88a9033b48 (svn r11998) -Fix [FS#1692](r10053): possible remote assert by setting bit 6 of p1 for CMD_REMOVE_ROAD
smatz
parents: 8413
diff changeset
   369
 * @param flags operation to perform
fb88a9033b48 (svn r11998) -Fix [FS#1692](r10053): possible remote assert by setting bit 6 of p1 for CMD_REMOVE_ROAD
smatz
parents: 8413
diff changeset
   370
 * @param p1 bit 0..3 road pieces to remove (RoadBits)
fb88a9033b48 (svn r11998) -Fix [FS#1692](r10053): possible remote assert by setting bit 6 of p1 for CMD_REMOVE_ROAD
smatz
parents: 8413
diff changeset
   371
 *           bit 4..5 road type
fb88a9033b48 (svn r11998) -Fix [FS#1692](r10053): possible remote assert by setting bit 6 of p1 for CMD_REMOVE_ROAD
smatz
parents: 8413
diff changeset
   372
 * @param p2 unused
fb88a9033b48 (svn r11998) -Fix [FS#1692](r10053): possible remote assert by setting bit 6 of p1 for CMD_REMOVE_ROAD
smatz
parents: 8413
diff changeset
   373
 */
fb88a9033b48 (svn r11998) -Fix [FS#1692](r10053): possible remote assert by setting bit 6 of p1 for CMD_REMOVE_ROAD
smatz
parents: 8413
diff changeset
   374
CommandCost CmdRemoveRoad(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
fb88a9033b48 (svn r11998) -Fix [FS#1692](r10053): possible remote assert by setting bit 6 of p1 for CMD_REMOVE_ROAD
smatz
parents: 8413
diff changeset
   375
{
fb88a9033b48 (svn r11998) -Fix [FS#1692](r10053): possible remote assert by setting bit 6 of p1 for CMD_REMOVE_ROAD
smatz
parents: 8413
diff changeset
   376
	RoadType rt = (RoadType)GB(p1, 4, 2);
fb88a9033b48 (svn r11998) -Fix [FS#1692](r10053): possible remote assert by setting bit 6 of p1 for CMD_REMOVE_ROAD
smatz
parents: 8413
diff changeset
   377
	if (!IsValidRoadType(rt)) return CMD_ERROR;
fb88a9033b48 (svn r11998) -Fix [FS#1692](r10053): possible remote assert by setting bit 6 of p1 for CMD_REMOVE_ROAD
smatz
parents: 8413
diff changeset
   378
fb88a9033b48 (svn r11998) -Fix [FS#1692](r10053): possible remote assert by setting bit 6 of p1 for CMD_REMOVE_ROAD
smatz
parents: 8413
diff changeset
   379
	RoadBits pieces = Extract<RoadBits, 0>(p1);
fb88a9033b48 (svn r11998) -Fix [FS#1692](r10053): possible remote assert by setting bit 6 of p1 for CMD_REMOVE_ROAD
smatz
parents: 8413
diff changeset
   380
fb88a9033b48 (svn r11998) -Fix [FS#1692](r10053): possible remote assert by setting bit 6 of p1 for CMD_REMOVE_ROAD
smatz
parents: 8413
diff changeset
   381
	return RemoveRoad(tile, flags, pieces, rt, true);
fb88a9033b48 (svn r11998) -Fix [FS#1692](r10053): possible remote assert by setting bit 6 of p1 for CMD_REMOVE_ROAD
smatz
parents: 8413
diff changeset
   382
}
fb88a9033b48 (svn r11998) -Fix [FS#1692](r10053): possible remote assert by setting bit 6 of p1 for CMD_REMOVE_ROAD
smatz
parents: 8413
diff changeset
   383
7641
3a75903fd892 (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: 7601
diff changeset
   384
/**
3a75903fd892 (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: 7601
diff changeset
   385
 * Calculate the costs for roads on slopes
3a75903fd892 (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: 7601
diff changeset
   386
 *  Aside modify the RoadBits to fit on the slopes
3a75903fd892 (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: 7601
diff changeset
   387
 *
3a75903fd892 (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: 7601
diff changeset
   388
 * @note The RoadBits are modified too!
3a75903fd892 (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: 7601
diff changeset
   389
 * @param tileh The current slope
3a75903fd892 (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: 7601
diff changeset
   390
 * @param pieces The RoadBits we want to add
8744
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   391
 * @param existing The existent RoadBits of the current type
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   392
 * @param other The other existent RoadBits
7641
3a75903fd892 (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: 7601
diff changeset
   393
 * @return The costs for these RoadBits on this slope
3a75903fd892 (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: 7601
diff changeset
   394
 */
8821
1411d08e26b3 (svn r12569) -Cleanup: variable scope and coding style in road*.cpp
smatz
parents: 8806
diff changeset
   395
static CommandCost CheckRoadSlope(Slope tileh, RoadBits *pieces, RoadBits existing, RoadBits other)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   396
{
8744
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   397
	/* Remove already build pieces */
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   398
	CLRBITS(*pieces, existing);
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   399
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   400
	/* If we can't build anything stop here */
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   401
	if (*pieces == ROAD_NONE) return CMD_ERROR;
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   402
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   403
	/* All RoadBit combos are valid on flat land */
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   404
	if (tileh == SLOPE_FLAT) return CommandCost();
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   405
8734
cf2c240d2e1b (svn r12419) -Cleanup: of the internal road-piece building and removing.
skidd13
parents: 8732
diff changeset
   406
	/* Proceed steep Slopes first to reduce lookup table size */
4246
6dcc0e44a367 (svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents: 4232
diff changeset
   407
	if (IsSteepSlope(tileh)) {
7641
3a75903fd892 (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: 7601
diff changeset
   408
		/* Force straight roads. */
3a75903fd892 (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: 7601
diff changeset
   409
		*pieces |= MirrorRoadBits(*pieces);
7332
543ecb9e2caf (svn r10695) -Fix [FS#1079]: building single pieces of road over tramtrack or vice versa on slopes did not work as expected.
rubidium
parents: 7266
diff changeset
   410
8744
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   411
		/* Use existing as all existing since only straight
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   412
		 * roads are allowed here. */
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   413
		existing |= other;
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   414
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   415
		if ((existing == ROAD_NONE || existing == *pieces) && IsStraightRoad(*pieces)) {
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   416
			return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform);
4246
6dcc0e44a367 (svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents: 4232
diff changeset
   417
		}
6dcc0e44a367 (svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents: 4232
diff changeset
   418
		return CMD_ERROR;
6dcc0e44a367 (svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents: 4232
diff changeset
   419
	}
7641
3a75903fd892 (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: 7601
diff changeset
   420
8744
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   421
	/* Save the merge of all bits of the current type */
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   422
	RoadBits type_bits = existing | *pieces;
7641
3a75903fd892 (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: 7601
diff changeset
   423
8744
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   424
	/* Roads on slopes */
9413
7042a8ec3fa8 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 9358
diff changeset
   425
	if (_settings_game.construction.build_on_slopes && (_invalid_tileh_slopes_road[0][tileh] & (other | type_bits)) == ROAD_NONE) {
8744
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   426
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   427
		/* If we add leveling we've got to pay for it */
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   428
		if ((other | existing) == ROAD_NONE) return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform);
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   429
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   430
		return CommandCost();
7641
3a75903fd892 (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: 7601
diff changeset
   431
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   432
8744
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   433
	/* Autocomplete uphill roads */
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   434
	*pieces |= MirrorRoadBits(*pieces);
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   435
	type_bits = existing | *pieces;
3381
91ee7484deff (svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents: 3379
diff changeset
   436
8744
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   437
	/* Uphill roads */
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   438
	if (IsStraightRoad(type_bits) && (other == type_bits || other == ROAD_NONE) &&
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   439
			(_invalid_tileh_slopes_road[1][tileh] & (other | type_bits)) == ROAD_NONE) {
3381
91ee7484deff (svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents: 3379
diff changeset
   440
8744
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   441
		/* Slopes with foundation ? */
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   442
		if (IsSlopeWithOneCornerRaised(tileh)) {
7332
543ecb9e2caf (svn r10695) -Fix [FS#1079]: building single pieces of road over tramtrack or vice versa on slopes did not work as expected.
rubidium
parents: 7266
diff changeset
   443
8744
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   444
			/* Prevent build on slopes if it isn't allowed */
9413
7042a8ec3fa8 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 9358
diff changeset
   445
			if (_settings_game.construction.build_on_slopes) {
8744
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   446
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   447
				/* If we add foundation we've got to pay for it */
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   448
				if ((other | existing) == ROAD_NONE) return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform);
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   449
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   450
				return CommandCost();
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   451
			}
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   452
		} else {
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   453
			if (CountBits(existing) == 1) return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform);
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   454
			return CommandCost();
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   455
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   456
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   457
	return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   458
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   459
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   460
/** Build a piece of road.
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3435
diff changeset
   461
 * @param tile tile where to build road
6483
ae78fc3c6b20 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6427
diff changeset
   462
 * @param flags operation to perform
6134
871305fd9ab7 (svn r8876) -Fix
tron
parents: 6133
diff changeset
   463
 * @param p1 bit 0..3 road pieces to build (RoadBits)
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
   464
 *           bit 4..5 road type
6764
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   465
 *           bit 6..7 disallowed directions to toggle
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   466
 * @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
   467
 */
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6857
diff changeset
   468
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
   469
{
8230
64f28fe2d5c8 (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8224
diff changeset
   470
	CommandCost cost(EXPENSES_CONSTRUCTION);
8821
1411d08e26b3 (svn r12569) -Cleanup: variable scope and coding style in road*.cpp
smatz
parents: 8806
diff changeset
   471
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   472
	RoadBits existing = ROAD_NONE;
8744
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   473
	RoadBits other_bits = ROAD_NONE;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   474
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   475
	/* Road pieces are max 4 bitset values (NE, NW, SE, SW) and town can only be non-zero
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   476
	 * if a non-player is building the road */
9652
0405e98d8e96 (svn r13719) -Codechange: rename IsValidPlayer to IsValidPlayerID in line with all other structs/classes that are in a pool.
rubidium
parents: 9583
diff changeset
   477
	if ((IsValidPlayerID(_current_player) && p2 != 0) || (_current_player == OWNER_TOWN && !IsValidTownID(p2))) return CMD_ERROR;
6134
871305fd9ab7 (svn r8876) -Fix
tron
parents: 6133
diff changeset
   478
871305fd9ab7 (svn r8876) -Fix
tron
parents: 6133
diff changeset
   479
	RoadBits pieces = Extract<RoadBits, 0>(p1);
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   480
8690
4ede80da46ff (svn r12363) -Fix: do not allow building 'zero' road bits
smatz
parents: 8647
diff changeset
   481
	/* do not allow building 'zero' road bits, code wouldn't handle it */
4ede80da46ff (svn r12363) -Fix: do not allow building 'zero' road bits
smatz
parents: 8647
diff changeset
   482
	if (pieces == ROAD_NONE) return CMD_ERROR;
4ede80da46ff (svn r12363) -Fix: do not allow building 'zero' road bits
smatz
parents: 8647
diff changeset
   483
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
   484
	RoadType rt = (RoadType)GB(p1, 4, 2);
7857
6572278b5822 (svn r11407) -Fix: do not allow building of tram-tracks when they are not available (SmatZ)
truelight
parents: 7849
diff changeset
   485
	if (!IsValidRoadType(rt) || !ValParamRoadType(rt)) return CMD_ERROR;
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
   486
6764
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   487
	DisallowedRoadDirections toggle_drd = (DisallowedRoadDirections)GB(p1, 6, 2);
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   488
8734
cf2c240d2e1b (svn r12419) -Cleanup: of the internal road-piece building and removing.
skidd13
parents: 8732
diff changeset
   489
	Slope tileh = GetTileSlope(tile, NULL);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   490
3434
0ada2e311826 (svn r4263) -Codechange: Road building no longer uses FindLandscapeHeight. Last occurence of FindLandscapeTile in the tile-specific functions gone. Thanks to Tron for doing lots of work in this direction
celestar
parents: 3430
diff changeset
   491
	switch (GetTileType(tile)) {
7370
41adc721b1fa (svn r10733) -Codechange: change MP_STREET into MP_ROAD as we use the word "road" everywhere except in the tile type.
rubidium
parents: 7355
diff changeset
   492
		case MP_ROAD:
3793
7fe24e10ea63 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3792
diff changeset
   493
			switch (GetRoadTileType(tile)) {
6764
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   494
				case ROAD_TILE_NORMAL: {
4046
5538f3a43418 (svn r5315) -Fix: Prohibit altering a road tile while road works are in progress
tron
parents: 4000
diff changeset
   495
					if (HasRoadWorks(tile)) return_cmd_error(STR_ROAD_WORKS_IN_PROGRESS);
6756
44f714e247ba (svn r9991) -Fix: one could build road when trams were driving on the tile and vice versa.
rubidium
parents: 6751
diff changeset
   496
8744
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   497
					other_bits = GetOtherRoadBits(tile, rt);
8563
13b1a41e46f1 (svn r12141) -Codechange: Introduce IsNormalRoad[Tile](), IsRoadDepot[Tile]() and HasTileRoadType(); and use them.
frosch
parents: 8560
diff changeset
   498
					if (!HasTileRoadType(tile, rt)) break;
4046
5538f3a43418 (svn r5315) -Fix: Prohibit altering a road tile while road works are in progress
tron
parents: 4000
diff changeset
   499
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
   500
					existing = GetRoadBits(tile, rt);
8734
cf2c240d2e1b (svn r12419) -Cleanup: of the internal road-piece building and removing.
skidd13
parents: 8732
diff changeset
   501
					bool crossing = !IsStraightRoad(existing | pieces);
6768
379e38fcab7e (svn r10004) -Fix: trams can always intersect/have junctions on one way roads (because they only work for busses and lorries).
rubidium
parents: 6764
diff changeset
   502
					if (rt != ROADTYPE_TRAM && (GetDisallowedRoadDirections(tile) != DRD_NONE || toggle_drd != DRD_NONE) && crossing) {
6764
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   503
						/* Junctions cannot be one-way */
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   504
						return_cmd_error(STR_ERR_ONEWAY_ROADS_CAN_T_HAVE_JUNCTION);
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   505
					}
3150
729951cb5448 (svn r3773) Shove some semantics down ottd's throat by replacing ints and magic numbers by enums and some related changes
tron
parents: 3149
diff changeset
   506
					if ((existing & pieces) == pieces) {
6764
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   507
						/* We only want to set the (dis)allowed road directions */
9341
bd60c3b2d1e0 (svn r13233) -Fix: Replace some (incorrect) evaluations of TileOwner by RoadOwner.
frosch
parents: 9322
diff changeset
   508
						if (toggle_drd != DRD_NONE && rt != ROADTYPE_TRAM && IsRoadOwner(tile, ROADTYPE_ROAD, _current_player)) {
6764
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   509
							if (crossing) return_cmd_error(STR_ERR_ONEWAY_ROADS_CAN_T_HAVE_JUNCTION);
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   510
8601
ae392409572e (svn r12183) -Codechange: give a better error message when building road over existing road with vehicle on it, or do not fail at all
smatz
parents: 8598
diff changeset
   511
							if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
ae392409572e (svn r12183) -Codechange: give a better error message when building road over existing road with vehicle on it, or do not fail at all
smatz
parents: 8598
diff changeset
   512
6764
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   513
							/* Ignore half built tiles */
8734
cf2c240d2e1b (svn r12419) -Cleanup: of the internal road-piece building and removing.
skidd13
parents: 8732
diff changeset
   514
							if (flags & DC_EXEC && rt != ROADTYPE_TRAM && IsStraightRoad(existing)) {
6764
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   515
								SetDisallowedRoadDirections(tile, GetDisallowedRoadDirections(tile) ^ toggle_drd);
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   516
								MarkTileDirtyByTile(tile);
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   517
							}
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6946
diff changeset
   518
							return CommandCost();
6764
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   519
						}
3066
26c43ab051b8 (svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents: 3061
diff changeset
   520
						return_cmd_error(STR_1007_ALREADY_BUILT);
26c43ab051b8 (svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents: 3061
diff changeset
   521
					}
6764
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   522
				} break;
3066
26c43ab051b8 (svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents: 3061
diff changeset
   523
3793
7fe24e10ea63 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3792
diff changeset
   524
				case ROAD_TILE_CROSSING:
8563
13b1a41e46f1 (svn r12141) -Codechange: Introduce IsNormalRoad[Tile](), IsRoadDepot[Tile]() and HasTileRoadType(); and use them.
frosch
parents: 8560
diff changeset
   525
					if (HasTileRoadType(tile, rt)) return_cmd_error(STR_1007_ALREADY_BUILT);
8744
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   526
					other_bits = GetCrossingRoadBits(tile);
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   527
					if (pieces & ComplementRoadBits(other_bits)) goto do_clear;
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
   528
					break;
3066
26c43ab051b8 (svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents: 3061
diff changeset
   529
3069
9a1fd047b595 (svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents: 3068
diff changeset
   530
				default:
3793
7fe24e10ea63 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3792
diff changeset
   531
				case ROAD_TILE_DEPOT:
3066
26c43ab051b8 (svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents: 3061
diff changeset
   532
					goto do_clear;
3060
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   533
			}
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   534
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   535
3060
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   536
		case MP_RAILWAY: {
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3560
diff changeset
   537
			if (IsSteepSlope(tileh)) {
3060
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   538
				return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   539
			}
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   540
3104
c039f8a65ba0 (svn r3699) Replace some magic numbers for checking for a suitable slope for a level crossing by some less magic numbers
tron
parents: 3103
diff changeset
   541
			/* Level crossings may only be built on these slopes */
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7857
diff changeset
   542
			if (!HasBit(VALID_LEVEL_CROSSING_SLOPES, tileh)) {
3060
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   543
				return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   544
			}
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   545
3792
67c865c9315c (svn r4788) - Codechange: RAILTYPE_{NORMAL,ELECTRIC,...} and RAIL_TYPE_{NORMAL,SIGNAL,...} have nearly the same name, rename RAIL_TYPE_* to RAIL_TILE_* of extra clarity
rubidium
parents: 3673
diff changeset
   546
			if (GetRailTileType(tile) != RAIL_TILE_NORMAL) goto do_clear;
8821
1411d08e26b3 (svn r12569) -Cleanup: variable scope and coding style in road*.cpp
smatz
parents: 8806
diff changeset
   547
1411d08e26b3 (svn r12569) -Cleanup: variable scope and coding style in road*.cpp
smatz
parents: 8806
diff changeset
   548
			Axis roaddir;
3269
62fb247bf94b (svn r3981) More work for the rail accessing functions and enums
tron
parents: 3267
diff changeset
   549
			switch (GetTrackBits(tile)) {
62fb247bf94b (svn r3981) More work for the rail accessing functions and enums
tron
parents: 3267
diff changeset
   550
				case TRACK_BIT_X:
62fb247bf94b (svn r3981) More work for the rail accessing functions and enums
tron
parents: 3267
diff changeset
   551
					if (pieces & ROAD_X) goto do_clear;
62fb247bf94b (svn r3981) More work for the rail accessing functions and enums
tron
parents: 3267
diff changeset
   552
					roaddir = AXIS_Y;
62fb247bf94b (svn r3981) More work for the rail accessing functions and enums
tron
parents: 3267
diff changeset
   553
					break;
62fb247bf94b (svn r3981) More work for the rail accessing functions and enums
tron
parents: 3267
diff changeset
   554
62fb247bf94b (svn r3981) More work for the rail accessing functions and enums
tron
parents: 3267
diff changeset
   555
				case TRACK_BIT_Y:
62fb247bf94b (svn r3981) More work for the rail accessing functions and enums
tron
parents: 3267
diff changeset
   556
					if (pieces & ROAD_Y) goto do_clear;
62fb247bf94b (svn r3981) More work for the rail accessing functions and enums
tron
parents: 3267
diff changeset
   557
					roaddir = AXIS_X;
62fb247bf94b (svn r3981) More work for the rail accessing functions and enums
tron
parents: 3267
diff changeset
   558
					break;
62fb247bf94b (svn r3981) More work for the rail accessing functions and enums
tron
parents: 3267
diff changeset
   559
62fb247bf94b (svn r3981) More work for the rail accessing functions and enums
tron
parents: 3267
diff changeset
   560
				default: goto do_clear;
3060
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   561
			}
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   562
6406
8ccf18e94c67 (svn r9542) -Fix(FS# 712): When checking if a vehicle is on a given tile, and you are working on the ground tile, do not take aircrafts into account, as they do not pose any danger for the construction/destruction/conversion itself. Z stuff, in other words
belugas
parents: 6393
diff changeset
   563
			if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
3381
91ee7484deff (svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents: 3379
diff changeset
   564
3060
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   565
			if (flags & DC_EXEC) {
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   566
				YapfNotifyTrackLayoutChange(tile, FindFirstTrack(GetTrackBits(tile)));
6697
dde1f5dced50 (svn r9929) -Fix [FS#803]: fix several drawing issues.
rubidium
parents: 6691
diff changeset
   567
				/* Always add road to the roadtypes (can't draw without it) */
9789
b753e2d50d99 (svn r13931) -Codechange [YAPP]: Retain the reservation state when building/removing waypoints or level crossings. (michi_cc)
rubidium
parents: 9785
diff changeset
   568
				bool reserved = HasBit(GetTrackReservation(tile), AxisToTrack(OtherAxis(roaddir)));
6697
dde1f5dced50 (svn r9929) -Fix [FS#803]: fix several drawing issues.
rubidium
parents: 6691
diff changeset
   569
				MakeRoadCrossing(tile, _current_player, _current_player, _current_player, GetTileOwner(tile), roaddir, GetRailType(tile), RoadTypeToRoadTypes(rt) | ROADTYPES_ROAD, p2);
9789
b753e2d50d99 (svn r13931) -Codechange [YAPP]: Retain the reservation state when building/removing waypoints or level crossings. (michi_cc)
rubidium
parents: 9785
diff changeset
   570
				SetCrossingReservation(tile, reserved);
8344
1cd2a831b06c (svn r11910) -Fix: play 'ding-ding' crossing sound in more cases (except gameload and crossing construction)
smatz
parents: 8342
diff changeset
   571
				UpdateLevelCrossing(tile, false);
3100
a6706067501d (svn r3695) Add 2 MarkTileByTile() which I forgot in r3689 (noticed by Belugas)
tron
parents: 3099
diff changeset
   572
				MarkTileDirtyByTile(tile);
3060
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   573
			}
8230
64f28fe2d5c8 (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8224
diff changeset
   574
			return CommandCost(EXPENSES_CONSTRUCTION, _price.build_road * (rt == ROADTYPE_ROAD ? 2 : 4));
3017
a75caf4efa2d (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents: 2989
diff changeset
   575
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   576
6679
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   577
		case MP_STATION:
9711
99549b968f4b (svn r13824) -Fix (r13822): also make sure a tile is a road stop tile before trying to get information about the roadstop...
rubidium
parents: 9710
diff changeset
   578
			if (!IsRoadStop(tile)) goto do_clear;
9710
6b6c38221d2e (svn r13822) -Fix [FS#2166]: building through the wrong side of a drive through station was allowed.
rubidium
parents: 9652
diff changeset
   579
			if (IsDriveThroughStopTile(tile)) {
6b6c38221d2e (svn r13822) -Fix [FS#2166]: building through the wrong side of a drive through station was allowed.
rubidium
parents: 9652
diff changeset
   580
				if (pieces & ~AxisToRoadBits(DiagDirToAxis(GetRoadStopDir(tile)))) goto do_clear;
6b6c38221d2e (svn r13822) -Fix [FS#2166]: building through the wrong side of a drive through station was allowed.
rubidium
parents: 9652
diff changeset
   581
			} else {
6b6c38221d2e (svn r13822) -Fix [FS#2166]: building through the wrong side of a drive through station was allowed.
rubidium
parents: 9652
diff changeset
   582
				if (pieces & ~DiagDirToRoadBits(GetRoadStopDir(tile))) goto do_clear;
6b6c38221d2e (svn r13822) -Fix [FS#2166]: building through the wrong side of a drive through station was allowed.
rubidium
parents: 9652
diff changeset
   583
			}
8563
13b1a41e46f1 (svn r12141) -Codechange: Introduce IsNormalRoad[Tile](), IsRoadDepot[Tile]() and HasTileRoadType(); and use them.
frosch
parents: 8560
diff changeset
   584
			if (HasTileRoadType(tile, rt)) return_cmd_error(STR_1007_ALREADY_BUILT);
6679
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   585
			break;
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   586
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   587
		case MP_TUNNELBRIDGE:
8390
f88f515e6557 (svn r11960) -Cleanup: simplify some IsTunnel(Tile) / IsBridge(Tile) conditions
smatz
parents: 8384
diff changeset
   588
			if (GetTunnelBridgeTransportType(tile) != TRANSPORT_ROAD) return CMD_ERROR;
9583
df05b97247fb (svn r13621) -Fix: building roadbits in the wrong direction on bridges or building roadbits from underneath the bridge to the bridgehead is impossible, so don't silently ignore that error when building over houses and industries is not ignored.
rubidium
parents: 9461
diff changeset
   589
			if (MirrorRoadBits(DiagDirToRoadBits(GetTunnelBridgeDirection(tile))) != pieces) return CMD_ERROR;
8563
13b1a41e46f1 (svn r12141) -Codechange: Introduce IsNormalRoad[Tile](), IsRoadDepot[Tile]() and HasTileRoadType(); and use them.
frosch
parents: 8560
diff changeset
   590
			if (HasTileRoadType(tile, rt)) return_cmd_error(STR_1007_ALREADY_BUILT);
8390
f88f515e6557 (svn r11960) -Cleanup: simplify some IsTunnel(Tile) / IsBridge(Tile) conditions
smatz
parents: 8384
diff changeset
   591
			/* Don't allow adding roadtype to the bridge/tunnel when vehicles are already driving on it */
f88f515e6557 (svn r11960) -Cleanup: simplify some IsTunnel(Tile) / IsBridge(Tile) conditions
smatz
parents: 8384
diff changeset
   592
			if (GetVehicleTunnelBridge(tile, GetOtherTunnelBridgeEnd(tile)) != NULL) return CMD_ERROR;
f88f515e6557 (svn r11960) -Cleanup: simplify some IsTunnel(Tile) / IsBridge(Tile) conditions
smatz
parents: 8384
diff changeset
   593
			break;
6679
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   594
8821
1411d08e26b3 (svn r12569) -Cleanup: variable scope and coding style in road*.cpp
smatz
parents: 8806
diff changeset
   595
		default: {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   596
do_clear:;
8821
1411d08e26b3 (svn r12569) -Cleanup: variable scope and coding style in road*.cpp
smatz
parents: 8806
diff changeset
   597
			CommandCost ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
3381
91ee7484deff (svn r4187) Simplify the code for building/removing a piece of road a bit
tron
parents: 3379
diff changeset
   598
			if (CmdFailed(ret)) return ret;
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6946
diff changeset
   599
			cost.AddCost(ret);
8821
1411d08e26b3 (svn r12569) -Cleanup: variable scope and coding style in road*.cpp
smatz
parents: 8806
diff changeset
   600
		} break;
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
8744
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   603
	if (other_bits != pieces) {
6715
b5c030551158 (svn r9947) -Fix [FS#807]: don't check whether roadbits may be built when they are already built for another type.
rubidium
parents: 6714
diff changeset
   604
		/* Check the foundation/slopes when adding road/tram bits */
8821
1411d08e26b3 (svn r12569) -Cleanup: variable scope and coding style in road*.cpp
smatz
parents: 8806
diff changeset
   605
		CommandCost ret = CheckRoadSlope(tileh, &pieces, existing, other_bits);
6715
b5c030551158 (svn r9947) -Fix [FS#807]: don't check whether roadbits may be built when they are already built for another type.
rubidium
parents: 6714
diff changeset
   606
		/* Return an error if we need to build a foundation (ret != 0) but the
b5c030551158 (svn r9947) -Fix [FS#807]: don't check whether roadbits may be built when they are already built for another type.
rubidium
parents: 6714
diff changeset
   607
		 * current patch-setting is turned off (or stupid AI@work) */
9413
7042a8ec3fa8 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 9358
diff changeset
   608
		if (CmdFailed(ret) || (ret.GetCost() != 0 && !_settings_game.construction.build_on_slopes)) {
6715
b5c030551158 (svn r9947) -Fix [FS#807]: don't check whether roadbits may be built when they are already built for another type.
rubidium
parents: 6714
diff changeset
   609
			return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
b5c030551158 (svn r9947) -Fix [FS#807]: don't check whether roadbits may be built when they are already built for another type.
rubidium
parents: 6714
diff changeset
   610
		}
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6946
diff changeset
   611
		cost.AddCost(ret);
6715
b5c030551158 (svn r9947) -Fix [FS#807]: don't check whether roadbits may be built when they are already built for another type.
rubidium
parents: 6714
diff changeset
   612
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   613
7370
41adc721b1fa (svn r10733) -Codechange: change MP_STREET into MP_ROAD as we use the word "road" everywhere except in the tile type.
rubidium
parents: 7355
diff changeset
   614
	if (IsTileType(tile, MP_ROAD)) {
6393
e1e4939d19b5 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6368
diff changeset
   615
		/* Don't put the pieces that already exist */
3150
729951cb5448 (svn r3773) Shove some semantics down ottd's throat by replacing ints and magic numbers by enums and some related changes
tron
parents: 3149
diff changeset
   616
		pieces &= ComplementRoadBits(existing);
8384
d46e5338da92 (svn r11953) -Fix (r11172): do not allow modifying roadbits when other roadtypes would need different foundation
smatz
parents: 8344
diff changeset
   617
d46e5338da92 (svn r11953) -Fix (r11172): do not allow modifying roadbits when other roadtypes would need different foundation
smatz
parents: 8344
diff changeset
   618
		/* Check if new road bits will have the same foundation as other existing road types */
8563
13b1a41e46f1 (svn r12141) -Codechange: Introduce IsNormalRoad[Tile](), IsRoadDepot[Tile]() and HasTileRoadType(); and use them.
frosch
parents: 8560
diff changeset
   619
		if (IsNormalRoad(tile)) {
8384
d46e5338da92 (svn r11953) -Fix (r11172): do not allow modifying roadbits when other roadtypes would need different foundation
smatz
parents: 8344
diff changeset
   620
			Slope slope = GetTileSlope(tile, NULL);
d46e5338da92 (svn r11953) -Fix (r11172): do not allow modifying roadbits when other roadtypes would need different foundation
smatz
parents: 8344
diff changeset
   621
			Foundation found_new = GetRoadFoundation(slope, pieces | existing);
d46e5338da92 (svn r11953) -Fix (r11172): do not allow modifying roadbits when other roadtypes would need different foundation
smatz
parents: 8344
diff changeset
   622
d46e5338da92 (svn r11953) -Fix (r11172): do not allow modifying roadbits when other roadtypes would need different foundation
smatz
parents: 8344
diff changeset
   623
			/* Test if all other roadtypes can be built at that foundation */
d46e5338da92 (svn r11953) -Fix (r11172): do not allow modifying roadbits when other roadtypes would need different foundation
smatz
parents: 8344
diff changeset
   624
			for (RoadType rtest = ROADTYPE_ROAD; rtest < ROADTYPE_END; rtest++) {
d46e5338da92 (svn r11953) -Fix (r11172): do not allow modifying roadbits when other roadtypes would need different foundation
smatz
parents: 8344
diff changeset
   625
				if (rtest != rt) { // check only other road types
d46e5338da92 (svn r11953) -Fix (r11172): do not allow modifying roadbits when other roadtypes would need different foundation
smatz
parents: 8344
diff changeset
   626
					RoadBits bits = GetRoadBits(tile, rtest);
d46e5338da92 (svn r11953) -Fix (r11172): do not allow modifying roadbits when other roadtypes would need different foundation
smatz
parents: 8344
diff changeset
   627
					/* do not check if there are not road bits of given type */
d46e5338da92 (svn r11953) -Fix (r11172): do not allow modifying roadbits when other roadtypes would need different foundation
smatz
parents: 8344
diff changeset
   628
					if (bits != ROAD_NONE && GetRoadFoundation(slope, bits) != found_new) {
d46e5338da92 (svn r11953) -Fix (r11172): do not allow modifying roadbits when other roadtypes would need different foundation
smatz
parents: 8344
diff changeset
   629
						return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
d46e5338da92 (svn r11953) -Fix (r11172): do not allow modifying roadbits when other roadtypes would need different foundation
smatz
parents: 8344
diff changeset
   630
					}
d46e5338da92 (svn r11953) -Fix (r11172): do not allow modifying roadbits when other roadtypes would need different foundation
smatz
parents: 8344
diff changeset
   631
				}
d46e5338da92 (svn r11953) -Fix (r11172): do not allow modifying roadbits when other roadtypes would need different foundation
smatz
parents: 8344
diff changeset
   632
			}
d46e5338da92 (svn r11953) -Fix (r11172): do not allow modifying roadbits when other roadtypes would need different foundation
smatz
parents: 8344
diff changeset
   633
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   634
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   635
8601
ae392409572e (svn r12183) -Codechange: give a better error message when building road over existing road with vehicle on it, or do not fail at all
smatz
parents: 8598
diff changeset
   636
	if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
ae392409572e (svn r12183) -Codechange: give a better error message when building road over existing road with vehicle on it, or do not fail at all
smatz
parents: 8598
diff changeset
   637
7832
60035eb28f08 (svn r11382) -Codechange: renamed COUNTBITS to CountBits, as it is no longer a macro (skidd13)
truelight
parents: 7819
diff changeset
   638
	cost.AddCost(CountBits(pieces) * _price.build_road);
6679
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   639
	if (IsTileType(tile, MP_TUNNELBRIDGE)) {
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   640
		/* Pay for *every* tile of the bridge or tunnel */
8398
1e181e2e4e15 (svn r11968) -Codechange: remove redundant FindLengthOfTunnel(), use GetTunnelBridgeLength() and/or GetOtherTunnelEnd() instead
smatz
parents: 8390
diff changeset
   641
		cost.MultiplyCost(GetTunnelBridgeLength(GetOtherTunnelBridgeEnd(tile), tile) + 2);
6679
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   642
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   643
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   644
	if (flags & DC_EXEC) {
6679
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   645
		switch (GetTileType(tile)) {
7370
41adc721b1fa (svn r10733) -Codechange: change MP_STREET into MP_ROAD as we use the word "road" everywhere except in the tile type.
rubidium
parents: 7355
diff changeset
   646
			case MP_ROAD: {
6679
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   647
				RoadTileType rtt = GetRoadTileType(tile);
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   648
				if (existing == ROAD_NONE || rtt == ROAD_TILE_CROSSING) {
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   649
					SetRoadTypes(tile, GetRoadTypes(tile) | RoadTypeToRoadTypes(rt));
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   650
					SetRoadOwner(tile, rt, _current_player);
6968
023364d194b9 (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: 6965
diff changeset
   651
					if (_current_player == OWNER_TOWN && rt == ROADTYPE_ROAD) SetTownIndex(tile, p2);
6679
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   652
				}
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   653
				if (rtt != ROAD_TILE_CROSSING) SetRoadBits(tile, existing | pieces, rt);
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   654
			} break;
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   655
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   656
			case MP_TUNNELBRIDGE: {
8197
3af783256580 (svn r11760) -Codechange: unify the way how other end of a tunnel/bridge is determined at some places
smatz
parents: 8187
diff changeset
   657
				TileIndex other_end = GetOtherTunnelBridgeEnd(tile);
6679
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   658
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   659
				SetRoadTypes(other_end, GetRoadTypes(other_end) | RoadTypeToRoadTypes(rt));
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
   660
				SetRoadTypes(tile, GetRoadTypes(tile) | RoadTypeToRoadTypes(rt));
6679
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   661
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   662
				/* Mark tiles diry that have been repaved */
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   663
				MarkTileDirtyByTile(other_end);
6714
f8edec66a9c4 (svn r9946) -Fix: more places that weren't correctly marked dirty...
rubidium
parents: 6713
diff changeset
   664
				MarkTileDirtyByTile(tile);
6679
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   665
				if (IsBridge(tile)) {
8083
ad22eade501f (svn r11644) -Codechange: merge some functions from tunnel_map.h and bridge_map.h into tunnelbridge_map.h
smatz
parents: 8081
diff changeset
   666
					TileIndexDiff delta = TileOffsByDiagDir(GetTunnelBridgeDirection(tile));
6679
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   667
6713
7962b523ecd6 (svn r9945) -Fix: bridges were not properly marked dirty when adding/removing roadtypes.
rubidium
parents: 6711
diff changeset
   668
					for (TileIndex t = tile + delta; t != other_end; t += delta) MarkTileDirtyByTile(t);
6679
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   669
				}
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   670
			} break;
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   671
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   672
			case MP_STATION:
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   673
				SetRoadTypes(tile, GetRoadTypes(tile) | RoadTypeToRoadTypes(rt));
9342
6daf441eee26 (svn r13234) -Fix: Check/affect town rating when removing/bulldozing town-owned road under drivethrough stops.
frosch
parents: 9341
diff changeset
   674
				if (IsDriveThroughStopTile(tile) && rt == ROADTYPE_ROAD) SetStopBuiltOnTownRoad(tile, false);
6679
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   675
				break;
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   676
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   677
			default:
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   678
				MakeRoadNormal(tile, pieces, RoadTypeToRoadTypes(rt), p2, _current_player, _current_player, _current_player);
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   679
				break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   680
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   681
8563
13b1a41e46f1 (svn r12141) -Codechange: Introduce IsNormalRoad[Tile](), IsRoadDepot[Tile]() and HasTileRoadType(); and use them.
frosch
parents: 8560
diff changeset
   682
		if (rt != ROADTYPE_TRAM && IsNormalRoadTile(tile)) {
6764
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   683
			existing |= pieces;
8734
cf2c240d2e1b (svn r12419) -Cleanup: of the internal road-piece building and removing.
skidd13
parents: 8732
diff changeset
   684
			SetDisallowedRoadDirections(tile, IsStraightRoad(existing) ?
6764
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   685
					GetDisallowedRoadDirections(tile) ^ toggle_drd : DRD_NONE);
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   686
		}
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   687
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   688
		MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   689
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   690
	return cost;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   691
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   692
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   693
/** Build a long piece of road.
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3435
diff changeset
   694
 * @param end_tile end tile of drag
6483
ae78fc3c6b20 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6427
diff changeset
   695
 * @param flags operation to perform
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   696
 * @param p1 start tile of drag
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   697
 * @param p2 various bitstuffed elements
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   698
 * - p2 = (bit 0) - start tile starts in the 2nd half of tile (p2 & 1)
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   699
 * - p2 = (bit 1) - end tile starts in the 2nd half of tile (p2 & 2)
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   700
 * - p2 = (bit 2) - direction: 0 = along x-axis, 1 = along y-axis (p2 & 4)
6662
ea30b3497d9a (svn r9893) -Fix (r9892): various small bugs that only act up when using something different than plain roads.
rubidium
parents: 6661
diff changeset
   701
 * - p2 = (bit 3 + 4) - road type
6764
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   702
 * - p2 = (bit 5) - set road direction
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   703
 */
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6857
diff changeset
   704
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
   705
{
8821
1411d08e26b3 (svn r12569) -Cleanup: variable scope and coding style in road*.cpp
smatz
parents: 8806
diff changeset
   706
	CommandCost cost(EXPENSES_CONSTRUCTION);
6710
fd3ade8bf17a (svn r9942) -Fix [FS#804]: crash when upgrading both ends of a bridge.
rubidium
parents: 6702
diff changeset
   707
	bool had_bridge = false;
7428
0ce522a7072b (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: 7389
diff changeset
   708
	bool had_tunnel = false;
6764
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   709
	bool had_success = false;
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   710
	DisallowedRoadDirections drd = DRD_NORTHBOUND;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   711
8601
ae392409572e (svn r12183) -Codechange: give a better error message when building road over existing road with vehicle on it, or do not fail at all
smatz
parents: 8598
diff changeset
   712
	_error_message = INVALID_STRING_ID;
ae392409572e (svn r12183) -Codechange: give a better error message when building road over existing road with vehicle on it, or do not fail at all
smatz
parents: 8598
diff changeset
   713
2934
3f29a7212713 (svn r3490) -Fix: A bunch (10) of off-by-one errors when checking if a TileIndex points to a tile on the map
tron
parents: 2916
diff changeset
   714
	if (p1 >= MapSize()) return CMD_ERROR;
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   715
8821
1411d08e26b3 (svn r12569) -Cleanup: variable scope and coding style in road*.cpp
smatz
parents: 8806
diff changeset
   716
	TileIndex start_tile = p1;
6662
ea30b3497d9a (svn r9893) -Fix (r9892): various small bugs that only act up when using something different than plain roads.
rubidium
parents: 6661
diff changeset
   717
	RoadType rt = (RoadType)GB(p2, 3, 2);
7857
6572278b5822 (svn r11407) -Fix: do not allow building of tram-tracks when they are not available (SmatZ)
truelight
parents: 7849
diff changeset
   718
	if (!IsValidRoadType(rt) || !ValParamRoadType(rt)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   719
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   720
	/* Only drag in X or Y direction dictated by the direction variable */
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7857
diff changeset
   721
	if (!HasBit(p2, 2) && TileY(start_tile) != TileY(end_tile)) return CMD_ERROR; // x-axis
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7857
diff changeset
   722
	if (HasBit(p2, 2)  && TileX(start_tile) != TileX(end_tile)) return CMD_ERROR; // y-axis
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   723
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   724
	/* Swap start and ending tile, also the half-tile drag var (bit 0 and 1) */
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7857
diff changeset
   725
	if (start_tile > end_tile || (start_tile == end_tile && HasBit(p2, 0))) {
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   726
		TileIndex t = start_tile;
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   727
		start_tile = end_tile;
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   728
		end_tile = t;
7954
57b51c69c072 (svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents: 7928
diff changeset
   729
		p2 ^= IsInsideMM(p2 & 3, 1, 3) ? 3 : 0;
6764
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   730
		drd = DRD_SOUTHBOUND;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   731
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   732
6764
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   733
	/* On the X-axis, we have to swap the initial bits, so they
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   734
	 * will be interpreted correctly in the GTTS. Futhermore
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   735
	 * when you just 'click' on one tile to build them. */
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7857
diff changeset
   736
	if (HasBit(p2, 2) == (start_tile == end_tile && HasBit(p2, 0) == HasBit(p2, 1))) drd ^= DRD_BOTH;
6764
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   737
	/* No disallowed direction bits have to be toggled */
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7857
diff changeset
   738
	if (!HasBit(p2, 5)) drd = DRD_NONE;
6764
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   739
8821
1411d08e26b3 (svn r12569) -Cleanup: variable scope and coding style in road*.cpp
smatz
parents: 8806
diff changeset
   740
	TileIndex tile = start_tile;
6393
e1e4939d19b5 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6368
diff changeset
   741
	/* Start tile is the small number. */
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   742
	for (;;) {
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7857
diff changeset
   743
		RoadBits bits = HasBit(p2, 2) ? ROAD_Y : ROAD_X;
3098
aed45c5c1e11 (svn r3687) Complete some bits I missed whenn adding accessor functions for road types and pieces
tron
parents: 3097
diff changeset
   744
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7857
diff changeset
   745
		if (tile == end_tile && !HasBit(p2, 1)) bits &= ROAD_NW | ROAD_NE;
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7857
diff changeset
   746
		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
   747
9583
df05b97247fb (svn r13621) -Fix: building roadbits in the wrong direction on bridges or building roadbits from underneath the bridge to the bridgehead is impossible, so don't silently ignore that error when building over houses and industries is not ignored.
rubidium
parents: 9461
diff changeset
   748
		_error_message = INVALID_STRING_ID;
8821
1411d08e26b3 (svn r12569) -Cleanup: variable scope and coding style in road*.cpp
smatz
parents: 8806
diff changeset
   749
		CommandCost ret = DoCommand(tile, drd << 6 | rt << 4 | bits, 0, flags, CMD_BUILD_ROAD);
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   750
		if (CmdFailed(ret)) {
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   751
			if (_error_message != STR_1007_ALREADY_BUILT) return CMD_ERROR;
2549
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
   752
		} else {
6764
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   753
			had_success = true;
7428
0ce522a7072b (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: 7389
diff changeset
   754
			/* Only pay for the upgrade on one side of the bridges and tunnels */
0ce522a7072b (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: 7389
diff changeset
   755
			if (IsTileType(tile, MP_TUNNELBRIDGE)) {
0ce522a7072b (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: 7389
diff changeset
   756
				if (IsBridge(tile)) {
8083
ad22eade501f (svn r11644) -Codechange: merge some functions from tunnel_map.h and bridge_map.h into tunnelbridge_map.h
smatz
parents: 8081
diff changeset
   757
					if ((!had_bridge || GetTunnelBridgeDirection(tile) == DIAGDIR_SE || GetTunnelBridgeDirection(tile) == DIAGDIR_SW)) {
7428
0ce522a7072b (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: 7389
diff changeset
   758
						cost.AddCost(ret);
0ce522a7072b (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: 7389
diff changeset
   759
					}
0ce522a7072b (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: 7389
diff changeset
   760
					had_bridge = true;
8390
f88f515e6557 (svn r11960) -Cleanup: simplify some IsTunnel(Tile) / IsBridge(Tile) conditions
smatz
parents: 8384
diff changeset
   761
				} else { // IsTunnel(tile)
8083
ad22eade501f (svn r11644) -Codechange: merge some functions from tunnel_map.h and bridge_map.h into tunnelbridge_map.h
smatz
parents: 8081
diff changeset
   762
					if ((!had_tunnel || GetTunnelBridgeDirection(tile) == DIAGDIR_SE || GetTunnelBridgeDirection(tile) == DIAGDIR_SW)) {
7428
0ce522a7072b (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: 7389
diff changeset
   763
						cost.AddCost(ret);
0ce522a7072b (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: 7389
diff changeset
   764
					}
0ce522a7072b (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: 7389
diff changeset
   765
					had_tunnel = true;
6710
fd3ade8bf17a (svn r9942) -Fix [FS#804]: crash when upgrading both ends of a bridge.
rubidium
parents: 6702
diff changeset
   766
				}
fd3ade8bf17a (svn r9942) -Fix [FS#804]: crash when upgrading both ends of a bridge.
rubidium
parents: 6702
diff changeset
   767
			} else {
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6946
diff changeset
   768
				cost.AddCost(ret);
6710
fd3ade8bf17a (svn r9942) -Fix [FS#804]: crash when upgrading both ends of a bridge.
rubidium
parents: 6702
diff changeset
   769
			}
2549
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
   770
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   771
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   772
		if (tile == end_tile) break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   773
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7857
diff changeset
   774
		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
   775
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   776
6764
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
   777
	return !had_success ? CMD_ERROR : cost;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   778
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   779
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   780
/** Remove a long piece of road.
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3435
diff changeset
   781
 * @param end_tile end tile of drag
6483
ae78fc3c6b20 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6427
diff changeset
   782
 * @param flags operation to perform
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   783
 * @param p1 start tile of drag
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   784
 * @param p2 various bitstuffed elements
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   785
 * - p2 = (bit 0) - start tile starts in the 2nd half of tile (p2 & 1)
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   786
 * - p2 = (bit 1) - end tile starts in the 2nd half of tile (p2 & 2)
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   787
 * - p2 = (bit 2) - direction: 0 = along x-axis, 1 = along y-axis (p2 & 4)
6662
ea30b3497d9a (svn r9893) -Fix (r9892): various small bugs that only act up when using something different than plain roads.
rubidium
parents: 6661
diff changeset
   788
 * - p2 = (bit 3 + 4) - road type
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   789
 */
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6857
diff changeset
   790
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
   791
{
8821
1411d08e26b3 (svn r12569) -Cleanup: variable scope and coding style in road*.cpp
smatz
parents: 8806
diff changeset
   792
	CommandCost cost(EXPENSES_CONSTRUCTION);
889
64d2f7d5f02b (svn r1375) -Fix: [1050990] Buying trains sometimes accounted for incorrectly. Was the result of the cost getting reset in a recursive call of docommand. That is fixed. In addition all cost-commands are typed explicitely. Please do not forget to do so or your costs will be credited to construction if you are unlucky.
darkvater
parents: 817
diff changeset
   793
2934
3f29a7212713 (svn r3490) -Fix: A bunch (10) of off-by-one errors when checking if a TileIndex points to a tile on the map
tron
parents: 2916
diff changeset
   794
	if (p1 >= MapSize()) return CMD_ERROR;
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   795
8821
1411d08e26b3 (svn r12569) -Cleanup: variable scope and coding style in road*.cpp
smatz
parents: 8806
diff changeset
   796
	TileIndex start_tile = p1;
6662
ea30b3497d9a (svn r9893) -Fix (r9892): various small bugs that only act up when using something different than plain roads.
rubidium
parents: 6661
diff changeset
   797
	RoadType rt = (RoadType)GB(p2, 3, 2);
ea30b3497d9a (svn r9893) -Fix (r9892): various small bugs that only act up when using something different than plain roads.
rubidium
parents: 6661
diff changeset
   798
	if (!IsValidRoadType(rt)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   799
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   800
	/* Only drag in X or Y direction dictated by the direction variable */
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7857
diff changeset
   801
	if (!HasBit(p2, 2) && TileY(start_tile) != TileY(end_tile)) return CMD_ERROR; // x-axis
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7857
diff changeset
   802
	if (HasBit(p2, 2)  && TileX(start_tile) != TileX(end_tile)) return CMD_ERROR; // y-axis
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   803
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   804
	/* Swap start and ending tile, also the half-tile drag var (bit 0 and 1) */
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7857
diff changeset
   805
	if (start_tile > end_tile || (start_tile == end_tile && HasBit(p2, 0))) {
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   806
		TileIndex t = start_tile;
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   807
		start_tile = end_tile;
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   808
		end_tile = t;
7954
57b51c69c072 (svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents: 7928
diff changeset
   809
		p2 ^= IsInsideMM(p2 & 3, 1, 3) ? 3 : 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   810
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   811
8821
1411d08e26b3 (svn r12569) -Cleanup: variable scope and coding style in road*.cpp
smatz
parents: 8806
diff changeset
   812
	Money money = GetAvailableMoneyForCommand();
1411d08e26b3 (svn r12569) -Cleanup: variable scope and coding style in road*.cpp
smatz
parents: 8806
diff changeset
   813
	TileIndex tile = start_tile;
6393
e1e4939d19b5 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6368
diff changeset
   814
	/* Start tile is the small number. */
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   815
	for (;;) {
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7857
diff changeset
   816
		RoadBits bits = HasBit(p2, 2) ? ROAD_Y : ROAD_X;
3098
aed45c5c1e11 (svn r3687) Complete some bits I missed whenn adding accessor functions for road types and pieces
tron
parents: 3097
diff changeset
   817
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7857
diff changeset
   818
		if (tile == end_tile && !HasBit(p2, 1)) bits &= ROAD_NW | ROAD_NE;
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7857
diff changeset
   819
		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
   820
6393
e1e4939d19b5 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6368
diff changeset
   821
		/* try to remove the halves. */
3098
aed45c5c1e11 (svn r3687) Complete some bits I missed whenn adding accessor functions for road types and pieces
tron
parents: 3097
diff changeset
   822
		if (bits != 0) {
8821
1411d08e26b3 (svn r12569) -Cleanup: variable scope and coding style in road*.cpp
smatz
parents: 8806
diff changeset
   823
			CommandCost ret = RemoveRoad(tile, flags & ~DC_EXEC, bits, rt, true);
7442
683a67b7eacd (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: 7428
diff changeset
   824
			if (CmdSucceeded(ret)) {
683a67b7eacd (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: 7428
diff changeset
   825
				if (flags & DC_EXEC) {
8230
64f28fe2d5c8 (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8224
diff changeset
   826
					money -= ret.GetCost();
64f28fe2d5c8 (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8224
diff changeset
   827
					if (money < 0) {
7442
683a67b7eacd (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: 7428
diff changeset
   828
						_additional_cash_required = DoCommand(end_tile, start_tile, p2, flags & ~DC_EXEC, CMD_REMOVE_LONG_ROAD).GetCost();
683a67b7eacd (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: 7428
diff changeset
   829
						return cost;
683a67b7eacd (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: 7428
diff changeset
   830
					}
8912
f8cb564a6109 (svn r12682) -Fix [FS#1920]: removing road pieces from a town gave you twice the intended penalty.
rubidium
parents: 8859
diff changeset
   831
					RemoveRoad(tile, flags, bits, rt, true, false);
7442
683a67b7eacd (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: 7428
diff changeset
   832
				}
683a67b7eacd (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: 7428
diff changeset
   833
				cost.AddCost(ret);
683a67b7eacd (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: 7428
diff changeset
   834
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   835
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   836
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   837
		if (tile == end_tile) break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   838
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7857
diff changeset
   839
		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
   840
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   841
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6946
diff changeset
   842
	return (cost.GetCost() == 0) ? CMD_ERROR : cost;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   843
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   844
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   845
/** Build a road depot.
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3435
diff changeset
   846
 * @param tile tile where to build the depot
6483
ae78fc3c6b20 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6427
diff changeset
   847
 * @param flags operation to perform
6134
871305fd9ab7 (svn r8876) -Fix
tron
parents: 6133
diff changeset
   848
 * @param p1 bit 0..1 entrance direction (DiagDirection)
6662
ea30b3497d9a (svn r9893) -Fix (r9892): various small bugs that only act up when using something different than plain roads.
rubidium
parents: 6661
diff changeset
   849
 *           bit 2..3 road type
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   850
 * @param p2 unused
2085
876f20a0e843 (svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents: 2074
diff changeset
   851
 *
876f20a0e843 (svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents: 2074
diff changeset
   852
 * @todo When checking for the tile slope,
876f20a0e843 (svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents: 2074
diff changeset
   853
 * 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
   854
 */
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6857
diff changeset
   855
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
   856
{
6134
871305fd9ab7 (svn r8876) -Fix
tron
parents: 6133
diff changeset
   857
	DiagDirection dir = Extract<DiagDirection, 0>(p1);
6662
ea30b3497d9a (svn r9893) -Fix (r9892): various small bugs that only act up when using something different than plain roads.
rubidium
parents: 6661
diff changeset
   858
	RoadType rt = (RoadType)GB(p1, 2, 2);
ea30b3497d9a (svn r9893) -Fix (r9892): various small bugs that only act up when using something different than plain roads.
rubidium
parents: 6661
diff changeset
   859
7857
6572278b5822 (svn r11407) -Fix: do not allow building of tram-tracks when they are not available (SmatZ)
truelight
parents: 7849
diff changeset
   860
	if (!IsValidRoadType(rt) || !ValParamRoadType(rt)) return CMD_ERROR;
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   861
8821
1411d08e26b3 (svn r12569) -Cleanup: variable scope and coding style in road*.cpp
smatz
parents: 8806
diff changeset
   862
	Slope tileh = GetTileSlope(tile, NULL);
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3560
diff changeset
   863
	if (tileh != SLOPE_FLAT && (
9413
7042a8ec3fa8 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 9358
diff changeset
   864
				!_settings_game.construction.build_on_slopes ||
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3560
diff changeset
   865
				IsSteepSlope(tileh) ||
6134
871305fd9ab7 (svn r8876) -Fix
tron
parents: 6133
diff changeset
   866
				!CanBuildDepotByTileh(dir, tileh)
2549
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
   867
			)) {
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
   868
		return_cmd_error(STR_0007_FLAT_LAND_REQUIRED);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   869
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   870
8821
1411d08e26b3 (svn r12569) -Cleanup: variable scope and coding style in road*.cpp
smatz
parents: 8806
diff changeset
   871
	CommandCost cost = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1638
diff changeset
   872
	if (CmdFailed(cost)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   873
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   874
	if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST);
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
   875
9036
6368fe55fd6d (svn r12855) -Codechange: do not use autoptr's for testing whether certain objects can be build, but check it directly in the pool so we do not have to call destructors in the testing phase. Stations still use the autoptr though.
rubidium
parents: 9009
diff changeset
   876
	if (!Depot::CanAllocateItem()) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   877
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   878
	if (flags & DC_EXEC) {
9036
6368fe55fd6d (svn r12855) -Codechange: do not use autoptr's for testing whether certain objects can be build, but check it directly in the pool so we do not have to call destructors in the testing phase. Stations still use the autoptr though.
rubidium
parents: 9009
diff changeset
   879
		Depot *dep = new Depot(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   880
		dep->town_index = ClosestTownFromTile(tile, (uint)-1)->index;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   881
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
   882
		MakeRoadDepot(tile, _current_player, dir, rt);
3100
a6706067501d (svn r3695) Add 2 MarkTileByTile() which I forgot in r3689 (noticed by Belugas)
tron
parents: 3099
diff changeset
   883
		MarkTileDirtyByTile(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   884
	}
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6946
diff changeset
   885
	return cost.AddCost(_price.build_road_depot);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   886
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   887
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6857
diff changeset
   888
static CommandCost RemoveRoadDepot(TileIndex tile, uint32 flags)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   889
{
8821
1411d08e26b3 (svn r12569) -Cleanup: variable scope and coding style in road*.cpp
smatz
parents: 8806
diff changeset
   890
	if (!CheckTileOwnership(tile) && _current_player != OWNER_WATER) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   891
7758
17ad53748c7b (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: 7730
diff changeset
   892
	if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   893
7389
08d6a6265ced (svn r10758) -Codechange: make the depot struct use the pool item class as super class.
rubidium
parents: 7370
diff changeset
   894
	if (flags & DC_EXEC) {
08d6a6265ced (svn r10758) -Codechange: make the depot struct use the pool item class as super class.
rubidium
parents: 7370
diff changeset
   895
		DoClearSquare(tile);
08d6a6265ced (svn r10758) -Codechange: make the depot struct use the pool item class as super class.
rubidium
parents: 7370
diff changeset
   896
		delete GetDepotByTile(tile);
08d6a6265ced (svn r10758) -Codechange: make the depot struct use the pool item class as super class.
rubidium
parents: 7370
diff changeset
   897
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   898
8230
64f28fe2d5c8 (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8224
diff changeset
   899
	return CommandCost(EXPENSES_CONSTRUCTION, _price.remove_road_depot);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   900
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   901
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6857
diff changeset
   902
static CommandCost ClearTile_Road(TileIndex tile, byte flags)
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
   903
{
3793
7fe24e10ea63 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3792
diff changeset
   904
	switch (GetRoadTileType(tile)) {
7fe24e10ea63 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3792
diff changeset
   905
		case ROAD_TILE_NORMAL: {
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
   906
			RoadBits b = GetAllRoadBits(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   907
5637
aa922e570f9a (svn r8096) -Codechange: Invert the check if you are allowed to clear a road tile so there are not so many negations (too confusing) and added some comments to further clarify what happens.
Darkvater
parents: 5587
diff changeset
   908
			/* Clear the road if only one piece is on the tile OR the AI tries
aa922e570f9a (svn r8096) -Codechange: Invert the check if you are allowed to clear a road tile so there are not so many negations (too confusing) and added some comments to further clarify what happens.
Darkvater
parents: 5587
diff changeset
   909
			 * to clear town road OR we are not using the DC_AUTO flag */
7832
60035eb28f08 (svn r11382) -Codechange: renamed COUNTBITS to CountBits, as it is no longer a macro (skidd13)
truelight
parents: 7819
diff changeset
   910
			if ((CountBits(b) == 1 && GetRoadBits(tile, ROADTYPE_TRAM) == ROAD_NONE) ||
9341
bd60c3b2d1e0 (svn r13233) -Fix: Replace some (incorrect) evaluations of TileOwner by RoadOwner.
frosch
parents: 9322
diff changeset
   911
			    ((flags & DC_AI_BUILDING) && GetOtherRoadBits(tile, ROADTYPE_ROAD) == ROAD_NONE && IsRoadOwner(tile, ROADTYPE_ROAD, OWNER_TOWN)) ||
5637
aa922e570f9a (svn r8096) -Codechange: Invert the check if you are allowed to clear a road tile so there are not so many negations (too confusing) and added some comments to further clarify what happens.
Darkvater
parents: 5587
diff changeset
   912
			    !(flags & DC_AUTO)
aa922e570f9a (svn r8096) -Codechange: Invert the check if you are allowed to clear a road tile so there are not so many negations (too confusing) and added some comments to further clarify what happens.
Darkvater
parents: 5587
diff changeset
   913
				) {
6679
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   914
				RoadTypes rts = GetRoadTypes(tile);
8230
64f28fe2d5c8 (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8224
diff changeset
   915
				CommandCost ret(EXPENSES_CONSTRUCTION);
6679
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   916
				for (RoadType rt = ROADTYPE_ROAD; rt < ROADTYPE_END; rt++) {
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7857
diff changeset
   917
					if (HasBit(rts, rt)) {
8428
fb88a9033b48 (svn r11998) -Fix [FS#1692](r10053): possible remote assert by setting bit 6 of p1 for CMD_REMOVE_ROAD
smatz
parents: 8413
diff changeset
   918
						CommandCost tmp_ret = RemoveRoad(tile, flags, GetRoadBits(tile, rt), rt, true);
6679
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   919
						if (CmdFailed(tmp_ret)) return tmp_ret;
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6946
diff changeset
   920
						ret.AddCost(tmp_ret);
6679
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   921
					}
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   922
				}
4f84acfb6c9d (svn r9910) -Codechange: prepare road building/removing commands for more road types.
rubidium
parents: 6666
diff changeset
   923
				return ret;
3060
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   924
			}
5637
aa922e570f9a (svn r8096) -Codechange: Invert the check if you are allowed to clear a road tile so there are not so many negations (too confusing) and added some comments to further clarify what happens.
Darkvater
parents: 5587
diff changeset
   925
			return_cmd_error(STR_1801_MUST_REMOVE_ROAD_FIRST);
5643
b373887faf8b (svn r8102) -Cleanup: Remove unreachable code (r8096), useless cast
Darkvater
parents: 5637
diff changeset
   926
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   927
3793
7fe24e10ea63 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3792
diff changeset
   928
		case ROAD_TILE_CROSSING: {
6814
46c7d033c926 (svn r10053) -Fix: could not clear a level-crossing tile with tram tracks.
rubidium
parents: 6768
diff changeset
   929
			RoadTypes rts = GetRoadTypes(tile);
8230
64f28fe2d5c8 (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8224
diff changeset
   930
			CommandCost ret(EXPENSES_CONSTRUCTION);
3060
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   931
3069
9a1fd047b595 (svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents: 3068
diff changeset
   932
			if (flags & DC_AUTO) return_cmd_error(STR_1801_MUST_REMOVE_ROAD_FIRST);
3060
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   933
6814
46c7d033c926 (svn r10053) -Fix: could not clear a level-crossing tile with tram tracks.
rubidium
parents: 6768
diff changeset
   934
			/* Must iterate over the roadtypes in a reverse manner because
46c7d033c926 (svn r10053) -Fix: could not clear a level-crossing tile with tram tracks.
rubidium
parents: 6768
diff changeset
   935
			 * tram tracks must be removed before the road bits. */
8859
b527de22bf3e (svn r12622) -Fix: infinite loop in case your compiler decides that enums are unsigned by default. Patch by Dominik.
rubidium
parents: 8821
diff changeset
   936
			RoadType rt = ROADTYPE_HWAY;
b527de22bf3e (svn r12622) -Fix: infinite loop in case your compiler decides that enums are unsigned by default. Patch by Dominik.
rubidium
parents: 8821
diff changeset
   937
			do {
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7857
diff changeset
   938
				if (HasBit(rts, rt)) {
8428
fb88a9033b48 (svn r11998) -Fix [FS#1692](r10053): possible remote assert by setting bit 6 of p1 for CMD_REMOVE_ROAD
smatz
parents: 8413
diff changeset
   939
					CommandCost tmp_ret = RemoveRoad(tile, flags, GetCrossingRoadBits(tile), rt, false);
6814
46c7d033c926 (svn r10053) -Fix: could not clear a level-crossing tile with tram tracks.
rubidium
parents: 6768
diff changeset
   940
					if (CmdFailed(tmp_ret)) return tmp_ret;
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6946
diff changeset
   941
					ret.AddCost(tmp_ret);
6814
46c7d033c926 (svn r10053) -Fix: could not clear a level-crossing tile with tram tracks.
rubidium
parents: 6768
diff changeset
   942
				}
8859
b527de22bf3e (svn r12622) -Fix: infinite loop in case your compiler decides that enums are unsigned by default. Patch by Dominik.
rubidium
parents: 8821
diff changeset
   943
			} while (rt-- != ROADTYPE_ROAD);
3060
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   944
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   945
			if (flags & DC_EXEC) {
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3435
diff changeset
   946
				DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
3060
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   947
			}
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   948
			return ret;
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   949
		}
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   950
3069
9a1fd047b595 (svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents: 3068
diff changeset
   951
		default:
3793
7fe24e10ea63 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3792
diff changeset
   952
		case ROAD_TILE_DEPOT:
3060
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   953
			if (flags & DC_AUTO) {
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   954
				return_cmd_error(STR_2004_BUILDING_MUST_BE_DEMOLISHED);
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   955
			}
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
   956
			return RemoveRoadDepot(tile, flags);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   957
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   958
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   959
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   960
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6172
diff changeset
   961
struct DrawRoadTileStruct {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   962
	uint16 image;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   963
	byte subcoord_x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   964
	byte subcoord_y;
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6172
diff changeset
   965
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   966
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   967
#include "table/road_land.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   968
8734
cf2c240d2e1b (svn r12419) -Cleanup: of the internal road-piece building and removing.
skidd13
parents: 8732
diff changeset
   969
/**
cf2c240d2e1b (svn r12419) -Cleanup: of the internal road-piece building and removing.
skidd13
parents: 8732
diff changeset
   970
 * Get the foundationtype of a RoadBits Slope combination
cf2c240d2e1b (svn r12419) -Cleanup: of the internal road-piece building and removing.
skidd13
parents: 8732
diff changeset
   971
 *
cf2c240d2e1b (svn r12419) -Cleanup: of the internal road-piece building and removing.
skidd13
parents: 8732
diff changeset
   972
 * @param tileh The Slope part
cf2c240d2e1b (svn r12419) -Cleanup: of the internal road-piece building and removing.
skidd13
parents: 8732
diff changeset
   973
 * @param bits The RoadBits part
cf2c240d2e1b (svn r12419) -Cleanup: of the internal road-piece building and removing.
skidd13
parents: 8732
diff changeset
   974
 * @return The resulting Foundation
cf2c240d2e1b (svn r12419) -Cleanup: of the internal road-piece building and removing.
skidd13
parents: 8732
diff changeset
   975
 */
7335
141c6b86ec1f (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: 7333
diff changeset
   976
Foundation GetRoadFoundation(Slope tileh, RoadBits bits)
2548
49c8a096033f (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2544
diff changeset
   977
{
8734
cf2c240d2e1b (svn r12419) -Cleanup: of the internal road-piece building and removing.
skidd13
parents: 8732
diff changeset
   978
	/* Flat land and land without a road doesn't require a foundation */
cf2c240d2e1b (svn r12419) -Cleanup: of the internal road-piece building and removing.
skidd13
parents: 8732
diff changeset
   979
	if (tileh == SLOPE_FLAT || bits == ROAD_NONE) return FOUNDATION_NONE;
cf2c240d2e1b (svn r12419) -Cleanup: of the internal road-piece building and removing.
skidd13
parents: 8732
diff changeset
   980
7335
141c6b86ec1f (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: 7333
diff changeset
   981
	if (!IsSteepSlope(tileh)) {
8744
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   982
		/* Leveled RoadBits on a slope */
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   983
		if ((_invalid_tileh_slopes_road[0][tileh] & bits) == ROAD_NONE) return FOUNDATION_LEVELED;
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   984
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   985
		/* Straight roads without foundation on a slope */
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   986
		if (!IsSlopeWithOneCornerRaised(tileh) &&
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   987
				(_invalid_tileh_slopes_road[1][tileh] & bits) == ROAD_NONE)
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   988
			return FOUNDATION_NONE;
4246
6dcc0e44a367 (svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents: 4232
diff changeset
   989
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   990
8744
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
   991
	/* Roads on steep Slopes or on Slopes with one corner raised */
7335
141c6b86ec1f (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: 7333
diff changeset
   992
	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
   993
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   994
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   995
const byte _road_sloped_sprites[14] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   996
	0,  0,  2,  0,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   997
	0,  1,  0,  0,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   998
	3,  0,  0,  0,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   999
	0,  0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1000
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1001
2471
5935596f14a8 (svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents: 2469
diff changeset
  1002
/**
6541
dfa5165a5ab7 (svn r9730) -Feature: [NewGRF] Add support for miscellaneous grf feature bit 1 - paved roads on desert tiles.
maedhros
parents: 6491
diff changeset
  1003
 * Whether to draw unpaved roads regardless of the town zone.
dfa5165a5ab7 (svn r9730) -Feature: [NewGRF] Add support for miscellaneous grf feature bit 1 - paved roads on desert tiles.
maedhros
parents: 6491
diff changeset
  1004
 * By default, OpenTTD always draws roads as unpaved if they are on a desert
dfa5165a5ab7 (svn r9730) -Feature: [NewGRF] Add support for miscellaneous grf feature bit 1 - paved roads on desert tiles.
maedhros
parents: 6491
diff changeset
  1005
 * tile or above the snowline. Newgrf files, however, can set a bit that allows
dfa5165a5ab7 (svn r9730) -Feature: [NewGRF] Add support for miscellaneous grf feature bit 1 - paved roads on desert tiles.
maedhros
parents: 6491
diff changeset
  1006
 * paved roads to be built on desert tiles as they would be on grassy tiles.
dfa5165a5ab7 (svn r9730) -Feature: [NewGRF] Add support for miscellaneous grf feature bit 1 - paved roads on desert tiles.
maedhros
parents: 6491
diff changeset
  1007
 *
dfa5165a5ab7 (svn r9730) -Feature: [NewGRF] Add support for miscellaneous grf feature bit 1 - paved roads on desert tiles.
maedhros
parents: 6491
diff changeset
  1008
 * @param tile The tile the road is on
dfa5165a5ab7 (svn r9730) -Feature: [NewGRF] Add support for miscellaneous grf feature bit 1 - paved roads on desert tiles.
maedhros
parents: 6491
diff changeset
  1009
 * @param roadside What sort of road this is
dfa5165a5ab7 (svn r9730) -Feature: [NewGRF] Add support for miscellaneous grf feature bit 1 - paved roads on desert tiles.
maedhros
parents: 6491
diff changeset
  1010
 * @return True if the road should be drawn unpaved regardless of the roadside.
dfa5165a5ab7 (svn r9730) -Feature: [NewGRF] Add support for miscellaneous grf feature bit 1 - paved roads on desert tiles.
maedhros
parents: 6491
diff changeset
  1011
 */
dfa5165a5ab7 (svn r9730) -Feature: [NewGRF] Add support for miscellaneous grf feature bit 1 - paved roads on desert tiles.
maedhros
parents: 6491
diff changeset
  1012
static bool AlwaysDrawUnpavedRoads(TileIndex tile, Roadside roadside)
dfa5165a5ab7 (svn r9730) -Feature: [NewGRF] Add support for miscellaneous grf feature bit 1 - paved roads on desert tiles.
maedhros
parents: 6491
diff changeset
  1013
{
dfa5165a5ab7 (svn r9730) -Feature: [NewGRF] Add support for miscellaneous grf feature bit 1 - paved roads on desert tiles.
maedhros
parents: 6491
diff changeset
  1014
	return (IsOnSnow(tile) &&
9413
7042a8ec3fa8 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 9358
diff changeset
  1015
			!(_settings_game.game_creation.landscape == LT_TROPIC && HasGrfMiscBit(GMB_DESERT_PAVED_ROADS) &&
6541
dfa5165a5ab7 (svn r9730) -Feature: [NewGRF] Add support for miscellaneous grf feature bit 1 - paved roads on desert tiles.
maedhros
parents: 6491
diff changeset
  1016
				roadside != ROADSIDE_BARREN && roadside != ROADSIDE_GRASS && roadside != ROADSIDE_GRASS_ROAD_WORKS));
dfa5165a5ab7 (svn r9730) -Feature: [NewGRF] Add support for miscellaneous grf feature bit 1 - paved roads on desert tiles.
maedhros
parents: 6491
diff changeset
  1017
}
dfa5165a5ab7 (svn r9730) -Feature: [NewGRF] Add support for miscellaneous grf feature bit 1 - paved roads on desert tiles.
maedhros
parents: 6491
diff changeset
  1018
dfa5165a5ab7 (svn r9730) -Feature: [NewGRF] Add support for miscellaneous grf feature bit 1 - paved roads on desert tiles.
maedhros
parents: 6491
diff changeset
  1019
/**
6691
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
  1020
 * Draws the catenary for the given tile
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
  1021
 * @param ti   information about the tile (slopes, height etc)
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
  1022
 * @param tram the roadbits for the tram
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
  1023
 */
8821
1411d08e26b3 (svn r12569) -Cleanup: variable scope and coding style in road*.cpp
smatz
parents: 8806
diff changeset
  1024
void DrawTramCatenary(const TileInfo *ti, RoadBits tram)
6691
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
  1025
{
8806
4fe163e0b52a (svn r12547) -Feature: invisibility options to make objects invisible instead of transparent
smatz
parents: 8747
diff changeset
  1026
	/* Do not draw catenary if it is invisible */
4fe163e0b52a (svn r12547) -Feature: invisibility options to make objects invisible instead of transparent
smatz
parents: 8747
diff changeset
  1027
	if (IsInvisibilitySet(TO_CATENARY)) return;
4fe163e0b52a (svn r12547) -Feature: invisibility options to make objects invisible instead of transparent
smatz
parents: 8747
diff changeset
  1028
6691
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
  1029
	/* Don't draw the catenary under a low bridge */
8528
6e61e651790e (svn r12103) -Feature(tte): separate catenary transparency settings from building transparency settings
smatz
parents: 8520
diff changeset
  1030
	if (MayHaveBridgeAbove(ti->tile) && IsBridgeAbove(ti->tile) && !IsTransparencySet(TO_CATENARY)) {
6691
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
  1031
		uint height = GetBridgeHeight(GetNorthernBridgeEnd(ti->tile));
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
  1032
6699
d2f35126c1a6 (svn r9931) -Fix: some glitches with catenary and bridges.
rubidium
parents: 6697
diff changeset
  1033
		if (height <= GetTileMaxZ(ti->tile) + TILE_HEIGHT) return;
6691
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
  1034
	}
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
  1035
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
  1036
	SpriteID front;
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
  1037
	SpriteID back;
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
  1038
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
  1039
	if (ti->tileh != SLOPE_FLAT) {
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
  1040
		back  = SPR_TRAMWAY_BACK_WIRES_SLOPED  + _road_sloped_sprites[ti->tileh - 1];
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
  1041
		front = SPR_TRAMWAY_FRONT_WIRES_SLOPED + _road_sloped_sprites[ti->tileh - 1];
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
  1042
	} else {
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
  1043
		back  = SPR_TRAMWAY_BASE + _road_backpole_sprites_1[tram];
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
  1044
		front = SPR_TRAMWAY_BASE + _road_frontwire_sprites_1[tram];
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
  1045
	}
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
  1046
8528
6e61e651790e (svn r12103) -Feature(tte): separate catenary transparency settings from building transparency settings
smatz
parents: 8520
diff changeset
  1047
	AddSortableSpriteToDraw(back,  PAL_NONE, ti->x, ti->y, 16, 16, TILE_HEIGHT + BB_HEIGHT_UNDER_BRIDGE, ti->z, IsTransparencySet(TO_CATENARY));
6e61e651790e (svn r12103) -Feature(tte): separate catenary transparency settings from building transparency settings
smatz
parents: 8520
diff changeset
  1048
	AddSortableSpriteToDraw(front, PAL_NONE, ti->x, ti->y, 16, 16, TILE_HEIGHT + BB_HEIGHT_UNDER_BRIDGE, ti->z, IsTransparencySet(TO_CATENARY));
6691
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
  1049
}
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
  1050
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
  1051
/**
6764
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
  1052
 * Draws details on/around the road
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
  1053
 * @param img the sprite to draw
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
  1054
 * @param ti  the tile to draw on
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
  1055
 * @param dx  the offset from the top of the BB of the tile
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
  1056
 * @param dy  the offset from the top of the BB of the tile
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
  1057
 * @param h   the height of the sprite to draw
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
  1058
 */
8821
1411d08e26b3 (svn r12569) -Cleanup: variable scope and coding style in road*.cpp
smatz
parents: 8806
diff changeset
  1059
static void DrawRoadDetail(SpriteID img, const TileInfo *ti, int dx, int dy, int h)
6764
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
  1060
{
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
  1061
	int x = ti->x | dx;
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
  1062
	int y = ti->y | dy;
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
  1063
	byte z = ti->z;
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
  1064
	if (ti->tileh != SLOPE_FLAT) z = GetSlopeZ(x, y);
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
  1065
	AddSortableSpriteToDraw(img, PAL_NONE, x, y, 2, 2, h, z);
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
  1066
}
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
  1067
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
  1068
/**
2471
5935596f14a8 (svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents: 2469
diff changeset
  1069
 * Draw ground sprite and road pieces
5935596f14a8 (svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents: 2469
diff changeset
  1070
 * @param ti TileInfo
5935596f14a8 (svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents: 2469
diff changeset
  1071
 */
8821
1411d08e26b3 (svn r12569) -Cleanup: variable scope and coding style in road*.cpp
smatz
parents: 8806
diff changeset
  1072
static void DrawRoadBits(TileInfo *ti)
2471
5935596f14a8 (svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents: 2469
diff changeset
  1073
{
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
  1074
	RoadBits road = GetRoadBits(ti->tile, ROADTYPE_ROAD);
6691
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
  1075
	RoadBits tram = GetRoadBits(ti->tile, ROADTYPE_TRAM);
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
  1076
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5643
diff changeset
  1077
	SpriteID image = 0;
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5643
diff changeset
  1078
	SpriteID pal = PAL_NONE;
2471
5935596f14a8 (svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents: 2469
diff changeset
  1079
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3560
diff changeset
  1080
	if (ti->tileh != SLOPE_FLAT) {
7335
141c6b86ec1f (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: 7333
diff changeset
  1081
		DrawFoundation(ti, GetRoadFoundation(ti->tileh, road | tram));
2471
5935596f14a8 (svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents: 2469
diff changeset
  1082
6393
e1e4939d19b5 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6368
diff changeset
  1083
		/* DrawFoundation() modifies ti.
e1e4939d19b5 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6368
diff changeset
  1084
		 * Default sloped sprites.. */
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3560
diff changeset
  1085
		if (ti->tileh != SLOPE_FLAT) image = _road_sloped_sprites[ti->tileh - 1] + 0x53F;
2471
5935596f14a8 (svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents: 2469
diff changeset
  1086
	}
5935596f14a8 (svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents: 2469
diff changeset
  1087
6691
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
  1088
	if (image == 0) image = _road_tile_sprites_1[road != ROAD_NONE ? road : tram];
2471
5935596f14a8 (svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents: 2469
diff changeset
  1089
8821
1411d08e26b3 (svn r12569) -Cleanup: variable scope and coding style in road*.cpp
smatz
parents: 8806
diff changeset
  1090
	Roadside roadside = GetRoadside(ti->tile);
2471
5935596f14a8 (svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents: 2469
diff changeset
  1091
6541
dfa5165a5ab7 (svn r9730) -Feature: [NewGRF] Add support for miscellaneous grf feature bit 1 - paved roads on desert tiles.
maedhros
parents: 6491
diff changeset
  1092
	if (AlwaysDrawUnpavedRoads(ti->tile, roadside)) {
2471
5935596f14a8 (svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents: 2469
diff changeset
  1093
		image += 19;
4048
5d653b47d349 (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1094
	} else {
5d653b47d349 (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1095
		switch (roadside) {
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5643
diff changeset
  1096
			case ROADSIDE_BARREN:           pal = PALETTE_TO_BARE_LAND; break;
4048
5d653b47d349 (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1097
			case ROADSIDE_GRASS:            break;
5d653b47d349 (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1098
			case ROADSIDE_GRASS_ROAD_WORKS: break;
5d653b47d349 (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1099
			default:                        image -= 19; break; // Paved
5d653b47d349 (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1100
		}
2471
5935596f14a8 (svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents: 2469
diff changeset
  1101
	}
5935596f14a8 (svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents: 2469
diff changeset
  1102
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5643
diff changeset
  1103
	DrawGroundSprite(image, pal);
2471
5935596f14a8 (svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents: 2469
diff changeset
  1104
6691
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
  1105
	/* For tram we overlay the road graphics with either tram tracks only
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
  1106
	 * (when there is actual road beneath the trams) or with tram tracks
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
  1107
	 * and some dirts which hides the road graphics */
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
  1108
	if (tram != ROAD_NONE) {
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
  1109
		if (ti->tileh != SLOPE_FLAT) {
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
  1110
			image = _road_sloped_sprites[ti->tileh - 1] + SPR_TRAMWAY_SLOPED_OFFSET;
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
  1111
		} else {
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
  1112
			image = _road_tile_sprites_1[tram] - SPR_ROAD_Y;
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
  1113
		}
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
  1114
		image += (road == ROAD_NONE) ? SPR_TRAMWAY_TRAM : SPR_TRAMWAY_OVERLAY;
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
  1115
		DrawGroundSprite(image, pal);
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
  1116
	}
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
  1117
6965
8cb36817b61d (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: 6950
diff changeset
  1118
	if (road != ROAD_NONE) {
8cb36817b61d (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: 6950
diff changeset
  1119
		DisallowedRoadDirections drd = GetDisallowedRoadDirections(ti->tile);
8cb36817b61d (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: 6950
diff changeset
  1120
		if (drd != DRD_NONE) {
8cb36817b61d (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: 6950
diff changeset
  1121
			DrawRoadDetail(SPR_ONEWAY_BASE + drd - 1 + ((road == ROAD_X) ? 0 : 3), ti, 8, 8, 0);
8cb36817b61d (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: 6950
diff changeset
  1122
		}
8cb36817b61d (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: 6950
diff changeset
  1123
	}
8cb36817b61d (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: 6950
diff changeset
  1124
3430
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
  1125
	if (HasRoadWorks(ti->tile)) {
6393
e1e4939d19b5 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6368
diff changeset
  1126
		/* Road works */
6691
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
  1127
		DrawGroundSprite((road | tram) & ROAD_X ? SPR_EXCAVATION_X : SPR_EXCAVATION_Y, PAL_NONE);
2471
5935596f14a8 (svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents: 2469
diff changeset
  1128
		return;
5935596f14a8 (svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents: 2469
diff changeset
  1129
	}
5935596f14a8 (svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents: 2469
diff changeset
  1130
6691
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
  1131
	if (tram != ROAD_NONE) DrawTramCatenary(ti, tram);
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
  1132
6393
e1e4939d19b5 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6368
diff changeset
  1133
	/* Return if full detail is disabled, or we are zoomed fully out. */
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7857
diff changeset
  1134
	if (!HasBit(_display_opt, DO_FULL_DETAIL) || _cur_dpi->zoom > ZOOM_LVL_DETAIL) return;
5148
3641479afb1d (svn r7240) -Fix: Always display the excavation of roadworks even when fully zoomed out (they are quite noticable) or "full details" are off (they are part of the game mechanics)
tron
parents: 5116
diff changeset
  1135
8589
e0294479574f (svn r12170) -Fix: do not draw trees along road and street lights under low bridges (spotted by _minime_)
smatz
parents: 8571
diff changeset
  1136
	/* Do not draw details (street lights, trees) under low bridge */
e0294479574f (svn r12170) -Fix: do not draw trees along road and street lights under low bridges (spotted by _minime_)
smatz
parents: 8571
diff changeset
  1137
	if (MayHaveBridgeAbove(ti->tile) && IsBridgeAbove(ti->tile) && (roadside == ROADSIDE_TREES || roadside == ROADSIDE_STREET_LIGHTS)) {
e0294479574f (svn r12170) -Fix: do not draw trees along road and street lights under low bridges (spotted by _minime_)
smatz
parents: 8571
diff changeset
  1138
		uint height = GetBridgeHeight(GetNorthernBridgeEnd(ti->tile));
e0294479574f (svn r12170) -Fix: do not draw trees along road and street lights under low bridges (spotted by _minime_)
smatz
parents: 8571
diff changeset
  1139
		uint minz = GetTileMaxZ(ti->tile) + 2 * TILE_HEIGHT;
e0294479574f (svn r12170) -Fix: do not draw trees along road and street lights under low bridges (spotted by _minime_)
smatz
parents: 8571
diff changeset
  1140
e0294479574f (svn r12170) -Fix: do not draw trees along road and street lights under low bridges (spotted by _minime_)
smatz
parents: 8571
diff changeset
  1141
		if (roadside == ROADSIDE_TREES) minz += TILE_HEIGHT;
e0294479574f (svn r12170) -Fix: do not draw trees along road and street lights under low bridges (spotted by _minime_)
smatz
parents: 8571
diff changeset
  1142
e0294479574f (svn r12170) -Fix: do not draw trees along road and street lights under low bridges (spotted by _minime_)
smatz
parents: 8571
diff changeset
  1143
		if (height < minz) return;
e0294479574f (svn r12170) -Fix: do not draw trees along road and street lights under low bridges (spotted by _minime_)
smatz
parents: 8571
diff changeset
  1144
	}
e0294479574f (svn r12170) -Fix: do not draw trees along road and street lights under low bridges (spotted by _minime_)
smatz
parents: 8571
diff changeset
  1145
8647
09cd382bf406 (svn r12290) -Fix[FS#1807]: Do not draw trees nor lamps between tram tracks.(Roujin)
belugas
parents: 8616
diff changeset
  1146
	/* If there are no road bits, return, as there is nothing left to do */
09cd382bf406 (svn r12290) -Fix[FS#1807]: Do not draw trees nor lamps between tram tracks.(Roujin)
belugas
parents: 8616
diff changeset
  1147
	if (CountBits(road) < 2) return;
09cd382bf406 (svn r12290) -Fix[FS#1807]: Do not draw trees nor lamps between tram tracks.(Roujin)
belugas
parents: 8616
diff changeset
  1148
6393
e1e4939d19b5 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6368
diff changeset
  1149
	/* Draw extra details. */
8821
1411d08e26b3 (svn r12569) -Cleanup: variable scope and coding style in road*.cpp
smatz
parents: 8806
diff changeset
  1150
	for (const DrawRoadTileStruct *drts = _road_display_table[roadside][road | tram]; drts->image != 0; drts++) {
6764
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
  1151
		DrawRoadDetail(drts->image, ti, drts->subcoord_x, drts->subcoord_y, 0x10);
2471
5935596f14a8 (svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents: 2469
diff changeset
  1152
	}
5935596f14a8 (svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents: 2469
diff changeset
  1153
}
5935596f14a8 (svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
peter1138
parents: 2469
diff changeset
  1154
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1155
static void DrawTile_Road(TileInfo *ti)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1156
{
3793
7fe24e10ea63 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3792
diff changeset
  1157
	switch (GetRoadTileType(ti->tile)) {
7fe24e10ea63 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3792
diff changeset
  1158
		case ROAD_TILE_NORMAL:
4081
46f02386923e (svn r5396) - Remove two fixed parameters
tron
parents: 4077
diff changeset
  1159
			DrawRoadBits(ti);
3060
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1160
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1161
3793
7fe24e10ea63 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3792
diff changeset
  1162
		case ROAD_TILE_CROSSING: {
7335
141c6b86ec1f (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: 7333
diff changeset
  1163
			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
  1164
8821
1411d08e26b3 (svn r12569) -Cleanup: variable scope and coding style in road*.cpp
smatz
parents: 8806
diff changeset
  1165
			SpriteID image = GetRailTypeInfo(GetRailType(ti->tile))->base_sprites.crossing;
1411d08e26b3 (svn r12569) -Cleanup: variable scope and coding style in road*.cpp
smatz
parents: 8806
diff changeset
  1166
			SpriteID pal = PAL_NONE;
3060
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1167
3272
b3e2d8e19937 (svn r3984) Add a function to get the road axis of a level crossing
tron
parents: 3269
diff changeset
  1168
			if (GetCrossingRoadAxis(ti->tile) == AXIS_X) image++;
3322
41b4d25b126d (svn r4088) -Codechange: Introduce {Unb,B}arCrossing and IsCrossingBarred to put and get the status of a level crossing
celestar
parents: 3319
diff changeset
  1169
			if (IsCrossingBarred(ti->tile)) image += 2;
3060
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1170
8821
1411d08e26b3 (svn r12569) -Cleanup: variable scope and coding style in road*.cpp
smatz
parents: 8806
diff changeset
  1171
			Roadside roadside = GetRoadside(ti->tile);
1411d08e26b3 (svn r12569) -Cleanup: variable scope and coding style in road*.cpp
smatz
parents: 8806
diff changeset
  1172
6541
dfa5165a5ab7 (svn r9730) -Feature: [NewGRF] Add support for miscellaneous grf feature bit 1 - paved roads on desert tiles.
maedhros
parents: 6491
diff changeset
  1173
			if (AlwaysDrawUnpavedRoads(ti->tile, roadside)) {
3060
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1174
				image += 8;
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1175
			} else {
6541
dfa5165a5ab7 (svn r9730) -Feature: [NewGRF] Add support for miscellaneous grf feature bit 1 - paved roads on desert tiles.
maedhros
parents: 6491
diff changeset
  1176
				switch (roadside) {
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5643
diff changeset
  1177
					case ROADSIDE_BARREN: pal = PALETTE_TO_BARE_LAND; break;
4048
5d653b47d349 (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1178
					case ROADSIDE_GRASS:  break;
5d653b47d349 (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1179
					default:              image += 4; break; // Paved
5d653b47d349 (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1180
				}
3060
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1181
			}
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1182
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5643
diff changeset
  1183
			DrawGroundSprite(image, pal);
9785
2005c34d0811 (svn r13927) -Add [YAPP]: Draw reserved tracks darker, toggeld by a patch setting. (michi_cc)
rubidium
parents: 9711
diff changeset
  1184
2005c34d0811 (svn r13927) -Add [YAPP]: Draw reserved tracks darker, toggeld by a patch setting. (michi_cc)
rubidium
parents: 9711
diff changeset
  1185
			/* PBS debugging, draw reserved tracks darker */
2005c34d0811 (svn r13927) -Add [YAPP]: Draw reserved tracks darker, toggeld by a patch setting. (michi_cc)
rubidium
parents: 9711
diff changeset
  1186
			if (_settings_client.gui.show_track_reservation && GetCrossingReservation(ti->tile)) {
2005c34d0811 (svn r13927) -Add [YAPP]: Draw reserved tracks darker, toggeld by a patch setting. (michi_cc)
rubidium
parents: 9711
diff changeset
  1187
				DrawGroundSprite(GetCrossingRoadAxis(ti->tile) == AXIS_Y ? GetRailTypeInfo(GetRailType(ti->tile))->base_sprites.single_y : GetRailTypeInfo(GetRailType(ti->tile))->base_sprites.single_x, PALETTE_CRASH);
2005c34d0811 (svn r13927) -Add [YAPP]: Draw reserved tracks darker, toggeld by a patch setting. (michi_cc)
rubidium
parents: 9711
diff changeset
  1188
			}
2005c34d0811 (svn r13927) -Add [YAPP]: Draw reserved tracks darker, toggeld by a patch setting. (michi_cc)
rubidium
parents: 9711
diff changeset
  1189
8563
13b1a41e46f1 (svn r12141) -Codechange: Introduce IsNormalRoad[Tile](), IsRoadDepot[Tile]() and HasTileRoadType(); and use them.
frosch
parents: 8560
diff changeset
  1190
			if (HasTileRoadType(ti->tile, ROADTYPE_TRAM)) {
6697
dde1f5dced50 (svn r9929) -Fix [FS#803]: fix several drawing issues.
rubidium
parents: 6691
diff changeset
  1191
				DrawGroundSprite(SPR_TRAMWAY_OVERLAY + (GetCrossingRoadAxis(ti->tile) ^ 1), pal);
dde1f5dced50 (svn r9929) -Fix [FS#803]: fix several drawing issues.
rubidium
parents: 6691
diff changeset
  1192
				DrawTramCatenary(ti, GetCrossingRoadBits(ti->tile));
dde1f5dced50 (svn r9929) -Fix [FS#803]: fix several drawing issues.
rubidium
parents: 6691
diff changeset
  1193
			}
9154
2c042b567165 (svn r13016) -Codechange: unify the detection if rail catenary should be drawn
smatz
parents: 9111
diff changeset
  1194
			if (HasCatenaryDrawn(GetRailType(ti->tile))) DrawCatenary(ti);
3060
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1195
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1196
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1197
3098
aed45c5c1e11 (svn r3687) Complete some bits I missed whenn adding accessor functions for road types and pieces
tron
parents: 3097
diff changeset
  1198
		default:
3793
7fe24e10ea63 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3792
diff changeset
  1199
		case ROAD_TILE_DEPOT: {
7335
141c6b86ec1f (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: 7333
diff changeset
  1200
			if (ti->tileh != SLOPE_FLAT) DrawFoundation(ti, FOUNDATION_LEVELED);
1398
3c5c97aba203 (svn r1902) Replace some casts with proper typing
tron
parents: 1359
diff changeset
  1201
8821
1411d08e26b3 (svn r12569) -Cleanup: variable scope and coding style in road*.cpp
smatz
parents: 8806
diff changeset
  1202
			SpriteID palette = PLAYER_SPRITE_COLOR(GetTileOwner(ti->tile));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1203
8821
1411d08e26b3 (svn r12569) -Cleanup: variable scope and coding style in road*.cpp
smatz
parents: 8806
diff changeset
  1204
			const DrawTileSprites *dts;
8563
13b1a41e46f1 (svn r12141) -Codechange: Introduce IsNormalRoad[Tile](), IsRoadDepot[Tile]() and HasTileRoadType(); and use them.
frosch
parents: 8560
diff changeset
  1205
			if (HasTileRoadType(ti->tile, ROADTYPE_TRAM)) {
6691
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
  1206
				dts =  &_tram_depot[GetRoadDepotDirection(ti->tile)];
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
  1207
			} else {
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
  1208
				dts =  &_road_depot[GetRoadDepotDirection(ti->tile)];
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
  1209
			}
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6689
diff changeset
  1210
8571
53c94d717e99 (svn r12149) -Codechange: Merge 'ground_sprite' and 'ground_pal' of DrawTileSprites into one PalSpriteID
frosch
parents: 8570
diff changeset
  1211
			DrawGroundSprite(dts->ground.sprite, PAL_NONE);
3060
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1212
8806
4fe163e0b52a (svn r12547) -Feature: invisibility options to make objects invisible instead of transparent
smatz
parents: 8747
diff changeset
  1213
			/* End now if buildings are invisible */
4fe163e0b52a (svn r12547) -Feature: invisibility options to make objects invisible instead of transparent
smatz
parents: 8747
diff changeset
  1214
			if (IsInvisibilitySet(TO_BUILDINGS)) break;
4fe163e0b52a (svn r12547) -Feature: invisibility options to make objects invisible instead of transparent
smatz
parents: 8747
diff changeset
  1215
8821
1411d08e26b3 (svn r12569) -Cleanup: variable scope and coding style in road*.cpp
smatz
parents: 8806
diff changeset
  1216
			for (const DrawTileSeqStruct *dtss = dts->seq; dtss->image.sprite != 0; dtss++) {
8570
f50de4804ff1 (svn r12148) -Codechange: Merge 'image' and 'pal' of DrawTileSeqStruct into one PalSpriteID
frosch
parents: 8563
diff changeset
  1217
				SpriteID image = dtss->image.sprite;
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5643
diff changeset
  1218
				SpriteID pal;
3060
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1219
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7857
diff changeset
  1220
				if (!IsTransparencySet(TO_BUILDINGS) && HasBit(image, PALETTE_MODIFIER_COLOR)) {
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5643
diff changeset
  1221
					pal = palette;
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5643
diff changeset
  1222
				} else {
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5643
diff changeset
  1223
					pal = PAL_NONE;
4226
10d7608f4c6c (svn r5772) Road depots always have an player as owner, so remove an useless check
tron
parents: 4212
diff changeset
  1224
				}
3060
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1225
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4048
diff changeset
  1226
				AddSortableSpriteToDraw(
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5643
diff changeset
  1227
					image, pal,
4232
136a11474264 (svn r5796) Use DrawTileSprites/DrawTileSeqStruct for road depot drawing data, too
tron
parents: 4231
diff changeset
  1228
					ti->x + dtss->delta_x, ti->y + dtss->delta_y,
136a11474264 (svn r5796) Use DrawTileSprites/DrawTileSeqStruct for road depot drawing data, too
tron
parents: 4231
diff changeset
  1229
					dtss->size_x, dtss->size_y,
7333
e48228e44be8 (svn r10696) -Codechange: remove duplication of the "make sprite transparent" code.
rubidium
parents: 7332
diff changeset
  1230
					dtss->size_z, ti->z,
7849
0a1c0af2c96c (svn r11399) -Feature(ette): transparency settings can now be saved and thus remembered.
belugas
parents: 7832
diff changeset
  1231
					IsTransparencySet(TO_BUILDINGS)
3060
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1232
				);
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1233
			}
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1234
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1235
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1236
	}
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5212
diff changeset
  1237
	DrawBridgeMiddle(ti);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1238
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1239
6666
41ceafa4c85e (svn r9897) -Codechange: prepare the toolbar for more road types.
rubidium
parents: 6662
diff changeset
  1240
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
  1241
{
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5643
diff changeset
  1242
	SpriteID palette = PLAYER_SPRITE_COLOR(_local_player);
8821
1411d08e26b3 (svn r12569) -Cleanup: variable scope and coding style in road*.cpp
smatz
parents: 8806
diff changeset
  1243
	const DrawTileSprites *dts = (rt == ROADTYPE_TRAM) ? &_tram_depot[dir] : &_road_depot[dir];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1244
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2549
diff changeset
  1245
	x += 33;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2549
diff changeset
  1246
	y += 17;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1247
8571
53c94d717e99 (svn r12149) -Codechange: Merge 'ground_sprite' and 'ground_pal' of DrawTileSprites into one PalSpriteID
frosch
parents: 8570
diff changeset
  1248
	DrawSprite(dts->ground.sprite, PAL_NONE, x, y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1249
8821
1411d08e26b3 (svn r12569) -Cleanup: variable scope and coding style in road*.cpp
smatz
parents: 8806
diff changeset
  1250
	for (const DrawTileSeqStruct *dtss = dts->seq; dtss->image.sprite != 0; dtss++) {
4232
136a11474264 (svn r5796) Use DrawTileSprites/DrawTileSeqStruct for road depot drawing data, too
tron
parents: 4231
diff changeset
  1251
		Point pt = RemapCoords(dtss->delta_x, dtss->delta_y, dtss->delta_z);
8570
f50de4804ff1 (svn r12148) -Codechange: Merge 'image' and 'pal' of DrawTileSeqStruct into one PalSpriteID
frosch
parents: 8563
diff changeset
  1252
		SpriteID image = dtss->image.sprite;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1253
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7857
diff changeset
  1254
		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
  1255
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1256
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1257
4231
2823b3643862 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4226
diff changeset
  1258
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
  1259
{
4231
2823b3643862 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4226
diff changeset
  1260
	uint z;
2823b3643862 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4226
diff changeset
  1261
	Slope tileh = GetTileSlope(tile, &z);
3098
aed45c5c1e11 (svn r3687) Complete some bits I missed whenn adding accessor functions for road types and pieces
tron
parents: 3097
diff changeset
  1262
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3560
diff changeset
  1263
	if (tileh == SLOPE_FLAT) return z;
8563
13b1a41e46f1 (svn r12141) -Codechange: Introduce IsNormalRoad[Tile](), IsRoadDepot[Tile]() and HasTileRoadType(); and use them.
frosch
parents: 8560
diff changeset
  1264
	if (IsNormalRoad(tile)) {
7335
141c6b86ec1f (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: 7333
diff changeset
  1265
		Foundation f = GetRoadFoundation(tileh, GetAllRoadBits(tile));
141c6b86ec1f (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: 7333
diff changeset
  1266
		z += ApplyFoundationToSlope(f, &tileh);
4231
2823b3643862 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4226
diff changeset
  1267
		return z + GetPartialZ(x & 0xF, y & 0xF, tileh);
3286
5177aab0ec21 (svn r4000) Rewrite GetSlope{Tileh,Z}_{Road,Track} in a less confusing way
tron
parents: 3277
diff changeset
  1268
	} else {
3645
7f950533d510 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3637
diff changeset
  1269
		return z + TILE_HEIGHT;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1270
	}
39
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 22
diff changeset
  1271
}
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 22
diff changeset
  1272
7335
141c6b86ec1f (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: 7333
diff changeset
  1273
static Foundation GetFoundation_Road(TileIndex tile, Slope tileh)
39
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 22
diff changeset
  1274
{
8563
13b1a41e46f1 (svn r12141) -Codechange: Introduce IsNormalRoad[Tile](), IsRoadDepot[Tile]() and HasTileRoadType(); and use them.
frosch
parents: 8560
diff changeset
  1275
	if (IsNormalRoad(tile)) {
7335
141c6b86ec1f (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: 7333
diff changeset
  1276
		return GetRoadFoundation(tileh, GetAllRoadBits(tile));
3286
5177aab0ec21 (svn r4000) Rewrite GetSlope{Tileh,Z}_{Road,Track} in a less confusing way
tron
parents: 3277
diff changeset
  1277
	} else {
7335
141c6b86ec1f (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: 7333
diff changeset
  1278
		return FlatteningFoundation(tileh);
39
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 22
diff changeset
  1279
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1280
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1281
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
  1282
static void GetAcceptedCargo_Road(TileIndex tile, AcceptedCargo ac)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1283
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1284
	/* not used */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1285
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1286
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
  1287
static void AnimateTile_Road(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1288
{
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2549
diff changeset
  1289
	if (IsLevelCrossing(tile)) MarkTileDirtyByTile(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1290
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1291
4048
5d653b47d349 (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1292
5d653b47d349 (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1293
static const Roadside _town_road_types[][2] = {
5d653b47d349 (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1294
	{ ROADSIDE_GRASS,         ROADSIDE_GRASS },
5d653b47d349 (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1295
	{ ROADSIDE_PAVED,         ROADSIDE_PAVED },
5d653b47d349 (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1296
	{ ROADSIDE_PAVED,         ROADSIDE_PAVED },
5d653b47d349 (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1297
	{ ROADSIDE_TREES,         ROADSIDE_TREES },
5d653b47d349 (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1298
	{ ROADSIDE_STREET_LIGHTS, ROADSIDE_PAVED }
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1299
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1300
4048
5d653b47d349 (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1301
static const Roadside _town_road_types_2[][2] = {
5d653b47d349 (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1302
	{ ROADSIDE_GRASS,         ROADSIDE_GRASS },
5d653b47d349 (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1303
	{ ROADSIDE_PAVED,         ROADSIDE_PAVED },
5d653b47d349 (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1304
	{ ROADSIDE_STREET_LIGHTS, ROADSIDE_PAVED },
5d653b47d349 (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1305
	{ ROADSIDE_STREET_LIGHTS, ROADSIDE_PAVED },
5d653b47d349 (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1306
	{ ROADSIDE_STREET_LIGHTS, ROADSIDE_PAVED }
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1307
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1308
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1309
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
  1310
static void TileLoop_Road(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1311
{
9413
7042a8ec3fa8 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 9358
diff changeset
  1312
	switch (_settings_game.game_creation.landscape) {
6357
f0f5e7d1713c (svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents: 6343
diff changeset
  1313
		case LT_ARCTIC:
6343
76d17f784c13 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6259
diff changeset
  1314
			if (IsOnSnow(tile) != (GetTileZ(tile) > GetSnowLine())) {
3430
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
  1315
				ToggleSnow(tile);
3017
a75caf4efa2d (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents: 2989
diff changeset
  1316
				MarkTileDirtyByTile(tile);
a75caf4efa2d (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents: 2989
diff changeset
  1317
			}
a75caf4efa2d (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents: 2989
diff changeset
  1318
			break;
a75caf4efa2d (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents: 2989
diff changeset
  1319
6357
f0f5e7d1713c (svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents: 6343
diff changeset
  1320
		case LT_TROPIC:
3430
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
  1321
			if (GetTropicZone(tile) == TROPICZONE_DESERT && !IsOnDesert(tile)) {
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
  1322
				ToggleDesert(tile);
3017
a75caf4efa2d (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents: 2989
diff changeset
  1323
				MarkTileDirtyByTile(tile);
a75caf4efa2d (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents: 2989
diff changeset
  1324
			}
a75caf4efa2d (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents: 2989
diff changeset
  1325
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1326
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1327
8563
13b1a41e46f1 (svn r12141) -Codechange: Introduce IsNormalRoad[Tile](), IsRoadDepot[Tile]() and HasTileRoadType(); and use them.
frosch
parents: 8560
diff changeset
  1328
	if (IsRoadDepot(tile)) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1329
8821
1411d08e26b3 (svn r12569) -Cleanup: variable scope and coding style in road*.cpp
smatz
parents: 8806
diff changeset
  1330
	const Town *t = ClosestTownFromTile(tile, (uint)-1);
3430
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
  1331
	if (!HasRoadWorks(tile)) {
8308
bc75a4a27ec9 (svn r11873) -Codechange: less a few magical numbers and a tiny bit more comments on town zones
belugas
parents: 8264
diff changeset
  1332
		HouseZonesBits grp = HZB_TOWN_EDGE;
1280
33a251c30758 (svn r1784) -Fix: removed ClosestTownFromTile where possible, or replaced it
truelight
parents: 1264
diff changeset
  1333
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1334
		if (t != NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1335
			grp = GetTownRadiusGroup(t, tile);
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1336
6393
e1e4939d19b5 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6368
diff changeset
  1337
			/* 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
  1338
			if (t->road_build_months != 0 &&
8308
bc75a4a27ec9 (svn r11873) -Codechange: less a few magical numbers and a tiny bit more comments on town zones
belugas
parents: 8264
diff changeset
  1339
					(DistanceManhattan(t->xy, tile) < 8 || grp != HZB_TOWN_EDGE) &&
8563
13b1a41e46f1 (svn r12141) -Codechange: Introduce IsNormalRoad[Tile](), IsRoadDepot[Tile]() and HasTileRoadType(); and use them.
frosch
parents: 8560
diff changeset
  1340
					IsNormalRoad(tile) && CountBits(GetAllRoadBits(tile)) > 1 ) {
7967
a230c063a672 (svn r11523) -Codechange: Move the CHANCE macros to core/random_func.cpp cause they depend on Random()
skidd13
parents: 7954
diff changeset
  1341
				if (GetTileSlope(tile, NULL) == SLOPE_FLAT && EnsureNoVehicleOnGround(tile) && Chance16(1, 40)) {
3430
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
  1342
					StartRoadWorks(tile);
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1343
541
625227bb2a3d (svn r925) Use sound enums
tron
parents: 534
diff changeset
  1344
					SndPlayTileFx(SND_21_JACKHAMMER, tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1345
					CreateEffectVehicleAbove(
3421
7968a4b5ff0a (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3418
diff changeset
  1346
						TileX(tile) * TILE_SIZE + 7,
7968a4b5ff0a (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3418
diff changeset
  1347
						TileY(tile) * TILE_SIZE + 7,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1348
						0,
1359
52782e5cf7c9 (svn r1863) Give the effect vehicle type enums more descriptive names and use the enum as parameter type for CreateEffectVehicle*()
tron
parents: 1327
diff changeset
  1349
						EV_BULLDOZER);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1350
					MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1351
					return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1352
				}
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
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1355
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1356
		{
3430
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
  1357
			/* Adjust road ground type depending on 'grp' (grp is the distance to the center) */
9413
7042a8ec3fa8 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 9358
diff changeset
  1358
			const Roadside* new_rs = (_settings_game.game_creation.landscape == LT_TOYLAND) ? _town_road_types_2[grp] : _town_road_types[grp];
4048
5d653b47d349 (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1359
			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
  1360
3430
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
  1361
			/* We have our desired type, do nothing */
4048
5d653b47d349 (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1362
			if (cur_rs == new_rs[0]) return;
3430
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
  1363
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
  1364
			/* We have the pre-type of the desired type, switch to the desired type */
4048
5d653b47d349 (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1365
			if (cur_rs == new_rs[1]) {
5d653b47d349 (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1366
				cur_rs = new_rs[0];
3430
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
  1367
			/* We have barren land, install the pre-type */
4048
5d653b47d349 (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1368
			} else if (cur_rs == ROADSIDE_BARREN) {
5d653b47d349 (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1369
				cur_rs = new_rs[1];
3430
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
  1370
			/* 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
  1371
			} else {
4048
5d653b47d349 (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1372
				cur_rs = ROADSIDE_BARREN;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1373
			}
4048
5d653b47d349 (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4046
diff changeset
  1374
			SetRoadside(tile, cur_rs);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1375
			MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1376
		}
3430
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
  1377
	} else if (IncreaseRoadWorksCounter(tile)) {
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3421
diff changeset
  1378
		TerminateRoadWorks(tile);
7641
3a75903fd892 (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: 7601
diff changeset
  1379
9413
7042a8ec3fa8 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 9358
diff changeset
  1380
		if (_settings_game.economy.mod_road_rebuild) {
7641
3a75903fd892 (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: 7601
diff changeset
  1381
			/* Generate a nicer town surface */
3a75903fd892 (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: 7601
diff changeset
  1382
			const RoadBits old_rb = GetAnyRoadBits(tile, ROADTYPE_ROAD);
3a75903fd892 (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: 7601
diff changeset
  1383
			const RoadBits new_rb = CleanUpRoadBits(tile, old_rb);
3a75903fd892 (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: 7601
diff changeset
  1384
3a75903fd892 (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: 7601
diff changeset
  1385
			if (old_rb != new_rb) {
8428
fb88a9033b48 (svn r11998) -Fix [FS#1692](r10053): possible remote assert by setting bit 6 of p1 for CMD_REMOVE_ROAD
smatz
parents: 8413
diff changeset
  1386
				RemoveRoad(tile, DC_EXEC | DC_AUTO | DC_NO_WATER, (old_rb ^ new_rb), ROADTYPE_ROAD, true);
7641
3a75903fd892 (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: 7601
diff changeset
  1387
			}
3a75903fd892 (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: 7601
diff changeset
  1388
		}
3a75903fd892 (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: 7601
diff changeset
  1389
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1390
		MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1391
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1392
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1393
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
  1394
static void ClickTile_Road(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1395
{
8563
13b1a41e46f1 (svn r12141) -Codechange: Introduce IsNormalRoad[Tile](), IsRoadDepot[Tile]() and HasTileRoadType(); and use them.
frosch
parents: 8560
diff changeset
  1396
	if (IsRoadDepot(tile)) ShowDepotWindow(tile, VEH_ROAD);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1397
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1398
8616
fd862a55c47f (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8603
diff changeset
  1399
/* Converts RoadBits to TrackBits */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1400
static const byte _road_trackbits[16] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1401
	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
  1402
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1403
8616
fd862a55c47f (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8603
diff changeset
  1404
static TrackStatus GetTileTrackStatus_Road(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
  1405
{
8616
fd862a55c47f (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8603
diff changeset
  1406
	TrackdirBits trackdirbits = TRACKDIR_BIT_NONE;
fd862a55c47f (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8603
diff changeset
  1407
	TrackdirBits red_signals = TRACKDIR_BIT_NONE; // crossing barred
3066
26c43ab051b8 (svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents: 3061
diff changeset
  1408
	switch (mode) {
26c43ab051b8 (svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents: 3061
diff changeset
  1409
		case TRANSPORT_RAIL:
8616
fd862a55c47f (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8603
diff changeset
  1410
			if (IsLevelCrossing(tile)) trackdirbits = TrackBitsToTrackdirBits(GetCrossingRailBits(tile));
fd862a55c47f (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8603
diff changeset
  1411
			break;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1412
3066
26c43ab051b8 (svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents: 3061
diff changeset
  1413
		case TRANSPORT_ROAD:
8616
fd862a55c47f (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8603
diff changeset
  1414
			if ((GetRoadTypes(tile) & sub_mode) == 0) break;
3793
7fe24e10ea63 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3792
diff changeset
  1415
			switch (GetRoadTileType(tile)) {
6683
b88ae30866ce (svn r9914) -Codechange: prepare GTTS and the pathfinders to handle multiple road types on a single tile.
rubidium
parents: 6679
diff changeset
  1416
				case ROAD_TILE_NORMAL: {
6764
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
  1417
					const uint drd_to_multiplier[DRD_END] = { 0x101, 0x100, 0x1, 0x0 };
8596
c3404405f3f5 (svn r12177) -Codechange: use 'side' parameter in GetTileTrackStatus so there can be less checks in pathfinders for depots/stations/tunnels/bridges
smatz
parents: 8589
diff changeset
  1418
					RoadType rt = (RoadType)FindFirstBit(sub_mode);
c3404405f3f5 (svn r12177) -Codechange: use 'side' parameter in GetTileTrackStatus so there can be less checks in pathfinders for depots/stations/tunnels/bridges
smatz
parents: 8589
diff changeset
  1419
					RoadBits bits = GetRoadBits(tile, rt);
c3404405f3f5 (svn r12177) -Codechange: use 'side' parameter in GetTileTrackStatus so there can be less checks in pathfinders for depots/stations/tunnels/bridges
smatz
parents: 8589
diff changeset
  1420
c3404405f3f5 (svn r12177) -Codechange: use 'side' parameter in GetTileTrackStatus so there can be less checks in pathfinders for depots/stations/tunnels/bridges
smatz
parents: 8589
diff changeset
  1421
					/* no roadbit at this side of tile, return 0 */
8616
fd862a55c47f (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8603
diff changeset
  1422
					if (side != INVALID_DIAGDIR && (DiagDirToRoadBits(side) & bits) == 0) break;
8596
c3404405f3f5 (svn r12177) -Codechange: use 'side' parameter in GetTileTrackStatus so there can be less checks in pathfinders for depots/stations/tunnels/bridges
smatz
parents: 8589
diff changeset
  1423
6764
d09d8d618a07 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 6761
diff changeset
  1424
					uint multiplier = drd_to_multiplier[rt == ROADTYPE_TRAM ? DRD_NONE : GetDisallowedRoadDirections(tile)];
8616
fd862a55c47f (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8603
diff changeset
  1425
					if (!HasRoadWorks(tile)) trackdirbits = (TrackdirBits)(_road_trackbits[bits] * multiplier);
fd862a55c47f (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8603
diff changeset
  1426
					break;
6683
b88ae30866ce (svn r9914) -Codechange: prepare GTTS and the pathfinders to handle multiple road types on a single tile.
rubidium
parents: 6679
diff changeset
  1427
				}
3066
26c43ab051b8 (svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents: 3061
diff changeset
  1428
3793
7fe24e10ea63 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3792
diff changeset
  1429
				case ROAD_TILE_CROSSING: {
8596
c3404405f3f5 (svn r12177) -Codechange: use 'side' parameter in GetTileTrackStatus so there can be less checks in pathfinders for depots/stations/tunnels/bridges
smatz
parents: 8589
diff changeset
  1430
					Axis axis = GetCrossingRoadAxis(tile);
3272
b3e2d8e19937 (svn r3984) Add a function to get the road axis of a level crossing
tron
parents: 3269
diff changeset
  1431
8616
fd862a55c47f (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8603
diff changeset
  1432
					if (side != INVALID_DIAGDIR && axis != DiagDirToAxis(side)) break;
8596
c3404405f3f5 (svn r12177) -Codechange: use 'side' parameter in GetTileTrackStatus so there can be less checks in pathfinders for depots/stations/tunnels/bridges
smatz
parents: 8589
diff changeset
  1433
8616
fd862a55c47f (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8603
diff changeset
  1434
					trackdirbits = TrackBitsToTrackdirBits(AxisToTrackBits(axis));
fd862a55c47f (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8603
diff changeset
  1435
					if (IsCrossingBarred(tile)) red_signals = trackdirbits;
fd862a55c47f (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8603
diff changeset
  1436
					break;
3066
26c43ab051b8 (svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents: 3061
diff changeset
  1437
				}
26c43ab051b8 (svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents: 3061
diff changeset
  1438
3069
9a1fd047b595 (svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents: 3068
diff changeset
  1439
				default:
8596
c3404405f3f5 (svn r12177) -Codechange: use 'side' parameter in GetTileTrackStatus so there can be less checks in pathfinders for depots/stations/tunnels/bridges
smatz
parents: 8589
diff changeset
  1440
				case ROAD_TILE_DEPOT: {
c3404405f3f5 (svn r12177) -Codechange: use 'side' parameter in GetTileTrackStatus so there can be less checks in pathfinders for depots/stations/tunnels/bridges
smatz
parents: 8589
diff changeset
  1441
					DiagDirection dir = GetRoadDepotDirection(tile);
c3404405f3f5 (svn r12177) -Codechange: use 'side' parameter in GetTileTrackStatus so there can be less checks in pathfinders for depots/stations/tunnels/bridges
smatz
parents: 8589
diff changeset
  1442
8616
fd862a55c47f (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8603
diff changeset
  1443
					if (side != INVALID_DIAGDIR && side != dir) break;
8596
c3404405f3f5 (svn r12177) -Codechange: use 'side' parameter in GetTileTrackStatus so there can be less checks in pathfinders for depots/stations/tunnels/bridges
smatz
parents: 8589
diff changeset
  1444
9224
93528d9cb96d (svn r13090) -Codechange: add functions for direct conversion from DiagDirection to Track and Trackbits
smatz
parents: 9154
diff changeset
  1445
					trackdirbits = TrackBitsToTrackdirBits(DiagDirToDiagTrackBits(dir));
8616
fd862a55c47f (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8603
diff changeset
  1446
					break;
8596
c3404405f3f5 (svn r12177) -Codechange: use 'side' parameter in GetTileTrackStatus so there can be less checks in pathfinders for depots/stations/tunnels/bridges
smatz
parents: 8589
diff changeset
  1447
				}
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1448
			}
3066
26c43ab051b8 (svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents: 3061
diff changeset
  1449
			break;
26c43ab051b8 (svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents: 3061
diff changeset
  1450
26c43ab051b8 (svn r3655) Simplify a boolean expression and turn 3 if-cascades into switches
tron
parents: 3061
diff changeset
  1451
		default: break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1452
	}
8616
fd862a55c47f (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8603
diff changeset
  1453
	return CombineTrackStatus(trackdirbits, red_signals);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1454
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1455
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1456
static const StringID _road_tile_strings[] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1457
	STR_1814_ROAD,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1458
	STR_1814_ROAD,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1459
	STR_1814_ROAD,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1460
	STR_1815_ROAD_WITH_STREETLIGHTS,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1461
	STR_1814_ROAD,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1462
	STR_1816_TREE_LINED_ROAD,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1463
	STR_1814_ROAD,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1464
	STR_1814_ROAD,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1465
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1466
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
  1467
static void GetTileDesc_Road(TileIndex tile, TileDesc *td)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1468
{
9322
cf7dc39f9576 (svn r13206) -Feature(ette): Display all owners of a tile in the tile-info-window.
frosch
parents: 9298
diff changeset
  1469
	Owner rail_owner = INVALID_OWNER;
cf7dc39f9576 (svn r13206) -Feature(ette): Display all owners of a tile in the tile-info-window.
frosch
parents: 9298
diff changeset
  1470
	Owner road_owner = INVALID_OWNER;
cf7dc39f9576 (svn r13206) -Feature(ette): Display all owners of a tile in the tile-info-window.
frosch
parents: 9298
diff changeset
  1471
	Owner tram_owner = INVALID_OWNER;
cf7dc39f9576 (svn r13206) -Feature(ette): Display all owners of a tile in the tile-info-window.
frosch
parents: 9298
diff changeset
  1472
3793
7fe24e10ea63 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3792
diff changeset
  1473
	switch (GetRoadTileType(tile)) {
9322
cf7dc39f9576 (svn r13206) -Feature(ette): Display all owners of a tile in the tile-info-window.
frosch
parents: 9298
diff changeset
  1474
		case ROAD_TILE_CROSSING: {
cf7dc39f9576 (svn r13206) -Feature(ette): Display all owners of a tile in the tile-info-window.
frosch
parents: 9298
diff changeset
  1475
			td->str = STR_1818_ROAD_RAIL_LEVEL_CROSSING;
cf7dc39f9576 (svn r13206) -Feature(ette): Display all owners of a tile in the tile-info-window.
frosch
parents: 9298
diff changeset
  1476
			RoadTypes rts = GetRoadTypes(tile);
cf7dc39f9576 (svn r13206) -Feature(ette): Display all owners of a tile in the tile-info-window.
frosch
parents: 9298
diff changeset
  1477
			rail_owner = GetTileOwner(tile);
cf7dc39f9576 (svn r13206) -Feature(ette): Display all owners of a tile in the tile-info-window.
frosch
parents: 9298
diff changeset
  1478
			if (HasBit(rts, ROADTYPE_ROAD)) road_owner = GetRoadOwner(tile, ROADTYPE_ROAD);
cf7dc39f9576 (svn r13206) -Feature(ette): Display all owners of a tile in the tile-info-window.
frosch
parents: 9298
diff changeset
  1479
			if (HasBit(rts, ROADTYPE_TRAM)) tram_owner = GetRoadOwner(tile, ROADTYPE_TRAM);
cf7dc39f9576 (svn r13206) -Feature(ette): Display all owners of a tile in the tile-info-window.
frosch
parents: 9298
diff changeset
  1480
			break;
cf7dc39f9576 (svn r13206) -Feature(ette): Display all owners of a tile in the tile-info-window.
frosch
parents: 9298
diff changeset
  1481
		}
cf7dc39f9576 (svn r13206) -Feature(ette): Display all owners of a tile in the tile-info-window.
frosch
parents: 9298
diff changeset
  1482
cf7dc39f9576 (svn r13206) -Feature(ette): Display all owners of a tile in the tile-info-window.
frosch
parents: 9298
diff changeset
  1483
		case ROAD_TILE_DEPOT:
cf7dc39f9576 (svn r13206) -Feature(ette): Display all owners of a tile in the tile-info-window.
frosch
parents: 9298
diff changeset
  1484
			td->str = STR_1817_ROAD_VEHICLE_DEPOT;
cf7dc39f9576 (svn r13206) -Feature(ette): Display all owners of a tile in the tile-info-window.
frosch
parents: 9298
diff changeset
  1485
			road_owner = GetTileOwner(tile); // Tile has only one owner, roadtype does not matter
cf7dc39f9576 (svn r13206) -Feature(ette): Display all owners of a tile in the tile-info-window.
frosch
parents: 9298
diff changeset
  1486
			break;
cf7dc39f9576 (svn r13206) -Feature(ette): Display all owners of a tile in the tile-info-window.
frosch
parents: 9298
diff changeset
  1487
cf7dc39f9576 (svn r13206) -Feature(ette): Display all owners of a tile in the tile-info-window.
frosch
parents: 9298
diff changeset
  1488
		default: {
cf7dc39f9576 (svn r13206) -Feature(ette): Display all owners of a tile in the tile-info-window.
frosch
parents: 9298
diff changeset
  1489
			RoadTypes rts = GetRoadTypes(tile);
cf7dc39f9576 (svn r13206) -Feature(ette): Display all owners of a tile in the tile-info-window.
frosch
parents: 9298
diff changeset
  1490
			td->str = (HasBit(rts, ROADTYPE_ROAD) ? _road_tile_strings[GetRoadside(tile)] : STR_TRAMWAY);
cf7dc39f9576 (svn r13206) -Feature(ette): Display all owners of a tile in the tile-info-window.
frosch
parents: 9298
diff changeset
  1491
			if (HasBit(rts, ROADTYPE_ROAD)) road_owner = GetRoadOwner(tile, ROADTYPE_ROAD);
cf7dc39f9576 (svn r13206) -Feature(ette): Display all owners of a tile in the tile-info-window.
frosch
parents: 9298
diff changeset
  1492
			if (HasBit(rts, ROADTYPE_TRAM)) tram_owner = GetRoadOwner(tile, ROADTYPE_TRAM);
cf7dc39f9576 (svn r13206) -Feature(ette): Display all owners of a tile in the tile-info-window.
frosch
parents: 9298
diff changeset
  1493
			break;
cf7dc39f9576 (svn r13206) -Feature(ette): Display all owners of a tile in the tile-info-window.
frosch
parents: 9298
diff changeset
  1494
		}
cf7dc39f9576 (svn r13206) -Feature(ette): Display all owners of a tile in the tile-info-window.
frosch
parents: 9298
diff changeset
  1495
	}
cf7dc39f9576 (svn r13206) -Feature(ette): Display all owners of a tile in the tile-info-window.
frosch
parents: 9298
diff changeset
  1496
cf7dc39f9576 (svn r13206) -Feature(ette): Display all owners of a tile in the tile-info-window.
frosch
parents: 9298
diff changeset
  1497
	/* Now we have to discover, if the tile has only one owner or many:
cf7dc39f9576 (svn r13206) -Feature(ette): Display all owners of a tile in the tile-info-window.
frosch
parents: 9298
diff changeset
  1498
	 *   - Find a first_owner of the tile. (Currently road or tram must be present, but this will break when the third type becomes available)
cf7dc39f9576 (svn r13206) -Feature(ette): Display all owners of a tile in the tile-info-window.
frosch
parents: 9298
diff changeset
  1499
	 *   - Compare the found owner with the other owners, and test if they differ.
cf7dc39f9576 (svn r13206) -Feature(ette): Display all owners of a tile in the tile-info-window.
frosch
parents: 9298
diff changeset
  1500
	 * Note: If road exists it will be the first_owner.
cf7dc39f9576 (svn r13206) -Feature(ette): Display all owners of a tile in the tile-info-window.
frosch
parents: 9298
diff changeset
  1501
	 */
cf7dc39f9576 (svn r13206) -Feature(ette): Display all owners of a tile in the tile-info-window.
frosch
parents: 9298
diff changeset
  1502
	Owner first_owner = (road_owner == INVALID_OWNER ? tram_owner : road_owner);
cf7dc39f9576 (svn r13206) -Feature(ette): Display all owners of a tile in the tile-info-window.
frosch
parents: 9298
diff changeset
  1503
	bool mixed_owners = (tram_owner != INVALID_OWNER && tram_owner != first_owner) || (rail_owner != INVALID_OWNER && rail_owner != first_owner);
cf7dc39f9576 (svn r13206) -Feature(ette): Display all owners of a tile in the tile-info-window.
frosch
parents: 9298
diff changeset
  1504
cf7dc39f9576 (svn r13206) -Feature(ette): Display all owners of a tile in the tile-info-window.
frosch
parents: 9298
diff changeset
  1505
	if (mixed_owners) {
cf7dc39f9576 (svn r13206) -Feature(ette): Display all owners of a tile in the tile-info-window.
frosch
parents: 9298
diff changeset
  1506
		/* Multiple owners */
cf7dc39f9576 (svn r13206) -Feature(ette): Display all owners of a tile in the tile-info-window.
frosch
parents: 9298
diff changeset
  1507
		td->owner_type[0] = (rail_owner == INVALID_OWNER ? STR_NULL : STR_RAIL_OWNER);
cf7dc39f9576 (svn r13206) -Feature(ette): Display all owners of a tile in the tile-info-window.
frosch
parents: 9298
diff changeset
  1508
		td->owner[0] = rail_owner;
cf7dc39f9576 (svn r13206) -Feature(ette): Display all owners of a tile in the tile-info-window.
frosch
parents: 9298
diff changeset
  1509
		td->owner_type[1] = (road_owner == INVALID_OWNER ? STR_NULL : STR_ROAD_OWNER);
cf7dc39f9576 (svn r13206) -Feature(ette): Display all owners of a tile in the tile-info-window.
frosch
parents: 9298
diff changeset
  1510
		td->owner[1] = road_owner;
cf7dc39f9576 (svn r13206) -Feature(ette): Display all owners of a tile in the tile-info-window.
frosch
parents: 9298
diff changeset
  1511
		td->owner_type[2] = (tram_owner == INVALID_OWNER ? STR_NULL : STR_TRAM_OWNER);
cf7dc39f9576 (svn r13206) -Feature(ette): Display all owners of a tile in the tile-info-window.
frosch
parents: 9298
diff changeset
  1512
		td->owner[2] = tram_owner;
cf7dc39f9576 (svn r13206) -Feature(ette): Display all owners of a tile in the tile-info-window.
frosch
parents: 9298
diff changeset
  1513
	} else {
cf7dc39f9576 (svn r13206) -Feature(ette): Display all owners of a tile in the tile-info-window.
frosch
parents: 9298
diff changeset
  1514
		/* One to rule them all */
cf7dc39f9576 (svn r13206) -Feature(ette): Display all owners of a tile in the tile-info-window.
frosch
parents: 9298
diff changeset
  1515
		td->owner[0] = first_owner;
3069
9a1fd047b595 (svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents: 3068
diff changeset
  1516
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1517
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1518
6723
89182b2f015a (svn r9955) -Codechange: Make _roadveh_enter_depot_unk0 slightly less mysterious.
maedhros
parents: 6719
diff changeset
  1519
/**
89182b2f015a (svn r9955) -Codechange: Make _roadveh_enter_depot_unk0 slightly less mysterious.
maedhros
parents: 6719
diff changeset
  1520
 * Given the direction the road depot is pointing, this is the direction the
89182b2f015a (svn r9955) -Codechange: Make _roadveh_enter_depot_unk0 slightly less mysterious.
maedhros
parents: 6719
diff changeset
  1521
 * vehicle should be travelling in in order to enter the depot.
89182b2f015a (svn r9955) -Codechange: Make _roadveh_enter_depot_unk0 slightly less mysterious.
maedhros
parents: 6719
diff changeset
  1522
 */
89182b2f015a (svn r9955) -Codechange: Make _roadveh_enter_depot_unk0 slightly less mysterious.
maedhros
parents: 6719
diff changeset
  1523
static const byte _roadveh_enter_depot_dir[4] = {
89182b2f015a (svn r9955) -Codechange: Make _roadveh_enter_depot_unk0 slightly less mysterious.
maedhros
parents: 6719
diff changeset
  1524
	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
  1525
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1526
8119
52b48108425a (svn r11680) -Codechange: refactor more out of openttd.h and functions.h.
rubidium
parents: 8116
diff changeset
  1527
static VehicleEnterTileStatus 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
  1528
{
3793
7fe24e10ea63 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3792
diff changeset
  1529
	switch (GetRoadTileType(tile)) {
7fe24e10ea63 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3792
diff changeset
  1530
		case ROAD_TILE_CROSSING:
8342
bf710180e7ce (svn r11908) -Fix: update crossing when merging a company, when building a crossing and after loading older savegame
smatz
parents: 8308
diff changeset
  1531
			if (v->type == VEH_TRAIN) {
bf710180e7ce (svn r11908) -Fix: update crossing when merging a company, when building a crossing and after loading older savegame
smatz
parents: 8308
diff changeset
  1532
				/* it should be barred */
bf710180e7ce (svn r11908) -Fix: update crossing when merging a company, when building a crossing and after loading older savegame
smatz
parents: 8308
diff changeset
  1533
				assert(IsCrossingBarred(tile));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1534
			}
3060
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1535
			break;
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1536
3793
7fe24e10ea63 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3792
diff changeset
  1537
		case ROAD_TILE_DEPOT:
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6256
diff changeset
  1538
			if (v->type == VEH_ROAD &&
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4048
diff changeset
  1539
					v->u.road.frame == 11 &&
6723
89182b2f015a (svn r9955) -Codechange: Make _roadveh_enter_depot_unk0 slightly less mysterious.
maedhros
parents: 6719
diff changeset
  1540
					_roadveh_enter_depot_dir[GetRoadDepotDirection(tile)] == v->u.road.state) {
6857
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6814
diff changeset
  1541
				v->u.road.state = RVSB_IN_DEPOT;
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6814
diff changeset
  1542
				v->vehstatus |= VS_HIDDEN;
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6814
diff changeset
  1543
				v->direction = ReverseDir(v->direction);
7492
35acee076719 (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: 7442
diff changeset
  1544
				if (v->Next() == NULL) VehicleEnterDepot(v);
6857
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6814
diff changeset
  1545
				v->tile = tile;
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6814
diff changeset
  1546
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6814
diff changeset
  1547
				InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile);
5991
ec2eebfe86de (svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents: 5942
diff changeset
  1548
				return VETSB_ENTERED_WORMHOLE;
3060
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1549
			}
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1550
			break;
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1551
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1552
		default: break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1553
	}
5991
ec2eebfe86de (svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents: 5942
diff changeset
  1554
	return VETSB_CONTINUE;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1555
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1556
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1557
2436
7d5df545bd5d (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents: 2425
diff changeset
  1558
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
  1559
{
8563
13b1a41e46f1 (svn r12141) -Codechange: Introduce IsNormalRoad[Tile](), IsRoadDepot[Tile]() and HasTileRoadType(); and use them.
frosch
parents: 8560
diff changeset
  1560
	if (IsRoadDepot(tile)) {
6717
804853737caa (svn r9949) -Fix: (road) depots got deowned on bankrupts.
rubidium
parents: 6716
diff changeset
  1561
		if (GetTileOwner(tile) == old_player) {
804853737caa (svn r9949) -Fix: (road) depots got deowned on bankrupts.
rubidium
parents: 6716
diff changeset
  1562
			if (new_player == PLAYER_SPECTATOR) {
8519
fe61d7aa3053 (svn r12094) -Codechange: use DC_BANKRUPT command flag when removing player property to allow further fixes
smatz
parents: 8428
diff changeset
  1563
				DoCommand(tile, 0, 0, DC_EXEC | DC_BANKRUPT, CMD_LANDSCAPE_CLEAR);
6717
804853737caa (svn r9949) -Fix: (road) depots got deowned on bankrupts.
rubidium
parents: 6716
diff changeset
  1564
			} else {
804853737caa (svn r9949) -Fix: (road) depots got deowned on bankrupts.
rubidium
parents: 6716
diff changeset
  1565
				SetTileOwner(tile, new_player);
804853737caa (svn r9949) -Fix: (road) depots got deowned on bankrupts.
rubidium
parents: 6716
diff changeset
  1566
			}
6689
84811200d69c (svn r9921) -Fix (r9892): ownership wasn't properly propagated on owner changes.
rubidium
parents: 6683
diff changeset
  1567
		}
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
  1568
		return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1569
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1570
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
  1571
	for (RoadType rt = ROADTYPE_ROAD; rt < ROADTYPE_END; rt++) {
9341
bd60c3b2d1e0 (svn r13233) -Fix: Replace some (incorrect) evaluations of TileOwner by RoadOwner.
frosch
parents: 9322
diff changeset
  1572
		/* Update all roadtypes, no matter if they are present */
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
  1573
		if (GetRoadOwner(tile, rt) == old_player) {
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
  1574
			SetRoadOwner(tile, rt, new_player == PLAYER_SPECTATOR ? OWNER_NONE : new_player);
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
  1575
		}
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
  1576
	}
3060
7cfc591c4ba6 (svn r3649) Turn several if-cascades into switch()es
tron
parents: 3055
diff changeset
  1577
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6626
diff changeset
  1578
	if (IsLevelCrossing(tile)) {
6689
84811200d69c (svn r9921) -Fix (r9892): ownership wasn't properly propagated on owner changes.
rubidium
parents: 6683
diff changeset
  1579
		if (GetTileOwner(tile) == old_player) {
84811200d69c (svn r9921) -Fix (r9892): ownership wasn't properly propagated on owner changes.
rubidium
parents: 6683
diff changeset
  1580
			if (new_player == PLAYER_SPECTATOR) {
8598
ddd1f342b0da (svn r12179) -Codechange: use GetCrossingRailTrack() and GetCrossingRailAxis() to improve code readability
smatz
parents: 8596
diff changeset
  1581
				DoCommand(tile, 0, GetCrossingRailTrack(tile), DC_EXEC | DC_BANKRUPT, CMD_REMOVE_SINGLE_RAIL);
6689
84811200d69c (svn r9921) -Fix (r9892): ownership wasn't properly propagated on owner changes.
rubidium
parents: 6683
diff changeset
  1582
			} else {
84811200d69c (svn r9921) -Fix (r9892): ownership wasn't properly propagated on owner changes.
rubidium
parents: 6683
diff changeset
  1583
				SetTileOwner(tile, new_player);
84811200d69c (svn r9921) -Fix (r9892): ownership wasn't properly propagated on owner changes.
rubidium
parents: 6683
diff changeset
  1584
			}
84811200d69c (svn r9921) -Fix (r9892): ownership wasn't properly propagated on owner changes.
rubidium
parents: 6683
diff changeset
  1585
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1586
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1587
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1588
7494
ab05bad37410 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7492
diff changeset
  1589
static CommandCost TerraformTile_Road(TileIndex tile, uint32 flags, uint z_new, Slope tileh_new)
ab05bad37410 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7492
diff changeset
  1590
{
9413
7042a8ec3fa8 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 9358
diff changeset
  1591
	if (_settings_game.construction.build_on_slopes && AutoslopeEnabled()) {
7582
80c8517b08d1 (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: 7539
diff changeset
  1592
		switch (GetRoadTileType(tile)) {
80c8517b08d1 (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: 7539
diff changeset
  1593
			case ROAD_TILE_CROSSING:
8230
64f28fe2d5c8 (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8224
diff changeset
  1594
				if (!IsSteepSlope(tileh_new) && (GetTileMaxZ(tile) == z_new + GetSlopeMaxZ(tileh_new)) && HasBit(VALID_LEVEL_CROSSING_SLOPES, tileh_new)) return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform);
7582
80c8517b08d1 (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: 7539
diff changeset
  1595
				break;
80c8517b08d1 (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: 7539
diff changeset
  1596
80c8517b08d1 (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: 7539
diff changeset
  1597
			case ROAD_TILE_DEPOT:
8230
64f28fe2d5c8 (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8224
diff changeset
  1598
				if (AutoslopeCheckForEntranceEdge(tile, z_new, tileh_new, GetRoadDepotDirection(tile))) return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform);
7582
80c8517b08d1 (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: 7539
diff changeset
  1599
				break;
80c8517b08d1 (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: 7539
diff changeset
  1600
80c8517b08d1 (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: 7539
diff changeset
  1601
			case ROAD_TILE_NORMAL: {
80c8517b08d1 (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: 7539
diff changeset
  1602
				RoadBits bits = GetAllRoadBits(tile);
80c8517b08d1 (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: 7539
diff changeset
  1603
				RoadBits bits_copy = bits;
80c8517b08d1 (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: 7539
diff changeset
  1604
				/* Check if the slope-road_bits combination is valid at all, i.e. it is save to call GetRoadFoundation(). */
8744
099f75f4b51f (svn r12440) -Fix [FS#1694]: Make the road building and road removing conditions more union
skidd13
parents: 8734
diff changeset
  1605
				if (!CmdFailed(CheckRoadSlope(tileh_new, &bits_copy, ROAD_NONE, ROAD_NONE))) {
7582
80c8517b08d1 (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: 7539
diff changeset
  1606
					/* CheckRoadSlope() sometimes changes the road_bits, if it does not agree with them. */
80c8517b08d1 (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: 7539
diff changeset
  1607
					if (bits == bits_copy) {
80c8517b08d1 (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: 7539
diff changeset
  1608
						uint z_old;
80c8517b08d1 (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: 7539
diff changeset
  1609
						Slope tileh_old = GetTileSlope(tile, &z_old);
80c8517b08d1 (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: 7539
diff changeset
  1610
80c8517b08d1 (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: 7539
diff changeset
  1611
						/* Get the slope on top of the foundation */
80c8517b08d1 (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: 7539
diff changeset
  1612
						z_old += ApplyFoundationToSlope(GetRoadFoundation(tileh_old, bits), &tileh_old);
80c8517b08d1 (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: 7539
diff changeset
  1613
						z_new += ApplyFoundationToSlope(GetRoadFoundation(tileh_new, bits), &tileh_new);
80c8517b08d1 (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: 7539
diff changeset
  1614
80c8517b08d1 (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: 7539
diff changeset
  1615
						/* The surface slope must not be changed */
8230
64f28fe2d5c8 (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8224
diff changeset
  1616
						if ((z_old == z_new) && (tileh_old == tileh_new)) return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform);
7582
80c8517b08d1 (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: 7539
diff changeset
  1617
					}
80c8517b08d1 (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: 7539
diff changeset
  1618
				}
80c8517b08d1 (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: 7539
diff changeset
  1619
				break;
80c8517b08d1 (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: 7539
diff changeset
  1620
			}
80c8517b08d1 (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: 7539
diff changeset
  1621
80c8517b08d1 (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: 7539
diff changeset
  1622
			default: NOT_REACHED();
80c8517b08d1 (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: 7539
diff changeset
  1623
		}
80c8517b08d1 (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: 7539
diff changeset
  1624
	}
80c8517b08d1 (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: 7539
diff changeset
  1625
7494
ab05bad37410 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7492
diff changeset
  1626
	return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
ab05bad37410 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7492
diff changeset
  1627
}
ab05bad37410 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7492
diff changeset
  1628
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1629
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
  1630
extern const TileTypeProcs _tile_type_road_procs = {
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4246
diff changeset
  1631
	DrawTile_Road,           /* draw_tile_proc */
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4246
diff changeset
  1632
	GetSlopeZ_Road,          /* get_slope_z_proc */
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4246
diff changeset
  1633
	ClearTile_Road,          /* clear_tile_proc */
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4246
diff changeset
  1634
	GetAcceptedCargo_Road,   /* get_accepted_cargo_proc */
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4246
diff changeset
  1635
	GetTileDesc_Road,        /* get_tile_desc_proc */
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4246
diff changeset
  1636
	GetTileTrackStatus_Road, /* get_tile_track_status_proc */
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4246
diff changeset
  1637
	ClickTile_Road,          /* click_tile_proc */
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4246
diff changeset
  1638
	AnimateTile_Road,        /* animate_tile_proc */
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4246
diff changeset
  1639
	TileLoop_Road,           /* tile_loop_clear */
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4246
diff changeset
  1640
	ChangeTileOwner_Road,    /* change_tile_owner_clear */
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4246
diff changeset
  1641
	NULL,                    /* get_produced_cargo_proc */
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4246
diff changeset
  1642
	VehicleEnter_Road,       /* vehicle_enter_tile_proc */
7335
141c6b86ec1f (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: 7333
diff changeset
  1643
	GetFoundation_Road,      /* get_foundation_proc */
7494
ab05bad37410 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7492
diff changeset
  1644
	TerraformTile_Road,      /* terraform_tile_proc */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1645
};