src/rail_cmd.cpp
author rubidium
Thu, 18 Dec 2008 12:23:08 +0000
changeset 10436 8d3a9fbe8f19
parent 10423 293726ac3faa
permissions -rw-r--r--
(svn r14689) -Change: make configure die on commonly made user mistakes, like not having SDL development files or zlib headers installed; you can still compile a dedicated server or a binary without zlib, but you have to explicitly force it.
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: 9070
diff changeset
     3
/** @file rail_cmd.cpp Handling of rail 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: 1818
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: 3185
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"
1922
bda6f85eefaa (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents: 1903
diff changeset
    10
#include "debug.h"
8119
52b48108425a (svn r11680) -Codechange: refactor more out of openttd.h and functions.h.
rubidium
parents: 8116
diff changeset
    11
#include "tile_cmd.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: 3099
diff changeset
    12
#include "rail_map.h"
3144
33e42feae531 (svn r3763) Adapt to the new 'map accessors go in foo_map.h'-scheme
tron
parents: 3142
diff changeset
    13
#include "road_map.h"
6343
76d17f784c13 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6259
diff changeset
    14
#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
    15
#include "town_map.h"
3154
6ab0cb6b7ab3 (svn r3777) Add some functions to handle tunnels
tron
parents: 3153
diff changeset
    16
#include "tunnel_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: 8108
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 "pathfind.h"
8786
1823ff88a054 (svn r12490) -Codechange: rename engine.h to engine_func.h and remove unneeded inclusions of engine.h and/or replace them with engine_type.h.
rubidium
parents: 8785
diff changeset
    20
#include "engine_func.h"
9070
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 9038
diff changeset
    21
#include "engine_base.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    22
#include "town.h"
405
415546028e8d (svn r602) -newgrf: Move DrawTileSeqStruct & co and struct SpriteGroup to sprite.h (pasky)
darkvater
parents: 403
diff changeset
    23
#include "sprite.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: 8961
diff changeset
    24
#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: 8961
diff changeset
    25
#include "depot_func.h"
1542
62a03537ad0b (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1536
diff changeset
    26
#include "waypoint.h"
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
    27
#include "rail.h"
3638
3e655c6e0914 (svn r4546) - NewGRF: add support for Action 0x05, type 0x04: replacement signal graphics. Thanks to Purno for supplying data to test
peter1138
parents: 3636
diff changeset
    28
#include "newgrf.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
    29
#include "yapf/yapf.h"
7539
5f41050498bd (svn r11059) -Fix [FS#1182]: inconsistency between Rail<->ElRail conversions of different kinds of rail containing tiles (normal rail, stations, depots, etc). Patch by SmatZ.
rubidium
parents: 7494
diff changeset
    30
#include "newgrf_engine.h"
3757
0c6a690e6b41 (svn r4748) - Newstations: use custom sprite layout callback for waypoints as well as stations. Supports merging of adjacent waypoints if the GRF supports it (newstatsw.grf)
peter1138
parents: 3751
diff changeset
    31
#include "newgrf_callbacks.h"
0c6a690e6b41 (svn r4748) - Newstations: use custom sprite layout callback for waypoints as well as stations. Supports merging of adjacent waypoints if the GRF supports it (newstatsw.grf)
peter1138
parents: 3751
diff changeset
    32
#include "newgrf_station.h"
10355
8a930759b457 (svn r14606) -Codechange: Unify usage of PALETTE_MODIFIER_TRANSPARENT and PALETTE_MODIFIER_COLOR in spritelayout drawing.
frosch
parents: 10330
diff changeset
    33
#include "newgrf_commons.h"
4556
cb82978e84ed (svn r6395) -Fix: when converting a depot from/to elrail, update the power of trains that are in it
glx
parents: 4549
diff changeset
    34
#include "train.h"
8211
29a8510dfd62 (svn r11774) -Change: do not include variables.h in a header when it is not needed.
rubidium
parents: 8197
diff changeset
    35
#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
    36
#include "autoslope.h"
7849
0a1c0af2c96c (svn r11399) -Feature(ette): transparency settings can now be saved and thus remembered.
belugas
parents: 7833
diff changeset
    37
#include "transparency.h"
7948
e408508f5727 (svn r11504) -Fix [FS#1467]: removing docks/ship depots could result in non-canal water where canals should have been build.
rubidium
parents: 7932
diff changeset
    38
#include "water.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
    39
#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: 8096
diff changeset
    40
#include "window_func.h"
8144
65cec0877b78 (svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium
parents: 8139
diff changeset
    41
#include "vehicle_func.h"
8157
1505def01945 (svn r11719) -Codechange: split sound.h in a header with types and one with functions.
rubidium
parents: 8153
diff changeset
    42
#include "sound_func.h"
8238
d47a86c79603 (svn r11802) -Fix [FS#716]: do not crash trains when leaving depot to a very long track
smatz
parents: 8236
diff changeset
    43
#include "signal_func.h"
8398
1e181e2e4e15 (svn r11968) -Codechange: remove redundant FindLengthOfTunnel(), use GetTunnelBridgeLength() and/or GetOtherTunnelEnd() instead
smatz
parents: 8344
diff changeset
    44
#include "tunnelbridge.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: 8961
diff changeset
    45
#include "station_map.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: 8961
diff changeset
    46
#include "water_map.h"
9006
7666e7b47088 (svn r12801) -Codechange: remove the dependency of function.h in town_map.h
rubidium
parents: 8962
diff changeset
    47
#include "functions.h"
9154
2c042b567165 (svn r13016) -Codechange: unify the detection if rail catenary should be drawn
smatz
parents: 9111
diff changeset
    48
#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
    49
#include "oldpool_func.h"
9815
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9795
diff changeset
    50
#include "pbs.h"
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9795
diff changeset
    51
#include "core/smallvec_type.hpp"
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
    52
8264
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8238
diff changeset
    53
#include "table/sprites.h"
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8238
diff changeset
    54
#include "table/strings.h"
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8238
diff changeset
    55
#include "table/railtypes.h"
8567
270fa0866286 (svn r12145) -Codechange: includes should be at the top of the source file
belugas
parents: 8563
diff changeset
    56
#include "table/track_land.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    57
10001
df9284007ed5 (svn r14158) -Codechange: Initialization of rail type data from static source, so data can be changed.
peter1138
parents: 9972
diff changeset
    58
RailtypeInfo _railtypes[RAILTYPE_END];
df9284007ed5 (svn r14158) -Codechange: Initialization of rail type data from static source, so data can be changed.
peter1138
parents: 9972
diff changeset
    59
df9284007ed5 (svn r14158) -Codechange: Initialization of rail type data from static source, so data can be changed.
peter1138
parents: 9972
diff changeset
    60
assert_compile(sizeof(_original_railtypes) <= sizeof(_railtypes));
df9284007ed5 (svn r14158) -Codechange: Initialization of rail type data from static source, so data can be changed.
peter1138
parents: 9972
diff changeset
    61
df9284007ed5 (svn r14158) -Codechange: Initialization of rail type data from static source, so data can be changed.
peter1138
parents: 9972
diff changeset
    62
/**
df9284007ed5 (svn r14158) -Codechange: Initialization of rail type data from static source, so data can be changed.
peter1138
parents: 9972
diff changeset
    63
 * Initialize rail type information.
df9284007ed5 (svn r14158) -Codechange: Initialization of rail type data from static source, so data can be changed.
peter1138
parents: 9972
diff changeset
    64
 */
df9284007ed5 (svn r14158) -Codechange: Initialization of rail type data from static source, so data can be changed.
peter1138
parents: 9972
diff changeset
    65
void ResetRailTypes()
df9284007ed5 (svn r14158) -Codechange: Initialization of rail type data from static source, so data can be changed.
peter1138
parents: 9972
diff changeset
    66
{
df9284007ed5 (svn r14158) -Codechange: Initialization of rail type data from static source, so data can be changed.
peter1138
parents: 9972
diff changeset
    67
	memset(_railtypes, 0, sizeof(_railtypes));
df9284007ed5 (svn r14158) -Codechange: Initialization of rail type data from static source, so data can be changed.
peter1138
parents: 9972
diff changeset
    68
	memcpy(_railtypes, _original_railtypes, sizeof(_original_railtypes));
df9284007ed5 (svn r14158) -Codechange: Initialization of rail type data from static source, so data can be changed.
peter1138
parents: 9972
diff changeset
    69
}
df9284007ed5 (svn r14158) -Codechange: Initialization of rail type data from static source, so data can be changed.
peter1138
parents: 9972
diff changeset
    70
2261
d3554e5d3e86 (svn r2781) Fix some of the issues with variables in .h files.
ludde
parents: 2254
diff changeset
    71
const byte _track_sloped_sprites[14] = {
d3554e5d3e86 (svn r2781) Fix some of the issues with variables in .h files.
ludde
parents: 2254
diff changeset
    72
	14, 15, 22, 13,
d3554e5d3e86 (svn r2781) Fix some of the issues with variables in .h files.
ludde
parents: 2254
diff changeset
    73
	 0, 21, 17, 12,
d3554e5d3e86 (svn r2781) Fix some of the issues with variables in .h files.
ludde
parents: 2254
diff changeset
    74
	23,  0, 18, 20,
d3554e5d3e86 (svn r2781) Fix some of the issues with variables in .h files.
ludde
parents: 2254
diff changeset
    75
	19, 16
d3554e5d3e86 (svn r2781) Fix some of the issues with variables in .h files.
ludde
parents: 2254
diff changeset
    76
};
d3554e5d3e86 (svn r2781) Fix some of the issues with variables in .h files.
ludde
parents: 2254
diff changeset
    77
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    78
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    79
/*         4
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    80
 *     ---------
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    81
 *    |\       /|
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    82
 *    | \    1/ |
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    83
 *    |  \   /  |
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    84
 *    |   \ /   |
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    85
 *  16|    \    |32
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
    86
 *    |   / \2  |
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    87
 *    |  /   \  |
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    88
 *    | /     \ |
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    89
 *    |/       \|
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    90
 *     ---------
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    91
 *         8
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    92
 */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    93
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    94
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    95
22
fe6f35cc987b (svn r23) -Some omments on the code (blathijs)
darkvater
parents: 13
diff changeset
    96
/* MAP2 byte:    abcd???? => Signal On? Same coding as map3lo
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
    97
 * MAP3LO byte:  abcd???? => Signal Exists?
4434
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4388
diff changeset
    98
 *               a and b are for diagonals, upper and left,
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4388
diff changeset
    99
 *               one for each direction. (ie a == NE->SW, b ==
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4388
diff changeset
   100
 *               SW->NE, or v.v., I don't know. b and c are
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4388
diff changeset
   101
 *               similar for lower and right.
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   102
 * MAP2 byte:    ????abcd => Type of ground.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   103
 * MAP3LO byte:  ????abcd => Type of rail.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   104
 * MAP5:         00abcdef => rail
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   105
 *               01abcdef => rail w/ signals
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   106
 *               10uuuuuu => unused
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   107
 *               11uuuudd => rail depot
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   108
 */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   109
7448
dbcc29a92db8 (svn r10922) -Codechange: Allow building and removing tracks and signals when there is a
maedhros
parents: 7389
diff changeset
   110
9775
22e256c3bf46 (svn r13912) -Codechange: remove some casts by returning the proper type instead of void*.
rubidium
parents: 9652
diff changeset
   111
Vehicle *EnsureNoTrainOnTrackProc(Vehicle *v, void *data)
7448
dbcc29a92db8 (svn r10922) -Codechange: Allow building and removing tracks and signals when there is a
maedhros
parents: 7389
diff changeset
   112
{
8081
4fddceb00aa6 (svn r11642) -Codechange: VehicleFromPos does check for v->tile == tile, so remove useless checks
smatz
parents: 8077
diff changeset
   113
	TrackBits rail_bits = *(TrackBits *)data;
4fddceb00aa6 (svn r11642) -Codechange: VehicleFromPos does check for v->tile == tile, so remove useless checks
smatz
parents: 8077
diff changeset
   114
4fddceb00aa6 (svn r11642) -Codechange: VehicleFromPos does check for v->tile == tile, so remove useless checks
smatz
parents: 8077
diff changeset
   115
	if (v->type != VEH_TRAIN) return NULL;
4fddceb00aa6 (svn r11642) -Codechange: VehicleFromPos does check for v->tile == tile, so remove useless checks
smatz
parents: 8077
diff changeset
   116
4fddceb00aa6 (svn r11642) -Codechange: VehicleFromPos does check for v->tile == tile, so remove useless checks
smatz
parents: 8077
diff changeset
   117
	if ((v->u.rail.track != rail_bits) && !TracksOverlap(v->u.rail.track | rail_bits)) return NULL;
7448
dbcc29a92db8 (svn r10922) -Codechange: Allow building and removing tracks and signals when there is a
maedhros
parents: 7389
diff changeset
   118
dbcc29a92db8 (svn r10922) -Codechange: Allow building and removing tracks and signals when there is a
maedhros
parents: 7389
diff changeset
   119
	_error_message = VehicleInTheWayErrMsg(v);
dbcc29a92db8 (svn r10922) -Codechange: Allow building and removing tracks and signals when there is a
maedhros
parents: 7389
diff changeset
   120
	return v;
dbcc29a92db8 (svn r10922) -Codechange: Allow building and removing tracks and signals when there is a
maedhros
parents: 7389
diff changeset
   121
}
dbcc29a92db8 (svn r10922) -Codechange: Allow building and removing tracks and signals when there is a
maedhros
parents: 7389
diff changeset
   122
dbcc29a92db8 (svn r10922) -Codechange: Allow building and removing tracks and signals when there is a
maedhros
parents: 7389
diff changeset
   123
/**
dbcc29a92db8 (svn r10922) -Codechange: Allow building and removing tracks and signals when there is a
maedhros
parents: 7389
diff changeset
   124
 * Tests if a vehicle interacts with the specified track.
dbcc29a92db8 (svn r10922) -Codechange: Allow building and removing tracks and signals when there is a
maedhros
parents: 7389
diff changeset
   125
 * All track bits interact except parallel TRACK_BIT_HORZ or TRACK_BIT_VERT.
dbcc29a92db8 (svn r10922) -Codechange: Allow building and removing tracks and signals when there is a
maedhros
parents: 7389
diff changeset
   126
 *
dbcc29a92db8 (svn r10922) -Codechange: Allow building and removing tracks and signals when there is a
maedhros
parents: 7389
diff changeset
   127
 * @param tile The tile.
dbcc29a92db8 (svn r10922) -Codechange: Allow building and removing tracks and signals when there is a
maedhros
parents: 7389
diff changeset
   128
 * @param track The track.
dbcc29a92db8 (svn r10922) -Codechange: Allow building and removing tracks and signals when there is a
maedhros
parents: 7389
diff changeset
   129
 */
dbcc29a92db8 (svn r10922) -Codechange: Allow building and removing tracks and signals when there is a
maedhros
parents: 7389
diff changeset
   130
static bool EnsureNoTrainOnTrack(TileIndex tile, Track track)
dbcc29a92db8 (svn r10922) -Codechange: Allow building and removing tracks and signals when there is a
maedhros
parents: 7389
diff changeset
   131
{
8081
4fddceb00aa6 (svn r11642) -Codechange: VehicleFromPos does check for v->tile == tile, so remove useless checks
smatz
parents: 8077
diff changeset
   132
	TrackBits rail_bits = TrackToTrackBits(track);
4fddceb00aa6 (svn r11642) -Codechange: VehicleFromPos does check for v->tile == tile, so remove useless checks
smatz
parents: 8077
diff changeset
   133
10083
eee4e42aa15b (svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium
parents: 10017
diff changeset
   134
	return !HasVehicleOnPos(tile, &rail_bits, &EnsureNoTrainOnTrackProc);
7448
dbcc29a92db8 (svn r10922) -Codechange: Allow building and removing tracks and signals when there is a
maedhros
parents: 7389
diff changeset
   135
}
dbcc29a92db8 (svn r10922) -Codechange: Allow building and removing tracks and signals when there is a
maedhros
parents: 7389
diff changeset
   136
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   137
static bool CheckTrackCombination(TileIndex tile, TrackBits to_build, uint flags)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   138
{
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6406
diff changeset
   139
	TrackBits current; // The current track layout
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6406
diff changeset
   140
	TrackBits future;  // The track layout we want to build
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   141
	_error_message = STR_1001_IMPOSSIBLE_TRACK_COMBINATION;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   142
4182
48dba107ff43 (svn r5624) Use {IsPlainRailTile,IsRailDepot,IsRailWaypoint,HasSignals}() instead of GetRailTile{T,Subt}ype() - this is more concise and a bit more flexible if/when the rail tile encoding changes
tron
parents: 4180
diff changeset
   143
	if (!IsPlainRailTile(tile)) return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   144
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   145
	/* So, we have a tile with tracks on it (and possibly signals). Let's see
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   146
	 * what tracks first */
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   147
	current = GetTrackBits(tile);
1946
f197fb0d840f (svn r2452) Fix defect in r2448 which caused building tracks unexpectedly fail or succeed
tron
parents: 1942
diff changeset
   148
	future = current | to_build;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   149
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   150
	/* Are we really building something new? */
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   151
	if (current == future) {
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   152
		/* Nothing new is being built */
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   153
		_error_message = STR_1007_ALREADY_BUILT;
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   154
		return false;
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   155
	}
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   156
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   157
	/* Let's see if we may build this */
4182
48dba107ff43 (svn r5624) Use {IsPlainRailTile,IsRailDepot,IsRailWaypoint,HasSignals}() instead of GetRailTile{T,Subt}ype() - this is more concise and a bit more flexible if/when the rail tile encoding changes
tron
parents: 4180
diff changeset
   158
	if (flags & DC_NO_RAIL_OVERLAP || HasSignals(tile)) {
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10172
diff changeset
   159
		/* If we are not allowed to overlap (flag is on for ai companies or we have
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   160
		 * signals on the tile), check that */
3258
1c079364726d (svn r3946) Add short hand names for common track combinations
tron
parents: 3254
diff changeset
   161
		return future == TRACK_BIT_HORZ || future == TRACK_BIT_VERT;
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   162
	} else {
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   163
		/* Normally, we may overlap and any combination is valid */
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   164
		return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   165
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   166
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   167
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   168
7703
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7642
diff changeset
   169
/** Valid TrackBits on a specific (non-steep)-slope without foundation */
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7642
diff changeset
   170
static const TrackBits _valid_tracks_without_foundation[15] = {
3258
1c079364726d (svn r3946) Add short hand names for common track combinations
tron
parents: 3254
diff changeset
   171
	TRACK_BIT_ALL,
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   172
	TRACK_BIT_RIGHT,
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   173
	TRACK_BIT_UPPER,
3102
f9ca4379db9d (svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron
parents: 3101
diff changeset
   174
	TRACK_BIT_X,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   175
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   176
	TRACK_BIT_LEFT,
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   177
	TRACK_BIT_NONE,
3102
f9ca4379db9d (svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron
parents: 3101
diff changeset
   178
	TRACK_BIT_Y,
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   179
	TRACK_BIT_LOWER,
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   180
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   181
	TRACK_BIT_LOWER,
3102
f9ca4379db9d (svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron
parents: 3101
diff changeset
   182
	TRACK_BIT_Y,
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   183
	TRACK_BIT_NONE,
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   184
	TRACK_BIT_LEFT,
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   185
3102
f9ca4379db9d (svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron
parents: 3101
diff changeset
   186
	TRACK_BIT_X,
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   187
	TRACK_BIT_UPPER,
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   188
	TRACK_BIT_RIGHT,
7703
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7642
diff changeset
   189
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   190
7703
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7642
diff changeset
   191
/** Valid TrackBits on a specific (non-steep)-slope with leveled foundation */
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7642
diff changeset
   192
static const TrackBits _valid_tracks_on_leveled_foundation[15] = {
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   193
	TRACK_BIT_NONE,
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   194
	TRACK_BIT_LEFT,
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   195
	TRACK_BIT_LOWER,
3102
f9ca4379db9d (svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron
parents: 3101
diff changeset
   196
	TRACK_BIT_Y | TRACK_BIT_LOWER | TRACK_BIT_LEFT,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   197
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   198
	TRACK_BIT_RIGHT,
3258
1c079364726d (svn r3946) Add short hand names for common track combinations
tron
parents: 3254
diff changeset
   199
	TRACK_BIT_ALL,
3102
f9ca4379db9d (svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron
parents: 3101
diff changeset
   200
	TRACK_BIT_X | TRACK_BIT_LOWER | TRACK_BIT_RIGHT,
3258
1c079364726d (svn r3946) Add short hand names for common track combinations
tron
parents: 3254
diff changeset
   201
	TRACK_BIT_ALL,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   202
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   203
	TRACK_BIT_UPPER,
3102
f9ca4379db9d (svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron
parents: 3101
diff changeset
   204
	TRACK_BIT_X | TRACK_BIT_UPPER | TRACK_BIT_LEFT,
3258
1c079364726d (svn r3946) Add short hand names for common track combinations
tron
parents: 3254
diff changeset
   205
	TRACK_BIT_ALL,
1c079364726d (svn r3946) Add short hand names for common track combinations
tron
parents: 3254
diff changeset
   206
	TRACK_BIT_ALL,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   207
3102
f9ca4379db9d (svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron
parents: 3101
diff changeset
   208
	TRACK_BIT_Y | TRACK_BIT_UPPER | TRACK_BIT_RIGHT,
3258
1c079364726d (svn r3946) Add short hand names for common track combinations
tron
parents: 3254
diff changeset
   209
	TRACK_BIT_ALL,
1c079364726d (svn r3946) Add short hand names for common track combinations
tron
parents: 3254
diff changeset
   210
	TRACK_BIT_ALL
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   211
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   212
7703
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7642
diff changeset
   213
/**
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7642
diff changeset
   214
 * Checks if a track combination is valid on a specific slope and returns the needed foundation.
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7642
diff changeset
   215
 *
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7642
diff changeset
   216
 * @param tileh Tile slope.
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7642
diff changeset
   217
 * @param bits  Trackbits.
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7642
diff changeset
   218
 * @return Needed foundation or FOUNDATION_INVALID if track/slope combination is not allowed.
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7642
diff changeset
   219
 */
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
   220
Foundation GetRailFoundation(Slope tileh, TrackBits bits)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   221
{
7703
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7642
diff changeset
   222
	if (bits == TRACK_BIT_NONE) return FOUNDATION_NONE;
3878
ef06782573c0 (svn r4927) Replace 3 big ifs (which regard foundations) by a bit less confusing code
tron
parents: 3869
diff changeset
   223
7703
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7642
diff changeset
   224
	if (IsSteepSlope(tileh)) {
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7642
diff changeset
   225
		/* Test for inclined foundations */
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7642
diff changeset
   226
		if (bits == TRACK_BIT_X) return FOUNDATION_INCLINED_X;
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7642
diff changeset
   227
		if (bits == TRACK_BIT_Y) return FOUNDATION_INCLINED_Y;
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7642
diff changeset
   228
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7642
diff changeset
   229
		/* Get higher track */
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7642
diff changeset
   230
		Corner highest_corner = GetHighestSlopeCorner(tileh);
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7642
diff changeset
   231
		TrackBits higher_track = CornerToTrackBits(highest_corner);
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7642
diff changeset
   232
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7642
diff changeset
   233
		/* Only higher track? */
7770
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
   234
		if (bits == higher_track) return HalftileFoundation(highest_corner);
7703
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7642
diff changeset
   235
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7642
diff changeset
   236
		/* Overlap with higher track? */
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7642
diff changeset
   237
		if (TracksOverlap(bits | higher_track)) return FOUNDATION_INVALID;
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7642
diff changeset
   238
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7642
diff changeset
   239
		/* either lower track or both higher and lower track */
7770
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
   240
		return ((bits & higher_track) != 0 ? FOUNDATION_STEEP_BOTH : FOUNDATION_STEEP_LOWER);
7703
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7642
diff changeset
   241
	} else {
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7642
diff changeset
   242
		if ((~_valid_tracks_without_foundation[tileh] & bits) == 0) return FOUNDATION_NONE;
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7642
diff changeset
   243
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7642
diff changeset
   244
		bool valid_on_leveled = ((~_valid_tracks_on_leveled_foundation[tileh] & bits) == 0);
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7642
diff changeset
   245
7770
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
   246
		Corner track_corner;
7703
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7642
diff changeset
   247
		switch (bits) {
7770
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
   248
			case TRACK_BIT_LEFT:  track_corner = CORNER_W; break;
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
   249
			case TRACK_BIT_LOWER: track_corner = CORNER_S; break;
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
   250
			case TRACK_BIT_RIGHT: track_corner = CORNER_E; break;
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
   251
			case TRACK_BIT_UPPER: track_corner = CORNER_N; break;
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
   252
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
   253
			case TRACK_BIT_HORZ:
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
   254
				if (tileh == SLOPE_N) return HalftileFoundation(CORNER_N);
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
   255
				if (tileh == SLOPE_S) return HalftileFoundation(CORNER_S);
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
   256
				return (valid_on_leveled ? FOUNDATION_LEVELED : FOUNDATION_INVALID);
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
   257
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
   258
			case TRACK_BIT_VERT:
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
   259
				if (tileh == SLOPE_W) return HalftileFoundation(CORNER_W);
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
   260
				if (tileh == SLOPE_E) return HalftileFoundation(CORNER_E);
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
   261
				return (valid_on_leveled ? FOUNDATION_LEVELED : FOUNDATION_INVALID);
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
   262
7703
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7642
diff changeset
   263
			case TRACK_BIT_X:
8413
c7f3384330a3 (svn r11983) -Codechange: Add some helper functions for slopes and use them.
frosch
parents: 8398
diff changeset
   264
				if (IsSlopeWithOneCornerRaised(tileh)) return FOUNDATION_INCLINED_X;
7703
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7642
diff changeset
   265
				return (valid_on_leveled ? FOUNDATION_LEVELED : FOUNDATION_INVALID);
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7642
diff changeset
   266
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7642
diff changeset
   267
			case TRACK_BIT_Y:
8413
c7f3384330a3 (svn r11983) -Codechange: Add some helper functions for slopes and use them.
frosch
parents: 8398
diff changeset
   268
				if (IsSlopeWithOneCornerRaised(tileh)) return FOUNDATION_INCLINED_Y;
7703
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7642
diff changeset
   269
				return (valid_on_leveled ? FOUNDATION_LEVELED : FOUNDATION_INVALID);
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7642
diff changeset
   270
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7642
diff changeset
   271
			default:
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7642
diff changeset
   272
				return (valid_on_leveled ? FOUNDATION_LEVELED : FOUNDATION_INVALID);
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7642
diff changeset
   273
		}
7770
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
   274
		/* Single diagonal track */
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
   275
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
   276
		/* Track must be at least valid on leveled foundation */
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
   277
		if (!valid_on_leveled) return FOUNDATION_INVALID;
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
   278
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
   279
		/* If slope has three raised corners, build leveled foundation */
8413
c7f3384330a3 (svn r11983) -Codechange: Add some helper functions for slopes and use them.
frosch
parents: 8398
diff changeset
   280
		if (IsSlopeWithThreeCornersRaised(tileh)) return FOUNDATION_LEVELED;
7770
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
   281
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
   282
		/* If neighboured corners of track_corner are lowered, build halftile foundation */
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
   283
		if ((tileh & SlopeWithThreeCornersRaised(OppositeCorner(track_corner))) == SlopeWithOneCornerRaised(track_corner)) return HalftileFoundation(track_corner);
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
   284
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
   285
		/* else special anti-zig-zag foundation */
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
   286
		return SpecialRailFoundation(track_corner);
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2934
diff changeset
   287
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   288
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   289
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   290
7703
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7642
diff changeset
   291
/**
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7642
diff changeset
   292
 * Tests if a track can be build on a tile.
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7642
diff changeset
   293
 *
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7642
diff changeset
   294
 * @param tileh Tile slope.
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7642
diff changeset
   295
 * @param rail_bits Tracks to build.
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7642
diff changeset
   296
 * @param existing Tracks already built.
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7642
diff changeset
   297
 * @param tile Tile (used for water test)
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7642
diff changeset
   298
 * @return Error message or cost for foundation building.
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7642
diff changeset
   299
 */
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6791
diff changeset
   300
static CommandCost CheckRailSlope(Slope tileh, TrackBits rail_bits, TrackBits existing, TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   301
{
7703
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7642
diff changeset
   302
	/* don't allow building on the lower side of a coast */
7771
a900b80b48f2 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 7770
diff changeset
   303
	if (IsTileType(tile, MP_WATER) || (IsTileType(tile, MP_RAILWAY) && (GetRailGroundType(tile) == RAIL_GROUND_WATER))) {
7703
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7642
diff changeset
   304
		if (!IsSteepSlope(tileh) && ((~_valid_tracks_on_leveled_foundation[tileh] & (rail_bits | existing)) != 0)) return_cmd_error(STR_3807_CAN_T_BUILD_ON_WATER);
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7642
diff changeset
   305
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   306
7703
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7642
diff changeset
   307
	Foundation f_new = GetRailFoundation(tileh, rail_bits | existing);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   308
7703
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7642
diff changeset
   309
	/* check track/slope combination */
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7642
diff changeset
   310
	if ((f_new == FOUNDATION_INVALID) ||
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10172
diff changeset
   311
			((f_new != FOUNDATION_NONE) && (!_settings_game.construction.build_on_slopes || _is_old_ai_company))) {
9860
b7e82afa0df7 (svn r14005) -Codechange: minor coding style fix
smatz
parents: 9830
diff changeset
   312
		return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
b7e82afa0df7 (svn r14005) -Codechange: minor coding style fix
smatz
parents: 9830
diff changeset
   313
	}
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   314
7703
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7642
diff changeset
   315
	Foundation f_old = GetRailFoundation(tileh, existing);
8230
64f28fe2d5c8 (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8228
diff changeset
   316
	return CommandCost(EXPENSES_CONSTRUCTION, f_new != f_old ? _price.terraform : (Money)0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   317
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   318
1775
548dc04d50e2 (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1719
diff changeset
   319
/* Validate functions for rail building */
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   320
static inline bool ValParamTrackOrientation(Track track) {return IsValidTrack(track);}
1775
548dc04d50e2 (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1719
diff changeset
   321
548dc04d50e2 (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1719
diff changeset
   322
/** Build a single piece of rail
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: 3486
diff changeset
   323
 * @param tile tile  to build on
6483
ae78fc3c6b20 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6452
diff changeset
   324
 * @param flags operation to perform
1775
548dc04d50e2 (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1719
diff changeset
   325
 * @param p1 railtype of being built piece (normal, mono, maglev)
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   326
 * @param p2 rail track to build
1775
548dc04d50e2 (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1719
diff changeset
   327
 */
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6791
diff changeset
   328
CommandCost CmdBuildSingleRail(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   329
{
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3575
diff changeset
   330
	Slope tileh;
8236
8a5dd0b42e47 (svn r11800) -Codechange: move some functions to a more logical location + some type safety.
rubidium
parents: 8230
diff changeset
   331
	RailType railtype = (RailType)p1;
8a5dd0b42e47 (svn r11800) -Codechange: move some functions to a more logical location + some type safety.
rubidium
parents: 8230
diff changeset
   332
	Track track = (Track)p2;
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   333
	TrackBits trackbit;
8230
64f28fe2d5c8 (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8228
diff changeset
   334
	CommandCost cost(EXPENSES_CONSTRUCTION);
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6791
diff changeset
   335
	CommandCost ret;
1627
f365c96e74a4 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   336
8236
8a5dd0b42e47 (svn r11800) -Codechange: move some functions to a more logical location + some type safety.
rubidium
parents: 8230
diff changeset
   337
	if (!ValParamRailtype(railtype) || !ValParamTrackOrientation(track)) return CMD_ERROR;
1627
f365c96e74a4 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   338
f365c96e74a4 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   339
	tileh = GetTileSlope(tile, NULL);
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   340
	trackbit = TrackToTrackBits(track);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   341
1627
f365c96e74a4 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   342
	switch (GetTileType(tile)) {
f365c96e74a4 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   343
		case MP_RAILWAY:
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   344
			if (!CheckTrackCombination(tile, trackbit, flags) ||
7448
dbcc29a92db8 (svn r10922) -Codechange: Allow building and removing tracks and signals when there is a
maedhros
parents: 7389
diff changeset
   345
					!EnsureNoTrainOnTrack(tile, track)) {
1627
f365c96e74a4 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   346
				return CMD_ERROR;
f365c96e74a4 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   347
			}
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10172
diff changeset
   348
			if (!IsTileOwner(tile, _current_company) ||
5394
bce82a9368c7 (svn r7583) -Fix (r7573): Merging of bridge branch broke (partially reverted?) automatic railtype conversion when building track on existing rail.
peter1138
parents: 5385
diff changeset
   349
					!IsCompatibleRail(GetRailType(tile), railtype)) {
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6406
diff changeset
   350
				/* Get detailed error message */
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: 3486
diff changeset
   351
				return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
1627
f365c96e74a4 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   352
			}
f365c96e74a4 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   353
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   354
			ret = CheckRailSlope(tileh, trackbit, GetTrackBits(tile), tile);
1691
852ca27d6eef (svn r2195) Add CmdFailed() as the One True Way(tm) to check if a command failed.
tron
parents: 1669
diff changeset
   355
			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
   356
			cost.AddCost(ret);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   357
5059
fec3defb6e67 (svn r7112) -Codechange (r7106): Improve the test for determining if the rail type should be converted
peter1138
parents: 5058
diff changeset
   358
			/* If the rail types don't match, try to convert only if engines of
10006
40037bb4b4ce (svn r14165) -Codechange: When over-building rail with a different type, don't convert the rail if the engines of the new type are powered on the existing type.
peter1138
parents: 10001
diff changeset
   359
			 * the new rail type are not powered on the present rail type and engines of
5059
fec3defb6e67 (svn r7112) -Codechange (r7106): Improve the test for determining if the rail type should be converted
peter1138
parents: 5058
diff changeset
   360
			 * the present rail type are powered on the new rail type. */
10006
40037bb4b4ce (svn r14165) -Codechange: When over-building rail with a different type, don't convert the rail if the engines of the new type are powered on the existing type.
peter1138
parents: 10001
diff changeset
   361
			if (GetRailType(tile) != railtype && !HasPowerOnRail(railtype, GetRailType(tile))) {
40037bb4b4ce (svn r14165) -Codechange: When over-building rail with a different type, don't convert the rail if the engines of the new type are powered on the existing type.
peter1138
parents: 10001
diff changeset
   362
				if (HasPowerOnRail(GetRailType(tile), railtype)) {
40037bb4b4ce (svn r14165) -Codechange: When over-building rail with a different type, don't convert the rail if the engines of the new type are powered on the existing type.
peter1138
parents: 10001
diff changeset
   363
					ret = DoCommand(tile, tile, railtype, flags, CMD_CONVERT_RAIL);
40037bb4b4ce (svn r14165) -Codechange: When over-building rail with a different type, don't convert the rail if the engines of the new type are powered on the existing type.
peter1138
parents: 10001
diff changeset
   364
					if (CmdFailed(ret)) return ret;
40037bb4b4ce (svn r14165) -Codechange: When over-building rail with a different type, don't convert the rail if the engines of the new type are powered on the existing type.
peter1138
parents: 10001
diff changeset
   365
					cost.AddCost(ret);
40037bb4b4ce (svn r14165) -Codechange: When over-building rail with a different type, don't convert the rail if the engines of the new type are powered on the existing type.
peter1138
parents: 10001
diff changeset
   366
				} else {
40037bb4b4ce (svn r14165) -Codechange: When over-building rail with a different type, don't convert the rail if the engines of the new type are powered on the existing type.
peter1138
parents: 10001
diff changeset
   367
					return CMD_ERROR;
40037bb4b4ce (svn r14165) -Codechange: When over-building rail with a different type, don't convert the rail if the engines of the new type are powered on the existing type.
peter1138
parents: 10001
diff changeset
   368
				}
5054
45cfda0fd7eb (svn r7106) -Feature: Allow over-building of compatible railtypes, i.e. normal and
peter1138
parents: 5015
diff changeset
   369
			}
45cfda0fd7eb (svn r7106) -Feature: Allow over-building of compatible railtypes, i.e. normal and
peter1138
parents: 5015
diff changeset
   370
1719
ddb7e8c7d1a4 (svn r2223) When adding tracks to a railway tile reset the ground to bare land, fix for a glitch in r2131
tron
parents: 1691
diff changeset
   371
			if (flags & DC_EXEC) {
3523
549603ffba5d (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
   372
				SetRailGroundType(tile, RAIL_GROUND_BARREN);
5411
9ad8285b2f0d (svn r7609) -Codechange: remove some direct map accesses to m5 and some unneeded signal removal code in ClearTileTrack as it is done in CmdRemoveSingleRail too, which is called for every removed trackbit.
rubidium
parents: 5394
diff changeset
   373
				SetTrackBits(tile, GetTrackBits(tile) | trackbit);
1719
ddb7e8c7d1a4 (svn r2223) When adding tracks to a railway tile reset the ground to bare land, fix for a glitch in r2131
tron
parents: 1691
diff changeset
   374
			}
1627
f365c96e74a4 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   375
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   376
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: 7335
diff changeset
   377
		case MP_ROAD:
3142
ef213f02d4bf (svn r3760) Replace some magic numbers for checking for a suitable slope for a level crossing by some less magic numbers. Quite similar to r3699, though this time for placing the rails
tron
parents: 3103
diff changeset
   378
#define M(x) (1 << (x))
ef213f02d4bf (svn r3760) Replace some magic numbers for checking for a suitable slope for a level crossing by some less magic numbers. Quite similar to r3699, though this time for placing the rails
tron
parents: 3103
diff changeset
   379
			/* 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: 7882
diff changeset
   380
			if (!HasBit(M(SLOPE_SEN) | M(SLOPE_ENW) | M(SLOPE_NWS) | M(SLOPE_NS) | M(SLOPE_WSE) | M(SLOPE_EW) | M(SLOPE_FLAT), tileh)) {
1627
f365c96e74a4 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   381
				return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
3142
ef213f02d4bf (svn r3760) Replace some magic numbers for checking for a suitable slope for a level crossing by some less magic numbers. Quite similar to r3699, though this time for placing the rails
tron
parents: 3103
diff changeset
   382
			}
ef213f02d4bf (svn r3760) Replace some magic numbers for checking for a suitable slope for a level crossing by some less magic numbers. Quite similar to r3699, though this time for placing the rails
tron
parents: 3103
diff changeset
   383
#undef M
ef213f02d4bf (svn r3760) Replace some magic numbers for checking for a suitable slope for a level crossing by some less magic numbers. Quite similar to r3699, though this time for placing the rails
tron
parents: 3103
diff changeset
   384
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
   385
			if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   386
8563
13b1a41e46f1 (svn r12141) -Codechange: Introduce IsNormalRoad[Tile](), IsRoadDepot[Tile]() and HasTileRoadType(); and use them.
frosch
parents: 8547
diff changeset
   387
			if (IsNormalRoad(tile)) {
4140
1765a8dd17dc (svn r5500) Undo r4597, because it breaks the intended change of r5315 to prohibit building rails on a road tile while road works are in progress
tron
parents: 4139
diff changeset
   388
				if (HasRoadWorks(tile)) return_cmd_error(STR_ROAD_WORKS_IN_PROGRESS);
1765a8dd17dc (svn r5500) Undo r4597, because it breaks the intended change of r5315 to prohibit building rails on a road tile while road works are in progress
tron
parents: 4139
diff changeset
   389
8664
b555e7be9da3 (svn r12329) -Fix [FS#1819]: Disallow building level crossings over one-way roads as this allowed competitors to remove the one-way state.
peter1138
parents: 8616
diff changeset
   390
				if (GetDisallowedRoadDirections(tile) != DRD_NONE) return_cmd_error(STR_ERR_CROSSING_ON_ONEWAY_ROAD);
b555e7be9da3 (svn r12329) -Fix [FS#1819]: Disallow building level crossings over one-way roads as this allowed competitors to remove the one-way state.
peter1138
parents: 8616
diff changeset
   391
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6591
diff changeset
   392
				RoadTypes roadtypes = GetRoadTypes(tile);
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6591
diff changeset
   393
				RoadBits road = GetRoadBits(tile, ROADTYPE_ROAD);
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6591
diff changeset
   394
				RoadBits tram = GetRoadBits(tile, ROADTYPE_TRAM);
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6591
diff changeset
   395
				switch (roadtypes) {
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6591
diff changeset
   396
					default: break;
6728
61568a945b40 (svn r9960) -Fix [FS#813]: road wasn't properly added when overbuilding a tram rails with normal rails to for a crossing.
rubidium
parents: 6683
diff changeset
   397
					case ROADTYPES_TRAM:
61568a945b40 (svn r9960) -Fix [FS#813]: road wasn't properly added when overbuilding a tram rails with normal rails to for a crossing.
rubidium
parents: 6683
diff changeset
   398
						/* Tram crossings must always have road. */
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10172
diff changeset
   399
						if (flags & DC_EXEC) SetRoadOwner(tile, ROADTYPE_ROAD, _current_company);
6728
61568a945b40 (svn r9960) -Fix [FS#813]: road wasn't properly added when overbuilding a tram rails with normal rails to for a crossing.
rubidium
parents: 6683
diff changeset
   400
						roadtypes |= ROADTYPES_ROAD;
61568a945b40 (svn r9960) -Fix [FS#813]: road wasn't properly added when overbuilding a tram rails with normal rails to for a crossing.
rubidium
parents: 6683
diff changeset
   401
						break;
61568a945b40 (svn r9960) -Fix [FS#813]: road wasn't properly added when overbuilding a tram rails with normal rails to for a crossing.
rubidium
parents: 6683
diff changeset
   402
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6591
diff changeset
   403
					case ROADTYPES_ROADTRAM: if (road == tram) break;
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6591
diff changeset
   404
						/* FALL THROUGH */
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6591
diff changeset
   405
					case ROADTYPES_ROADHWAY: // Road and highway are incompatible in this case
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6591
diff changeset
   406
					case ROADTYPES_TRAMHWAY: // Tram and highway are incompatible in this case
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6591
diff changeset
   407
					case ROADTYPES_ALL:      // Also incompatible
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6591
diff changeset
   408
						return CMD_ERROR;
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6591
diff changeset
   409
				}
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6591
diff changeset
   410
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6591
diff changeset
   411
				road |= tram | GetRoadBits(tile, ROADTYPE_HWAY);
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6591
diff changeset
   412
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6591
diff changeset
   413
				if ((track == TRACK_X && road == ROAD_Y) ||
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6591
diff changeset
   414
						(track == TRACK_Y && road == ROAD_X)) {
4140
1765a8dd17dc (svn r5500) Undo r4597, because it breaks the intended change of r5315 to prohibit building rails on a road tile while road works are in progress
tron
parents: 4139
diff changeset
   415
					if (flags & DC_EXEC) {
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10172
diff changeset
   416
						MakeRoadCrossing(tile, GetRoadOwner(tile, ROADTYPE_ROAD), GetRoadOwner(tile, ROADTYPE_TRAM), GetRoadOwner(tile, ROADTYPE_HWAY), _current_company, (track == TRACK_X ? AXIS_Y : AXIS_X), railtype, roadtypes, GetTownIndex(tile));
8344
1cd2a831b06c (svn r11910) -Fix: play 'ding-ding' crossing sound in more cases (except gameload and crossing construction)
smatz
parents: 8342
diff changeset
   417
						UpdateLevelCrossing(tile, false);
4140
1765a8dd17dc (svn r5500) Undo r4597, because it breaks the intended change of r5315 to prohibit building rails on a road tile while road works are in progress
tron
parents: 4139
diff changeset
   418
					}
1765a8dd17dc (svn r5500) Undo r4597, because it breaks the intended change of r5315 to prohibit building rails on a road tile while road works are in progress
tron
parents: 4139
diff changeset
   419
					break;
4139
611ec4ec9a3b (svn r5497) -Fix: somehow in r5315 slipped some wrong logic, allowed you to build rail on all road pieces without really building it ;)
truelight
parents: 4081
diff changeset
   420
				}
1627
f365c96e74a4 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   421
			}
f365c96e74a4 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   422
3267
feff95208a9f (svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents: 3265
diff changeset
   423
			if (IsLevelCrossing(tile) && GetCrossingRailBits(tile) == trackbit) {
1627
f365c96e74a4 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   424
				return_cmd_error(STR_1007_ALREADY_BUILT);
3267
feff95208a9f (svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents: 3265
diff changeset
   425
			}
1627
f365c96e74a4 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   426
			/* FALLTHROUGH */
f365c96e74a4 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   427
f365c96e74a4 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   428
		default:
8414
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
   429
			/* Will there be flat water on the lower halftile? */
8413
c7f3384330a3 (svn r11983) -Codechange: Add some helper functions for slopes and use them.
frosch
parents: 8398
diff changeset
   430
			bool water_ground = IsTileType(tile, MP_WATER) && IsSlopeWithOneCornerRaised(tileh);
7771
a900b80b48f2 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 7770
diff changeset
   431
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   432
			ret = CheckRailSlope(tileh, trackbit, TRACK_BIT_NONE, tile);
1691
852ca27d6eef (svn r2195) Add CmdFailed() as the One True Way(tm) to check if a command failed.
tron
parents: 1669
diff changeset
   433
			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
   434
			cost.AddCost(ret);
1627
f365c96e74a4 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   435
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: 3486
diff changeset
   436
			ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
1691
852ca27d6eef (svn r2195) Add CmdFailed() as the One True Way(tm) to check if a command failed.
tron
parents: 1669
diff changeset
   437
			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
   438
			cost.AddCost(ret);
1627
f365c96e74a4 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   439
7771
a900b80b48f2 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 7770
diff changeset
   440
			if (water_ground) {
a900b80b48f2 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 7770
diff changeset
   441
				cost.AddCost(-_price.clear_water);
7977
4a4e11757be5 (svn r11533) -Codechange: Rename some unclear clear_x prices member names.
belugas
parents: 7948
diff changeset
   442
				cost.AddCost(_price.clear_roughland);
7771
a900b80b48f2 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 7770
diff changeset
   443
			}
a900b80b48f2 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 7770
diff changeset
   444
a900b80b48f2 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 7770
diff changeset
   445
			if (flags & DC_EXEC) {
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10172
diff changeset
   446
				MakeRailNormal(tile, _current_company, trackbit, railtype);
7771
a900b80b48f2 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 7770
diff changeset
   447
				if (water_ground) SetRailGroundType(tile, RAIL_GROUND_WATER);
a900b80b48f2 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 7770
diff changeset
   448
			}
1627
f365c96e74a4 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   449
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   450
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   451
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   452
	if (flags & DC_EXEC) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   453
		MarkTileDirtyByTile(tile);
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10172
diff changeset
   454
		AddTrackToSignalBuffer(tile, track, _current_company);
3900
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3884
diff changeset
   455
		YapfNotifyTrackLayoutChange(tile, track);
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
7730
4293ba29ce21 (svn r11265) -Feature: Make more advanced rail types more expensive to build.
maedhros
parents: 7703
diff changeset
   458
	return cost.AddCost(RailBuildCost(railtype));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   459
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   460
1775
548dc04d50e2 (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1719
diff changeset
   461
/** Remove a single piece of track
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: 3486
diff changeset
   462
 * @param tile tile to remove track from
6483
ae78fc3c6b20 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6452
diff changeset
   463
 * @param flags operation to perform
1775
548dc04d50e2 (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1719
diff changeset
   464
 * @param p1 unused
548dc04d50e2 (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1719
diff changeset
   465
 * @param p2 rail orientation
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   466
 */
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6791
diff changeset
   467
CommandCost CmdRemoveSingleRail(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   468
{
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   469
	Track track = (Track)p2;
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   470
	TrackBits trackbit;
8230
64f28fe2d5c8 (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8228
diff changeset
   471
	CommandCost cost(EXPENSES_CONSTRUCTION, _price.remove_rail );
3284
84eda61a0167 (svn r3998) - Fix: When removing rail track from a while where only X and Y (/ and \) pieces exist, explicitly update signals in both directions.
peter1138
parents: 3279
diff changeset
   472
	bool crossing = false;
1775
548dc04d50e2 (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1719
diff changeset
   473
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   474
	if (!ValParamTrackOrientation((Track)p2)) return CMD_ERROR;
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   475
	trackbit = TrackToTrackBits(track);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   476
8318
74803dd94572 (svn r11883) -Fix (r11864): assert when trying to remove rail from a house or industry tile
smatz
parents: 8306
diff changeset
   477
	/* Need to read tile owner now because it may change when the rail is removed
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10172
diff changeset
   478
	 * Also, in case of floods, _current_company != owner
8318
74803dd94572 (svn r11883) -Fix (r11864): assert when trying to remove rail from a house or industry tile
smatz
parents: 8306
diff changeset
   479
	 * There may be invalid tiletype even in exec run (when removing long track),
74803dd94572 (svn r11883) -Fix (r11864): assert when trying to remove rail from a house or industry tile
smatz
parents: 8306
diff changeset
   480
	 * so do not call GetTileOwner(tile) in any case here */
74803dd94572 (svn r11883) -Fix (r11864): assert when trying to remove rail from a house or industry tile
smatz
parents: 8306
diff changeset
   481
	Owner owner = INVALID_OWNER;
8300
dfd530665621 (svn r11864) -Codechange: pass owner whose signals we will update instead of complex detection later
smatz
parents: 8264
diff changeset
   482
9815
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9795
diff changeset
   483
	Vehicle *v = NULL;
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9795
diff changeset
   484
3273
3089ecca8e21 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents: 3271
diff changeset
   485
	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: 7335
diff changeset
   486
		case MP_ROAD: {
3273
3089ecca8e21 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents: 3271
diff changeset
   487
			if (!IsLevelCrossing(tile) ||
3089ecca8e21 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents: 3271
diff changeset
   488
					GetCrossingRailBits(tile) != trackbit ||
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10172
diff changeset
   489
					(_current_company != OWNER_WATER && !CheckTileOwnership(tile)) ||
8519
fe61d7aa3053 (svn r12094) -Codechange: use DC_BANKRUPT command flag when removing player property to allow further fixes
smatz
parents: 8414
diff changeset
   490
					(!(flags & DC_BANKRUPT) && !EnsureNoVehicleOnGround(tile))) {
3273
3089ecca8e21 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents: 3271
diff changeset
   491
				return CMD_ERROR;
3089ecca8e21 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents: 3271
diff changeset
   492
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   493
3273
3089ecca8e21 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents: 3271
diff changeset
   494
			if (flags & DC_EXEC) {
9815
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9795
diff changeset
   495
				if (HasReservedTracks(tile, trackbit)) {
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9795
diff changeset
   496
					v = GetTrainForReservation(tile, track);
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9795
diff changeset
   497
					if (v != NULL) FreeTrainTrackReservation(v);
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9795
diff changeset
   498
				}
8318
74803dd94572 (svn r11883) -Fix (r11864): assert when trying to remove rail from a house or industry tile
smatz
parents: 8306
diff changeset
   499
				owner = GetTileOwner(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: 6591
diff changeset
   500
				MakeRoadNormal(tile, GetCrossingRoadBits(tile), GetRoadTypes(tile), GetTownIndex(tile), GetRoadOwner(tile, ROADTYPE_ROAD), GetRoadOwner(tile, ROADTYPE_TRAM), GetRoadOwner(tile, ROADTYPE_HWAY));
3273
3089ecca8e21 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents: 3271
diff changeset
   501
			}
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   502
			break;
3071
6f3417a859d4 (svn r3660) Convert further road bits and type references to the functions/enums
tron
parents: 3069
diff changeset
   503
		}
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
   504
3273
3089ecca8e21 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents: 3271
diff changeset
   505
		case MP_RAILWAY: {
3089ecca8e21 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents: 3271
diff changeset
   506
			TrackBits present;
3089ecca8e21 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents: 3271
diff changeset
   507
3089ecca8e21 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents: 3271
diff changeset
   508
			if (!IsPlainRailTile(tile) ||
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10172
diff changeset
   509
					(_current_company != OWNER_WATER && !CheckTileOwnership(tile)) ||
7448
dbcc29a92db8 (svn r10922) -Codechange: Allow building and removing tracks and signals when there is a
maedhros
parents: 7389
diff changeset
   510
					!EnsureNoTrainOnTrack(tile, track)) {
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   511
				return CMD_ERROR;
3273
3089ecca8e21 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents: 3271
diff changeset
   512
			}
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   513
3273
3089ecca8e21 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents: 3271
diff changeset
   514
			present = GetTrackBits(tile);
3089ecca8e21 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents: 3271
diff changeset
   515
			if ((present & trackbit) == 0) return CMD_ERROR;
3284
84eda61a0167 (svn r3998) - Fix: When removing rail track from a while where only X and Y (/ and \) pieces exist, explicitly update signals in both directions.
peter1138
parents: 3279
diff changeset
   516
			if (present == (TRACK_BIT_X | TRACK_BIT_Y)) crossing = true;
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   517
1963
877cc0deb5b1 (svn r2469) - Add: When removing tracks with the 'remove' tool, have it automatically remove signals on the tracks.
hackykid
parents: 1954
diff changeset
   518
			/* Charge extra to remove signals on the track, if they are there */
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   519
			if (HasSignalOnTrack(tile, track))
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6946
diff changeset
   520
				cost.AddCost(DoCommand(tile, track, 0, flags, CMD_REMOVE_SIGNALS));
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   521
3273
3089ecca8e21 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents: 3271
diff changeset
   522
			if (flags & DC_EXEC) {
9815
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9795
diff changeset
   523
				if (HasReservedTracks(tile, trackbit)) {
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9795
diff changeset
   524
					v = GetTrainForReservation(tile, track);
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9795
diff changeset
   525
					if (v != NULL) FreeTrainTrackReservation(v);
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9795
diff changeset
   526
				}
8318
74803dd94572 (svn r11883) -Fix (r11864): assert when trying to remove rail from a house or industry tile
smatz
parents: 8306
diff changeset
   527
				owner = GetTileOwner(tile);
3273
3089ecca8e21 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents: 3271
diff changeset
   528
				present ^= trackbit;
3089ecca8e21 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents: 3271
diff changeset
   529
				if (present == 0) {
8414
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
   530
					Slope tileh = GetTileSlope(tile, NULL);
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
   531
					/* If there is flat water on the lower halftile, convert the tile to shore so the water remains */
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
   532
					if (GetRailGroundType(tile) == RAIL_GROUND_WATER && IsSlopeWithOneCornerRaised(tileh)) {
7771
a900b80b48f2 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 7770
diff changeset
   533
						MakeShore(tile);
a900b80b48f2 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 7770
diff changeset
   534
					} else {
a900b80b48f2 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 7770
diff changeset
   535
						DoClearSquare(tile);
a900b80b48f2 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 7770
diff changeset
   536
					}
3273
3089ecca8e21 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents: 3271
diff changeset
   537
				} else {
3089ecca8e21 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents: 3271
diff changeset
   538
					SetTrackBits(tile, present);
9788
8d1bdf1ba220 (svn r13930) -Codechange [YAPP]: Clear track reservation when removing a rail track. (michi_cc)
rubidium
parents: 9785
diff changeset
   539
					SetTrackReservation(tile, GetTrackReservation(tile) & present);
3273
3089ecca8e21 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents: 3271
diff changeset
   540
				}
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   541
			}
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   542
			break;
3273
3089ecca8e21 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents: 3271
diff changeset
   543
		}
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
   544
3273
3089ecca8e21 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents: 3271
diff changeset
   545
		default: return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   546
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   547
3273
3089ecca8e21 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents: 3271
diff changeset
   548
	if (flags & DC_EXEC) {
8318
74803dd94572 (svn r11883) -Fix (r11864): assert when trying to remove rail from a house or industry tile
smatz
parents: 8306
diff changeset
   549
		/* if we got that far, 'owner' variable is set correctly */
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10172
diff changeset
   550
		assert(IsValidCompanyID(owner));
8318
74803dd94572 (svn r11883) -Fix (r11864): assert when trying to remove rail from a house or industry tile
smatz
parents: 8306
diff changeset
   551
3273
3089ecca8e21 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents: 3271
diff changeset
   552
		MarkTileDirtyByTile(tile);
3284
84eda61a0167 (svn r3998) - Fix: When removing rail track from a while where only X and Y (/ and \) pieces exist, explicitly update signals in both directions.
peter1138
parents: 3279
diff changeset
   553
		if (crossing) {
84eda61a0167 (svn r3998) - Fix: When removing rail track from a while where only X and Y (/ and \) pieces exist, explicitly update signals in both directions.
peter1138
parents: 3279
diff changeset
   554
			/* crossing is set when only TRACK_BIT_X and TRACK_BIT_Y are set. As we
84eda61a0167 (svn r3998) - Fix: When removing rail track from a while where only X and Y (/ and \) pieces exist, explicitly update signals in both directions.
peter1138
parents: 3279
diff changeset
   555
			 * are removing one of these pieces, we'll need to update signals for
84eda61a0167 (svn r3998) - Fix: When removing rail track from a while where only X and Y (/ and \) pieces exist, explicitly update signals in both directions.
peter1138
parents: 3279
diff changeset
   556
			 * both directions explicitly, as after the track is removed it won't
84eda61a0167 (svn r3998) - Fix: When removing rail track from a while where only X and Y (/ and \) pieces exist, explicitly update signals in both directions.
peter1138
parents: 3279
diff changeset
   557
			 * 'connect' with the other piece. */
8306
22e1344c5457 (svn r11871) -Fix [FS#1074]: do not update signals after each tile when building/removing a large block of track/signals/station
smatz
parents: 8300
diff changeset
   558
			AddTrackToSignalBuffer(tile, TRACK_X, owner);
22e1344c5457 (svn r11871) -Fix [FS#1074]: do not update signals after each tile when building/removing a large block of track/signals/station
smatz
parents: 8300
diff changeset
   559
			AddTrackToSignalBuffer(tile, TRACK_Y, owner);
3900
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3884
diff changeset
   560
			YapfNotifyTrackLayoutChange(tile, TRACK_X);
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3884
diff changeset
   561
			YapfNotifyTrackLayoutChange(tile, TRACK_Y);
3284
84eda61a0167 (svn r3998) - Fix: When removing rail track from a while where only X and Y (/ and \) pieces exist, explicitly update signals in both directions.
peter1138
parents: 3279
diff changeset
   562
		} else {
8306
22e1344c5457 (svn r11871) -Fix [FS#1074]: do not update signals after each tile when building/removing a large block of track/signals/station
smatz
parents: 8300
diff changeset
   563
			AddTrackToSignalBuffer(tile, track, owner);
3900
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3884
diff changeset
   564
			YapfNotifyTrackLayoutChange(tile, track);
3284
84eda61a0167 (svn r3998) - Fix: When removing rail track from a while where only X and Y (/ and \) pieces exist, explicitly update signals in both directions.
peter1138
parents: 3279
diff changeset
   565
		}
9815
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9795
diff changeset
   566
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9795
diff changeset
   567
		if (v != NULL) TryPathReserve(v, true);
3273
3089ecca8e21 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents: 3271
diff changeset
   568
	}
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   569
1963
877cc0deb5b1 (svn r2469) - Add: When removing tracks with the 'remove' tool, have it automatically remove signals on the tracks.
hackykid
parents: 1954
diff changeset
   570
	return cost;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   571
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   572
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   573
7771
a900b80b48f2 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 7770
diff changeset
   574
/**
a900b80b48f2 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 7770
diff changeset
   575
 * Called from water_cmd if a non-flat rail-tile gets flooded and should be converted to shore.
a900b80b48f2 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 7770
diff changeset
   576
 * The function floods the lower halftile, if the tile has a halftile foundation.
a900b80b48f2 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 7770
diff changeset
   577
 *
a900b80b48f2 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 7770
diff changeset
   578
 * @param t The tile to flood.
8332
7226194fb681 (svn r11898) -Fix: Update neighboured canals + signals when flooding non-flat tiles, too.
frosch
parents: 8318
diff changeset
   579
 * @return true if something was flooded.
7771
a900b80b48f2 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 7770
diff changeset
   580
 */
8332
7226194fb681 (svn r11898) -Fix: Update neighboured canals + signals when flooding non-flat tiles, too.
frosch
parents: 8318
diff changeset
   581
bool FloodHalftile(TileIndex t)
7771
a900b80b48f2 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 7770
diff changeset
   582
{
8332
7226194fb681 (svn r11898) -Fix: Update neighboured canals + signals when flooding non-flat tiles, too.
frosch
parents: 8318
diff changeset
   583
	bool flooded = false;
7226194fb681 (svn r11898) -Fix: Update neighboured canals + signals when flooding non-flat tiles, too.
frosch
parents: 8318
diff changeset
   584
	if (GetRailGroundType(t) == RAIL_GROUND_WATER) return flooded;
7771
a900b80b48f2 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 7770
diff changeset
   585
a900b80b48f2 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 7770
diff changeset
   586
	Slope tileh = GetTileSlope(t, NULL);
a900b80b48f2 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 7770
diff changeset
   587
	TrackBits rail_bits = GetTrackBits(t);
a900b80b48f2 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 7770
diff changeset
   588
8413
c7f3384330a3 (svn r11983) -Codechange: Add some helper functions for slopes and use them.
frosch
parents: 8398
diff changeset
   589
	if (IsSlopeWithOneCornerRaised(tileh)) {
7771
a900b80b48f2 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 7770
diff changeset
   590
		TrackBits lower_track = CornerToTrackBits(OppositeCorner(GetHighestSlopeCorner(tileh)));
a900b80b48f2 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 7770
diff changeset
   591
a900b80b48f2 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 7770
diff changeset
   592
		TrackBits to_remove = lower_track & rail_bits;
a900b80b48f2 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 7770
diff changeset
   593
		if (to_remove != 0) {
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10172
diff changeset
   594
			_current_company = OWNER_WATER;
8332
7226194fb681 (svn r11898) -Fix: Update neighboured canals + signals when flooding non-flat tiles, too.
frosch
parents: 8318
diff changeset
   595
			if (CmdFailed(DoCommand(t, 0, FIND_FIRST_BIT(to_remove), DC_EXEC, CMD_REMOVE_SINGLE_RAIL))) return flooded; // not yet floodable
7226194fb681 (svn r11898) -Fix: Update neighboured canals + signals when flooding non-flat tiles, too.
frosch
parents: 8318
diff changeset
   596
			flooded = true;
7771
a900b80b48f2 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 7770
diff changeset
   597
			rail_bits = rail_bits & ~to_remove;
a900b80b48f2 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 7770
diff changeset
   598
			if (rail_bits == 0) {
a900b80b48f2 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 7770
diff changeset
   599
				MakeShore(t);
a900b80b48f2 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 7770
diff changeset
   600
				MarkTileDirtyByTile(t);
8332
7226194fb681 (svn r11898) -Fix: Update neighboured canals + signals when flooding non-flat tiles, too.
frosch
parents: 8318
diff changeset
   601
				return flooded;
7771
a900b80b48f2 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 7770
diff changeset
   602
			}
a900b80b48f2 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 7770
diff changeset
   603
		}
a900b80b48f2 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 7770
diff changeset
   604
a900b80b48f2 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 7770
diff changeset
   605
		if (IsNonContinuousFoundation(GetRailFoundation(tileh, rail_bits))) {
8332
7226194fb681 (svn r11898) -Fix: Update neighboured canals + signals when flooding non-flat tiles, too.
frosch
parents: 8318
diff changeset
   606
			flooded = true;
7771
a900b80b48f2 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 7770
diff changeset
   607
			SetRailGroundType(t, RAIL_GROUND_WATER);
a900b80b48f2 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 7770
diff changeset
   608
			MarkTileDirtyByTile(t);
a900b80b48f2 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 7770
diff changeset
   609
		}
8414
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
   610
	} else {
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
   611
		/* Make shore on steep slopes and 'three-corners-raised'-slopes. */
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
   612
		if (ApplyFoundationToSlope(GetRailFoundation(tileh, rail_bits), &tileh) == 0) {
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
   613
			if (IsSteepSlope(tileh) || IsSlopeWithThreeCornersRaised(tileh)) {
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
   614
				flooded = true;
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
   615
				SetRailGroundType(t, RAIL_GROUND_WATER);
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
   616
				MarkTileDirtyByTile(t);
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
   617
			}
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
   618
		}
7771
a900b80b48f2 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 7770
diff changeset
   619
	}
8332
7226194fb681 (svn r11898) -Fix: Update neighboured canals + signals when flooding non-flat tiles, too.
frosch
parents: 8318
diff changeset
   620
	return flooded;
7771
a900b80b48f2 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 7770
diff changeset
   621
}
a900b80b48f2 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 7770
diff changeset
   622
3493
c77bcf04294d (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   623
static const TileIndexDiffC _trackdelta[] = {
c77bcf04294d (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   624
	{ -1,  0 }, {  0,  1 }, { -1,  0 }, {  0,  1 }, {  1,  0 }, {  0,  1 },
c77bcf04294d (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   625
	{  0,  0 },
c77bcf04294d (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   626
	{  0,  0 },
c77bcf04294d (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   627
	{  1,  0 }, {  0, -1 }, {  0, -1 }, {  1,  0 }, {  0, -1 }, { -1,  0 },
c77bcf04294d (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   628
	{  0,  0 },
c77bcf04294d (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   629
	{  0,  0 }
c77bcf04294d (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   630
};
c77bcf04294d (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   631
c77bcf04294d (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   632
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6791
diff changeset
   633
static CommandCost ValidateAutoDrag(Trackdir *trackdir, TileIndex start, TileIndex end)
1227
1d940a5e02d2 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater
parents: 1209
diff changeset
   634
{
3493
c77bcf04294d (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   635
	int x = TileX(start);
c77bcf04294d (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   636
	int y = TileY(start);
c77bcf04294d (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   637
	int ex = TileX(end);
c77bcf04294d (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   638
	int ey = TileY(end);
1227
1d940a5e02d2 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater
parents: 1209
diff changeset
   639
	int dx, dy, trdx, trdy;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   640
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   641
	if (!ValParamTrackOrientation(TrackdirToTrack(*trackdir))) return CMD_ERROR;
1227
1d940a5e02d2 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater
parents: 1209
diff changeset
   642
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6406
diff changeset
   643
	/* calculate delta x,y from start to end tile */
1227
1d940a5e02d2 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater
parents: 1209
diff changeset
   644
	dx = ex - x;
1d940a5e02d2 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater
parents: 1209
diff changeset
   645
	dy = ey - y;
1d940a5e02d2 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater
parents: 1209
diff changeset
   646
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6406
diff changeset
   647
	/* calculate delta x,y for the first direction */
3493
c77bcf04294d (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   648
	trdx = _trackdelta[*trackdir].x;
c77bcf04294d (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   649
	trdy = _trackdelta[*trackdir].y;
1227
1d940a5e02d2 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater
parents: 1209
diff changeset
   650
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   651
	if (!IsDiagonalTrackdir(*trackdir)) {
3493
c77bcf04294d (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   652
		trdx += _trackdelta[*trackdir ^ 1].x;
c77bcf04294d (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   653
		trdy += _trackdelta[*trackdir ^ 1].y;
1227
1d940a5e02d2 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater
parents: 1209
diff changeset
   654
	}
1d940a5e02d2 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater
parents: 1209
diff changeset
   655
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6406
diff changeset
   656
	/* validate the direction */
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2934
diff changeset
   657
	while (
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2934
diff changeset
   658
		(trdx <= 0 && dx > 0) ||
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2934
diff changeset
   659
		(trdx >= 0 && dx < 0) ||
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2934
diff changeset
   660
		(trdy <= 0 && dy > 0) ||
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2934
diff changeset
   661
		(trdy >= 0 && dy < 0)
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2934
diff changeset
   662
	) {
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7882
diff changeset
   663
		if (!HasBit(*trackdir, 3)) { // first direction is invalid, try the other
7931
b0a46cd92225 (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents: 7929
diff changeset
   664
			SetBit(*trackdir, 3); // reverse the direction
1227
1d940a5e02d2 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater
parents: 1209
diff changeset
   665
			trdx = -trdx;
1d940a5e02d2 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater
parents: 1209
diff changeset
   666
			trdy = -trdy;
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4067
diff changeset
   667
		} else { // other direction is invalid too, invalid drag
1227
1d940a5e02d2 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater
parents: 1209
diff changeset
   668
			return CMD_ERROR;
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4067
diff changeset
   669
		}
1227
1d940a5e02d2 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater
parents: 1209
diff changeset
   670
	}
1d940a5e02d2 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater
parents: 1209
diff changeset
   671
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6406
diff changeset
   672
	/* (for diagonal tracks, this is already made sure of by above test), but:
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6406
diff changeset
   673
	 * for non-diagonal tracks, check if the start and end tile are on 1 line */
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   674
	if (!IsDiagonalTrackdir(*trackdir)) {
3493
c77bcf04294d (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   675
		trdx = _trackdelta[*trackdir].x;
c77bcf04294d (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   676
		trdy = _trackdelta[*trackdir].y;
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2934
diff changeset
   677
		if (abs(dx) != abs(dy) && abs(dx) + abs(trdy) != abs(dy) + abs(trdx))
1227
1d940a5e02d2 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater
parents: 1209
diff changeset
   678
			return CMD_ERROR;
1d940a5e02d2 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater
parents: 1209
diff changeset
   679
	}
1d940a5e02d2 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater
parents: 1209
diff changeset
   680
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6946
diff changeset
   681
	return CommandCost();
1227
1d940a5e02d2 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater
parents: 1209
diff changeset
   682
}
1d940a5e02d2 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater
parents: 1209
diff changeset
   683
1775
548dc04d50e2 (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1719
diff changeset
   684
/** Build a stretch of railroad tracks.
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: 3486
diff changeset
   685
 * @param tile start tile of drag
6483
ae78fc3c6b20 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6452
diff changeset
   686
 * @param flags operation to perform
1775
548dc04d50e2 (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1719
diff changeset
   687
 * @param p1 end tile of drag
548dc04d50e2 (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1719
diff changeset
   688
 * @param p2 various bitstuffed elements
548dc04d50e2 (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1719
diff changeset
   689
 * - p2 = (bit 0-3) - railroad type normal/maglev (0 = normal, 1 = mono, 2 = maglev)
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   690
 * - p2 = (bit 4-6) - track-orientation, valid values: 0-5 (Track enum)
1775
548dc04d50e2 (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1719
diff changeset
   691
 * - p2 = (bit 7)   - 0 = build, 1 = remove tracks
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   692
 */
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6791
diff changeset
   693
static CommandCost CmdRailTrackHelper(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
1227
1d940a5e02d2 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater
parents: 1209
diff changeset
   694
{
8230
64f28fe2d5c8 (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8228
diff changeset
   695
	CommandCost ret, total_cost(EXPENSES_CONSTRUCTION);
2140
a04d0142ad65 (svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents: 2111
diff changeset
   696
	Track track = (Track)GB(p2, 4, 3);
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   697
	Trackdir trackdir;
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7882
diff changeset
   698
	byte mode = HasBit(p2, 7);
2604
e3e60351c067 (svn r3141) Replace incorrect railtype bitmask in CmdRailTrackHelper with appropriate GB()
peter1138
parents: 2549
diff changeset
   699
	RailType railtype = (RailType)GB(p2, 0, 4);
3493
c77bcf04294d (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   700
	TileIndex end_tile;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   701
2604
e3e60351c067 (svn r3141) Replace incorrect railtype bitmask in CmdRailTrackHelper with appropriate GB()
peter1138
parents: 2549
diff changeset
   702
	if (!ValParamRailtype(railtype) || !ValParamTrackOrientation(track)) return CMD_ERROR;
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
   703
	if (p1 >= MapSize()) return CMD_ERROR;
3493
c77bcf04294d (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   704
	end_tile = p1;
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   705
	trackdir = TrackToTrackdir(track);
1775
548dc04d50e2 (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1719
diff changeset
   706
3493
c77bcf04294d (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   707
	if (CmdFailed(ValidateAutoDrag(&trackdir, tile, end_tile))) return CMD_ERROR;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   708
3493
c77bcf04294d (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   709
	if (flags & DC_EXEC) SndPlayTileFx(SND_20_SPLAT_2, tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   710
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2951
diff changeset
   711
	for (;;) {
3493
c77bcf04294d (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   712
		ret = DoCommand(tile, railtype, TrackdirToTrack(trackdir), flags, (mode == 0) ? CMD_BUILD_SINGLE_RAIL : CMD_REMOVE_SINGLE_RAIL);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   713
1775
548dc04d50e2 (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1719
diff changeset
   714
		if (CmdFailed(ret)) {
3671
5b6a80e29dd6 (svn r4586) - Codechange: Recursive commands that rely on _error_message to handle success/failure can fail if a recursive call fails but doesn't set the error message, thus resulting in an old, possibly erroneous being used (see FS#130 prior to r4585). Now properly reset the global variable _error_message in these cases.
Darkvater
parents: 3657
diff changeset
   715
			if ((_error_message != STR_1007_ALREADY_BUILT) && (mode == 0)) break;
5b6a80e29dd6 (svn r4586) - Codechange: Recursive commands that rely on _error_message to handle success/failure can fail if a recursive call fails but doesn't set the error message, thus resulting in an old, possibly erroneous being used (see FS#130 prior to r4585). Now properly reset the global variable _error_message in these cases.
Darkvater
parents: 3657
diff changeset
   716
			_error_message = INVALID_STRING_ID;
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4067
diff changeset
   717
		} else {
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6946
diff changeset
   718
			total_cost.AddCost(ret);
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4067
diff changeset
   719
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   720
3493
c77bcf04294d (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   721
		if (tile == end_tile) break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   722
3493
c77bcf04294d (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   723
		tile += ToTileIndexDiff(_trackdelta[trackdir]);
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   724
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6406
diff changeset
   725
		/* toggle railbit for the non-diagonal tracks */
7932
6c3d71e8a129 (svn r11485) -Codechange: Remove the doubled function ToggleBitT and rename the remaining to fit with the naming style
skidd13
parents: 7931
diff changeset
   726
		if (!IsDiagonalTrackdir(trackdir)) ToggleBit(trackdir, 0);
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   727
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   728
10330
26352b2a0337 (svn r14581) -Fix: make rail, road and canal building behave the same when overbuilding already built stretches.
rubidium
parents: 10322
diff changeset
   729
	return (total_cost.GetCost() == 0) ? CommandCost(STR_1007_ALREADY_BUILT) : total_cost;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   730
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   731
1796
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1782
diff changeset
   732
/** Build rail on a stretch of track.
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1782
diff changeset
   733
 * Stub for the unified rail builder/remover
6483
ae78fc3c6b20 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6452
diff changeset
   734
 * @param tile start tile of drag
ae78fc3c6b20 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6452
diff changeset
   735
 * @param flags operation to perform
ae78fc3c6b20 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6452
diff changeset
   736
 * @param p1 end tile of drag
ae78fc3c6b20 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6452
diff changeset
   737
 * @param p2 various bitstuffed elements
ae78fc3c6b20 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6452
diff changeset
   738
 * - p2 = (bit 0-3) - railroad type normal/maglev (0 = normal, 1 = mono, 2 = maglev)
ae78fc3c6b20 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6452
diff changeset
   739
 * - p2 = (bit 4-6) - track-orientation, valid values: 0-5 (Track enum)
ae78fc3c6b20 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6452
diff changeset
   740
 * - p2 = (bit 7)   - 0 = build, 1 = remove tracks
1796
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1782
diff changeset
   741
 * @see CmdRailTrackHelper
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1782
diff changeset
   742
 */
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6791
diff changeset
   743
CommandCost CmdBuildRailroadTrack(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
1227
1d940a5e02d2 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater
parents: 1209
diff changeset
   744
{
7929
6c9b25842b0f (svn r11482) -Codechange: Remove the doubled function ClrBitT and rename the remaining to fit with the naming style
skidd13
parents: 7928
diff changeset
   745
	return CmdRailTrackHelper(tile, flags, p1, ClrBit(p2, 7));
1227
1d940a5e02d2 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater
parents: 1209
diff changeset
   746
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   747
1796
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1782
diff changeset
   748
/** Build rail on a stretch of track.
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1782
diff changeset
   749
 * Stub for the unified rail builder/remover
6483
ae78fc3c6b20 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6452
diff changeset
   750
 * @param tile start tile of drag
ae78fc3c6b20 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6452
diff changeset
   751
 * @param flags operation to perform
ae78fc3c6b20 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6452
diff changeset
   752
 * @param p1 end tile of drag
ae78fc3c6b20 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6452
diff changeset
   753
 * @param p2 various bitstuffed elements
ae78fc3c6b20 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6452
diff changeset
   754
 * - p2 = (bit 0-3) - railroad type normal/maglev (0 = normal, 1 = mono, 2 = maglev)
ae78fc3c6b20 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6452
diff changeset
   755
 * - p2 = (bit 4-6) - track-orientation, valid values: 0-5 (Track enum)
ae78fc3c6b20 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6452
diff changeset
   756
 * - p2 = (bit 7)   - 0 = build, 1 = remove tracks
1796
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1782
diff changeset
   757
 * @see CmdRailTrackHelper
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1782
diff changeset
   758
 */
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6791
diff changeset
   759
CommandCost CmdRemoveRailroadTrack(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   760
{
7931
b0a46cd92225 (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents: 7929
diff changeset
   761
	return CmdRailTrackHelper(tile, flags, p1, SetBit(p2, 7));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   762
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   763
1775
548dc04d50e2 (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1719
diff changeset
   764
/** Build a train 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: 3486
diff changeset
   765
 * @param tile position of the train depot
6483
ae78fc3c6b20 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6452
diff changeset
   766
 * @param flags operation to perform
1775
548dc04d50e2 (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1719
diff changeset
   767
 * @param p1 rail type
6134
871305fd9ab7 (svn r8876) -Fix
tron
parents: 6133
diff changeset
   768
 * @param p2 bit 0..1 entrance direction (DiagDirection)
2085
876f20a0e843 (svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents: 2049
diff changeset
   769
 *
876f20a0e843 (svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents: 2049
diff changeset
   770
 * @todo When checking for the tile slope,
876f20a0e843 (svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents: 2049
diff changeset
   771
 * 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
   772
 */
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6791
diff changeset
   773
CommandCost CmdBuildTrainDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   774
{
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3575
diff changeset
   775
	Slope tileh;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   776
1775
548dc04d50e2 (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1719
diff changeset
   777
	/* check railtype and valid direction for depot (0 through 3), 4 in total */
8236
8a5dd0b42e47 (svn r11800) -Codechange: move some functions to a more logical location + some type safety.
rubidium
parents: 8230
diff changeset
   778
	if (!ValParamRailtype((RailType)p1)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   779
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   780
	tileh = GetTileSlope(tile, NULL);
2085
876f20a0e843 (svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents: 2049
diff changeset
   781
6134
871305fd9ab7 (svn r8876) -Fix
tron
parents: 6133
diff changeset
   782
	DiagDirection dir = Extract<DiagDirection, 0>(p2);
871305fd9ab7 (svn r8876) -Fix
tron
parents: 6133
diff changeset
   783
2085
876f20a0e843 (svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents: 2049
diff changeset
   784
	/* Prohibit construction if
4549
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4483
diff changeset
   785
	 * The tile is non-flat AND
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4483
diff changeset
   786
	 * 1) The AI is "old-school"
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4483
diff changeset
   787
	 * 2) build-on-slopes is disabled
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4483
diff changeset
   788
	 * 3) the tile is steep i.e. spans two height levels
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4483
diff changeset
   789
	 * 4) the exit points in the wrong direction
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4483
diff changeset
   790
	 */
2085
876f20a0e843 (svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents: 2049
diff changeset
   791
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3575
diff changeset
   792
	if (tileh != SLOPE_FLAT && (
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10172
diff changeset
   793
				_is_old_ai_company ||
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
   794
				!_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: 3575
diff changeset
   795
				IsSteepSlope(tileh) ||
6134
871305fd9ab7 (svn r8876) -Fix
tron
parents: 6133
diff changeset
   796
				!CanBuildDepotByTileh(dir, tileh)
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
   797
			)) {
49c8a096033f (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2544
diff changeset
   798
		return_cmd_error(STR_0007_FLAT_LAND_REQUIRED);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   799
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   800
8230
64f28fe2d5c8 (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8228
diff changeset
   801
	CommandCost cost = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6946
diff changeset
   802
	if (CmdFailed(cost)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   803
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
   804
	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: 5380
diff changeset
   805
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: 9006
diff changeset
   806
	if (!Depot::CanAllocateItem()) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   807
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   808
	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: 9006
diff changeset
   809
		Depot *d = new Depot(tile);
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10172
diff changeset
   810
		MakeRailDepot(tile, _current_company, dir, (RailType)p1);
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: 3099
diff changeset
   811
		MarkTileDirtyByTile(tile);
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   812
10236
50afe9dd466e (svn r14464) -Codechange: replace (uint)-1 with UINT_MAX (PhilSophus)
rubidium
parents: 10213
diff changeset
   813
		d->town_index = ClosestTownFromTile(tile, UINT_MAX)->index;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   814
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10172
diff changeset
   815
		AddSideToSignalBuffer(tile, INVALID_DIAGDIR, _current_company);
9224
93528d9cb96d (svn r13090) -Codechange: add functions for direct conversion from DiagDirection to Track and Trackbits
smatz
parents: 9154
diff changeset
   816
		YapfNotifyTrackLayoutChange(tile, DiagDirToDiagTrack(dir));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   817
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   818
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6946
diff changeset
   819
	return cost.AddCost(_price.build_train_depot);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   820
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   821
1775
548dc04d50e2 (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1719
diff changeset
   822
/** Build signals, alternate between double/single, signal/semaphore,
5731
c68613da5c4d (svn r8274) -Codechange (r8151): Move the automatic semaphore/signal checks inside the CMD_ functions where they are supposed to be. Achieve this by adding a seperate bit to p1/p2 to hold the CTRL-modifier. While here, use proper types, and 'unify' the parameter bit-meanings. 0 - ctrl-pressed, 1 - signal/semaphore, 2-4 - trackbits, 5 - remove (internal), 24-31 - drag density.
Darkvater
parents: 5668
diff changeset
   823
 * pre/exit/combo-signals, and what-else not. If the rail piece does not
c68613da5c4d (svn r8274) -Codechange (r8151): Move the automatic semaphore/signal checks inside the CMD_ functions where they are supposed to be. Achieve this by adding a seperate bit to p1/p2 to hold the CTRL-modifier. While here, use proper types, and 'unify' the parameter bit-meanings. 0 - ctrl-pressed, 1 - signal/semaphore, 2-4 - trackbits, 5 - remove (internal), 24-31 - drag density.
Darkvater
parents: 5668
diff changeset
   824
 * have any signals, bit 4 (cycle signal-type) is ignored
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: 3486
diff changeset
   825
 * @param tile tile where to build the signals
6483
ae78fc3c6b20 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6452
diff changeset
   826
 * @param flags operation to perform
1775
548dc04d50e2 (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1719
diff changeset
   827
 * @param p1 various bitstuffed elements
5735
9f3729784816 (svn r8279) -Regression (r8274): Removing signals could fail under certain circumstances (not the proper bits of p1/p2 were set to trackbits). Moved trackbits back to bits 0..2, ctrl to 3, semaphore to 4. Also lower the decision of the ctrl-override of signal/semaphore from the GUI into the cmd function since we are passing the ctrl-bit anyways. Bug(s) found by Frostregen; thanks
Darkvater
parents: 5731
diff changeset
   828
 * - p1 = (bit 0-2) - track-orientation, valid values: 0-5 (Track enum)
7991
d6a95a5593ba (svn r11547) -Add: signal selection GUI for the ones that really like to use that over CTRL. Patch by BigBB.
rubidium
parents: 7977
diff changeset
   829
 * - p1 = (bit 3)   - 1 = override signal/semaphore, or pre/exit/combo signal or (for bit 7) toggle variant (CTRL-toggle)
5735
9f3729784816 (svn r8279) -Regression (r8274): Removing signals could fail under certain circumstances (not the proper bits of p1/p2 were set to trackbits). Moved trackbits back to bits 0..2, ctrl to 3, semaphore to 4. Also lower the decision of the ctrl-override of signal/semaphore from the GUI into the cmd function since we are passing the ctrl-bit anyways. Bug(s) found by Frostregen; thanks
Darkvater
parents: 5731
diff changeset
   830
 * - p1 = (bit 4)   - 0 = signals, 1 = semaphores
9793
359d2460833b (svn r13935) -Codechange [YAPP]: PBS signals can now be built with the normal signal tools. (michi_cc)
rubidium
parents: 9791
diff changeset
   831
 * - p1 = (bit 5-7) - type of the signal, for valid values see enum SignalType in rail_map.h
359d2460833b (svn r13935) -Codechange [YAPP]: PBS signals can now be built with the normal signal tools. (michi_cc)
rubidium
parents: 9791
diff changeset
   832
 * - p1 = (bit 8)   - convert the present signal type and variant
359d2460833b (svn r13935) -Codechange [YAPP]: PBS signals can now be built with the normal signal tools. (michi_cc)
rubidium
parents: 9791
diff changeset
   833
 * - p1 = (bit 9-11)- start cycle from this signal type
359d2460833b (svn r13935) -Codechange [YAPP]: PBS signals can now be built with the normal signal tools. (michi_cc)
rubidium
parents: 9791
diff changeset
   834
 * - p1 = (bit 12-14)-wrap around after this signal type
10172
dba313cad70f (svn r14365) -Backport (r14364 from NoAI): add the ability do CmdBuildSingleSignal to directly place the correct signal, instead requiring multiple inputs before doing so
glx
parents: 10165
diff changeset
   835
 * - p1 = (bit 15-16)-cycle the signal direction this many times
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   836
 * @param p2 used for CmdBuildManySignals() to copy direction of first signal
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   837
 * TODO: p2 should be replaced by two bits for "along" and "against" the track.
58
b9fdcc9b5c90 (svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents: 39
diff changeset
   838
 */
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6791
diff changeset
   839
CommandCost CmdBuildSingleSignal(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   840
{
5735
9f3729784816 (svn r8279) -Regression (r8274): Removing signals could fail under certain circumstances (not the proper bits of p1/p2 were set to trackbits). Moved trackbits back to bits 0..2, ctrl to 3, semaphore to 4. Also lower the decision of the ctrl-override of signal/semaphore from the GUI into the cmd function since we are passing the ctrl-bit anyways. Bug(s) found by Frostregen; thanks
Darkvater
parents: 5731
diff changeset
   841
	Track track = (Track)GB(p1, 0, 3);
7991
d6a95a5593ba (svn r11547) -Add: signal selection GUI for the ones that really like to use that over CTRL. Patch by BigBB.
rubidium
parents: 7977
diff changeset
   842
	bool ctrl_pressed = HasBit(p1, 3); // was the CTRL button pressed
d6a95a5593ba (svn r11547) -Add: signal selection GUI for the ones that really like to use that over CTRL. Patch by BigBB.
rubidium
parents: 7977
diff changeset
   843
	SignalVariant sigvar = (ctrl_pressed ^ HasBit(p1, 4)) ? SIG_SEMAPHORE : SIG_ELECTRIC; // the signal variant of the new signal
9793
359d2460833b (svn r13935) -Codechange [YAPP]: PBS signals can now be built with the normal signal tools. (michi_cc)
rubidium
parents: 9791
diff changeset
   844
	SignalType sigtype = (SignalType)GB(p1, 5, 3); // the signal type of the new signal
359d2460833b (svn r13935) -Codechange [YAPP]: PBS signals can now be built with the normal signal tools. (michi_cc)
rubidium
parents: 9791
diff changeset
   845
	bool convert_signal = HasBit(p1, 8); // convert button pressed
359d2460833b (svn r13935) -Codechange [YAPP]: PBS signals can now be built with the normal signal tools. (michi_cc)
rubidium
parents: 9791
diff changeset
   846
	SignalType cycle_start = (SignalType)GB(p1, 9, 3);
359d2460833b (svn r13935) -Codechange [YAPP]: PBS signals can now be built with the normal signal tools. (michi_cc)
rubidium
parents: 9791
diff changeset
   847
	SignalType cycle_stop = (SignalType)GB(p1, 12, 3);
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6791
diff changeset
   848
	CommandCost cost;
10172
dba313cad70f (svn r14365) -Backport (r14364 from NoAI): add the ability do CmdBuildSingleSignal to directly place the correct signal, instead requiring multiple inputs before doing so
glx
parents: 10165
diff changeset
   849
	uint num_dir_cycle = GB(p1, 15, 2);
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   850
9793
359d2460833b (svn r13935) -Codechange [YAPP]: PBS signals can now be built with the normal signal tools. (michi_cc)
rubidium
parents: 9791
diff changeset
   851
	if (sigtype > SIGTYPE_LAST) return CMD_ERROR;
359d2460833b (svn r13935) -Codechange [YAPP]: PBS signals can now be built with the normal signal tools. (michi_cc)
rubidium
parents: 9791
diff changeset
   852
7448
dbcc29a92db8 (svn r10922) -Codechange: Allow building and removing tracks and signals when there is a
maedhros
parents: 7389
diff changeset
   853
	if (!ValParamTrackOrientation(track) || !IsTileType(tile, MP_RAILWAY) || !EnsureNoTrainOnTrack(tile, track))
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   854
		return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   855
1775
548dc04d50e2 (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1719
diff changeset
   856
	/* Protect against invalid signal copying */
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   857
	if (p2 != 0 && (p2 & SignalOnTrack(track)) == 0) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   858
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   859
	/* You can only build signals on plain rail tiles, and the selected track must exist */
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   860
	if (!IsPlainRailTile(tile) || !HasTrack(tile, track)) return CMD_ERROR;
1084
95b7385f8b7b (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   861
95b7385f8b7b (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   862
	if (!CheckTileOwnership(tile)) return CMD_ERROR;
95b7385f8b7b (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   863
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   864
	{
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4067
diff changeset
   865
		/* See if this is a valid track combination for signals, (ie, no overlap) */
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4067
diff changeset
   866
		TrackBits trackbits = GetTrackBits(tile);
7833
ba402b153b79 (svn r11383) -Codechange: fixed all the mess around KillFirstBit (tnx to Rubidium and skidd13)
truelight
parents: 7793
diff changeset
   867
		if (KillFirstBit(trackbits) != TRACK_BIT_NONE && /* More than one track present */
3258
1c079364726d (svn r3946) Add short hand names for common track combinations
tron
parents: 3254
diff changeset
   868
				trackbits != TRACK_BIT_HORZ &&
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4067
diff changeset
   869
				trackbits != TRACK_BIT_VERT) {
7991
d6a95a5593ba (svn r11547) -Add: signal selection GUI for the ones that really like to use that over CTRL. Patch by BigBB.
rubidium
parents: 7977
diff changeset
   870
			return_cmd_error(STR_1005_NO_SUITABLE_RAILROAD_TRACK);
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4067
diff changeset
   871
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   872
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   873
7991
d6a95a5593ba (svn r11547) -Add: signal selection GUI for the ones that really like to use that over CTRL. Patch by BigBB.
rubidium
parents: 7977
diff changeset
   874
	/* you can not convert a signal if no signal is on track */
d6a95a5593ba (svn r11547) -Add: signal selection GUI for the ones that really like to use that over CTRL. Patch by BigBB.
rubidium
parents: 7977
diff changeset
   875
	if (convert_signal && !HasSignalOnTrack(tile, track)) return CMD_ERROR;
d6a95a5593ba (svn r11547) -Add: signal selection GUI for the ones that really like to use that over CTRL. Patch by BigBB.
rubidium
parents: 7977
diff changeset
   876
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   877
	if (!HasSignalOnTrack(tile, track)) {
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6406
diff changeset
   878
		/* build new signals */
8230
64f28fe2d5c8 (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8228
diff changeset
   879
		cost = CommandCost(EXPENSES_CONSTRUCTION, _price.build_signals);
1066
eaef1465d3ab (svn r1567) -Fix: [110452] On horizontal/vertical tracks you are also charged for building/removing signals on the parallel track on the same tile. Signal updating is also correct. (Hackykid)
darkvater
parents: 1059
diff changeset
   880
	} else {
6770
408585d467f9 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 6753
diff changeset
   881
		if (p2 != 0 && sigvar != GetSignalVariant(tile, track)) {
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6406
diff changeset
   882
			/* convert signals <-> semaphores */
8230
64f28fe2d5c8 (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8228
diff changeset
   883
			cost = CommandCost(EXPENSES_CONSTRUCTION, _price.build_signals + _price.remove_signals);
7991
d6a95a5593ba (svn r11547) -Add: signal selection GUI for the ones that really like to use that over CTRL. Patch by BigBB.
rubidium
parents: 7977
diff changeset
   884
d6a95a5593ba (svn r11547) -Add: signal selection GUI for the ones that really like to use that over CTRL. Patch by BigBB.
rubidium
parents: 7977
diff changeset
   885
		} else if (convert_signal) {
d6a95a5593ba (svn r11547) -Add: signal selection GUI for the ones that really like to use that over CTRL. Patch by BigBB.
rubidium
parents: 7977
diff changeset
   886
			/* convert button pressed */
d6a95a5593ba (svn r11547) -Add: signal selection GUI for the ones that really like to use that over CTRL. Patch by BigBB.
rubidium
parents: 7977
diff changeset
   887
			if (ctrl_pressed || GetSignalVariant(tile, track) != sigvar) {
d6a95a5593ba (svn r11547) -Add: signal selection GUI for the ones that really like to use that over CTRL. Patch by BigBB.
rubidium
parents: 7977
diff changeset
   888
				/* convert electric <-> semaphore */
8230
64f28fe2d5c8 (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8228
diff changeset
   889
				cost = CommandCost(EXPENSES_CONSTRUCTION, _price.build_signals + _price.remove_signals);
7991
d6a95a5593ba (svn r11547) -Add: signal selection GUI for the ones that really like to use that over CTRL. Patch by BigBB.
rubidium
parents: 7977
diff changeset
   890
			} else {
d6a95a5593ba (svn r11547) -Add: signal selection GUI for the ones that really like to use that over CTRL. Patch by BigBB.
rubidium
parents: 7977
diff changeset
   891
				/* it is free to change signal type: normal-pre-exit-combo */
d6a95a5593ba (svn r11547) -Add: signal selection GUI for the ones that really like to use that over CTRL. Patch by BigBB.
rubidium
parents: 7977
diff changeset
   892
				cost = CommandCost();
d6a95a5593ba (svn r11547) -Add: signal selection GUI for the ones that really like to use that over CTRL. Patch by BigBB.
rubidium
parents: 7977
diff changeset
   893
			}
d6a95a5593ba (svn r11547) -Add: signal selection GUI for the ones that really like to use that over CTRL. Patch by BigBB.
rubidium
parents: 7977
diff changeset
   894
1084
95b7385f8b7b (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   895
		} else {
6432
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6427
diff changeset
   896
			/* it is free to change orientation/pre-exit-combo signals */
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6946
diff changeset
   897
			cost = CommandCost();
1084
95b7385f8b7b (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   898
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   899
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   900
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   901
	if (flags & DC_EXEC) {
9830
566cbd04836f (svn r13973) -Codechange [YAPP]: Improve the behavior when changing signals to not cause stale reservations. (michi_cc)
smatz
parents: 9815
diff changeset
   902
		Vehicle *v = NULL;
566cbd04836f (svn r13973) -Codechange [YAPP]: Improve the behavior when changing signals to not cause stale reservations. (michi_cc)
smatz
parents: 9815
diff changeset
   903
		/* The new/changed signal could block our path. As this can lead to
566cbd04836f (svn r13973) -Codechange [YAPP]: Improve the behavior when changing signals to not cause stale reservations. (michi_cc)
smatz
parents: 9815
diff changeset
   904
		 * stale reservations, we clear the path reservation here and try
566cbd04836f (svn r13973) -Codechange [YAPP]: Improve the behavior when changing signals to not cause stale reservations. (michi_cc)
smatz
parents: 9815
diff changeset
   905
		 * to redo it later on. */
566cbd04836f (svn r13973) -Codechange [YAPP]: Improve the behavior when changing signals to not cause stale reservations. (michi_cc)
smatz
parents: 9815
diff changeset
   906
		if (HasReservedTracks(tile, TrackToTrackBits(track))) {
566cbd04836f (svn r13973) -Codechange [YAPP]: Improve the behavior when changing signals to not cause stale reservations. (michi_cc)
smatz
parents: 9815
diff changeset
   907
			v = GetTrainForReservation(tile, track);
566cbd04836f (svn r13973) -Codechange [YAPP]: Improve the behavior when changing signals to not cause stale reservations. (michi_cc)
smatz
parents: 9815
diff changeset
   908
			if (v != NULL) FreeTrainTrackReservation(v);
566cbd04836f (svn r13973) -Codechange [YAPP]: Improve the behavior when changing signals to not cause stale reservations. (michi_cc)
smatz
parents: 9815
diff changeset
   909
		}
566cbd04836f (svn r13973) -Codechange [YAPP]: Improve the behavior when changing signals to not cause stale reservations. (michi_cc)
smatz
parents: 9815
diff changeset
   910
4182
48dba107ff43 (svn r5624) Use {IsPlainRailTile,IsRailDepot,IsRailWaypoint,HasSignals}() instead of GetRailTile{T,Subt}ype() - this is more concise and a bit more flexible if/when the rail tile encoding changes
tron
parents: 4180
diff changeset
   911
		if (!HasSignals(tile)) {
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6406
diff changeset
   912
			/* there are no signals at all on this tile yet */
6172
e6d7a5b3d63f (svn r8935) -Codechange: unification of track type between road and rail tiles, unification of ground type between normal rail tiles and depots/waypoints and removing the need for RailTileSubType.
rubidium
parents: 6160
diff changeset
   913
			SetHasSignals(tile, true);
6753
c1013c837417 (svn r9988) -Codechange: remove the last direct map accesses, except the ones needed for the savegame saving/loading mechanisms.
rubidium
parents: 6728
diff changeset
   914
			SetSignalStates(tile, 0xF); // all signals are on
c1013c837417 (svn r9988) -Codechange: remove the last direct map accesses, except the ones needed for the savegame saving/loading mechanisms.
rubidium
parents: 6728
diff changeset
   915
			SetPresentSignals(tile, 0); // no signals built by default
7991
d6a95a5593ba (svn r11547) -Add: signal selection GUI for the ones that really like to use that over CTRL. Patch by BigBB.
rubidium
parents: 7977
diff changeset
   916
			SetSignalType(tile, track, sigtype);
6770
408585d467f9 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 6753
diff changeset
   917
			SetSignalVariant(tile, track, sigvar);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   918
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   919
1084
95b7385f8b7b (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   920
		if (p2 == 0) {
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   921
			if (!HasSignalOnTrack(tile, track)) {
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6406
diff changeset
   922
				/* build new signals */
9793
359d2460833b (svn r13935) -Codechange [YAPP]: PBS signals can now be built with the normal signal tools. (michi_cc)
rubidium
parents: 9791
diff changeset
   923
				SetPresentSignals(tile, GetPresentSignals(tile) | (IsPbsSignal(sigtype) ? KillFirstBit(SignalOnTrack(track)) : SignalOnTrack(track)));
7991
d6a95a5593ba (svn r11547) -Add: signal selection GUI for the ones that really like to use that over CTRL. Patch by BigBB.
rubidium
parents: 7977
diff changeset
   924
				SetSignalType(tile, track, sigtype);
6770
408585d467f9 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 6753
diff changeset
   925
				SetSignalVariant(tile, track, sigvar);
10172
dba313cad70f (svn r14365) -Backport (r14364 from NoAI): add the ability do CmdBuildSingleSignal to directly place the correct signal, instead requiring multiple inputs before doing so
glx
parents: 10165
diff changeset
   926
				while (num_dir_cycle-- > 0) CycleSignalSide(tile, track);
1084
95b7385f8b7b (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   927
			} else {
7991
d6a95a5593ba (svn r11547) -Add: signal selection GUI for the ones that really like to use that over CTRL. Patch by BigBB.
rubidium
parents: 7977
diff changeset
   928
				if (convert_signal) {
d6a95a5593ba (svn r11547) -Add: signal selection GUI for the ones that really like to use that over CTRL. Patch by BigBB.
rubidium
parents: 7977
diff changeset
   929
					/* convert signal button pressed */
d6a95a5593ba (svn r11547) -Add: signal selection GUI for the ones that really like to use that over CTRL. Patch by BigBB.
rubidium
parents: 7977
diff changeset
   930
					if (ctrl_pressed) {
d6a95a5593ba (svn r11547) -Add: signal selection GUI for the ones that really like to use that over CTRL. Patch by BigBB.
rubidium
parents: 7977
diff changeset
   931
						/* toggle the pressent signal variant: SIG_ELECTRIC <-> SIG_SEMAPHORE */
d6a95a5593ba (svn r11547) -Add: signal selection GUI for the ones that really like to use that over CTRL. Patch by BigBB.
rubidium
parents: 7977
diff changeset
   932
						SetSignalVariant(tile, track, (GetSignalVariant(tile, track) == SIG_ELECTRIC) ? SIG_SEMAPHORE : SIG_ELECTRIC);
9972
ec5617f4ae33 (svn r14129) -Fix (r13935) [FS#2247]: Signal state for PBS signals was not updated when cycling the signal side. Patch by michi_cc with a small addition from me.
frosch
parents: 9949
diff changeset
   933
						/* Query current signal type so the check for PBS signals below works. */
ec5617f4ae33 (svn r14129) -Fix (r13935) [FS#2247]: Signal state for PBS signals was not updated when cycling the signal side. Patch by michi_cc with a small addition from me.
frosch
parents: 9949
diff changeset
   934
						sigtype = GetSignalType(tile, track);
7991
d6a95a5593ba (svn r11547) -Add: signal selection GUI for the ones that really like to use that over CTRL. Patch by BigBB.
rubidium
parents: 7977
diff changeset
   935
					} else {
d6a95a5593ba (svn r11547) -Add: signal selection GUI for the ones that really like to use that over CTRL. Patch by BigBB.
rubidium
parents: 7977
diff changeset
   936
						/* convert the present signal to the chosen type and variant */
d6a95a5593ba (svn r11547) -Add: signal selection GUI for the ones that really like to use that over CTRL. Patch by BigBB.
rubidium
parents: 7977
diff changeset
   937
						SetSignalType(tile, track, sigtype);
d6a95a5593ba (svn r11547) -Add: signal selection GUI for the ones that really like to use that over CTRL. Patch by BigBB.
rubidium
parents: 7977
diff changeset
   938
						SetSignalVariant(tile, track, sigvar);
9795
55c38728362c (svn r13937) -Codechange [YAPP]: Don't cycle through two-sided PBS signals during build. (michi_cc)
rubidium
parents: 9794
diff changeset
   939
						if (IsPbsSignal(sigtype) && (GetPresentSignals(tile) & SignalOnTrack(track)) == SignalOnTrack(track)) {
55c38728362c (svn r13937) -Codechange [YAPP]: Don't cycle through two-sided PBS signals during build. (michi_cc)
rubidium
parents: 9794
diff changeset
   940
							SetPresentSignals(tile, (GetPresentSignals(tile) & ~SignalOnTrack(track)) | KillFirstBit(SignalOnTrack(track)));
55c38728362c (svn r13937) -Codechange [YAPP]: Don't cycle through two-sided PBS signals during build. (michi_cc)
rubidium
parents: 9794
diff changeset
   941
						}
7991
d6a95a5593ba (svn r11547) -Add: signal selection GUI for the ones that really like to use that over CTRL. Patch by BigBB.
rubidium
parents: 7977
diff changeset
   942
					}
d6a95a5593ba (svn r11547) -Add: signal selection GUI for the ones that really like to use that over CTRL. Patch by BigBB.
rubidium
parents: 7977
diff changeset
   943
d6a95a5593ba (svn r11547) -Add: signal selection GUI for the ones that really like to use that over CTRL. Patch by BigBB.
rubidium
parents: 7977
diff changeset
   944
				} else if (ctrl_pressed) {
9793
359d2460833b (svn r13935) -Codechange [YAPP]: PBS signals can now be built with the normal signal tools. (michi_cc)
rubidium
parents: 9791
diff changeset
   945
					/* cycle between cycle_start and cycle_end */
359d2460833b (svn r13935) -Codechange [YAPP]: PBS signals can now be built with the normal signal tools. (michi_cc)
rubidium
parents: 9791
diff changeset
   946
					sigtype = (SignalType)(GetSignalType(tile, track) + 1);
359d2460833b (svn r13935) -Codechange [YAPP]: PBS signals can now be built with the normal signal tools. (michi_cc)
rubidium
parents: 9791
diff changeset
   947
359d2460833b (svn r13935) -Codechange [YAPP]: PBS signals can now be built with the normal signal tools. (michi_cc)
rubidium
parents: 9791
diff changeset
   948
					if (sigtype < cycle_start || sigtype > cycle_stop) sigtype = cycle_start;
359d2460833b (svn r13935) -Codechange [YAPP]: PBS signals can now be built with the normal signal tools. (michi_cc)
rubidium
parents: 9791
diff changeset
   949
359d2460833b (svn r13935) -Codechange [YAPP]: PBS signals can now be built with the normal signal tools. (michi_cc)
rubidium
parents: 9791
diff changeset
   950
					SetSignalType(tile, track, sigtype);
9795
55c38728362c (svn r13937) -Codechange [YAPP]: Don't cycle through two-sided PBS signals during build. (michi_cc)
rubidium
parents: 9794
diff changeset
   951
					if (IsPbsSignal(sigtype) && (GetPresentSignals(tile) & SignalOnTrack(track)) == SignalOnTrack(track)) {
55c38728362c (svn r13937) -Codechange [YAPP]: Don't cycle through two-sided PBS signals during build. (michi_cc)
rubidium
parents: 9794
diff changeset
   952
						SetPresentSignals(tile, (GetPresentSignals(tile) & ~SignalOnTrack(track)) | KillFirstBit(SignalOnTrack(track)));
55c38728362c (svn r13937) -Codechange [YAPP]: Don't cycle through two-sided PBS signals during build. (michi_cc)
rubidium
parents: 9794
diff changeset
   953
					}
1084
95b7385f8b7b (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   954
				} else {
7991
d6a95a5593ba (svn r11547) -Add: signal selection GUI for the ones that really like to use that over CTRL. Patch by BigBB.
rubidium
parents: 7977
diff changeset
   955
					/* cycle the signal side: both -> left -> right -> both -> ... */
3522
888ac5081c6e (svn r4378) -Add and make use of an accessor function two-way => one-way => one-way => two-way signal cycling
celestar
parents: 3521
diff changeset
   956
					CycleSignalSide(tile, track);
9972
ec5617f4ae33 (svn r14129) -Fix (r13935) [FS#2247]: Signal state for PBS signals was not updated when cycling the signal side. Patch by michi_cc with a small addition from me.
frosch
parents: 9949
diff changeset
   957
					/* Query current signal type so the check for PBS signals below works. */
ec5617f4ae33 (svn r14129) -Fix (r13935) [FS#2247]: Signal state for PBS signals was not updated when cycling the signal side. Patch by michi_cc with a small addition from me.
frosch
parents: 9949
diff changeset
   958
					sigtype = GetSignalType(tile, track);
1084
95b7385f8b7b (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   959
				}
95b7385f8b7b (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   960
			}
58
b9fdcc9b5c90 (svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents: 39
diff changeset
   961
		} else {
1084
95b7385f8b7b (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   962
			/* If CmdBuildManySignals is called with copying signals, just copy the
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   963
			 * direction of the first signal given as parameter by CmdBuildManySignals */
6753
c1013c837417 (svn r9988) -Codechange: remove the last direct map accesses, except the ones needed for the savegame saving/loading mechanisms.
rubidium
parents: 6728
diff changeset
   964
			SetPresentSignals(tile, (GetPresentSignals(tile) & ~SignalOnTrack(track)) | (p2 & SignalOnTrack(track)));
6770
408585d467f9 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 6753
diff changeset
   965
			SetSignalVariant(tile, track, sigvar);
9794
dd4a7638d2d6 (svn r13936) -Codechange [YAPP]: Enable the auto-signal tool to build PBS signals and honor the default signal type. (michi_cc)
rubidium
parents: 9793
diff changeset
   966
			SetSignalType(tile, track, sigtype);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   967
		}
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   968
9793
359d2460833b (svn r13935) -Codechange [YAPP]: PBS signals can now be built with the normal signal tools. (michi_cc)
rubidium
parents: 9791
diff changeset
   969
		if (IsPbsSignal(sigtype)) {
9972
ec5617f4ae33 (svn r14129) -Fix (r13935) [FS#2247]: Signal state for PBS signals was not updated when cycling the signal side. Patch by michi_cc with a small addition from me.
frosch
parents: 9949
diff changeset
   970
			/* PBS signals should show red unless they are on a reservation. */
9793
359d2460833b (svn r13935) -Codechange [YAPP]: PBS signals can now be built with the normal signal tools. (michi_cc)
rubidium
parents: 9791
diff changeset
   971
			uint mask = GetPresentSignals(tile) & SignalOnTrack(track);
10236
50afe9dd466e (svn r14464) -Codechange: replace (uint)-1 with UINT_MAX (PhilSophus)
rubidium
parents: 10213
diff changeset
   972
			SetSignalStates(tile, (GetSignalStates(tile) & ~mask) | ((HasBit(GetTrackReservation(tile), track) ? UINT_MAX : 0) & mask));
9793
359d2460833b (svn r13935) -Codechange [YAPP]: PBS signals can now be built with the normal signal tools. (michi_cc)
rubidium
parents: 9791
diff changeset
   973
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   974
		MarkTileDirtyByTile(tile);
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10172
diff changeset
   975
		AddTrackToSignalBuffer(tile, track, _current_company);
3900
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3884
diff changeset
   976
		YapfNotifyTrackLayoutChange(tile, track);
9830
566cbd04836f (svn r13973) -Codechange [YAPP]: Improve the behavior when changing signals to not cause stale reservations. (michi_cc)
smatz
parents: 9815
diff changeset
   977
		if (v != NULL) TryPathReserve(v, true);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   978
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   979
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   980
	return cost;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   981
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   982
7163
99ef91ad6415 (svn r10437) -Feature: Automatic signal completion, enabled by pressing ctrl when dragging signals. Signals will continue following track until an existing signal, junction or station are reached. This currently replaces the existing use of ctrl-drag for changing existing signal type.
peter1138
parents: 7158
diff changeset
   983
static bool CheckSignalAutoFill(TileIndex &tile, Trackdir &trackdir, int &signal_ctr, bool remove)
99ef91ad6415 (svn r10437) -Feature: Automatic signal completion, enabled by pressing ctrl when dragging signals. Signals will continue following track until an existing signal, junction or station are reached. This currently replaces the existing use of ctrl-drag for changing existing signal type.
peter1138
parents: 7158
diff changeset
   984
{
99ef91ad6415 (svn r10437) -Feature: Automatic signal completion, enabled by pressing ctrl when dragging signals. Signals will continue following track until an existing signal, junction or station are reached. This currently replaces the existing use of ctrl-drag for changing existing signal type.
peter1138
parents: 7158
diff changeset
   985
	tile = AddTileIndexDiffCWrap(tile, _trackdelta[trackdir]);
99ef91ad6415 (svn r10437) -Feature: Automatic signal completion, enabled by pressing ctrl when dragging signals. Signals will continue following track until an existing signal, junction or station are reached. This currently replaces the existing use of ctrl-drag for changing existing signal type.
peter1138
parents: 7158
diff changeset
   986
	if (tile == INVALID_TILE) return false;
99ef91ad6415 (svn r10437) -Feature: Automatic signal completion, enabled by pressing ctrl when dragging signals. Signals will continue following track until an existing signal, junction or station are reached. This currently replaces the existing use of ctrl-drag for changing existing signal type.
peter1138
parents: 7158
diff changeset
   987
99ef91ad6415 (svn r10437) -Feature: Automatic signal completion, enabled by pressing ctrl when dragging signals. Signals will continue following track until an existing signal, junction or station are reached. This currently replaces the existing use of ctrl-drag for changing existing signal type.
peter1138
parents: 7158
diff changeset
   988
	/* Check for track bits on the new tile */
8616
fd862a55c47f (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8598
diff changeset
   989
	TrackdirBits trackdirbits = TrackStatusToTrackdirBits(GetTileTrackStatus(tile, TRANSPORT_RAIL, 0));
7163
99ef91ad6415 (svn r10437) -Feature: Automatic signal completion, enabled by pressing ctrl when dragging signals. Signals will continue following track until an existing signal, junction or station are reached. This currently replaces the existing use of ctrl-drag for changing existing signal type.
peter1138
parents: 7158
diff changeset
   990
99ef91ad6415 (svn r10437) -Feature: Automatic signal completion, enabled by pressing ctrl when dragging signals. Signals will continue following track until an existing signal, junction or station are reached. This currently replaces the existing use of ctrl-drag for changing existing signal type.
peter1138
parents: 7158
diff changeset
   991
	if (TracksOverlap(TrackdirBitsToTrackBits(trackdirbits))) return false;
99ef91ad6415 (svn r10437) -Feature: Automatic signal completion, enabled by pressing ctrl when dragging signals. Signals will continue following track until an existing signal, junction or station are reached. This currently replaces the existing use of ctrl-drag for changing existing signal type.
peter1138
parents: 7158
diff changeset
   992
	trackdirbits &= TrackdirReachesTrackdirs(trackdir);
99ef91ad6415 (svn r10437) -Feature: Automatic signal completion, enabled by pressing ctrl when dragging signals. Signals will continue following track until an existing signal, junction or station are reached. This currently replaces the existing use of ctrl-drag for changing existing signal type.
peter1138
parents: 7158
diff changeset
   993
99ef91ad6415 (svn r10437) -Feature: Automatic signal completion, enabled by pressing ctrl when dragging signals. Signals will continue following track until an existing signal, junction or station are reached. This currently replaces the existing use of ctrl-drag for changing existing signal type.
peter1138
parents: 7158
diff changeset
   994
	/* No track bits, must stop */
99ef91ad6415 (svn r10437) -Feature: Automatic signal completion, enabled by pressing ctrl when dragging signals. Signals will continue following track until an existing signal, junction or station are reached. This currently replaces the existing use of ctrl-drag for changing existing signal type.
peter1138
parents: 7158
diff changeset
   995
	if (trackdirbits == TRACKDIR_BIT_NONE) return false;
99ef91ad6415 (svn r10437) -Feature: Automatic signal completion, enabled by pressing ctrl when dragging signals. Signals will continue following track until an existing signal, junction or station are reached. This currently replaces the existing use of ctrl-drag for changing existing signal type.
peter1138
parents: 7158
diff changeset
   996
99ef91ad6415 (svn r10437) -Feature: Automatic signal completion, enabled by pressing ctrl when dragging signals. Signals will continue following track until an existing signal, junction or station are reached. This currently replaces the existing use of ctrl-drag for changing existing signal type.
peter1138
parents: 7158
diff changeset
   997
	/* Get the first track dir */
99ef91ad6415 (svn r10437) -Feature: Automatic signal completion, enabled by pressing ctrl when dragging signals. Signals will continue following track until an existing signal, junction or station are reached. This currently replaces the existing use of ctrl-drag for changing existing signal type.
peter1138
parents: 7158
diff changeset
   998
	trackdir = RemoveFirstTrackdir(&trackdirbits);
99ef91ad6415 (svn r10437) -Feature: Automatic signal completion, enabled by pressing ctrl when dragging signals. Signals will continue following track until an existing signal, junction or station are reached. This currently replaces the existing use of ctrl-drag for changing existing signal type.
peter1138
parents: 7158
diff changeset
   999
99ef91ad6415 (svn r10437) -Feature: Automatic signal completion, enabled by pressing ctrl when dragging signals. Signals will continue following track until an existing signal, junction or station are reached. This currently replaces the existing use of ctrl-drag for changing existing signal type.
peter1138
parents: 7158
diff changeset
  1000
	/* Any left? It's a junction so we stop */
99ef91ad6415 (svn r10437) -Feature: Automatic signal completion, enabled by pressing ctrl when dragging signals. Signals will continue following track until an existing signal, junction or station are reached. This currently replaces the existing use of ctrl-drag for changing existing signal type.
peter1138
parents: 7158
diff changeset
  1001
	if (trackdirbits != TRACKDIR_BIT_NONE) return false;
99ef91ad6415 (svn r10437) -Feature: Automatic signal completion, enabled by pressing ctrl when dragging signals. Signals will continue following track until an existing signal, junction or station are reached. This currently replaces the existing use of ctrl-drag for changing existing signal type.
peter1138
parents: 7158
diff changeset
  1002
99ef91ad6415 (svn r10437) -Feature: Automatic signal completion, enabled by pressing ctrl when dragging signals. Signals will continue following track until an existing signal, junction or station are reached. This currently replaces the existing use of ctrl-drag for changing existing signal type.
peter1138
parents: 7158
diff changeset
  1003
	switch (GetTileType(tile)) {
99ef91ad6415 (svn r10437) -Feature: Automatic signal completion, enabled by pressing ctrl when dragging signals. Signals will continue following track until an existing signal, junction or station are reached. This currently replaces the existing use of ctrl-drag for changing existing signal type.
peter1138
parents: 7158
diff changeset
  1004
		case MP_RAILWAY:
99ef91ad6415 (svn r10437) -Feature: Automatic signal completion, enabled by pressing ctrl when dragging signals. Signals will continue following track until an existing signal, junction or station are reached. This currently replaces the existing use of ctrl-drag for changing existing signal type.
peter1138
parents: 7158
diff changeset
  1005
			if (IsRailDepot(tile)) return false;
99ef91ad6415 (svn r10437) -Feature: Automatic signal completion, enabled by pressing ctrl when dragging signals. Signals will continue following track until an existing signal, junction or station are reached. This currently replaces the existing use of ctrl-drag for changing existing signal type.
peter1138
parents: 7158
diff changeset
  1006
			if (!remove && HasSignalOnTrack(tile, TrackdirToTrack(trackdir))) return false;
99ef91ad6415 (svn r10437) -Feature: Automatic signal completion, enabled by pressing ctrl when dragging signals. Signals will continue following track until an existing signal, junction or station are reached. This currently replaces the existing use of ctrl-drag for changing existing signal type.
peter1138
parents: 7158
diff changeset
  1007
			signal_ctr++;
99ef91ad6415 (svn r10437) -Feature: Automatic signal completion, enabled by pressing ctrl when dragging signals. Signals will continue following track until an existing signal, junction or station are reached. This currently replaces the existing use of ctrl-drag for changing existing signal type.
peter1138
parents: 7158
diff changeset
  1008
			if (IsDiagonalTrackdir(trackdir)) {
99ef91ad6415 (svn r10437) -Feature: Automatic signal completion, enabled by pressing ctrl when dragging signals. Signals will continue following track until an existing signal, junction or station are reached. This currently replaces the existing use of ctrl-drag for changing existing signal type.
peter1138
parents: 7158
diff changeset
  1009
				signal_ctr++;
99ef91ad6415 (svn r10437) -Feature: Automatic signal completion, enabled by pressing ctrl when dragging signals. Signals will continue following track until an existing signal, junction or station are reached. This currently replaces the existing use of ctrl-drag for changing existing signal type.
peter1138
parents: 7158
diff changeset
  1010
				/* Ensure signal_ctr even so X and Y pieces get signals */
7929
6c9b25842b0f (svn r11482) -Codechange: Remove the doubled function ClrBitT and rename the remaining to fit with the naming style
skidd13
parents: 7928
diff changeset
  1011
				ClrBit(signal_ctr, 0);
7163
99ef91ad6415 (svn r10437) -Feature: Automatic signal completion, enabled by pressing ctrl when dragging signals. Signals will continue following track until an existing signal, junction or station are reached. This currently replaces the existing use of ctrl-drag for changing existing signal type.
peter1138
parents: 7158
diff changeset
  1012
			}
99ef91ad6415 (svn r10437) -Feature: Automatic signal completion, enabled by pressing ctrl when dragging signals. Signals will continue following track until an existing signal, junction or station are reached. This currently replaces the existing use of ctrl-drag for changing existing signal type.
peter1138
parents: 7158
diff changeset
  1013
			return true;
99ef91ad6415 (svn r10437) -Feature: Automatic signal completion, enabled by pressing ctrl when dragging signals. Signals will continue following track until an existing signal, junction or station are reached. This currently replaces the existing use of ctrl-drag for changing existing signal type.
peter1138
parents: 7158
diff changeset
  1014
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: 7335
diff changeset
  1015
		case MP_ROAD:
7163
99ef91ad6415 (svn r10437) -Feature: Automatic signal completion, enabled by pressing ctrl when dragging signals. Signals will continue following track until an existing signal, junction or station are reached. This currently replaces the existing use of ctrl-drag for changing existing signal type.
peter1138
parents: 7158
diff changeset
  1016
			if (!IsLevelCrossing(tile)) return false;
99ef91ad6415 (svn r10437) -Feature: Automatic signal completion, enabled by pressing ctrl when dragging signals. Signals will continue following track until an existing signal, junction or station are reached. This currently replaces the existing use of ctrl-drag for changing existing signal type.
peter1138
parents: 7158
diff changeset
  1017
			signal_ctr += 2;
99ef91ad6415 (svn r10437) -Feature: Automatic signal completion, enabled by pressing ctrl when dragging signals. Signals will continue following track until an existing signal, junction or station are reached. This currently replaces the existing use of ctrl-drag for changing existing signal type.
peter1138
parents: 7158
diff changeset
  1018
			return true;
99ef91ad6415 (svn r10437) -Feature: Automatic signal completion, enabled by pressing ctrl when dragging signals. Signals will continue following track until an existing signal, junction or station are reached. This currently replaces the existing use of ctrl-drag for changing existing signal type.
peter1138
parents: 7158
diff changeset
  1019
99ef91ad6415 (svn r10437) -Feature: Automatic signal completion, enabled by pressing ctrl when dragging signals. Signals will continue following track until an existing signal, junction or station are reached. This currently replaces the existing use of ctrl-drag for changing existing signal type.
peter1138
parents: 7158
diff changeset
  1020
		case MP_TUNNELBRIDGE: {
8088
92fca5b09665 (svn r11649) -Codechange: some code can be simplified thanks to changes in r11642
smatz
parents: 8083
diff changeset
  1021
			TileIndex orig_tile = tile; // backup old value
92fca5b09665 (svn r11649) -Codechange: some code can be simplified thanks to changes in r11642
smatz
parents: 8083
diff changeset
  1022
92fca5b09665 (svn r11649) -Codechange: some code can be simplified thanks to changes in r11642
smatz
parents: 8083
diff changeset
  1023
			if (GetTunnelBridgeTransportType(tile) != TRANSPORT_RAIL) return false;
92fca5b09665 (svn r11649) -Codechange: some code can be simplified thanks to changes in r11642
smatz
parents: 8083
diff changeset
  1024
			if (GetTunnelBridgeDirection(tile) != TrackdirToExitdir(trackdir)) return false;
92fca5b09665 (svn r11649) -Codechange: some code can be simplified thanks to changes in r11642
smatz
parents: 8083
diff changeset
  1025
92fca5b09665 (svn r11649) -Codechange: some code can be simplified thanks to changes in r11642
smatz
parents: 8083
diff changeset
  1026
			/* Skip to end of tunnel or bridge
92fca5b09665 (svn r11649) -Codechange: some code can be simplified thanks to changes in r11642
smatz
parents: 8083
diff changeset
  1027
			 * note that tile is a parameter by reference, so it must be updated */
8197
3af783256580 (svn r11760) -Codechange: unify the way how other end of a tunnel/bridge is determined at some places
smatz
parents: 8158
diff changeset
  1028
			tile = GetOtherTunnelBridgeEnd(tile);
8088
92fca5b09665 (svn r11649) -Codechange: some code can be simplified thanks to changes in r11642
smatz
parents: 8083
diff changeset
  1029
8398
1e181e2e4e15 (svn r11968) -Codechange: remove redundant FindLengthOfTunnel(), use GetTunnelBridgeLength() and/or GetOtherTunnelEnd() instead
smatz
parents: 8344
diff changeset
  1030
			signal_ctr += (GetTunnelBridgeLength(orig_tile, tile) + 2) * 2;
7163
99ef91ad6415 (svn r10437) -Feature: Automatic signal completion, enabled by pressing ctrl when dragging signals. Signals will continue following track until an existing signal, junction or station are reached. This currently replaces the existing use of ctrl-drag for changing existing signal type.
peter1138
parents: 7158
diff changeset
  1031
			return true;
99ef91ad6415 (svn r10437) -Feature: Automatic signal completion, enabled by pressing ctrl when dragging signals. Signals will continue following track until an existing signal, junction or station are reached. This currently replaces the existing use of ctrl-drag for changing existing signal type.
peter1138
parents: 7158
diff changeset
  1032
		}
99ef91ad6415 (svn r10437) -Feature: Automatic signal completion, enabled by pressing ctrl when dragging signals. Signals will continue following track until an existing signal, junction or station are reached. This currently replaces the existing use of ctrl-drag for changing existing signal type.
peter1138
parents: 7158
diff changeset
  1033
99ef91ad6415 (svn r10437) -Feature: Automatic signal completion, enabled by pressing ctrl when dragging signals. Signals will continue following track until an existing signal, junction or station are reached. This currently replaces the existing use of ctrl-drag for changing existing signal type.
peter1138
parents: 7158
diff changeset
  1034
		default: return false;
99ef91ad6415 (svn r10437) -Feature: Automatic signal completion, enabled by pressing ctrl when dragging signals. Signals will continue following track until an existing signal, junction or station are reached. This currently replaces the existing use of ctrl-drag for changing existing signal type.
peter1138
parents: 7158
diff changeset
  1035
	}
99ef91ad6415 (svn r10437) -Feature: Automatic signal completion, enabled by pressing ctrl when dragging signals. Signals will continue following track until an existing signal, junction or station are reached. This currently replaces the existing use of ctrl-drag for changing existing signal type.
peter1138
parents: 7158
diff changeset
  1036
}
99ef91ad6415 (svn r10437) -Feature: Automatic signal completion, enabled by pressing ctrl when dragging signals. Signals will continue following track until an existing signal, junction or station are reached. This currently replaces the existing use of ctrl-drag for changing existing signal type.
peter1138
parents: 7158
diff changeset
  1037
4434
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4388
diff changeset
  1038
/** Build many signals by dragging; AutoSignals
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: 3486
diff changeset
  1039
 * @param tile start tile of drag
6483
ae78fc3c6b20 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6452
diff changeset
  1040
 * @param flags operation to perform
1796
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1782
diff changeset
  1041
 * @param p1  end tile of drag
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1782
diff changeset
  1042
 * @param p2 various bitstuffed elements
5735
9f3729784816 (svn r8279) -Regression (r8274): Removing signals could fail under certain circumstances (not the proper bits of p1/p2 were set to trackbits). Moved trackbits back to bits 0..2, ctrl to 3, semaphore to 4. Also lower the decision of the ctrl-override of signal/semaphore from the GUI into the cmd function since we are passing the ctrl-bit anyways. Bug(s) found by Frostregen; thanks
Darkvater
parents: 5731
diff changeset
  1043
 * - p2 = (bit  0- 2) - track-orientation, valid values: 0-5 (Track enum)
9f3729784816 (svn r8279) -Regression (r8274): Removing signals could fail under certain circumstances (not the proper bits of p1/p2 were set to trackbits). Moved trackbits back to bits 0..2, ctrl to 3, semaphore to 4. Also lower the decision of the ctrl-override of signal/semaphore from the GUI into the cmd function since we are passing the ctrl-bit anyways. Bug(s) found by Frostregen; thanks
Darkvater
parents: 5731
diff changeset
  1044
 * - p2 = (bit  3)    - 1 = override signal/semaphore, or pre/exit/combo signal (CTRL-toggle)
9f3729784816 (svn r8279) -Regression (r8274): Removing signals could fail under certain circumstances (not the proper bits of p1/p2 were set to trackbits). Moved trackbits back to bits 0..2, ctrl to 3, semaphore to 4. Also lower the decision of the ctrl-override of signal/semaphore from the GUI into the cmd function since we are passing the ctrl-bit anyways. Bug(s) found by Frostregen; thanks
Darkvater
parents: 5731
diff changeset
  1045
 * - p2 = (bit  4)    - 0 = signals, 1 = semaphores
5731
c68613da5c4d (svn r8274) -Codechange (r8151): Move the automatic semaphore/signal checks inside the CMD_ functions where they are supposed to be. Achieve this by adding a seperate bit to p1/p2 to hold the CTRL-modifier. While here, use proper types, and 'unify' the parameter bit-meanings. 0 - ctrl-pressed, 1 - signal/semaphore, 2-4 - trackbits, 5 - remove (internal), 24-31 - drag density.
Darkvater
parents: 5668
diff changeset
  1046
 * - p2 = (bit  5)    - 0 = build, 1 = remove signals
7163
99ef91ad6415 (svn r10437) -Feature: Automatic signal completion, enabled by pressing ctrl when dragging signals. Signals will continue following track until an existing signal, junction or station are reached. This currently replaces the existing use of ctrl-drag for changing existing signal type.
peter1138
parents: 7158
diff changeset
  1047
 * - p2 = (bit  6)    - 0 = selected stretch, 1 = auto fill
9794
dd4a7638d2d6 (svn r13936) -Codechange [YAPP]: Enable the auto-signal tool to build PBS signals and honor the default signal type. (michi_cc)
rubidium
parents: 9793
diff changeset
  1048
 * - p2 = (bit  7- 9) - default signal type
1796
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1782
diff changeset
  1049
 * - p2 = (bit 24-31) - user defined signals_density
58
b9fdcc9b5c90 (svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents: 39
diff changeset
  1050
 */
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6791
diff changeset
  1051
static CommandCost CmdSignalTrackHelper(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
58
b9fdcc9b5c90 (svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents: 39
diff changeset
  1052
{
8230
64f28fe2d5c8 (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8228
diff changeset
  1053
	CommandCost ret, total_cost(EXPENSES_CONSTRUCTION);
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6791
diff changeset
  1054
	int signal_ctr;
1954
2beb56cfddbb (svn r2460) - Fix: Prevent assertion failure when trying to drag signals starting from a non-rail tile.
hackykid
parents: 1946
diff changeset
  1055
	byte signals;
1796
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1782
diff changeset
  1056
	bool error = true;
3493
c77bcf04294d (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
  1057
	TileIndex end_tile;
7163
99ef91ad6415 (svn r10437) -Feature: Automatic signal completion, enabled by pressing ctrl when dragging signals. Signals will continue following track until an existing signal, junction or station are reached. This currently replaces the existing use of ctrl-drag for changing existing signal type.
peter1138
parents: 7158
diff changeset
  1058
	TileIndex start_tile = tile;
1796
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1782
diff changeset
  1059
5735
9f3729784816 (svn r8279) -Regression (r8274): Removing signals could fail under certain circumstances (not the proper bits of p1/p2 were set to trackbits). Moved trackbits back to bits 0..2, ctrl to 3, semaphore to 4. Also lower the decision of the ctrl-override of signal/semaphore from the GUI into the cmd function since we are passing the ctrl-bit anyways. Bug(s) found by Frostregen; thanks
Darkvater
parents: 5731
diff changeset
  1060
	Track track = (Track)GB(p2, 0, 3);
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7882
diff changeset
  1061
	bool mode = HasBit(p2, 3);
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7882
diff changeset
  1062
	bool semaphores = HasBit(p2, 4);
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7882
diff changeset
  1063
	bool remove = HasBit(p2, 5);
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7882
diff changeset
  1064
	bool autofill = HasBit(p2, 6);
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
  1065
	Trackdir trackdir = TrackToTrackdir(track);
5731
c68613da5c4d (svn r8274) -Codechange (r8151): Move the automatic semaphore/signal checks inside the CMD_ functions where they are supposed to be. Achieve this by adding a seperate bit to p1/p2 to hold the CTRL-modifier. While here, use proper types, and 'unify' the parameter bit-meanings. 0 - ctrl-pressed, 1 - signal/semaphore, 2-4 - trackbits, 5 - remove (internal), 24-31 - drag density.
Darkvater
parents: 5668
diff changeset
  1066
	byte signal_density = GB(p2, 24, 8);
1796
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1782
diff changeset
  1067
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
  1068
	if (p1 >= MapSize()) return CMD_ERROR;
3493
c77bcf04294d (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
  1069
	end_tile = p1;
1796
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1782
diff changeset
  1070
	if (signal_density == 0 || signal_density > 20) return CMD_ERROR;
58
b9fdcc9b5c90 (svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents: 39
diff changeset
  1071
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1072
	if (!IsTileType(tile, MP_RAILWAY)) return CMD_ERROR;
1954
2beb56cfddbb (svn r2460) - Fix: Prevent assertion failure when trying to drag signals starting from a non-rail tile.
hackykid
parents: 1946
diff changeset
  1073
1796
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1782
diff changeset
  1074
	/* for vertical/horizontal tracks, double the given signals density
4549
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4483
diff changeset
  1075
	 * since the original amount will be too dense (shorter tracks) */
7163
99ef91ad6415 (svn r10437) -Feature: Automatic signal completion, enabled by pressing ctrl when dragging signals. Signals will continue following track until an existing signal, junction or station are reached. This currently replaces the existing use of ctrl-drag for changing existing signal type.
peter1138
parents: 7158
diff changeset
  1076
	signal_density *= 2;
1796
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1782
diff changeset
  1077
3493
c77bcf04294d (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
  1078
	if (CmdFailed(ValidateAutoDrag(&trackdir, tile, end_tile))) return CMD_ERROR;
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
  1079
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
  1080
	track = TrackdirToTrack(trackdir); /* trackdir might have changed, keep track in sync */
7163
99ef91ad6415 (svn r10437) -Feature: Automatic signal completion, enabled by pressing ctrl when dragging signals. Signals will continue following track until an existing signal, junction or station are reached. This currently replaces the existing use of ctrl-drag for changing existing signal type.
peter1138
parents: 7158
diff changeset
  1081
	Trackdir start_trackdir = trackdir;
99ef91ad6415 (svn r10437) -Feature: Automatic signal completion, enabled by pressing ctrl when dragging signals. Signals will continue following track until an existing signal, junction or station are reached. This currently replaces the existing use of ctrl-drag for changing existing signal type.
peter1138
parents: 7158
diff changeset
  1082
9867
f5d0c061f048 (svn r14013) -Fix [FS#2202]: do not allow extending signals by dragging in any direction other than the track direction.
rubidium
parents: 9866
diff changeset
  1083
	/* Must start on a valid track to be able to avoid loops */
f5d0c061f048 (svn r14013) -Fix [FS#2202]: do not allow extending signals by dragging in any direction other than the track direction.
rubidium
parents: 9866
diff changeset
  1084
	if (!HasTrack(tile, track)) return CMD_ERROR;
58
b9fdcc9b5c90 (svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents: 39
diff changeset
  1085
9794
dd4a7638d2d6 (svn r13936) -Codechange [YAPP]: Enable the auto-signal tool to build PBS signals and honor the default signal type. (michi_cc)
rubidium
parents: 9793
diff changeset
  1086
	SignalType sigtype = (SignalType)GB(p2, 7, 3);
dd4a7638d2d6 (svn r13936) -Codechange [YAPP]: Enable the auto-signal tool to build PBS signals and honor the default signal type. (michi_cc)
rubidium
parents: 9793
diff changeset
  1087
	if (sigtype > SIGTYPE_LAST) return CMD_ERROR;
dd4a7638d2d6 (svn r13936) -Codechange [YAPP]: Enable the auto-signal tool to build PBS signals and honor the default signal type. (michi_cc)
rubidium
parents: 9793
diff changeset
  1088
6432
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6427
diff changeset
  1089
	/* copy the signal-style of the first rail-piece if existing */
10423
293726ac3faa (svn r14676) -Fix: Do not copy the signal type of parallel vertical/horizontal track, when dragging signals.
frosch
parents: 10355
diff changeset
  1090
	if (HasSignalOnTrack(tile, track)) {
6753
c1013c837417 (svn r9988) -Codechange: remove the last direct map accesses, except the ones needed for the savegame saving/loading mechanisms.
rubidium
parents: 6728
diff changeset
  1091
		signals = GetPresentSignals(tile) & SignalOnTrack(track);
10423
293726ac3faa (svn r14676) -Fix: Do not copy the signal type of parallel vertical/horizontal track, when dragging signals.
frosch
parents: 10355
diff changeset
  1092
		assert(signals != 0);
58
b9fdcc9b5c90 (svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents: 39
diff changeset
  1093
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6406
diff changeset
  1094
		/* copy signal/semaphores style (independent of CTRL) */
6770
408585d467f9 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 6753
diff changeset
  1095
		semaphores = GetSignalVariant(tile, track) != SIG_ELECTRIC;
9794
dd4a7638d2d6 (svn r13936) -Codechange [YAPP]: Enable the auto-signal tool to build PBS signals and honor the default signal type. (michi_cc)
rubidium
parents: 9793
diff changeset
  1096
dd4a7638d2d6 (svn r13936) -Codechange [YAPP]: Enable the auto-signal tool to build PBS signals and honor the default signal type. (michi_cc)
rubidium
parents: 9793
diff changeset
  1097
		sigtype = GetSignalType(tile, track);
9866
c99f3ec0b91f (svn r14012) -Fix (r13936): Don't copy pre-signal type when dragging signals.
peter1138
parents: 9860
diff changeset
  1098
		/* Don't but copy pre-signal type */
c99f3ec0b91f (svn r14012) -Fix (r13936): Don't copy pre-signal type when dragging signals.
peter1138
parents: 9860
diff changeset
  1099
		if (sigtype < SIGTYPE_PBS) sigtype = SIGTYPE_NORMAL;
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4067
diff changeset
  1100
	} else { // no signals exist, drag a two-way signal stretch
9794
dd4a7638d2d6 (svn r13936) -Codechange [YAPP]: Enable the auto-signal tool to build PBS signals and honor the default signal type. (michi_cc)
rubidium
parents: 9793
diff changeset
  1101
		signals = IsPbsSignal(sigtype) ? SignalAlongTrackdir(trackdir) : SignalOnTrack(track);
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4067
diff changeset
  1102
	}
58
b9fdcc9b5c90 (svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents: 39
diff changeset
  1103
7163
99ef91ad6415 (svn r10437) -Feature: Automatic signal completion, enabled by pressing ctrl when dragging signals. Signals will continue following track until an existing signal, junction or station are reached. This currently replaces the existing use of ctrl-drag for changing existing signal type.
peter1138
parents: 7158
diff changeset
  1104
	byte signal_dir = 0;
7931
b0a46cd92225 (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents: 7929
diff changeset
  1105
	if (signals & SignalAlongTrackdir(trackdir))   SetBit(signal_dir, 0);
b0a46cd92225 (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents: 7929
diff changeset
  1106
	if (signals & SignalAgainstTrackdir(trackdir)) SetBit(signal_dir, 1);
7163
99ef91ad6415 (svn r10437) -Feature: Automatic signal completion, enabled by pressing ctrl when dragging signals. Signals will continue following track until an existing signal, junction or station are reached. This currently replaces the existing use of ctrl-drag for changing existing signal type.
peter1138
parents: 7158
diff changeset
  1107
1954
2beb56cfddbb (svn r2460) - Fix: Prevent assertion failure when trying to drag signals starting from a non-rail tile.
hackykid
parents: 1946
diff changeset
  1108
	/* signal_ctr         - amount of tiles already processed
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
  1109
	 * signals_density    - patch setting to put signal on every Nth tile (double space on |, -- tracks)
58
b9fdcc9b5c90 (svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents: 39
diff changeset
  1110
	 **********
1954
2beb56cfddbb (svn r2460) - Fix: Prevent assertion failure when trying to drag signals starting from a non-rail tile.
hackykid
parents: 1946
diff changeset
  1111
	 * trackdir   - trackdir to build with autorail
2beb56cfddbb (svn r2460) - Fix: Prevent assertion failure when trying to drag signals starting from a non-rail tile.
hackykid
parents: 1946
diff changeset
  1112
	 * semaphores - semaphores or signals
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
  1113
	 * signals    - is there a signal/semaphore on the first tile, copy its style (two-way/single-way)
4549
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4483
diff changeset
  1114
	 *              and convert all others to semaphore/signal
5731
c68613da5c4d (svn r8274) -Codechange (r8151): Move the automatic semaphore/signal checks inside the CMD_ functions where they are supposed to be. Achieve this by adding a seperate bit to p1/p2 to hold the CTRL-modifier. While here, use proper types, and 'unify' the parameter bit-meanings. 0 - ctrl-pressed, 1 - signal/semaphore, 2-4 - trackbits, 5 - remove (internal), 24-31 - drag density.
Darkvater
parents: 5668
diff changeset
  1115
	 * remove     - 1 remove signals, 0 build signals */
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6946
diff changeset
  1116
	signal_ctr = 0;
1796
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1782
diff changeset
  1117
	for (;;) {
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6406
diff changeset
  1118
		/* only build/remove signals with the specified density */
7163
99ef91ad6415 (svn r10437) -Feature: Automatic signal completion, enabled by pressing ctrl when dragging signals. Signals will continue following track until an existing signal, junction or station are reached. This currently replaces the existing use of ctrl-drag for changing existing signal type.
peter1138
parents: 7158
diff changeset
  1119
		if ((remove && autofill) || signal_ctr % signal_density == 0) {
5735
9f3729784816 (svn r8279) -Regression (r8274): Removing signals could fail under certain circumstances (not the proper bits of p1/p2 were set to trackbits). Moved trackbits back to bits 0..2, ctrl to 3, semaphore to 4. Also lower the decision of the ctrl-override of signal/semaphore from the GUI into the cmd function since we are passing the ctrl-bit anyways. Bug(s) found by Frostregen; thanks
Darkvater
parents: 5731
diff changeset
  1120
			uint32 p1 = GB(TrackdirToTrack(trackdir), 0, 3);
9f3729784816 (svn r8279) -Regression (r8274): Removing signals could fail under certain circumstances (not the proper bits of p1/p2 were set to trackbits). Moved trackbits back to bits 0..2, ctrl to 3, semaphore to 4. Also lower the decision of the ctrl-override of signal/semaphore from the GUI into the cmd function since we are passing the ctrl-bit anyways. Bug(s) found by Frostregen; thanks
Darkvater
parents: 5731
diff changeset
  1121
			SB(p1, 3, 1, mode);
9f3729784816 (svn r8279) -Regression (r8274): Removing signals could fail under certain circumstances (not the proper bits of p1/p2 were set to trackbits). Moved trackbits back to bits 0..2, ctrl to 3, semaphore to 4. Also lower the decision of the ctrl-override of signal/semaphore from the GUI into the cmd function since we are passing the ctrl-bit anyways. Bug(s) found by Frostregen; thanks
Darkvater
parents: 5731
diff changeset
  1122
			SB(p1, 4, 1, semaphores);
9794
dd4a7638d2d6 (svn r13936) -Codechange [YAPP]: Enable the auto-signal tool to build PBS signals and honor the default signal type. (michi_cc)
rubidium
parents: 9793
diff changeset
  1123
			SB(p1, 5, 3, sigtype);
7163
99ef91ad6415 (svn r10437) -Feature: Automatic signal completion, enabled by pressing ctrl when dragging signals. Signals will continue following track until an existing signal, junction or station are reached. This currently replaces the existing use of ctrl-drag for changing existing signal type.
peter1138
parents: 7158
diff changeset
  1124
99ef91ad6415 (svn r10437) -Feature: Automatic signal completion, enabled by pressing ctrl when dragging signals. Signals will continue following track until an existing signal, junction or station are reached. This currently replaces the existing use of ctrl-drag for changing existing signal type.
peter1138
parents: 7158
diff changeset
  1125
			/* Pick the correct orientation for the track direction */
99ef91ad6415 (svn r10437) -Feature: Automatic signal completion, enabled by pressing ctrl when dragging signals. Signals will continue following track until an existing signal, junction or station are reached. This currently replaces the existing use of ctrl-drag for changing existing signal type.
peter1138
parents: 7158
diff changeset
  1126
			signals = 0;
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7882
diff changeset
  1127
			if (HasBit(signal_dir, 0)) signals |= SignalAlongTrackdir(trackdir);
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7882
diff changeset
  1128
			if (HasBit(signal_dir, 1)) signals |= SignalAgainstTrackdir(trackdir);
7163
99ef91ad6415 (svn r10437) -Feature: Automatic signal completion, enabled by pressing ctrl when dragging signals. Signals will continue following track until an existing signal, junction or station are reached. This currently replaces the existing use of ctrl-drag for changing existing signal type.
peter1138
parents: 7158
diff changeset
  1129
5731
c68613da5c4d (svn r8274) -Codechange (r8151): Move the automatic semaphore/signal checks inside the CMD_ functions where they are supposed to be. Achieve this by adding a seperate bit to p1/p2 to hold the CTRL-modifier. While here, use proper types, and 'unify' the parameter bit-meanings. 0 - ctrl-pressed, 1 - signal/semaphore, 2-4 - trackbits, 5 - remove (internal), 24-31 - drag density.
Darkvater
parents: 5668
diff changeset
  1130
			ret = DoCommand(tile, p1, signals, flags, remove ? CMD_REMOVE_SIGNALS : CMD_BUILD_SIGNALS);
58
b9fdcc9b5c90 (svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents: 39
diff changeset
  1131
5069
68beabd19dca (svn r7127) -Codechange [FS#149]: Improve the usability of the signal-dragger, do not bail out
Darkvater
parents: 5059
diff changeset
  1132
			/* Be user-friendly and try placing signals as much as possible */
6946
a48b23f1cc8a (svn r10200) -Codechange: add "shortcut" for !CmdFailed (CmdSucceeded).
rubidium
parents: 6943
diff changeset
  1133
			if (CmdSucceeded(ret)) {
58
b9fdcc9b5c90 (svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents: 39
diff changeset
  1134
				error = false;
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6946
diff changeset
  1135
				total_cost.AddCost(ret);
58
b9fdcc9b5c90 (svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents: 39
diff changeset
  1136
			}
b9fdcc9b5c90 (svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents: 39
diff changeset
  1137
		}
b9fdcc9b5c90 (svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents: 39
diff changeset
  1138
7163
99ef91ad6415 (svn r10437) -Feature: Automatic signal completion, enabled by pressing ctrl when dragging signals. Signals will continue following track until an existing signal, junction or station are reached. This currently replaces the existing use of ctrl-drag for changing existing signal type.
peter1138
parents: 7158
diff changeset
  1139
		if (autofill) {
99ef91ad6415 (svn r10437) -Feature: Automatic signal completion, enabled by pressing ctrl when dragging signals. Signals will continue following track until an existing signal, junction or station are reached. This currently replaces the existing use of ctrl-drag for changing existing signal type.
peter1138
parents: 7158
diff changeset
  1140
			if (!CheckSignalAutoFill(tile, trackdir, signal_ctr, remove)) break;
58
b9fdcc9b5c90 (svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents: 39
diff changeset
  1141
7163
99ef91ad6415 (svn r10437) -Feature: Automatic signal completion, enabled by pressing ctrl when dragging signals. Signals will continue following track until an existing signal, junction or station are reached. This currently replaces the existing use of ctrl-drag for changing existing signal type.
peter1138
parents: 7158
diff changeset
  1142
			/* Prevent possible loops */
99ef91ad6415 (svn r10437) -Feature: Automatic signal completion, enabled by pressing ctrl when dragging signals. Signals will continue following track until an existing signal, junction or station are reached. This currently replaces the existing use of ctrl-drag for changing existing signal type.
peter1138
parents: 7158
diff changeset
  1143
			if (tile == start_tile && trackdir == start_trackdir) break;
99ef91ad6415 (svn r10437) -Feature: Automatic signal completion, enabled by pressing ctrl when dragging signals. Signals will continue following track until an existing signal, junction or station are reached. This currently replaces the existing use of ctrl-drag for changing existing signal type.
peter1138
parents: 7158
diff changeset
  1144
		} else {
99ef91ad6415 (svn r10437) -Feature: Automatic signal completion, enabled by pressing ctrl when dragging signals. Signals will continue following track until an existing signal, junction or station are reached. This currently replaces the existing use of ctrl-drag for changing existing signal type.
peter1138
parents: 7158
diff changeset
  1145
			if (tile == end_tile) break;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1146
7163
99ef91ad6415 (svn r10437) -Feature: Automatic signal completion, enabled by pressing ctrl when dragging signals. Signals will continue following track until an existing signal, junction or station are reached. This currently replaces the existing use of ctrl-drag for changing existing signal type.
peter1138
parents: 7158
diff changeset
  1147
			tile += ToTileIndexDiff(_trackdelta[trackdir]);
99ef91ad6415 (svn r10437) -Feature: Automatic signal completion, enabled by pressing ctrl when dragging signals. Signals will continue following track until an existing signal, junction or station are reached. This currently replaces the existing use of ctrl-drag for changing existing signal type.
peter1138
parents: 7158
diff changeset
  1148
			signal_ctr++;
99ef91ad6415 (svn r10437) -Feature: Automatic signal completion, enabled by pressing ctrl when dragging signals. Signals will continue following track until an existing signal, junction or station are reached. This currently replaces the existing use of ctrl-drag for changing existing signal type.
peter1138
parents: 7158
diff changeset
  1149
99ef91ad6415 (svn r10437) -Feature: Automatic signal completion, enabled by pressing ctrl when dragging signals. Signals will continue following track until an existing signal, junction or station are reached. This currently replaces the existing use of ctrl-drag for changing existing signal type.
peter1138
parents: 7158
diff changeset
  1150
			/* toggle railbit for the non-diagonal tracks (|, -- tracks) */
99ef91ad6415 (svn r10437) -Feature: Automatic signal completion, enabled by pressing ctrl when dragging signals. Signals will continue following track until an existing signal, junction or station are reached. This currently replaces the existing use of ctrl-drag for changing existing signal type.
peter1138
parents: 7158
diff changeset
  1151
			if (IsDiagonalTrackdir(trackdir)) {
99ef91ad6415 (svn r10437) -Feature: Automatic signal completion, enabled by pressing ctrl when dragging signals. Signals will continue following track until an existing signal, junction or station are reached. This currently replaces the existing use of ctrl-drag for changing existing signal type.
peter1138
parents: 7158
diff changeset
  1152
				signal_ctr++;
99ef91ad6415 (svn r10437) -Feature: Automatic signal completion, enabled by pressing ctrl when dragging signals. Signals will continue following track until an existing signal, junction or station are reached. This currently replaces the existing use of ctrl-drag for changing existing signal type.
peter1138
parents: 7158
diff changeset
  1153
			} else {
7932
6c3d71e8a129 (svn r11485) -Codechange: Remove the doubled function ToggleBitT and rename the remaining to fit with the naming style
skidd13
parents: 7931
diff changeset
  1154
				ToggleBit(trackdir, 0);
7163
99ef91ad6415 (svn r10437) -Feature: Automatic signal completion, enabled by pressing ctrl when dragging signals. Signals will continue following track until an existing signal, junction or station are reached. This currently replaces the existing use of ctrl-drag for changing existing signal type.
peter1138
parents: 7158
diff changeset
  1155
			}
99ef91ad6415 (svn r10437) -Feature: Automatic signal completion, enabled by pressing ctrl when dragging signals. Signals will continue following track until an existing signal, junction or station are reached. This currently replaces the existing use of ctrl-drag for changing existing signal type.
peter1138
parents: 7158
diff changeset
  1156
		}
58
b9fdcc9b5c90 (svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents: 39
diff changeset
  1157
	}
b9fdcc9b5c90 (svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents: 39
diff changeset
  1158
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2934
diff changeset
  1159
	return error ? CMD_ERROR : total_cost;
58
b9fdcc9b5c90 (svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents: 39
diff changeset
  1160
}
b9fdcc9b5c90 (svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents: 39
diff changeset
  1161
1796
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1782
diff changeset
  1162
/** Build signals on a stretch of track.
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1782
diff changeset
  1163
 * Stub for the unified signal builder/remover
6483
ae78fc3c6b20 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6452
diff changeset
  1164
 * @param tile start tile of drag
ae78fc3c6b20 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6452
diff changeset
  1165
 * @param flags operation to perform
ae78fc3c6b20 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6452
diff changeset
  1166
 * @param p1  end tile of drag
ae78fc3c6b20 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6452
diff changeset
  1167
 * @param p2 various bitstuffed elements
ae78fc3c6b20 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6452
diff changeset
  1168
 * - p2 = (bit  0- 2) - track-orientation, valid values: 0-5 (Track enum)
ae78fc3c6b20 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6452
diff changeset
  1169
 * - p2 = (bit  3)    - 1 = override signal/semaphore, or pre/exit/combo signal (CTRL-toggle)
ae78fc3c6b20 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6452
diff changeset
  1170
 * - p2 = (bit  4)    - 0 = signals, 1 = semaphores
ae78fc3c6b20 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6452
diff changeset
  1171
 * - p2 = (bit  5)    - 0 = build, 1 = remove signals
7163
99ef91ad6415 (svn r10437) -Feature: Automatic signal completion, enabled by pressing ctrl when dragging signals. Signals will continue following track until an existing signal, junction or station are reached. This currently replaces the existing use of ctrl-drag for changing existing signal type.
peter1138
parents: 7158
diff changeset
  1172
 * - p2 = (bit  6)    - 0 = selected stretch, 1 = auto fill
9794
dd4a7638d2d6 (svn r13936) -Codechange [YAPP]: Enable the auto-signal tool to build PBS signals and honor the default signal type. (michi_cc)
rubidium
parents: 9793
diff changeset
  1173
 * - p2 = (bit  7- 9) - default signal type
6483
ae78fc3c6b20 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6452
diff changeset
  1174
 * - p2 = (bit 24-31) - user defined signals_density
1796
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1782
diff changeset
  1175
 * @see CmdSignalTrackHelper
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1782
diff changeset
  1176
 */
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6791
diff changeset
  1177
CommandCost CmdBuildSignalTrack(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
1227
1d940a5e02d2 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater
parents: 1209
diff changeset
  1178
{
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: 3486
diff changeset
  1179
	return CmdSignalTrackHelper(tile, flags, p1, p2);
1227
1d940a5e02d2 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater
parents: 1209
diff changeset
  1180
}
1d940a5e02d2 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater
parents: 1209
diff changeset
  1181
1775
548dc04d50e2 (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1719
diff changeset
  1182
/** Remove signals
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: 3486
diff changeset
  1183
 * @param tile coordinates where signal is being deleted from
6483
ae78fc3c6b20 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6452
diff changeset
  1184
 * @param flags operation to perform
6488
b6c42e91bb35 (svn r9669) -Documentation: some more doxygen fixes
belugas
parents: 6483
diff changeset
  1185
 * @param p1 various bitstuffed elements, only track information is used
b6c42e91bb35 (svn r9669) -Documentation: some more doxygen fixes
belugas
parents: 6483
diff changeset
  1186
 *           - (bit  0- 2) - track-orientation, valid values: 0-5 (Track enum)
b6c42e91bb35 (svn r9669) -Documentation: some more doxygen fixes
belugas
parents: 6483
diff changeset
  1187
 *           - (bit  3)    - override signal/semaphore, or pre/exit/combo signal (CTRL-toggle)
b6c42e91bb35 (svn r9669) -Documentation: some more doxygen fixes
belugas
parents: 6483
diff changeset
  1188
 *           - (bit  4)    - 0 = signals, 1 = semaphores
b6c42e91bb35 (svn r9669) -Documentation: some more doxygen fixes
belugas
parents: 6483
diff changeset
  1189
 * @param p2 unused
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1190
 */
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6791
diff changeset
  1191
CommandCost CmdRemoveSingleSignal(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1192
{
5735
9f3729784816 (svn r8279) -Regression (r8274): Removing signals could fail under certain circumstances (not the proper bits of p1/p2 were set to trackbits). Moved trackbits back to bits 0..2, ctrl to 3, semaphore to 4. Also lower the decision of the ctrl-override of signal/semaphore from the GUI into the cmd function since we are passing the ctrl-bit anyways. Bug(s) found by Frostregen; thanks
Darkvater
parents: 5731
diff changeset
  1193
	Track track = (Track)GB(p1, 0, 3);
1518
9a876c45238b (svn r2022) Revise CmdRemoveSingleSignal: Check parameters for validity and simplify the function
tron
parents: 1477
diff changeset
  1194
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4067
diff changeset
  1195
	if (!ValParamTrackOrientation(track) ||
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4067
diff changeset
  1196
			!IsTileType(tile, MP_RAILWAY) ||
9587
82019b7539b3 (svn r13626) -Fix (r11871): signals were not updated when player removed signals from nonexistent track sharing bits with existing track
smatz
parents: 9549
diff changeset
  1197
			!HasTrack(tile, track) ||
7448
dbcc29a92db8 (svn r10922) -Codechange: Allow building and removing tracks and signals when there is a
maedhros
parents: 7389
diff changeset
  1198
			!EnsureNoTrainOnTrack(tile, track) ||
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4067
diff changeset
  1199
			!HasSignalOnTrack(tile, track)) {
1518
9a876c45238b (svn r2022) Revise CmdRemoveSingleSignal: Check parameters for validity and simplify the function
tron
parents: 1477
diff changeset
  1200
		return CMD_ERROR;
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4067
diff changeset
  1201
	}
1518
9a876c45238b (svn r2022) Revise CmdRemoveSingleSignal: Check parameters for validity and simplify the function
tron
parents: 1477
diff changeset
  1202
1775
548dc04d50e2 (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1719
diff changeset
  1203
	/* Only water can remove signals from anyone */
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10172
diff changeset
  1204
	if (_current_company != OWNER_WATER && !CheckTileOwnership(tile)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1205
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1206
	/* Do it? */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1207
	if (flags & DC_EXEC) {
9830
566cbd04836f (svn r13973) -Codechange [YAPP]: Improve the behavior when changing signals to not cause stale reservations. (michi_cc)
smatz
parents: 9815
diff changeset
  1208
		Vehicle *v = NULL;
566cbd04836f (svn r13973) -Codechange [YAPP]: Improve the behavior when changing signals to not cause stale reservations. (michi_cc)
smatz
parents: 9815
diff changeset
  1209
		if (HasReservedTracks(tile, TrackToTrackBits(track))) {
566cbd04836f (svn r13973) -Codechange [YAPP]: Improve the behavior when changing signals to not cause stale reservations. (michi_cc)
smatz
parents: 9815
diff changeset
  1210
			v = GetTrainForReservation(tile, track);
566cbd04836f (svn r13973) -Codechange [YAPP]: Improve the behavior when changing signals to not cause stale reservations. (michi_cc)
smatz
parents: 9815
diff changeset
  1211
		}
6753
c1013c837417 (svn r9988) -Codechange: remove the last direct map accesses, except the ones needed for the savegame saving/loading mechanisms.
rubidium
parents: 6728
diff changeset
  1212
		SetPresentSignals(tile, GetPresentSignals(tile) & ~SignalOnTrack(track));
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1213
1066
eaef1465d3ab (svn r1567) -Fix: [110452] On horizontal/vertical tracks you are also charged for building/removing signals on the parallel track on the same tile. Signal updating is also correct. (Hackykid)
darkvater
parents: 1059
diff changeset
  1214
		/* removed last signal from tile? */
6753
c1013c837417 (svn r9988) -Codechange: remove the last direct map accesses, except the ones needed for the savegame saving/loading mechanisms.
rubidium
parents: 6728
diff changeset
  1215
		if (GetPresentSignals(tile) == 0) {
c1013c837417 (svn r9988) -Codechange: remove the last direct map accesses, except the ones needed for the savegame saving/loading mechanisms.
rubidium
parents: 6728
diff changeset
  1216
			SetSignalStates(tile, 0);
6172
e6d7a5b3d63f (svn r8935) -Codechange: unification of track type between road and rail tiles, unification of ground type between normal rail tiles and depots/waypoints and removing the need for RailTileSubType.
rubidium
parents: 6160
diff changeset
  1217
			SetHasSignals(tile, false);
6770
408585d467f9 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 6753
diff changeset
  1218
			SetSignalVariant(tile, INVALID_TRACK, SIG_ELECTRIC); // remove any possible semaphores
1066
eaef1465d3ab (svn r1567) -Fix: [110452] On horizontal/vertical tracks you are also charged for building/removing signals on the parallel track on the same tile. Signal updating is also correct. (Hackykid)
darkvater
parents: 1059
diff changeset
  1219
		}
1109
ecb98f43ba2c (svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents: 1095
diff changeset
  1220
8306
22e1344c5457 (svn r11871) -Fix [FS#1074]: do not update signals after each tile when building/removing a large block of track/signals/station
smatz
parents: 8300
diff changeset
  1221
		AddTrackToSignalBuffer(tile, track, GetTileOwner(tile));
3900
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3884
diff changeset
  1222
		YapfNotifyTrackLayoutChange(tile, track);
9830
566cbd04836f (svn r13973) -Codechange [YAPP]: Improve the behavior when changing signals to not cause stale reservations. (michi_cc)
smatz
parents: 9815
diff changeset
  1223
		if (v != NULL) TryPathReserve(v, false);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1224
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1225
		MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1226
	}
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1227
8230
64f28fe2d5c8 (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8228
diff changeset
  1228
	return CommandCost(EXPENSES_CONSTRUCTION, _price.remove_signals);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1229
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1230
1796
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1782
diff changeset
  1231
/** Remove signals on a stretch of track.
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1782
diff changeset
  1232
 * Stub for the unified signal builder/remover
6483
ae78fc3c6b20 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6452
diff changeset
  1233
 * @param tile start tile of drag
ae78fc3c6b20 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6452
diff changeset
  1234
 * @param flags operation to perform
ae78fc3c6b20 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6452
diff changeset
  1235
 * @param p1  end tile of drag
ae78fc3c6b20 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6452
diff changeset
  1236
 * @param p2 various bitstuffed elements
ae78fc3c6b20 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6452
diff changeset
  1237
 * - p2 = (bit  0- 2) - track-orientation, valid values: 0-5 (Track enum)
ae78fc3c6b20 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6452
diff changeset
  1238
 * - p2 = (bit  3)    - 1 = override signal/semaphore, or pre/exit/combo signal (CTRL-toggle)
ae78fc3c6b20 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6452
diff changeset
  1239
 * - p2 = (bit  4)    - 0 = signals, 1 = semaphores
ae78fc3c6b20 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6452
diff changeset
  1240
 * - p2 = (bit  5)    - 0 = build, 1 = remove signals
7163
99ef91ad6415 (svn r10437) -Feature: Automatic signal completion, enabled by pressing ctrl when dragging signals. Signals will continue following track until an existing signal, junction or station are reached. This currently replaces the existing use of ctrl-drag for changing existing signal type.
peter1138
parents: 7158
diff changeset
  1241
 * - p2 = (bit  6)    - 0 = selected stretch, 1 = auto fill
9794
dd4a7638d2d6 (svn r13936) -Codechange [YAPP]: Enable the auto-signal tool to build PBS signals and honor the default signal type. (michi_cc)
rubidium
parents: 9793
diff changeset
  1242
 * - p2 = (bit  7- 9) - default signal type
6483
ae78fc3c6b20 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6452
diff changeset
  1243
 * - p2 = (bit 24-31) - user defined signals_density
1796
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1782
diff changeset
  1244
 * @see CmdSignalTrackHelper
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1782
diff changeset
  1245
 */
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6791
diff changeset
  1246
CommandCost CmdRemoveSignalTrack(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
1227
1d940a5e02d2 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater
parents: 1209
diff changeset
  1247
{
7931
b0a46cd92225 (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents: 7929
diff changeset
  1248
	return CmdSignalTrackHelper(tile, flags, p1, SetBit(p2, 5)); // bit 5 is remove bit
1227
1d940a5e02d2 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater
parents: 1209
diff changeset
  1249
}
1d940a5e02d2 (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater
parents: 1209
diff changeset
  1250
8096
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1251
/** Update power of train under which is the railtype being converted */
9775
22e256c3bf46 (svn r13912) -Codechange: remove some casts by returning the proper type instead of void*.
rubidium
parents: 9652
diff changeset
  1252
Vehicle *UpdateTrainPowerProc(Vehicle *v, void *data)
7539
5f41050498bd (svn r11059) -Fix [FS#1182]: inconsistency between Rail<->ElRail conversions of different kinds of rail containing tiles (normal rail, stations, depots, etc). Patch by SmatZ.
rubidium
parents: 7494
diff changeset
  1253
{
5f41050498bd (svn r11059) -Fix [FS#1182]: inconsistency between Rail<->ElRail conversions of different kinds of rail containing tiles (normal rail, stations, depots, etc). Patch by SmatZ.
rubidium
parents: 7494
diff changeset
  1254
	/* Similiar checks as in TrainPowerChanged() */
5f41050498bd (svn r11059) -Fix [FS#1182]: inconsistency between Rail<->ElRail conversions of different kinds of rail containing tiles (normal rail, stations, depots, etc). Patch by SmatZ.
rubidium
parents: 7494
diff changeset
  1255
8081
4fddceb00aa6 (svn r11642) -Codechange: VehicleFromPos does check for v->tile == tile, so remove useless checks
smatz
parents: 8077
diff changeset
  1256
	if (v->type == VEH_TRAIN && !IsArticulatedPart(v)) {
7539
5f41050498bd (svn r11059) -Fix [FS#1182]: inconsistency between Rail<->ElRail conversions of different kinds of rail containing tiles (normal rail, stations, depots, etc). Patch by SmatZ.
rubidium
parents: 7494
diff changeset
  1257
		const RailVehicleInfo *rvi = RailVehInfo(v->engine_type);
5f41050498bd (svn r11059) -Fix [FS#1182]: inconsistency between Rail<->ElRail conversions of different kinds of rail containing tiles (normal rail, stations, depots, etc). Patch by SmatZ.
rubidium
parents: 7494
diff changeset
  1258
		if (GetVehicleProperty(v, 0x0B, rvi->power) != 0) TrainPowerChanged(v->First());
5f41050498bd (svn r11059) -Fix [FS#1182]: inconsistency between Rail<->ElRail conversions of different kinds of rail containing tiles (normal rail, stations, depots, etc). Patch by SmatZ.
rubidium
parents: 7494
diff changeset
  1259
	}
5f41050498bd (svn r11059) -Fix [FS#1182]: inconsistency between Rail<->ElRail conversions of different kinds of rail containing tiles (normal rail, stations, depots, etc). Patch by SmatZ.
rubidium
parents: 7494
diff changeset
  1260
5f41050498bd (svn r11059) -Fix [FS#1182]: inconsistency between Rail<->ElRail conversions of different kinds of rail containing tiles (normal rail, stations, depots, etc). Patch by SmatZ.
rubidium
parents: 7494
diff changeset
  1261
	return NULL;
5f41050498bd (svn r11059) -Fix [FS#1182]: inconsistency between Rail<->ElRail conversions of different kinds of rail containing tiles (normal rail, stations, depots, etc). Patch by SmatZ.
rubidium
parents: 7494
diff changeset
  1262
}
5f41050498bd (svn r11059) -Fix [FS#1182]: inconsistency between Rail<->ElRail conversions of different kinds of rail containing tiles (normal rail, stations, depots, etc). Patch by SmatZ.
rubidium
parents: 7494
diff changeset
  1263
1782
48749e4c2dc6 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1781
diff changeset
  1264
/** Convert one rail type to the other. You can convert normal rail to
48749e4c2dc6 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1781
diff changeset
  1265
 * monorail/maglev easily or vice-versa.
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: 3486
diff changeset
  1266
 * @param tile end tile of rail conversion drag
6483
ae78fc3c6b20 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6452
diff changeset
  1267
 * @param flags operation to perform
1782
48749e4c2dc6 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1781
diff changeset
  1268
 * @param p1 start tile of drag
48749e4c2dc6 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1781
diff changeset
  1269
 * @param p2 new railtype to convert to
48749e4c2dc6 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1781
diff changeset
  1270
 */
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6791
diff changeset
  1271
CommandCost CmdConvertRail(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1272
{
8230
64f28fe2d5c8 (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8228
diff changeset
  1273
	CommandCost cost(EXPENSES_CONSTRUCTION);
8236
8a5dd0b42e47 (svn r11800) -Codechange: move some functions to a more logical location + some type safety.
rubidium
parents: 8230
diff changeset
  1274
	RailType totype = (RailType)p2;
8a5dd0b42e47 (svn r11800) -Codechange: move some functions to a more logical location + some type safety.
rubidium
parents: 8230
diff changeset
  1275
8a5dd0b42e47 (svn r11800) -Codechange: move some functions to a more logical location + some type safety.
rubidium
parents: 8230
diff changeset
  1276
	if (!ValParamRailtype(totype)) return CMD_ERROR;
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
  1277
	if (p1 >= MapSize()) return CMD_ERROR;
1782
48749e4c2dc6 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1781
diff changeset
  1278
8096
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1279
	uint ex = TileX(tile);
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1280
	uint ey = TileY(tile);
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1281
	uint sx = TileX(p1);
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1282
	uint sy = TileY(p1);
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1283
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6406
diff changeset
  1284
	/* make sure sx,sy are smaller than ex,ey */
6106
2898cd9417fd (svn r8841) -Fix
tron
parents: 5993
diff changeset
  1285
	if (ex < sx) Swap(ex, sx);
2898cd9417fd (svn r8841) -Fix
tron
parents: 5993
diff changeset
  1286
	if (ey < sy) Swap(ey, sy);
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1287
8096
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1288
	_error_message = STR_1005_NO_SUITABLE_RAILROAD_TRACK; // by default, there is no track to convert
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1289
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1290
	for (uint x = sx; x <= ex; ++x) {
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1291
		for (uint y = sy; y <= ey; ++y) {
3493
c77bcf04294d (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
  1292
			TileIndex tile = TileXY(x, y);
8096
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1293
			TileType tt = GetTileType(tile);
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1294
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1295
			/* Check if there is any track on tile */
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1296
			switch (tt) {
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1297
				case MP_RAILWAY:
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1298
					break;
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1299
				case MP_STATION:
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1300
					if (!IsRailwayStation(tile)) continue;
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1301
					break;
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1302
				case MP_ROAD:
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1303
					if (!IsLevelCrossing(tile)) continue;
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1304
					break;
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1305
				case MP_TUNNELBRIDGE:
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1306
					if (GetTunnelBridgeTransportType(tile) != TRANSPORT_RAIL) continue;
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1307
					break;
2549
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1308
				default: continue;
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1309
			}
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1310
8096
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1311
			/* Original railtype we are converting from */
7539
5f41050498bd (svn r11059) -Fix [FS#1182]: inconsistency between Rail<->ElRail conversions of different kinds of rail containing tiles (normal rail, stations, depots, etc). Patch by SmatZ.
rubidium
parents: 7494
diff changeset
  1312
			RailType type = GetRailType(tile);
5f41050498bd (svn r11059) -Fix [FS#1182]: inconsistency between Rail<->ElRail conversions of different kinds of rail containing tiles (normal rail, stations, depots, etc). Patch by SmatZ.
rubidium
parents: 7494
diff changeset
  1313
8096
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1314
			/* Converting to the same type or converting 'hidden' elrail -> rail */
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
  1315
			if (type == totype || (_settings_game.vehicle.disable_elrails && totype == RAILTYPE_RAIL && type == RAILTYPE_ELECTRIC)) continue;
8096
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1316
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1317
			/* Trying to convert other's rail */
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1318
			if (!CheckTileOwnership(tile)) continue;
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1319
9815
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9795
diff changeset
  1320
			SmallVector<Vehicle*, 2> vehicles_affected;
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9795
diff changeset
  1321
8096
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1322
			/* Vehicle on the tile when not converting Rail <-> ElRail
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1323
			 * Tunnels and bridges have special check later */
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1324
			if (tt != MP_TUNNELBRIDGE) {
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1325
				if (!IsCompatibleRail(type, totype) && !EnsureNoVehicleOnGround(tile)) continue;
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1326
				if (flags & DC_EXEC) { // we can safely convert, too
9815
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9795
diff changeset
  1327
					TrackBits reserved = GetReservedTrackbits(tile);
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9795
diff changeset
  1328
					Track     track;
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9795
diff changeset
  1329
					while ((track = RemoveFirstTrack(&reserved)) != INVALID_TRACK) {
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9795
diff changeset
  1330
						Vehicle *v = GetTrainForReservation(tile, track);
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9795
diff changeset
  1331
						if (v != NULL && !HasPowerOnRail(v->u.rail.railtype, totype)) {
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9795
diff changeset
  1332
							/* No power on new rail type, reroute. */
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9795
diff changeset
  1333
							FreeTrainTrackReservation(v);
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9795
diff changeset
  1334
							*vehicles_affected.Append() = v;
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9795
diff changeset
  1335
						}
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9795
diff changeset
  1336
					}
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9795
diff changeset
  1337
8096
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1338
					SetRailType(tile, totype);
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1339
					MarkTileDirtyByTile(tile);
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1340
					/* update power of train engines on this tile */
10083
eee4e42aa15b (svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium
parents: 10017
diff changeset
  1341
					FindVehicleOnPos(tile, NULL, &UpdateTrainPowerProc);
8096
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1342
				}
7539
5f41050498bd (svn r11059) -Fix [FS#1182]: inconsistency between Rail<->ElRail conversions of different kinds of rail containing tiles (normal rail, stations, depots, etc). Patch by SmatZ.
rubidium
parents: 7494
diff changeset
  1343
			}
5f41050498bd (svn r11059) -Fix [FS#1182]: inconsistency between Rail<->ElRail conversions of different kinds of rail containing tiles (normal rail, stations, depots, etc). Patch by SmatZ.
rubidium
parents: 7494
diff changeset
  1344
8096
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1345
			switch (tt) {
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1346
				case MP_RAILWAY:
8153
3f5ba7ee376f (svn r11715) -Fix: do not use GetTrackBits() for depots and waypoints while converting railtype
smatz
parents: 8144
diff changeset
  1347
					switch (GetRailTileType(tile)) {
3f5ba7ee376f (svn r11715) -Fix: do not use GetTrackBits() for depots and waypoints while converting railtype
smatz
parents: 8144
diff changeset
  1348
						case RAIL_TILE_WAYPOINT:
3f5ba7ee376f (svn r11715) -Fix: do not use GetTrackBits() for depots and waypoints while converting railtype
smatz
parents: 8144
diff changeset
  1349
							if (flags & DC_EXEC) {
3f5ba7ee376f (svn r11715) -Fix: do not use GetTrackBits() for depots and waypoints while converting railtype
smatz
parents: 8144
diff changeset
  1350
								/* notify YAPF about the track layout change */
9224
93528d9cb96d (svn r13090) -Codechange: add functions for direct conversion from DiagDirection to Track and Trackbits
smatz
parents: 9154
diff changeset
  1351
								YapfNotifyTrackLayoutChange(tile, GetRailWaypointTrack(tile));
8153
3f5ba7ee376f (svn r11715) -Fix: do not use GetTrackBits() for depots and waypoints while converting railtype
smatz
parents: 8144
diff changeset
  1352
							}
3f5ba7ee376f (svn r11715) -Fix: do not use GetTrackBits() for depots and waypoints while converting railtype
smatz
parents: 8144
diff changeset
  1353
							cost.AddCost(RailConvertCost(type, totype));
3f5ba7ee376f (svn r11715) -Fix: do not use GetTrackBits() for depots and waypoints while converting railtype
smatz
parents: 8144
diff changeset
  1354
							break;
3f5ba7ee376f (svn r11715) -Fix: do not use GetTrackBits() for depots and waypoints while converting railtype
smatz
parents: 8144
diff changeset
  1355
3f5ba7ee376f (svn r11715) -Fix: do not use GetTrackBits() for depots and waypoints while converting railtype
smatz
parents: 8144
diff changeset
  1356
						case RAIL_TILE_DEPOT:
3f5ba7ee376f (svn r11715) -Fix: do not use GetTrackBits() for depots and waypoints while converting railtype
smatz
parents: 8144
diff changeset
  1357
							if (flags & DC_EXEC) {
3f5ba7ee376f (svn r11715) -Fix: do not use GetTrackBits() for depots and waypoints while converting railtype
smatz
parents: 8144
diff changeset
  1358
								/* notify YAPF about the track layout change */
9224
93528d9cb96d (svn r13090) -Codechange: add functions for direct conversion from DiagDirection to Track and Trackbits
smatz
parents: 9154
diff changeset
  1359
								YapfNotifyTrackLayoutChange(tile, GetRailDepotTrack(tile));
8153
3f5ba7ee376f (svn r11715) -Fix: do not use GetTrackBits() for depots and waypoints while converting railtype
smatz
parents: 8144
diff changeset
  1360
3f5ba7ee376f (svn r11715) -Fix: do not use GetTrackBits() for depots and waypoints while converting railtype
smatz
parents: 8144
diff changeset
  1361
								/* Update build vehicle window related to this depot */
3f5ba7ee376f (svn r11715) -Fix: do not use GetTrackBits() for depots and waypoints while converting railtype
smatz
parents: 8144
diff changeset
  1362
								InvalidateWindowData(WC_VEHICLE_DEPOT, tile);
3f5ba7ee376f (svn r11715) -Fix: do not use GetTrackBits() for depots and waypoints while converting railtype
smatz
parents: 8144
diff changeset
  1363
								InvalidateWindowData(WC_BUILD_VEHICLE, tile);
3f5ba7ee376f (svn r11715) -Fix: do not use GetTrackBits() for depots and waypoints while converting railtype
smatz
parents: 8144
diff changeset
  1364
							}
3f5ba7ee376f (svn r11715) -Fix: do not use GetTrackBits() for depots and waypoints while converting railtype
smatz
parents: 8144
diff changeset
  1365
							cost.AddCost(RailConvertCost(type, totype));
3f5ba7ee376f (svn r11715) -Fix: do not use GetTrackBits() for depots and waypoints while converting railtype
smatz
parents: 8144
diff changeset
  1366
							break;
3f5ba7ee376f (svn r11715) -Fix: do not use GetTrackBits() for depots and waypoints while converting railtype
smatz
parents: 8144
diff changeset
  1367
3f5ba7ee376f (svn r11715) -Fix: do not use GetTrackBits() for depots and waypoints while converting railtype
smatz
parents: 8144
diff changeset
  1368
						default: // RAIL_TILE_NORMAL, RAIL_TILE_SIGNALS
3f5ba7ee376f (svn r11715) -Fix: do not use GetTrackBits() for depots and waypoints while converting railtype
smatz
parents: 8144
diff changeset
  1369
							if (flags & DC_EXEC) {
3f5ba7ee376f (svn r11715) -Fix: do not use GetTrackBits() for depots and waypoints while converting railtype
smatz
parents: 8144
diff changeset
  1370
								/* notify YAPF about the track layout change */
3f5ba7ee376f (svn r11715) -Fix: do not use GetTrackBits() for depots and waypoints while converting railtype
smatz
parents: 8144
diff changeset
  1371
								TrackBits tracks = GetTrackBits(tile);
3f5ba7ee376f (svn r11715) -Fix: do not use GetTrackBits() for depots and waypoints while converting railtype
smatz
parents: 8144
diff changeset
  1372
								while (tracks != TRACK_BIT_NONE) {
3f5ba7ee376f (svn r11715) -Fix: do not use GetTrackBits() for depots and waypoints while converting railtype
smatz
parents: 8144
diff changeset
  1373
									YapfNotifyTrackLayoutChange(tile, RemoveFirstTrack(&tracks));
3f5ba7ee376f (svn r11715) -Fix: do not use GetTrackBits() for depots and waypoints while converting railtype
smatz
parents: 8144
diff changeset
  1374
								}
3f5ba7ee376f (svn r11715) -Fix: do not use GetTrackBits() for depots and waypoints while converting railtype
smatz
parents: 8144
diff changeset
  1375
							}
3f5ba7ee376f (svn r11715) -Fix: do not use GetTrackBits() for depots and waypoints while converting railtype
smatz
parents: 8144
diff changeset
  1376
							cost.AddCost(RailConvertCost(type, totype) * CountBits(GetTrackBits(tile)));
3f5ba7ee376f (svn r11715) -Fix: do not use GetTrackBits() for depots and waypoints while converting railtype
smatz
parents: 8144
diff changeset
  1377
							break;
8096
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1378
					}
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1379
					break;
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1380
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1381
				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: 8158
diff changeset
  1382
					TileIndex endtile = GetOtherTunnelBridgeEnd(tile);
8096
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1383
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1384
					/* If both ends of tunnel/bridge are in the range, do not try to convert twice -
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1385
					 * it would cause assert because of different test and exec runs */
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1386
					if (endtile < tile && TileX(endtile) >= sx && TileX(endtile) <= ex &&
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1387
							TileY(endtile) >= sy && TileY(endtile) <= ey) continue;
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1388
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1389
					/* When not coverting rail <-> el. rail, any vehicle cannot be in tunnel/bridge */
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1390
					if (!IsCompatibleRail(GetRailType(tile), totype) &&
10165
d884de1b3f81 (svn r14356) -Fix [FS#2307](r14258): converting of railtype was broken for tunnels and bridges
smatz
parents: 10159
diff changeset
  1391
							HasVehicleOnTunnelBridge(tile, endtile)) continue;
8096
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1392
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1393
					if (flags & DC_EXEC) {
9815
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9795
diff changeset
  1394
						Track track = DiagDirToDiagTrack(GetTunnelBridgeDirection(tile));
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9795
diff changeset
  1395
						if (GetTunnelBridgeReservation(tile)) {
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9795
diff changeset
  1396
							Vehicle *v = GetTrainForReservation(tile, track);
10313
57bba78128d2 (svn r14558) -Fix (r13957): Converting the track type of a tunnel/bridge could cause trains to get stuck.
michi_cc
parents: 10260
diff changeset
  1397
							if (v != NULL && !HasPowerOnRail(v->u.rail.railtype, totype)) {
57bba78128d2 (svn r14558) -Fix (r13957): Converting the track type of a tunnel/bridge could cause trains to get stuck.
michi_cc
parents: 10260
diff changeset
  1398
								/* No power on new rail type, reroute. */
9815
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9795
diff changeset
  1399
								FreeTrainTrackReservation(v);
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9795
diff changeset
  1400
								*vehicles_affected.Append() = v;
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9795
diff changeset
  1401
							}
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9795
diff changeset
  1402
						}
8096
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1403
						SetRailType(tile, totype);
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1404
						SetRailType(endtile, totype);
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1405
10083
eee4e42aa15b (svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium
parents: 10017
diff changeset
  1406
						FindVehicleOnPos(tile, NULL, &UpdateTrainPowerProc);
eee4e42aa15b (svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium
parents: 10017
diff changeset
  1407
						FindVehicleOnPos(endtile, NULL, &UpdateTrainPowerProc);
8096
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1408
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1409
						YapfNotifyTrackLayoutChange(tile, track);
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1410
						YapfNotifyTrackLayoutChange(endtile, track);
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1411
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1412
						MarkTileDirtyByTile(tile);
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1413
						MarkTileDirtyByTile(endtile);
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1414
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1415
						if (IsBridge(tile)) {
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1416
							TileIndexDiff delta = TileOffsByDiagDir(GetTunnelBridgeDirection(tile));
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1417
							TileIndex t = tile + delta;
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1418
							for (; t != endtile; t += delta) MarkTileDirtyByTile(t); // TODO encapsulate this into a function
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1419
						}
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1420
					}
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1421
8398
1e181e2e4e15 (svn r11968) -Codechange: remove redundant FindLengthOfTunnel(), use GetTunnelBridgeLength() and/or GetOtherTunnelEnd() instead
smatz
parents: 8344
diff changeset
  1422
					cost.AddCost((GetTunnelBridgeLength(tile, endtile) + 2) * RailConvertCost(type, totype));
8096
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1423
				} break;
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1424
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1425
				default: // MP_STATION, MP_ROAD
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1426
					if (flags & DC_EXEC) {
8598
ddd1f342b0da (svn r12179) -Codechange: use GetCrossingRailTrack() and GetCrossingRailAxis() to improve code readability
smatz
parents: 8596
diff changeset
  1427
						Track track = ((tt == MP_STATION) ? GetRailStationTrack(tile) : GetCrossingRailTrack(tile));
8096
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1428
						YapfNotifyTrackLayoutChange(tile, track);
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1429
					}
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1430
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1431
					cost.AddCost(RailConvertCost(type, totype));
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1432
					break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1433
			}
9815
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9795
diff changeset
  1434
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9795
diff changeset
  1435
			for (uint i = 0; i < vehicles_affected.Length(); ++i) {
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9795
diff changeset
  1436
				TryPathReserve(vehicles_affected[i], true);
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9795
diff changeset
  1437
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1438
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1439
	}
1782
48749e4c2dc6 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1781
diff changeset
  1440
8096
bc9bc6c35b9b (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8088
diff changeset
  1441
	return (cost.GetCost() == 0) ? CMD_ERROR : cost;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1442
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1443
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6791
diff changeset
  1444
static CommandCost RemoveTrainDepot(TileIndex tile, uint32 flags)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1445
{
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10172
diff changeset
  1446
	if (!CheckTileOwnership(tile) && _current_company != OWNER_WATER)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1447
		return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1448
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
  1449
	if (!EnsureNoVehicleOnGround(tile))
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1450
		return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1451
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1452
	if (flags & DC_EXEC) {
8300
dfd530665621 (svn r11864) -Codechange: pass owner whose signals we will update instead of complex detection later
smatz
parents: 8264
diff changeset
  1453
		/* read variables before the depot is removed */
3191
b2bebf380cd7 (svn r3851) Rail depots only have an entrance at one side, therefore use UpdateSignalsOnSegment() instead of SetSignalsOnBothDir()
tron
parents: 3189
diff changeset
  1454
		DiagDirection dir = GetRailDepotDirection(tile);
8300
dfd530665621 (svn r11864) -Codechange: pass owner whose signals we will update instead of complex detection later
smatz
parents: 8264
diff changeset
  1455
		Owner owner = GetTileOwner(tile);
9815
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9795
diff changeset
  1456
		Vehicle *v = NULL;
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9795
diff changeset
  1457
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9795
diff changeset
  1458
		if (GetDepotWaypointReservation(tile)) {
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9795
diff changeset
  1459
			v = GetTrainForReservation(tile, DiagDirToDiagTrack(dir));
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9795
diff changeset
  1460
			if (v != NULL) FreeTrainTrackReservation(v);
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9795
diff changeset
  1461
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1462
7389
08d6a6265ced (svn r10758) -Codechange: make the depot struct use the pool item class as super class.
rubidium
parents: 7371
diff changeset
  1463
		DoClearSquare(tile);
08d6a6265ced (svn r10758) -Codechange: make the depot struct use the pool item class as super class.
rubidium
parents: 7371
diff changeset
  1464
		delete GetDepotByTile(tile);
8306
22e1344c5457 (svn r11871) -Fix [FS#1074]: do not update signals after each tile when building/removing a large block of track/signals/station
smatz
parents: 8300
diff changeset
  1465
		AddSideToSignalBuffer(tile, dir, owner);
9224
93528d9cb96d (svn r13090) -Codechange: add functions for direct conversion from DiagDirection to Track and Trackbits
smatz
parents: 9154
diff changeset
  1466
		YapfNotifyTrackLayoutChange(tile, DiagDirToDiagTrack(dir));
9815
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9795
diff changeset
  1467
		if (v != NULL) TryPathReserve(v, true);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1468
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1469
8230
64f28fe2d5c8 (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8228
diff changeset
  1470
	return CommandCost(EXPENSES_CONSTRUCTION, _price.remove_train_depot);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1471
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1472
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6791
diff changeset
  1473
static CommandCost ClearTile_Track(TileIndex tile, byte flags)
1534
304124d6b5e3 (svn r2038) -Fix: A player only received the money for one rail when clearing a tile with 2 rails and signals
tron
parents: 1518
diff changeset
  1474
{
8230
64f28fe2d5c8 (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8228
diff changeset
  1475
	CommandCost cost(EXPENSES_CONSTRUCTION);
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6791
diff changeset
  1476
	CommandCost ret;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1477
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1478
	if (flags & DC_AUTO) {
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10172
diff changeset
  1479
		if (!IsTileOwner(tile, _current_company))
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1480
			return_cmd_error(STR_1024_AREA_IS_OWNED_BY_ANOTHER);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1481
4182
48dba107ff43 (svn r5624) Use {IsPlainRailTile,IsRailDepot,IsRailWaypoint,HasSignals}() instead of GetRailTile{T,Subt}ype() - this is more concise and a bit more flexible if/when the rail tile encoding changes
tron
parents: 4180
diff changeset
  1482
		if (IsPlainRailTile(tile)) {
48dba107ff43 (svn r5624) Use {IsPlainRailTile,IsRailDepot,IsRailWaypoint,HasSignals}() instead of GetRailTile{T,Subt}ype() - this is more concise and a bit more flexible if/when the rail tile encoding changes
tron
parents: 4180
diff changeset
  1483
			return_cmd_error(STR_1008_MUST_REMOVE_RAILROAD_TRACK);
48dba107ff43 (svn r5624) Use {IsPlainRailTile,IsRailDepot,IsRailWaypoint,HasSignals}() instead of GetRailTile{T,Subt}ype() - this is more concise and a bit more flexible if/when the rail tile encoding changes
tron
parents: 4180
diff changeset
  1484
		} else {
48dba107ff43 (svn r5624) Use {IsPlainRailTile,IsRailDepot,IsRailWaypoint,HasSignals}() instead of GetRailTile{T,Subt}ype() - this is more concise and a bit more flexible if/when the rail tile encoding changes
tron
parents: 4180
diff changeset
  1485
			return_cmd_error(STR_2004_BUILDING_MUST_BE_DEMOLISHED);
48dba107ff43 (svn r5624) Use {IsPlainRailTile,IsRailDepot,IsRailWaypoint,HasSignals}() instead of GetRailTile{T,Subt}ype() - this is more concise and a bit more flexible if/when the rail tile encoding changes
tron
parents: 4180
diff changeset
  1486
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1487
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1488
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
  1489
	switch (GetRailTileType(tile)) {
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: 3778
diff changeset
  1490
		case RAIL_TILE_SIGNALS:
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: 3778
diff changeset
  1491
		case RAIL_TILE_NORMAL: {
8414
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
  1492
			Slope tileh = GetTileSlope(tile, NULL);
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
  1493
			/* Is there flat water on the lower halftile, that gets cleared expensively? */
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
  1494
			bool water_ground = (GetRailGroundType(tile) == RAIL_GROUND_WATER && IsSlopeWithOneCornerRaised(tileh));
7771
a900b80b48f2 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 7770
diff changeset
  1495
5414
6469dbacdab8 (svn r7617) -Fix (7609): GetTrackBits only works (as intended) for plain rail tiles, so get the trackbits if it is certain it is a plain rail tile. Noticed by Tron.
rubidium
parents: 5411
diff changeset
  1496
			TrackBits tracks = GetTrackBits(tile);
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
  1497
			while (tracks != TRACK_BIT_NONE) {
5598
2fadbd43709d (svn r8052) - Codechange: RemoveFirstTrack() and RemoveFirstTrackdir() now accept pointer to TrackBits/TrackdirBits instead of reference.
KUDr
parents: 5587
diff changeset
  1498
				Track track = RemoveFirstTrack(&tracks);
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
  1499
				ret = DoCommand(tile, 0, track, flags, CMD_REMOVE_SINGLE_RAIL);
5411
9ad8285b2f0d (svn r7609) -Codechange: remove some direct map accesses to m5 and some unneeded signal removal code in ClearTileTrack as it is done in CmdRemoveSingleRail too, which is called for every removed trackbit.
rubidium
parents: 5394
diff changeset
  1500
				if (CmdFailed(ret)) return CMD_ERROR;
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6946
diff changeset
  1501
				cost.AddCost(ret);
1534
304124d6b5e3 (svn r2038) -Fix: A player only received the money for one rail when clearing a tile with 2 rails and signals
tron
parents: 1518
diff changeset
  1502
			}
7771
a900b80b48f2 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 7770
diff changeset
  1503
9504
58b2ee0f53c9 (svn r13488) -Fix (r13485): track wasn't removed on company bankrupcy when there was a ship on lower halftile
smatz
parents: 9503
diff changeset
  1504
			/* when bankrupting, don't make water dirty, there could be a ship on lower halftile */
58b2ee0f53c9 (svn r13488) -Fix (r13485): track wasn't removed on company bankrupcy when there was a ship on lower halftile
smatz
parents: 9503
diff changeset
  1505
			if (water_ground && !(flags & DC_BANKRUPT)) {
9503
231e0b6b5b54 (svn r13485) -Fix: let ships also navigate on half-tile sloped watery rail tiles.
rubidium
parents: 9413
diff changeset
  1506
				if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
231e0b6b5b54 (svn r13485) -Fix: let ships also navigate on half-tile sloped watery rail tiles.
rubidium
parents: 9413
diff changeset
  1507
7771
a900b80b48f2 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 7770
diff changeset
  1508
				/* The track was removed, and left a coast tile. Now also clear the water. */
a900b80b48f2 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 7770
diff changeset
  1509
				if (flags & DC_EXEC) DoClearSquare(tile);
a900b80b48f2 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 7770
diff changeset
  1510
				cost.AddCost(_price.clear_water);
a900b80b48f2 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 7770
diff changeset
  1511
			}
a900b80b48f2 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 7770
diff changeset
  1512
1534
304124d6b5e3 (svn r2038) -Fix: A player only received the money for one rail when clearing a tile with 2 rails and signals
tron
parents: 1518
diff changeset
  1513
			return cost;
304124d6b5e3 (svn r2038) -Fix: A player only received the money for one rail when clearing a tile with 2 rails and signals
tron
parents: 1518
diff changeset
  1514
		}
304124d6b5e3 (svn r2038) -Fix: A player only received the money for one rail when clearing a tile with 2 rails and signals
tron
parents: 1518
diff changeset
  1515
6172
e6d7a5b3d63f (svn r8935) -Codechange: unification of track type between road and rail tiles, unification of ground type between normal rail tiles and depots/waypoints and removing the need for RailTileSubType.
rubidium
parents: 6160
diff changeset
  1516
		case RAIL_TILE_DEPOT:
e6d7a5b3d63f (svn r8935) -Codechange: unification of track type between road and rail tiles, unification of ground type between normal rail tiles and depots/waypoints and removing the need for RailTileSubType.
rubidium
parents: 6160
diff changeset
  1517
			return RemoveTrainDepot(tile, flags);
e6d7a5b3d63f (svn r8935) -Codechange: unification of track type between road and rail tiles, unification of ground type between normal rail tiles and depots/waypoints and removing the need for RailTileSubType.
rubidium
parents: 6160
diff changeset
  1518
e6d7a5b3d63f (svn r8935) -Codechange: unification of track type between road and rail tiles, unification of ground type between normal rail tiles and depots/waypoints and removing the need for RailTileSubType.
rubidium
parents: 6160
diff changeset
  1519
		case RAIL_TILE_WAYPOINT:
e6d7a5b3d63f (svn r8935) -Codechange: unification of track type between road and rail tiles, unification of ground type between normal rail tiles and depots/waypoints and removing the need for RailTileSubType.
rubidium
parents: 6160
diff changeset
  1520
			return RemoveTrainWaypoint(tile, flags, false);
1534
304124d6b5e3 (svn r2038) -Fix: A player only received the money for one rail when clearing a tile with 2 rails and signals
tron
parents: 1518
diff changeset
  1521
304124d6b5e3 (svn r2038) -Fix: A player only received the money for one rail when clearing a tile with 2 rails and signals
tron
parents: 1518
diff changeset
  1522
		default:
304124d6b5e3 (svn r2038) -Fix: A player only received the money for one rail when clearing a tile with 2 rails and signals
tron
parents: 1518
diff changeset
  1523
			return CMD_ERROR;
304124d6b5e3 (svn r2038) -Fix: A player only received the money for one rail when clearing a tile with 2 rails and signals
tron
parents: 1518
diff changeset
  1524
	}
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
7764
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7763
diff changeset
  1527
/**
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7763
diff changeset
  1528
 * Get surface height in point (x,y)
10017
c0eb11a864d7 (svn r14176) -Fix: better 'safe' than ... 'save'
smatz
parents: 10006
diff changeset
  1529
 * On tiles with halftile foundations move (x,y) to a safe point wrt. track
7764
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7763
diff changeset
  1530
 */
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7763
diff changeset
  1531
static uint GetSaveSlopeZ(uint x, uint y, Track track)
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7763
diff changeset
  1532
{
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7763
diff changeset
  1533
	switch (track) {
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7763
diff changeset
  1534
		case TRACK_UPPER: x &= ~0xF; y &= ~0xF; break;
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7763
diff changeset
  1535
		case TRACK_LOWER: x |=  0xF; y |=  0xF; break;
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7763
diff changeset
  1536
		case TRACK_LEFT:  x |=  0xF; y &= ~0xF; break;
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7763
diff changeset
  1537
		case TRACK_RIGHT: x &= ~0xF; y |=  0xF; break;
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7763
diff changeset
  1538
		default: break;
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7763
diff changeset
  1539
	}
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7763
diff changeset
  1540
	return GetSlopeZ(x, y);
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7763
diff changeset
  1541
}
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7763
diff changeset
  1542
6770
408585d467f9 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 6753
diff changeset
  1543
static void DrawSingleSignal(TileIndex tile, Track track, byte condition, uint image, uint pos)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1544
{
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
  1545
	bool side = (_settings_game.vehicle.road_side != 0) && _settings_game.construction.signal_side;
3502
b747d7225871 (svn r4353) Codechange: Move global _signal_position into the only function that uses it and convert the bit-hacking into a struct
celestar
parents: 3493
diff changeset
  1546
	static const Point SignalPositions[2][12] = {
b747d7225871 (svn r4353) Codechange: Move global _signal_position into the only function that uses it and convert the bit-hacking into a struct
celestar
parents: 3493
diff changeset
  1547
		{      /* Signals on the left side */
b747d7225871 (svn r4353) Codechange: Move global _signal_position into the only function that uses it and convert the bit-hacking into a struct
celestar
parents: 3493
diff changeset
  1548
		/*  LEFT      LEFT      RIGHT     RIGHT     UPPER     UPPER */
b747d7225871 (svn r4353) Codechange: Move global _signal_position into the only function that uses it and convert the bit-hacking into a struct
celestar
parents: 3493
diff changeset
  1549
			{ 8,  5}, {14,  1}, { 1, 14}, { 9, 11}, { 1,  0}, { 3, 10},
b747d7225871 (svn r4353) Codechange: Move global _signal_position into the only function that uses it and convert the bit-hacking into a struct
celestar
parents: 3493
diff changeset
  1550
		/*  LOWER     LOWER     X         X         Y         Y     */
b747d7225871 (svn r4353) Codechange: Move global _signal_position into the only function that uses it and convert the bit-hacking into a struct
celestar
parents: 3493
diff changeset
  1551
			{11,  4}, {14, 14}, {11,  3}, { 4, 13}, { 3,  4}, {11, 13}
b747d7225871 (svn r4353) Codechange: Move global _signal_position into the only function that uses it and convert the bit-hacking into a struct
celestar
parents: 3493
diff changeset
  1552
		}, {   /* Signals on the right side */
b747d7225871 (svn r4353) Codechange: Move global _signal_position into the only function that uses it and convert the bit-hacking into a struct
celestar
parents: 3493
diff changeset
  1553
		/*  LEFT      LEFT      RIGHT     RIGHT     UPPER     UPPER */
b747d7225871 (svn r4353) Codechange: Move global _signal_position into the only function that uses it and convert the bit-hacking into a struct
celestar
parents: 3493
diff changeset
  1554
			{14,  1}, {12, 10}, { 4,  6}, { 1, 14}, {10,  4}, { 0,  1},
b747d7225871 (svn r4353) Codechange: Move global _signal_position into the only function that uses it and convert the bit-hacking into a struct
celestar
parents: 3493
diff changeset
  1555
		/*  LOWER     LOWER     X         X         Y         Y     */
b747d7225871 (svn r4353) Codechange: Move global _signal_position into the only function that uses it and convert the bit-hacking into a struct
celestar
parents: 3493
diff changeset
  1556
			{14, 14}, { 5, 12}, {11, 13}, { 4,  3}, {13,  4}, { 3, 11}
b747d7225871 (svn r4353) Codechange: Move global _signal_position into the only function that uses it and convert the bit-hacking into a struct
celestar
parents: 3493
diff changeset
  1557
		}
b747d7225871 (svn r4353) Codechange: Move global _signal_position into the only function that uses it and convert the bit-hacking into a struct
celestar
parents: 3493
diff changeset
  1558
	};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1559
3575
f5b56bd958c0 (svn r4461) -Codechange: Add and make use of map accessor functions for signal drawing. Includes some basic cleanup of the drawing functions
celestar
parents: 3562
diff changeset
  1560
	uint x = TileX(tile) * TILE_SIZE + SignalPositions[side][pos].x;
f5b56bd958c0 (svn r4461) -Codechange: Add and make use of map accessor functions for signal drawing. Includes some basic cleanup of the drawing functions
celestar
parents: 3562
diff changeset
  1561
	uint y = TileY(tile) * TILE_SIZE + SignalPositions[side][pos].y;
f5b56bd958c0 (svn r4461) -Codechange: Add and make use of map accessor functions for signal drawing. Includes some basic cleanup of the drawing functions
celestar
parents: 3562
diff changeset
  1562
3638
3e655c6e0914 (svn r4546) - NewGRF: add support for Action 0x05, type 0x04: replacement signal graphics. Thanks to Purno for supplying data to test
peter1138
parents: 3636
diff changeset
  1563
	SpriteID sprite;
3e655c6e0914 (svn r4546) - NewGRF: add support for Action 0x05, type 0x04: replacement signal graphics. Thanks to Purno for supplying data to test
peter1138
parents: 3636
diff changeset
  1564
8547
b711dcd549d8 (svn r12125) -Codechange: Remove redundant signal lookup table, and document why normal electric signals are handled specially.
peter1138
parents: 8523
diff changeset
  1565
	SignalType type       = GetSignalType(tile, track);
b711dcd549d8 (svn r12125) -Codechange: Remove redundant signal lookup table, and document why normal electric signals are handled specially.
peter1138
parents: 8523
diff changeset
  1566
	SignalVariant variant = GetSignalVariant(tile, track);
b711dcd549d8 (svn r12125) -Codechange: Remove redundant signal lookup table, and document why normal electric signals are handled specially.
peter1138
parents: 8523
diff changeset
  1567
b711dcd549d8 (svn r12125) -Codechange: Remove redundant signal lookup table, and document why normal electric signals are handled specially.
peter1138
parents: 8523
diff changeset
  1568
	if (type == SIGTYPE_NORMAL && variant == SIG_ELECTRIC) {
b711dcd549d8 (svn r12125) -Codechange: Remove redundant signal lookup table, and document why normal electric signals are handled specially.
peter1138
parents: 8523
diff changeset
  1569
		/* Normal electric signals are picked from original sprites. */
b711dcd549d8 (svn r12125) -Codechange: Remove redundant signal lookup table, and document why normal electric signals are handled specially.
peter1138
parents: 8523
diff changeset
  1570
		sprite = SPR_ORIGINAL_SIGNALS_BASE + image + condition;
3638
3e655c6e0914 (svn r4546) - NewGRF: add support for Action 0x05, type 0x04: replacement signal graphics. Thanks to Purno for supplying data to test
peter1138
parents: 3636
diff changeset
  1571
	} else {
8547
b711dcd549d8 (svn r12125) -Codechange: Remove redundant signal lookup table, and document why normal electric signals are handled specially.
peter1138
parents: 8523
diff changeset
  1572
		/* All other signals are picked from add on sprites. */
9790
5d5c70e0334e (svn r13932) -Add [YAPP]: PBS signals added to the map array. The signals are drawn using the old Patch-like PBS sprites. (michi_cc)
rubidium
parents: 9788
diff changeset
  1573
		sprite = SPR_SIGNALS_BASE + (type - 1) * 16 + variant * 64 + image + condition + (type > SIGTYPE_LAST_NOPBS ? 64 : 0);
3638
3e655c6e0914 (svn r4546) - NewGRF: add support for Action 0x05, type 0x04: replacement signal graphics. Thanks to Purno for supplying data to test
peter1138
parents: 3636
diff changeset
  1574
	}
3575
f5b56bd958c0 (svn r4461) -Codechange: Add and make use of map accessor functions for signal drawing. Includes some basic cleanup of the drawing functions
celestar
parents: 3562
diff changeset
  1575
7764
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7763
diff changeset
  1576
	AddSortableSpriteToDraw(sprite, PAL_NONE, x, y, 1, 1, BB_HEIGHT_UNDER_BRIDGE, GetSaveSlopeZ(x, y, track));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1577
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1578
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1579
static uint32 _drawtile_track_palette;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1580
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1581
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
  1582
static void DrawTrackFence_NW(const TileInfo *ti)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1583
{
7307
9f8922176b67 (svn r10659) -Codechange: updated documentation around RAIL_GROUND_FENCE_VERT[12] (frosch)
truelight
parents: 7272
diff changeset
  1584
	SpriteID image = SPR_TRACK_FENCE_FLAT_X;
9f8922176b67 (svn r10659) -Codechange: updated documentation around RAIL_GROUND_FENCE_VERT[12] (frosch)
truelight
parents: 7272
diff changeset
  1585
	if (ti->tileh != SLOPE_FLAT) image = (ti->tileh & SLOPE_S) ? SPR_TRACK_FENCE_SLOPE_SW : SPR_TRACK_FENCE_SLOPE_NE;
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5598
diff changeset
  1586
	AddSortableSpriteToDraw(image, _drawtile_track_palette,
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2934
diff changeset
  1587
		ti->x, ti->y + 1, 16, 1, 4, ti->z);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1588
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1589
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
  1590
static void DrawTrackFence_SE(const TileInfo *ti)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1591
{
7307
9f8922176b67 (svn r10659) -Codechange: updated documentation around RAIL_GROUND_FENCE_VERT[12] (frosch)
truelight
parents: 7272
diff changeset
  1592
	SpriteID image = SPR_TRACK_FENCE_FLAT_X;
9f8922176b67 (svn r10659) -Codechange: updated documentation around RAIL_GROUND_FENCE_VERT[12] (frosch)
truelight
parents: 7272
diff changeset
  1593
	if (ti->tileh != SLOPE_FLAT) image = (ti->tileh & SLOPE_S) ? SPR_TRACK_FENCE_SLOPE_SW : SPR_TRACK_FENCE_SLOPE_NE;
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5598
diff changeset
  1594
	AddSortableSpriteToDraw(image, _drawtile_track_palette,
3645
7f950533d510 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3638
diff changeset
  1595
		ti->x, ti->y + TILE_SIZE - 1, 16, 1, 4, ti->z);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1596
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1597
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
  1598
static void DrawTrackFence_NW_SE(const TileInfo *ti)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1599
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1600
	DrawTrackFence_NW(ti);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1601
	DrawTrackFence_SE(ti);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1602
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1603
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
  1604
static void DrawTrackFence_NE(const TileInfo *ti)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1605
{
7307
9f8922176b67 (svn r10659) -Codechange: updated documentation around RAIL_GROUND_FENCE_VERT[12] (frosch)
truelight
parents: 7272
diff changeset
  1606
	SpriteID image = SPR_TRACK_FENCE_FLAT_Y;
9f8922176b67 (svn r10659) -Codechange: updated documentation around RAIL_GROUND_FENCE_VERT[12] (frosch)
truelight
parents: 7272
diff changeset
  1607
	if (ti->tileh != SLOPE_FLAT) image = (ti->tileh & SLOPE_S) ? SPR_TRACK_FENCE_SLOPE_SE : SPR_TRACK_FENCE_SLOPE_NW;
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5598
diff changeset
  1608
	AddSortableSpriteToDraw(image, _drawtile_track_palette,
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2934
diff changeset
  1609
		ti->x + 1, ti->y, 1, 16, 4, ti->z);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1610
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1611
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
  1612
static void DrawTrackFence_SW(const TileInfo *ti)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1613
{
7307
9f8922176b67 (svn r10659) -Codechange: updated documentation around RAIL_GROUND_FENCE_VERT[12] (frosch)
truelight
parents: 7272
diff changeset
  1614
	SpriteID image = SPR_TRACK_FENCE_FLAT_Y;
9f8922176b67 (svn r10659) -Codechange: updated documentation around RAIL_GROUND_FENCE_VERT[12] (frosch)
truelight
parents: 7272
diff changeset
  1615
	if (ti->tileh != SLOPE_FLAT) image = (ti->tileh & SLOPE_S) ? SPR_TRACK_FENCE_SLOPE_SE : SPR_TRACK_FENCE_SLOPE_NW;
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5598
diff changeset
  1616
	AddSortableSpriteToDraw(image, _drawtile_track_palette,
3645
7f950533d510 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3638
diff changeset
  1617
		ti->x + TILE_SIZE - 1, ti->y, 1, 16, 4, ti->z);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1618
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1619
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
  1620
static void DrawTrackFence_NE_SW(const TileInfo *ti)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1621
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1622
	DrawTrackFence_NE(ti);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1623
	DrawTrackFence_SW(ti);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1624
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1625
7307
9f8922176b67 (svn r10659) -Codechange: updated documentation around RAIL_GROUND_FENCE_VERT[12] (frosch)
truelight
parents: 7272
diff changeset
  1626
/**
9f8922176b67 (svn r10659) -Codechange: updated documentation around RAIL_GROUND_FENCE_VERT[12] (frosch)
truelight
parents: 7272
diff changeset
  1627
 * Draw fence at eastern side of track.
9f8922176b67 (svn r10659) -Codechange: updated documentation around RAIL_GROUND_FENCE_VERT[12] (frosch)
truelight
parents: 7272
diff changeset
  1628
 */
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
  1629
static void DrawTrackFence_NS_1(const TileInfo *ti)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1630
{
8413
c7f3384330a3 (svn r11983) -Codechange: Add some helper functions for slopes and use them.
frosch
parents: 8398
diff changeset
  1631
	uint z = ti->z + GetSlopeZInCorner(RemoveHalftileSlope(ti->tileh), CORNER_W);
7307
9f8922176b67 (svn r10659) -Codechange: updated documentation around RAIL_GROUND_FENCE_VERT[12] (frosch)
truelight
parents: 7272
diff changeset
  1632
	AddSortableSpriteToDraw(SPR_TRACK_FENCE_FLAT_VERT, _drawtile_track_palette,
3645
7f950533d510 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3638
diff changeset
  1633
		ti->x + TILE_SIZE / 2, ti->y + TILE_SIZE / 2, 1, 1, 4, z);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1634
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1635
7307
9f8922176b67 (svn r10659) -Codechange: updated documentation around RAIL_GROUND_FENCE_VERT[12] (frosch)
truelight
parents: 7272
diff changeset
  1636
/**
9f8922176b67 (svn r10659) -Codechange: updated documentation around RAIL_GROUND_FENCE_VERT[12] (frosch)
truelight
parents: 7272
diff changeset
  1637
 * Draw fence at western side of track.
9f8922176b67 (svn r10659) -Codechange: updated documentation around RAIL_GROUND_FENCE_VERT[12] (frosch)
truelight
parents: 7272
diff changeset
  1638
 */
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
  1639
static void DrawTrackFence_NS_2(const TileInfo *ti)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1640
{
8413
c7f3384330a3 (svn r11983) -Codechange: Add some helper functions for slopes and use them.
frosch
parents: 8398
diff changeset
  1641
	uint z = ti->z + GetSlopeZInCorner(RemoveHalftileSlope(ti->tileh), CORNER_E);
7307
9f8922176b67 (svn r10659) -Codechange: updated documentation around RAIL_GROUND_FENCE_VERT[12] (frosch)
truelight
parents: 7272
diff changeset
  1642
	AddSortableSpriteToDraw(SPR_TRACK_FENCE_FLAT_VERT, _drawtile_track_palette,
3645
7f950533d510 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3638
diff changeset
  1643
		ti->x + TILE_SIZE / 2, ti->y + TILE_SIZE / 2, 1, 1, 4, z);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1644
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1645
7307
9f8922176b67 (svn r10659) -Codechange: updated documentation around RAIL_GROUND_FENCE_VERT[12] (frosch)
truelight
parents: 7272
diff changeset
  1646
/**
9f8922176b67 (svn r10659) -Codechange: updated documentation around RAIL_GROUND_FENCE_VERT[12] (frosch)
truelight
parents: 7272
diff changeset
  1647
 * Draw fence at southern side of track.
9f8922176b67 (svn r10659) -Codechange: updated documentation around RAIL_GROUND_FENCE_VERT[12] (frosch)
truelight
parents: 7272
diff changeset
  1648
 */
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
  1649
static void DrawTrackFence_WE_1(const TileInfo *ti)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1650
{
8413
c7f3384330a3 (svn r11983) -Codechange: Add some helper functions for slopes and use them.
frosch
parents: 8398
diff changeset
  1651
	uint z = ti->z + GetSlopeZInCorner(RemoveHalftileSlope(ti->tileh), CORNER_N);
7307
9f8922176b67 (svn r10659) -Codechange: updated documentation around RAIL_GROUND_FENCE_VERT[12] (frosch)
truelight
parents: 7272
diff changeset
  1652
	AddSortableSpriteToDraw(SPR_TRACK_FENCE_FLAT_HORZ, _drawtile_track_palette,
3645
7f950533d510 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3638
diff changeset
  1653
		ti->x + TILE_SIZE / 2, ti->y + TILE_SIZE / 2, 1, 1, 4, z);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1654
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1655
7307
9f8922176b67 (svn r10659) -Codechange: updated documentation around RAIL_GROUND_FENCE_VERT[12] (frosch)
truelight
parents: 7272
diff changeset
  1656
/**
9f8922176b67 (svn r10659) -Codechange: updated documentation around RAIL_GROUND_FENCE_VERT[12] (frosch)
truelight
parents: 7272
diff changeset
  1657
 * Draw fence at northern side of track.
9f8922176b67 (svn r10659) -Codechange: updated documentation around RAIL_GROUND_FENCE_VERT[12] (frosch)
truelight
parents: 7272
diff changeset
  1658
 */
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
  1659
static void DrawTrackFence_WE_2(const TileInfo *ti)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1660
{
8413
c7f3384330a3 (svn r11983) -Codechange: Add some helper functions for slopes and use them.
frosch
parents: 8398
diff changeset
  1661
	uint z = ti->z + GetSlopeZInCorner(RemoveHalftileSlope(ti->tileh), CORNER_S);
7307
9f8922176b67 (svn r10659) -Codechange: updated documentation around RAIL_GROUND_FENCE_VERT[12] (frosch)
truelight
parents: 7272
diff changeset
  1662
	AddSortableSpriteToDraw(SPR_TRACK_FENCE_FLAT_HORZ, _drawtile_track_palette,
3645
7f950533d510 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3638
diff changeset
  1663
		ti->x + TILE_SIZE / 2, ti->y + TILE_SIZE / 2, 1, 1, 4, z);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1664
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1665
4040
921eabdb0283 (svn r5308) Replace an array of function pointers with a switch: It's shorter, more comprehensible, less dependent on magic numbers
tron
parents: 4000
diff changeset
  1666
921eabdb0283 (svn r5308) Replace an array of function pointers with a switch: It's shorter, more comprehensible, less dependent on magic numbers
tron
parents: 4000
diff changeset
  1667
static void DrawTrackDetails(const TileInfo* ti)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1668
{
4040
921eabdb0283 (svn r5308) Replace an array of function pointers with a switch: It's shorter, more comprehensible, less dependent on magic numbers
tron
parents: 4000
diff changeset
  1669
	switch (GetRailGroundType(ti->tile)) {
921eabdb0283 (svn r5308) Replace an array of function pointers with a switch: It's shorter, more comprehensible, less dependent on magic numbers
tron
parents: 4000
diff changeset
  1670
		case RAIL_GROUND_FENCE_NW:     DrawTrackFence_NW(ti);    break;
921eabdb0283 (svn r5308) Replace an array of function pointers with a switch: It's shorter, more comprehensible, less dependent on magic numbers
tron
parents: 4000
diff changeset
  1671
		case RAIL_GROUND_FENCE_SE:     DrawTrackFence_SE(ti);    break;
921eabdb0283 (svn r5308) Replace an array of function pointers with a switch: It's shorter, more comprehensible, less dependent on magic numbers
tron
parents: 4000
diff changeset
  1672
		case RAIL_GROUND_FENCE_SENW:   DrawTrackFence_NW_SE(ti); break;
921eabdb0283 (svn r5308) Replace an array of function pointers with a switch: It's shorter, more comprehensible, less dependent on magic numbers
tron
parents: 4000
diff changeset
  1673
		case RAIL_GROUND_FENCE_NE:     DrawTrackFence_NE(ti);    break;
921eabdb0283 (svn r5308) Replace an array of function pointers with a switch: It's shorter, more comprehensible, less dependent on magic numbers
tron
parents: 4000
diff changeset
  1674
		case RAIL_GROUND_FENCE_SW:     DrawTrackFence_SW(ti);    break;
921eabdb0283 (svn r5308) Replace an array of function pointers with a switch: It's shorter, more comprehensible, less dependent on magic numbers
tron
parents: 4000
diff changeset
  1675
		case RAIL_GROUND_FENCE_NESW:   DrawTrackFence_NE_SW(ti); break;
921eabdb0283 (svn r5308) Replace an array of function pointers with a switch: It's shorter, more comprehensible, less dependent on magic numbers
tron
parents: 4000
diff changeset
  1676
		case RAIL_GROUND_FENCE_VERT1:  DrawTrackFence_NS_1(ti);  break;
921eabdb0283 (svn r5308) Replace an array of function pointers with a switch: It's shorter, more comprehensible, less dependent on magic numbers
tron
parents: 4000
diff changeset
  1677
		case RAIL_GROUND_FENCE_VERT2:  DrawTrackFence_NS_2(ti);  break;
921eabdb0283 (svn r5308) Replace an array of function pointers with a switch: It's shorter, more comprehensible, less dependent on magic numbers
tron
parents: 4000
diff changeset
  1678
		case RAIL_GROUND_FENCE_HORIZ1: DrawTrackFence_WE_1(ti);  break;
921eabdb0283 (svn r5308) Replace an array of function pointers with a switch: It's shorter, more comprehensible, less dependent on magic numbers
tron
parents: 4000
diff changeset
  1679
		case RAIL_GROUND_FENCE_HORIZ2: DrawTrackFence_WE_2(ti);  break;
8414
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
  1680
		case RAIL_GROUND_WATER: {
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
  1681
			Corner track_corner;
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
  1682
			if (IsHalftileSlope(ti->tileh)) {
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
  1683
				/* Steep slope or one-corner-raised slope with halftile foundation */
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
  1684
				track_corner = GetHalftileSlopeCorner(ti->tileh);
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
  1685
			} else {
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
  1686
				/* Three-corner-raised slope */
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
  1687
				track_corner = OppositeCorner(GetHighestSlopeCorner(ComplementSlope(ti->tileh)));
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
  1688
			}
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
  1689
			switch (track_corner) {
7771
a900b80b48f2 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 7770
diff changeset
  1690
				case CORNER_W: DrawTrackFence_NS_1(ti); break;
a900b80b48f2 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 7770
diff changeset
  1691
				case CORNER_S: DrawTrackFence_WE_2(ti); break;
a900b80b48f2 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 7770
diff changeset
  1692
				case CORNER_E: DrawTrackFence_NS_2(ti); break;
a900b80b48f2 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 7770
diff changeset
  1693
				case CORNER_N: DrawTrackFence_WE_1(ti); break;
a900b80b48f2 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 7770
diff changeset
  1694
				default: NOT_REACHED();
a900b80b48f2 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 7770
diff changeset
  1695
			}
a900b80b48f2 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 7770
diff changeset
  1696
			break;
8414
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
  1697
		}
4040
921eabdb0283 (svn r5308) Replace an array of function pointers with a switch: It's shorter, more comprehensible, less dependent on magic numbers
tron
parents: 4000
diff changeset
  1698
		default: break;
921eabdb0283 (svn r5308) Replace an array of function pointers with a switch: It's shorter, more comprehensible, less dependent on magic numbers
tron
parents: 4000
diff changeset
  1699
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1700
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1701
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1702
2472
2711a54b0498 (svn r2998) -Codechange: Split rail drawing code off from DrawTile_Rail into a separate function to be used elsewhere. (Deja vu?)
peter1138
parents: 2436
diff changeset
  1703
/**
2711a54b0498 (svn r2998) -Codechange: Split rail drawing code off from DrawTile_Rail into a separate function to be used elsewhere. (Deja vu?)
peter1138
parents: 2436
diff changeset
  1704
 * Draw ground sprite and track bits
2711a54b0498 (svn r2998) -Codechange: Split rail drawing code off from DrawTile_Rail into a separate function to be used elsewhere. (Deja vu?)
peter1138
parents: 2436
diff changeset
  1705
 * @param ti TileInfo
2711a54b0498 (svn r2998) -Codechange: Split rail drawing code off from DrawTile_Rail into a separate function to be used elsewhere. (Deja vu?)
peter1138
parents: 2436
diff changeset
  1706
 * @param track TrackBits to draw
2711a54b0498 (svn r2998) -Codechange: Split rail drawing code off from DrawTile_Rail into a separate function to be used elsewhere. (Deja vu?)
peter1138
parents: 2436
diff changeset
  1707
 */
4081
46f02386923e (svn r5396) - Remove two fixed parameters
tron
parents: 4077
diff changeset
  1708
static void DrawTrackBits(TileInfo* ti, TrackBits track)
2472
2711a54b0498 (svn r2998) -Codechange: Split rail drawing code off from DrawTile_Rail into a separate function to be used elsewhere. (Deja vu?)
peter1138
parents: 2436
diff changeset
  1709
{
8414
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
  1710
	/* SubSprite for drawing the track halftile of 'three-corners-raised'-sloped rail sprites. */
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
  1711
	static const int INF = 1000; // big number compared to tilesprite size
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
  1712
	static const SubSprite _halftile_sub_sprite[4] = {
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
  1713
		{ -INF    , -INF  , 32 - 33, INF     }, // CORNER_W, clip 33 pixels from right
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
  1714
		{ -INF    ,  0 + 7, INF    , INF     }, // CORNER_S, clip 7 pixels from top
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
  1715
		{ -31 + 33, -INF  , INF    , INF     }, // CORNER_E, clip 33 pixels from left
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
  1716
		{ -INF    , -INF  , INF    , 30 - 23 }  // CORNER_N, clip 23 pixels from bottom
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
  1717
	};
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
  1718
2472
2711a54b0498 (svn r2998) -Codechange: Split rail drawing code off from DrawTile_Rail into a separate function to be used elsewhere. (Deja vu?)
peter1138
parents: 2436
diff changeset
  1719
	const RailtypeInfo *rti = GetRailTypeInfo(GetRailType(ti->tile));
7770
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
  1720
	RailGroundType rgt = GetRailGroundType(ti->tile);
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
  1721
	Foundation f = GetRailFoundation(ti->tileh, track);
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
  1722
	Corner halftile_corner = CORNER_INVALID;
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
  1723
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
  1724
	if (IsNonContinuousFoundation(f)) {
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
  1725
		/* Save halftile corner */
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
  1726
		halftile_corner = (f == FOUNDATION_STEEP_BOTH ? GetHighestSlopeCorner(ti->tileh) : GetHalftileFoundationCorner(f));
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
  1727
		/* Draw lower part first */
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
  1728
		track &= ~CornerToTrackBits(halftile_corner);
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
  1729
		f = (f == FOUNDATION_STEEP_BOTH ? FOUNDATION_STEEP_LOWER : FOUNDATION_NONE);
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
  1730
	}
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
  1731
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
  1732
	DrawFoundation(ti, f);
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
  1733
	/* DrawFoundation modifies ti */
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
  1734
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5598
diff changeset
  1735
	SpriteID image;
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5598
diff changeset
  1736
	SpriteID pal = PAL_NONE;
8414
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
  1737
	const SubSprite *sub = NULL;
2472
2711a54b0498 (svn r2998) -Codechange: Split rail drawing code off from DrawTile_Rail into a separate function to be used elsewhere. (Deja vu?)
peter1138
parents: 2436
diff changeset
  1738
	bool junction = false;
2711a54b0498 (svn r2998) -Codechange: Split rail drawing code off from DrawTile_Rail into a separate function to be used elsewhere. (Deja vu?)
peter1138
parents: 2436
diff changeset
  1739
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6406
diff changeset
  1740
	/* Select the sprite to use. */
7770
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
  1741
	if (track == 0) {
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
  1742
		/* Clear ground (only track on halftile foundation) */
7771
a900b80b48f2 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 7770
diff changeset
  1743
		if (rgt == RAIL_GROUND_WATER) {
8414
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
  1744
			if (IsSteepSlope(ti->tileh)) {
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
  1745
				DrawShoreTile(ti->tileh);
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
  1746
				image = 0;
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
  1747
			} else {
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
  1748
				image = SPR_FLAT_WATER_TILE;
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
  1749
			}
7771
a900b80b48f2 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 7770
diff changeset
  1750
		} else {
a900b80b48f2 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 7770
diff changeset
  1751
			switch (rgt) {
a900b80b48f2 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 7770
diff changeset
  1752
				case RAIL_GROUND_BARREN:     image = SPR_FLAT_BARE_LAND;  break;
a900b80b48f2 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 7770
diff changeset
  1753
				case RAIL_GROUND_ICE_DESERT: image = SPR_FLAT_SNOWY_TILE; break;
a900b80b48f2 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 7770
diff changeset
  1754
				default:                     image = SPR_FLAT_GRASS_TILE; break;
a900b80b48f2 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 7770
diff changeset
  1755
			}
a900b80b48f2 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 7770
diff changeset
  1756
			image += _tileh_to_sprite[ti->tileh];
7770
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
  1757
		}
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
  1758
	} else {
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
  1759
		if (ti->tileh != SLOPE_FLAT) {
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
  1760
			/* track on non-flat ground */
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
  1761
			image = _track_sloped_sprites[ti->tileh - 1] + rti->base_sprites.track_y;
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
  1762
		} else {
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
  1763
			/* track on flat ground */
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
  1764
			(image = rti->base_sprites.track_y, track == TRACK_BIT_Y) ||
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
  1765
			(image++,                           track == TRACK_BIT_X) ||
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
  1766
			(image++,                           track == TRACK_BIT_UPPER) ||
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
  1767
			(image++,                           track == TRACK_BIT_LOWER) ||
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
  1768
			(image++,                           track == TRACK_BIT_RIGHT) ||
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
  1769
			(image++,                           track == TRACK_BIT_LEFT) ||
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
  1770
			(image++,                           track == TRACK_BIT_CROSS) ||
2472
2711a54b0498 (svn r2998) -Codechange: Split rail drawing code off from DrawTile_Rail into a separate function to be used elsewhere. (Deja vu?)
peter1138
parents: 2436
diff changeset
  1771
7770
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
  1772
			(image = rti->base_sprites.track_ns, track == TRACK_BIT_HORZ) ||
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
  1773
			(image++,                            track == TRACK_BIT_VERT) ||
2472
2711a54b0498 (svn r2998) -Codechange: Split rail drawing code off from DrawTile_Rail into a separate function to be used elsewhere. (Deja vu?)
peter1138
parents: 2436
diff changeset
  1774
7770
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
  1775
			(junction = true, false) ||
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
  1776
			(image = rti->base_sprites.ground, (track & TRACK_BIT_3WAY_NE) == 0) ||
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
  1777
			(image++,                          (track & TRACK_BIT_3WAY_SW) == 0) ||
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
  1778
			(image++,                          (track & TRACK_BIT_3WAY_NW) == 0) ||
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
  1779
			(image++,                          (track & TRACK_BIT_3WAY_SE) == 0) ||
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
  1780
			(image++, true);
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
  1781
		}
2472
2711a54b0498 (svn r2998) -Codechange: Split rail drawing code off from DrawTile_Rail into a separate function to be used elsewhere. (Deja vu?)
peter1138
parents: 2436
diff changeset
  1782
7770
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
  1783
		switch (rgt) {
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
  1784
			case RAIL_GROUND_BARREN:     pal = PALETTE_TO_BARE_LAND; break;
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
  1785
			case RAIL_GROUND_ICE_DESERT: image += rti->snow_offset;  break;
8414
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
  1786
			case RAIL_GROUND_WATER: {
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
  1787
				/* three-corner-raised slope */
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
  1788
				DrawShoreTile(ti->tileh);
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
  1789
				Corner track_corner = OppositeCorner(GetHighestSlopeCorner(ComplementSlope(ti->tileh)));
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
  1790
				sub = &(_halftile_sub_sprite[track_corner]);
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
  1791
				break;
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
  1792
			}
7770
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
  1793
			default: break;
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
  1794
		}
2472
2711a54b0498 (svn r2998) -Codechange: Split rail drawing code off from DrawTile_Rail into a separate function to be used elsewhere. (Deja vu?)
peter1138
parents: 2436
diff changeset
  1795
	}
2711a54b0498 (svn r2998) -Codechange: Split rail drawing code off from DrawTile_Rail into a separate function to be used elsewhere. (Deja vu?)
peter1138
parents: 2436
diff changeset
  1796
8414
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
  1797
	if (image != 0) DrawGroundSprite(image, pal, sub);
2472
2711a54b0498 (svn r2998) -Codechange: Split rail drawing code off from DrawTile_Rail into a separate function to be used elsewhere. (Deja vu?)
peter1138
parents: 2436
diff changeset
  1798
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6406
diff changeset
  1799
	/* Draw track pieces individually for junction tiles */
2472
2711a54b0498 (svn r2998) -Codechange: Split rail drawing code off from DrawTile_Rail into a separate function to be used elsewhere. (Deja vu?)
peter1138
parents: 2436
diff changeset
  1800
	if (junction) {
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5598
diff changeset
  1801
		if (track & TRACK_BIT_X)     DrawGroundSprite(rti->base_sprites.single_y, PAL_NONE);
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5598
diff changeset
  1802
		if (track & TRACK_BIT_Y)     DrawGroundSprite(rti->base_sprites.single_x, PAL_NONE);
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5598
diff changeset
  1803
		if (track & TRACK_BIT_UPPER) DrawGroundSprite(rti->base_sprites.single_n, PAL_NONE);
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5598
diff changeset
  1804
		if (track & TRACK_BIT_LOWER) DrawGroundSprite(rti->base_sprites.single_s, PAL_NONE);
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5598
diff changeset
  1805
		if (track & TRACK_BIT_LEFT)  DrawGroundSprite(rti->base_sprites.single_w, PAL_NONE);
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5598
diff changeset
  1806
		if (track & TRACK_BIT_RIGHT) DrawGroundSprite(rti->base_sprites.single_e, PAL_NONE);
2472
2711a54b0498 (svn r2998) -Codechange: Split rail drawing code off from DrawTile_Rail into a separate function to be used elsewhere. (Deja vu?)
peter1138
parents: 2436
diff changeset
  1807
	}
7770
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
  1808
9785
2005c34d0811 (svn r13927) -Add [YAPP]: Draw reserved tracks darker, toggeld by a patch setting. (michi_cc)
rubidium
parents: 9775
diff changeset
  1809
	/* PBS debugging, draw reserved tracks darker */
10109
882c4c0a5788 (svn r14293) -Change: do not show PBS track reservation in the intro game
smatz
parents: 10083
diff changeset
  1810
	if (_game_mode != GM_MENU && _settings_client.gui.show_track_reservation) {
9785
2005c34d0811 (svn r13927) -Add [YAPP]: Draw reserved tracks darker, toggeld by a patch setting. (michi_cc)
rubidium
parents: 9775
diff changeset
  1811
		TrackBits pbs = GetTrackReservation(ti->tile);
2005c34d0811 (svn r13927) -Add [YAPP]: Draw reserved tracks darker, toggeld by a patch setting. (michi_cc)
rubidium
parents: 9775
diff changeset
  1812
		if (pbs & TRACK_BIT_X) {
2005c34d0811 (svn r13927) -Add [YAPP]: Draw reserved tracks darker, toggeld by a patch setting. (michi_cc)
rubidium
parents: 9775
diff changeset
  1813
			if (ti->tileh == SLOPE_FLAT || ti->tileh == SLOPE_ELEVATED) {
2005c34d0811 (svn r13927) -Add [YAPP]: Draw reserved tracks darker, toggeld by a patch setting. (michi_cc)
rubidium
parents: 9775
diff changeset
  1814
				DrawGroundSprite(rti->base_sprites.single_y, PALETTE_CRASH);
2005c34d0811 (svn r13927) -Add [YAPP]: Draw reserved tracks darker, toggeld by a patch setting. (michi_cc)
rubidium
parents: 9775
diff changeset
  1815
			} else {
2005c34d0811 (svn r13927) -Add [YAPP]: Draw reserved tracks darker, toggeld by a patch setting. (michi_cc)
rubidium
parents: 9775
diff changeset
  1816
				DrawGroundSprite(_track_sloped_sprites[ti->tileh - 1] + rti->base_sprites.single_sloped - 20, PALETTE_CRASH);
2005c34d0811 (svn r13927) -Add [YAPP]: Draw reserved tracks darker, toggeld by a patch setting. (michi_cc)
rubidium
parents: 9775
diff changeset
  1817
			}
2005c34d0811 (svn r13927) -Add [YAPP]: Draw reserved tracks darker, toggeld by a patch setting. (michi_cc)
rubidium
parents: 9775
diff changeset
  1818
		}
2005c34d0811 (svn r13927) -Add [YAPP]: Draw reserved tracks darker, toggeld by a patch setting. (michi_cc)
rubidium
parents: 9775
diff changeset
  1819
		if (pbs & TRACK_BIT_Y) {
2005c34d0811 (svn r13927) -Add [YAPP]: Draw reserved tracks darker, toggeld by a patch setting. (michi_cc)
rubidium
parents: 9775
diff changeset
  1820
			if (ti->tileh == SLOPE_FLAT || ti->tileh == SLOPE_ELEVATED) {
2005c34d0811 (svn r13927) -Add [YAPP]: Draw reserved tracks darker, toggeld by a patch setting. (michi_cc)
rubidium
parents: 9775
diff changeset
  1821
				DrawGroundSprite(rti->base_sprites.single_x, PALETTE_CRASH);
2005c34d0811 (svn r13927) -Add [YAPP]: Draw reserved tracks darker, toggeld by a patch setting. (michi_cc)
rubidium
parents: 9775
diff changeset
  1822
			} else {
2005c34d0811 (svn r13927) -Add [YAPP]: Draw reserved tracks darker, toggeld by a patch setting. (michi_cc)
rubidium
parents: 9775
diff changeset
  1823
				DrawGroundSprite(_track_sloped_sprites[ti->tileh - 1] + rti->base_sprites.single_sloped - 20, PALETTE_CRASH);
2005c34d0811 (svn r13927) -Add [YAPP]: Draw reserved tracks darker, toggeld by a patch setting. (michi_cc)
rubidium
parents: 9775
diff changeset
  1824
			}
2005c34d0811 (svn r13927) -Add [YAPP]: Draw reserved tracks darker, toggeld by a patch setting. (michi_cc)
rubidium
parents: 9775
diff changeset
  1825
		}
2005c34d0811 (svn r13927) -Add [YAPP]: Draw reserved tracks darker, toggeld by a patch setting. (michi_cc)
rubidium
parents: 9775
diff changeset
  1826
		if (pbs & TRACK_BIT_UPPER) AddSortableSpriteToDraw(rti->base_sprites.single_n, PALETTE_CRASH, ti->x, ti->y, 16, 16, 0, ti->z + (ti->tileh & SLOPE_N ? 8 : 0));
2005c34d0811 (svn r13927) -Add [YAPP]: Draw reserved tracks darker, toggeld by a patch setting. (michi_cc)
rubidium
parents: 9775
diff changeset
  1827
		if (pbs & TRACK_BIT_LOWER) AddSortableSpriteToDraw(rti->base_sprites.single_s, PALETTE_CRASH, ti->x, ti->y, 16, 16, 0, ti->z + (ti->tileh & SLOPE_S ? 8 : 0));
2005c34d0811 (svn r13927) -Add [YAPP]: Draw reserved tracks darker, toggeld by a patch setting. (michi_cc)
rubidium
parents: 9775
diff changeset
  1828
		if (pbs & TRACK_BIT_LEFT)  AddSortableSpriteToDraw(rti->base_sprites.single_w, PALETTE_CRASH, ti->x, ti->y, 16, 16, 0, ti->z + (ti->tileh & SLOPE_W ? 8 : 0));
2005c34d0811 (svn r13927) -Add [YAPP]: Draw reserved tracks darker, toggeld by a patch setting. (michi_cc)
rubidium
parents: 9775
diff changeset
  1829
		if (pbs & TRACK_BIT_RIGHT) AddSortableSpriteToDraw(rti->base_sprites.single_e, PALETTE_CRASH, ti->x, ti->y, 16, 16, 0, ti->z + (ti->tileh & SLOPE_E ? 8 : 0));
2005c34d0811 (svn r13927) -Add [YAPP]: Draw reserved tracks darker, toggeld by a patch setting. (michi_cc)
rubidium
parents: 9775
diff changeset
  1830
	}
2005c34d0811 (svn r13927) -Add [YAPP]: Draw reserved tracks darker, toggeld by a patch setting. (michi_cc)
rubidium
parents: 9775
diff changeset
  1831
7770
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
  1832
	if (IsValidCorner(halftile_corner)) {
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
  1833
		DrawFoundation(ti, HalftileFoundation(halftile_corner));
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
  1834
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
  1835
		/* Draw higher halftile-overlay: Use the sloped sprites with three corners raised. They probably best fit the lightning. */
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
  1836
		Slope fake_slope = SlopeWithThreeCornersRaised(OppositeCorner(halftile_corner));
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
  1837
		image = _track_sloped_sprites[fake_slope - 1] + rti->base_sprites.track_y;
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
  1838
		pal = PAL_NONE;
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
  1839
		switch (rgt) {
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
  1840
			case RAIL_GROUND_BARREN:     pal = PALETTE_TO_BARE_LAND; break;
8523
2ded162394a9 (svn r12098) -Fix: make snow appear on rail tiles dependant on track height, not on height of the lowest part of the tile
smatz
parents: 8519
diff changeset
  1841
			case RAIL_GROUND_ICE_DESERT:
2ded162394a9 (svn r12098) -Fix: make snow appear on rail tiles dependant on track height, not on height of the lowest part of the tile
smatz
parents: 8519
diff changeset
  1842
			case RAIL_GROUND_HALF_SNOW:  image += rti->snow_offset;  break; // higher part has snow in this case too
7770
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
  1843
			default: break;
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
  1844
		}
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
  1845
		DrawGroundSprite(image, pal, &(_halftile_sub_sprite[halftile_corner]));
9785
2005c34d0811 (svn r13927) -Add [YAPP]: Draw reserved tracks darker, toggeld by a patch setting. (michi_cc)
rubidium
parents: 9775
diff changeset
  1846
10109
882c4c0a5788 (svn r14293) -Change: do not show PBS track reservation in the intro game
smatz
parents: 10083
diff changeset
  1847
		if (_game_mode != GM_MENU && _settings_client.gui.show_track_reservation && IsSteepSlope(ti->tileh) && HasReservedTracks(ti->tile, CornerToTrackBits(halftile_corner))) {
9785
2005c34d0811 (svn r13927) -Add [YAPP]: Draw reserved tracks darker, toggeld by a patch setting. (michi_cc)
rubidium
parents: 9775
diff changeset
  1848
			static const byte _corner_to_track_sprite[] = {3, 1, 2, 0};
2005c34d0811 (svn r13927) -Add [YAPP]: Draw reserved tracks darker, toggeld by a patch setting. (michi_cc)
rubidium
parents: 9775
diff changeset
  1849
			AddSortableSpriteToDraw(_corner_to_track_sprite[halftile_corner] + rti->base_sprites.single_n, PALETTE_CRASH, ti->x, ti->y, 16, 16, 0, ti->z + 16);
2005c34d0811 (svn r13927) -Add [YAPP]: Draw reserved tracks darker, toggeld by a patch setting. (michi_cc)
rubidium
parents: 9775
diff changeset
  1850
		}
7770
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
  1851
	}
2472
2711a54b0498 (svn r2998) -Codechange: Split rail drawing code off from DrawTile_Rail into a separate function to be used elsewhere. (Deja vu?)
peter1138
parents: 2436
diff changeset
  1852
}
2711a54b0498 (svn r2998) -Codechange: Split rail drawing code off from DrawTile_Rail into a separate function to be used elsewhere. (Deja vu?)
peter1138
parents: 2436
diff changeset
  1853
8674
d55ca759b1e1 (svn r12340) -Codechange: Remove some magic numbers (sprite IDs here) with some more meaningful values.
belugas
parents: 8669
diff changeset
  1854
/** Enums holding the offsets from base signal sprite,
d55ca759b1e1 (svn r12340) -Codechange: Remove some magic numbers (sprite IDs here) with some more meaningful values.
belugas
parents: 8669
diff changeset
  1855
 * according to the side it is representing.
d55ca759b1e1 (svn r12340) -Codechange: Remove some magic numbers (sprite IDs here) with some more meaningful values.
belugas
parents: 8669
diff changeset
  1856
 * The addtion of 2 per enum is necessary in order to "jump" over the
d55ca759b1e1 (svn r12340) -Codechange: Remove some magic numbers (sprite IDs here) with some more meaningful values.
belugas
parents: 8669
diff changeset
  1857
 * green state sprite, all signal sprites being in pair,
d55ca759b1e1 (svn r12340) -Codechange: Remove some magic numbers (sprite IDs here) with some more meaningful values.
belugas
parents: 8669
diff changeset
  1858
 * starting with the off-red state */
d55ca759b1e1 (svn r12340) -Codechange: Remove some magic numbers (sprite IDs here) with some more meaningful values.
belugas
parents: 8669
diff changeset
  1859
enum {
8676
77ab39e10f73 (svn r12342) -Fix(r12340): In order to avoid confusion, SIGN should be used for signs and SIGNAL for signals :)
belugas
parents: 8674
diff changeset
  1860
	SIGNAL_TO_SOUTHWEST =  0,
77ab39e10f73 (svn r12342) -Fix(r12340): In order to avoid confusion, SIGN should be used for signs and SIGNAL for signals :)
belugas
parents: 8674
diff changeset
  1861
	SIGNAL_TO_NORTHEAST =  2,
77ab39e10f73 (svn r12342) -Fix(r12340): In order to avoid confusion, SIGN should be used for signs and SIGNAL for signals :)
belugas
parents: 8674
diff changeset
  1862
	SIGNAL_TO_SOUTHEAST =  4,
77ab39e10f73 (svn r12342) -Fix(r12340): In order to avoid confusion, SIGN should be used for signs and SIGNAL for signals :)
belugas
parents: 8674
diff changeset
  1863
	SIGNAL_TO_NORTHWEST =  6,
77ab39e10f73 (svn r12342) -Fix(r12340): In order to avoid confusion, SIGN should be used for signs and SIGNAL for signals :)
belugas
parents: 8674
diff changeset
  1864
	SIGNAL_TO_EAST      =  8,
77ab39e10f73 (svn r12342) -Fix(r12340): In order to avoid confusion, SIGN should be used for signs and SIGNAL for signals :)
belugas
parents: 8674
diff changeset
  1865
	SIGNAL_TO_WEST      = 10,
77ab39e10f73 (svn r12342) -Fix(r12340): In order to avoid confusion, SIGN should be used for signs and SIGNAL for signals :)
belugas
parents: 8674
diff changeset
  1866
	SIGNAL_TO_SOUTH     = 12,
77ab39e10f73 (svn r12342) -Fix(r12340): In order to avoid confusion, SIGN should be used for signs and SIGNAL for signals :)
belugas
parents: 8674
diff changeset
  1867
	SIGNAL_TO_NORTH     = 14,
8674
d55ca759b1e1 (svn r12340) -Codechange: Remove some magic numbers (sprite IDs here) with some more meaningful values.
belugas
parents: 8669
diff changeset
  1868
};
d55ca759b1e1 (svn r12340) -Codechange: Remove some magic numbers (sprite IDs here) with some more meaningful values.
belugas
parents: 8669
diff changeset
  1869
3519
1b8eb174e528 (svn r4375) -Codechange: Move the signal drawing bit to an own function and rename DrawSignalHelper to DrawSingleSignal
celestar
parents: 3507
diff changeset
  1870
static void DrawSignals(TileIndex tile, TrackBits rails)
1b8eb174e528 (svn r4375) -Codechange: Move the signal drawing bit to an own function and rename DrawSignalHelper to DrawSingleSignal
celestar
parents: 3507
diff changeset
  1871
{
8674
d55ca759b1e1 (svn r12340) -Codechange: Remove some magic numbers (sprite IDs here) with some more meaningful values.
belugas
parents: 8669
diff changeset
  1872
#define MAYBE_DRAW_SIGNAL(x,y,z,t) if (IsSignalPresent(tile, x)) DrawSingleSignal(tile, t, GetSingleSignalState(tile, x), y, z)
3519
1b8eb174e528 (svn r4375) -Codechange: Move the signal drawing bit to an own function and rename DrawSignalHelper to DrawSingleSignal
celestar
parents: 3507
diff changeset
  1873
1b8eb174e528 (svn r4375) -Codechange: Move the signal drawing bit to an own function and rename DrawSignalHelper to DrawSingleSignal
celestar
parents: 3507
diff changeset
  1874
	if (!(rails & TRACK_BIT_Y)) {
1b8eb174e528 (svn r4375) -Codechange: Move the signal drawing bit to an own function and rename DrawSignalHelper to DrawSingleSignal
celestar
parents: 3507
diff changeset
  1875
		if (!(rails & TRACK_BIT_X)) {
1b8eb174e528 (svn r4375) -Codechange: Move the signal drawing bit to an own function and rename DrawSignalHelper to DrawSingleSignal
celestar
parents: 3507
diff changeset
  1876
			if (rails & TRACK_BIT_LEFT) {
8676
77ab39e10f73 (svn r12342) -Fix(r12340): In order to avoid confusion, SIGN should be used for signs and SIGNAL for signals :)
belugas
parents: 8674
diff changeset
  1877
				MAYBE_DRAW_SIGNAL(2, SIGNAL_TO_NORTH, 0, TRACK_LEFT);
77ab39e10f73 (svn r12342) -Fix(r12340): In order to avoid confusion, SIGN should be used for signs and SIGNAL for signals :)
belugas
parents: 8674
diff changeset
  1878
				MAYBE_DRAW_SIGNAL(3, SIGNAL_TO_SOUTH, 1, TRACK_LEFT);
3519
1b8eb174e528 (svn r4375) -Codechange: Move the signal drawing bit to an own function and rename DrawSignalHelper to DrawSingleSignal
celestar
parents: 3507
diff changeset
  1879
			}
1b8eb174e528 (svn r4375) -Codechange: Move the signal drawing bit to an own function and rename DrawSignalHelper to DrawSingleSignal
celestar
parents: 3507
diff changeset
  1880
			if (rails & TRACK_BIT_RIGHT) {
8676
77ab39e10f73 (svn r12342) -Fix(r12340): In order to avoid confusion, SIGN should be used for signs and SIGNAL for signals :)
belugas
parents: 8674
diff changeset
  1881
				MAYBE_DRAW_SIGNAL(0, SIGNAL_TO_NORTH, 2, TRACK_RIGHT);
77ab39e10f73 (svn r12342) -Fix(r12340): In order to avoid confusion, SIGN should be used for signs and SIGNAL for signals :)
belugas
parents: 8674
diff changeset
  1882
				MAYBE_DRAW_SIGNAL(1, SIGNAL_TO_SOUTH, 3, TRACK_RIGHT);
3519
1b8eb174e528 (svn r4375) -Codechange: Move the signal drawing bit to an own function and rename DrawSignalHelper to DrawSingleSignal
celestar
parents: 3507
diff changeset
  1883
			}
1b8eb174e528 (svn r4375) -Codechange: Move the signal drawing bit to an own function and rename DrawSignalHelper to DrawSingleSignal
celestar
parents: 3507
diff changeset
  1884
			if (rails & TRACK_BIT_UPPER) {
8676
77ab39e10f73 (svn r12342) -Fix(r12340): In order to avoid confusion, SIGN should be used for signs and SIGNAL for signals :)
belugas
parents: 8674
diff changeset
  1885
				MAYBE_DRAW_SIGNAL(3, SIGNAL_TO_WEST, 4, TRACK_UPPER);
77ab39e10f73 (svn r12342) -Fix(r12340): In order to avoid confusion, SIGN should be used for signs and SIGNAL for signals :)
belugas
parents: 8674
diff changeset
  1886
				MAYBE_DRAW_SIGNAL(2, SIGNAL_TO_EAST, 5, TRACK_UPPER);
3519
1b8eb174e528 (svn r4375) -Codechange: Move the signal drawing bit to an own function and rename DrawSignalHelper to DrawSingleSignal
celestar
parents: 3507
diff changeset
  1887
			}
1b8eb174e528 (svn r4375) -Codechange: Move the signal drawing bit to an own function and rename DrawSignalHelper to DrawSingleSignal
celestar
parents: 3507
diff changeset
  1888
			if (rails & TRACK_BIT_LOWER) {
8676
77ab39e10f73 (svn r12342) -Fix(r12340): In order to avoid confusion, SIGN should be used for signs and SIGNAL for signals :)
belugas
parents: 8674
diff changeset
  1889
				MAYBE_DRAW_SIGNAL(1, SIGNAL_TO_WEST, 6, TRACK_LOWER);
77ab39e10f73 (svn r12342) -Fix(r12340): In order to avoid confusion, SIGN should be used for signs and SIGNAL for signals :)
belugas
parents: 8674
diff changeset
  1890
				MAYBE_DRAW_SIGNAL(0, SIGNAL_TO_EAST, 7, TRACK_LOWER);
3519
1b8eb174e528 (svn r4375) -Codechange: Move the signal drawing bit to an own function and rename DrawSignalHelper to DrawSingleSignal
celestar
parents: 3507
diff changeset
  1891
			}
1b8eb174e528 (svn r4375) -Codechange: Move the signal drawing bit to an own function and rename DrawSignalHelper to DrawSingleSignal
celestar
parents: 3507
diff changeset
  1892
		} else {
8676
77ab39e10f73 (svn r12342) -Fix(r12340): In order to avoid confusion, SIGN should be used for signs and SIGNAL for signals :)
belugas
parents: 8674
diff changeset
  1893
			MAYBE_DRAW_SIGNAL(3, SIGNAL_TO_SOUTHWEST, 8, TRACK_X);
77ab39e10f73 (svn r12342) -Fix(r12340): In order to avoid confusion, SIGN should be used for signs and SIGNAL for signals :)
belugas
parents: 8674
diff changeset
  1894
			MAYBE_DRAW_SIGNAL(2, SIGNAL_TO_NORTHEAST, 9, TRACK_X);
3519
1b8eb174e528 (svn r4375) -Codechange: Move the signal drawing bit to an own function and rename DrawSignalHelper to DrawSingleSignal
celestar
parents: 3507
diff changeset
  1895
		}
1b8eb174e528 (svn r4375) -Codechange: Move the signal drawing bit to an own function and rename DrawSignalHelper to DrawSingleSignal
celestar
parents: 3507
diff changeset
  1896
	} else {
8676
77ab39e10f73 (svn r12342) -Fix(r12340): In order to avoid confusion, SIGN should be used for signs and SIGNAL for signals :)
belugas
parents: 8674
diff changeset
  1897
		MAYBE_DRAW_SIGNAL(3, SIGNAL_TO_SOUTHEAST, 10, TRACK_Y);
77ab39e10f73 (svn r12342) -Fix(r12340): In order to avoid confusion, SIGN should be used for signs and SIGNAL for signals :)
belugas
parents: 8674
diff changeset
  1898
		MAYBE_DRAW_SIGNAL(2, SIGNAL_TO_NORTHWEST, 11, TRACK_Y);
3519
1b8eb174e528 (svn r4375) -Codechange: Move the signal drawing bit to an own function and rename DrawSignalHelper to DrawSingleSignal
celestar
parents: 3507
diff changeset
  1899
	}
1b8eb174e528 (svn r4375) -Codechange: Move the signal drawing bit to an own function and rename DrawSignalHelper to DrawSingleSignal
celestar
parents: 3507
diff changeset
  1900
}
1b8eb174e528 (svn r4375) -Codechange: Move the signal drawing bit to an own function and rename DrawSignalHelper to DrawSingleSignal
celestar
parents: 3507
diff changeset
  1901
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1902
static void DrawTile_Track(TileInfo *ti)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1903
{
2233
ee31c1e1477c (svn r2753) -Codechange: Introduced a new struct "RailtypeInfo" to store rail type specific information. Begun populating it with a bunch of sprites, more to come later. This should result in cleaner, more compact code which allows easy introduction of new railtypes.
celestar
parents: 2187
diff changeset
  1904
	const RailtypeInfo *rti = GetRailTypeInfo(GetRailType(ti->tile));
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5598
diff changeset
  1905
	SpriteID image;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1906
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10172
diff changeset
  1907
	_drawtile_track_palette = COMPANY_SPRITE_COLOR(GetTileOwner(ti->tile));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1908
4182
48dba107ff43 (svn r5624) Use {IsPlainRailTile,IsRailDepot,IsRailWaypoint,HasSignals}() instead of GetRailTile{T,Subt}ype() - this is more concise and a bit more flexible if/when the rail tile encoding changes
tron
parents: 4180
diff changeset
  1909
	if (IsPlainRailTile(ti->tile)) {
3267
feff95208a9f (svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents: 3265
diff changeset
  1910
		TrackBits rails = GetTrackBits(ti->tile);
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1911
4081
46f02386923e (svn r5396) - Remove two fixed parameters
tron
parents: 4077
diff changeset
  1912
		DrawTrackBits(ti, rails);
2008
cdb444f6d43c (svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents: 2007
diff changeset
  1913
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7882
diff changeset
  1914
		if (HasBit(_display_opt, DO_FULL_DETAIL)) DrawTrackDetails(ti);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1915
9154
2c042b567165 (svn r13016) -Codechange: unify the detection if rail catenary should be drawn
smatz
parents: 9111
diff changeset
  1916
		if (HasCatenaryDrawn(GetRailType(ti->tile))) DrawCatenary(ti);
7043
842b2bc47729 (svn r10308) -Codechange: some "cleanup" chunks from B. N. SmatZ!' work on fixing FS#119.
rubidium
parents: 6990
diff changeset
  1917
4182
48dba107ff43 (svn r5624) Use {IsPlainRailTile,IsRailDepot,IsRailWaypoint,HasSignals}() instead of GetRailTile{T,Subt}ype() - this is more concise and a bit more flexible if/when the rail tile encoding changes
tron
parents: 4180
diff changeset
  1918
		if (HasSignals(ti->tile)) DrawSignals(ti->tile, rails);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1919
	} else {
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6406
diff changeset
  1920
		/* draw depot/waypoint */
4225
88d760a6a4bf (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  1921
		const DrawTileSprites* dts;
88d760a6a4bf (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  1922
		const DrawTileSeqStruct* dtss;
88d760a6a4bf (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  1923
		uint32 relocation;
10355
8a930759b457 (svn r14606) -Codechange: Unify usage of PALETTE_MODIFIER_TRANSPARENT and PALETTE_MODIFIER_COLOR in spritelayout drawing.
frosch
parents: 10330
diff changeset
  1924
		SpriteID pal = PAL_NONE;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1925
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
  1926
		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
  1927
6172
e6d7a5b3d63f (svn r8935) -Codechange: unification of track type between road and rail tiles, unification of ground type between normal rail tiles and depots/waypoints and removing the need for RailTileSubType.
rubidium
parents: 6160
diff changeset
  1928
		if (IsRailDepot(ti->tile)) {
8806
4fe163e0b52a (svn r12547) -Feature: invisibility options to make objects invisible instead of transparent
smatz
parents: 8786
diff changeset
  1929
			if (IsInvisibilitySet(TO_BUILDINGS)) {
4fe163e0b52a (svn r12547) -Feature: invisibility options to make objects invisible instead of transparent
smatz
parents: 8786
diff changeset
  1930
				/* Draw rail instead of depot */
4fe163e0b52a (svn r12547) -Feature: invisibility options to make objects invisible instead of transparent
smatz
parents: 8786
diff changeset
  1931
				dts = &_depot_invisible_gfx_table[GetRailDepotDirection(ti->tile)];
4fe163e0b52a (svn r12547) -Feature: invisibility options to make objects invisible instead of transparent
smatz
parents: 8786
diff changeset
  1932
			} else {
4fe163e0b52a (svn r12547) -Feature: invisibility options to make objects invisible instead of transparent
smatz
parents: 8786
diff changeset
  1933
				dts = &_depot_gfx_table[GetRailDepotDirection(ti->tile)];
4fe163e0b52a (svn r12547) -Feature: invisibility options to make objects invisible instead of transparent
smatz
parents: 8786
diff changeset
  1934
			}
4225
88d760a6a4bf (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  1935
88d760a6a4bf (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  1936
			relocation = rti->total_offset;
88d760a6a4bf (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  1937
8571
53c94d717e99 (svn r12149) -Codechange: Merge 'ground_sprite' and 'ground_pal' of DrawTileSprites into one PalSpriteID
frosch
parents: 8570
diff changeset
  1938
			image = dts->ground.sprite;
4225
88d760a6a4bf (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  1939
			if (image != SPR_FLAT_GRASS_TILE) image += rti->total_offset;
88d760a6a4bf (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  1940
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6406
diff changeset
  1941
			/* adjust ground tile for desert
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6406
diff changeset
  1942
			 * don't adjust for snow, because snow in depots looks weird */
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
  1943
			if (IsSnowRailGround(ti->tile) && _settings_game.game_creation.landscape == LT_TROPIC) {
4225
88d760a6a4bf (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  1944
				if (image != SPR_FLAT_GRASS_TILE) {
88d760a6a4bf (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  1945
					image += rti->snow_offset; // tile with tracks
88d760a6a4bf (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  1946
				} else {
88d760a6a4bf (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  1947
					image = SPR_FLAT_SNOWY_TILE; // flat ground
88d760a6a4bf (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  1948
				}
88d760a6a4bf (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  1949
			}
88d760a6a4bf (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  1950
		} else {
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6406
diff changeset
  1951
			/* look for customization */
2670
f2d6a8424e3e (svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents: 2668
diff changeset
  1952
			byte stat_id = GetWaypointByTile(ti->tile)->stat_id;
3676
680dfa6336a1 (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3671
diff changeset
  1953
			const StationSpec *statspec = GetCustomStationSpec(STAT_CLASS_WAYP, stat_id);
389
16ee9854091e (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 337
diff changeset
  1954
3676
680dfa6336a1 (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3671
diff changeset
  1955
			if (statspec != NULL) {
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6406
diff changeset
  1956
				/* emulate station tile - open with building */
4225
88d760a6a4bf (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  1957
				const Station* st = ComposeWaypointStation(ti->tile);
88d760a6a4bf (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  1958
				uint gfx = 2;
3757
0c6a690e6b41 (svn r4748) - Newstations: use custom sprite layout callback for waypoints as well as stations. Supports merging of adjacent waypoints if the GRF supports it (newstatsw.grf)
peter1138
parents: 3751
diff changeset
  1959
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7882
diff changeset
  1960
				if (HasBit(statspec->callbackmask, CBM_STATION_SPRITE_LAYOUT)) {
3757
0c6a690e6b41 (svn r4748) - Newstations: use custom sprite layout callback for waypoints as well as stations. Supports merging of adjacent waypoints if the GRF supports it (newstatsw.grf)
peter1138
parents: 3751
diff changeset
  1961
					uint16 callback = GetStationCallback(CBID_STATION_SPRITE_LAYOUT, 0, 0, statspec, st, ti->tile);
4225
88d760a6a4bf (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  1962
					if (callback != CALLBACK_FAILED) gfx = callback;
3757
0c6a690e6b41 (svn r4748) - Newstations: use custom sprite layout callback for waypoints as well as stations. Supports merging of adjacent waypoints if the GRF supports it (newstatsw.grf)
peter1138
parents: 3751
diff changeset
  1963
				}
0c6a690e6b41 (svn r4748) - Newstations: use custom sprite layout callback for waypoints as well as stations. Supports merging of adjacent waypoints if the GRF supports it (newstatsw.grf)
peter1138
parents: 3751
diff changeset
  1964
3763
7098c393c172 (svn r4754) - Newstations: expose default station display data via a function so we can use it (rarely) in other places.
peter1138
parents: 3757
diff changeset
  1965
				if (statspec->renderdata == NULL) {
7272
d47fc9e22d1c (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7163
diff changeset
  1966
					dts = GetStationTileLayout(STATION_RAIL, gfx);
3763
7098c393c172 (svn r4754) - Newstations: expose default station display data via a function so we can use it (rarely) in other places.
peter1138
parents: 3757
diff changeset
  1967
				} else {
4225
88d760a6a4bf (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  1968
					dts = &statspec->renderdata[(gfx < statspec->tiles ? gfx : 0) + GetWaypointAxis(ti->tile)];
3763
7098c393c172 (svn r4754) - Newstations: expose default station display data via a function so we can use it (rarely) in other places.
peter1138
parents: 3757
diff changeset
  1969
				}
447
7e4bb71b8752 (svn r657) Do not touch 0x8000 bit in sprite index for custom waypoints. (pasky)
celestar
parents: 438
diff changeset
  1970
4225
88d760a6a4bf (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  1971
				if (dts != NULL && dts->seq != NULL) {
88d760a6a4bf (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  1972
					relocation = GetCustomStationRelocation(statspec, st, ti->tile);
88d760a6a4bf (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  1973
8571
53c94d717e99 (svn r12149) -Codechange: Merge 'ground_sprite' and 'ground_pal' of DrawTileSprites into one PalSpriteID
frosch
parents: 8570
diff changeset
  1974
					image = dts->ground.sprite;
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7882
diff changeset
  1975
					if (HasBit(image, SPRITE_MODIFIER_USE_OFFSET)) {
3775
0fb5118536c3 (svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents: 3763
diff changeset
  1976
						image += GetCustomStationGroundRelocation(statspec, st, ti->tile);
0fb5118536c3 (svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents: 3763
diff changeset
  1977
						image += rti->custom_ground_offset;
0fb5118536c3 (svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents: 3763
diff changeset
  1978
					} else {
0fb5118536c3 (svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents: 3763
diff changeset
  1979
						image += rti->total_offset;
0fb5118536c3 (svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents: 3763
diff changeset
  1980
					}
10355
8a930759b457 (svn r14606) -Codechange: Unify usage of PALETTE_MODIFIER_TRANSPARENT and PALETTE_MODIFIER_COLOR in spritelayout drawing.
frosch
parents: 10330
diff changeset
  1981
8a930759b457 (svn r14606) -Codechange: Unify usage of PALETTE_MODIFIER_TRANSPARENT and PALETTE_MODIFIER_COLOR in spritelayout drawing.
frosch
parents: 10330
diff changeset
  1982
					pal = dts->ground.pal;
4225
88d760a6a4bf (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  1983
				} else {
88d760a6a4bf (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  1984
					goto default_waypoint;
389
16ee9854091e (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 337
diff changeset
  1985
				}
2549
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1986
			} else {
4225
88d760a6a4bf (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  1987
default_waypoint:
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6406
diff changeset
  1988
				/* There is no custom layout, fall back to the default graphics */
4225
88d760a6a4bf (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  1989
				dts = &_waypoint_gfx_table[GetWaypointAxis(ti->tile)];
88d760a6a4bf (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  1990
				relocation = 0;
8571
53c94d717e99 (svn r12149) -Codechange: Merge 'ground_sprite' and 'ground_pal' of DrawTileSprites into one PalSpriteID
frosch
parents: 8570
diff changeset
  1991
				image = dts->ground.sprite + rti->total_offset;
4225
88d760a6a4bf (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  1992
				if (IsSnowRailGround(ti->tile)) image += rti->snow_offset;
2549
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1993
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1994
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1995
10355
8a930759b457 (svn r14606) -Codechange: Unify usage of PALETTE_MODIFIER_TRANSPARENT and PALETTE_MODIFIER_COLOR in spritelayout drawing.
frosch
parents: 10330
diff changeset
  1996
		DrawGroundSprite(image, GroundSpritePaletteTransform(image, pal, _drawtile_track_palette));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1997
9785
2005c34d0811 (svn r13927) -Add [YAPP]: Draw reserved tracks darker, toggeld by a patch setting. (michi_cc)
rubidium
parents: 9775
diff changeset
  1998
		/* PBS debugging, draw reserved tracks darker */
10159
ed8755ed3810 (svn r14350) -Fix (r13927): do not draw PBS reservation for NW and NE depots, it is drawn through depot walls
smatz
parents: 10109
diff changeset
  1999
		if (_game_mode != GM_MENU && _settings_client.gui.show_track_reservation && GetDepotWaypointReservation(ti->tile) &&
ed8755ed3810 (svn r14350) -Fix (r13927): do not draw PBS reservation for NW and NE depots, it is drawn through depot walls
smatz
parents: 10109
diff changeset
  2000
				(!IsRailDepot(ti->tile) || GetRailDepotDirection(ti->tile) == DIAGDIR_SW || GetRailDepotDirection(ti->tile) == DIAGDIR_SE)) {
9785
2005c34d0811 (svn r13927) -Add [YAPP]: Draw reserved tracks darker, toggeld by a patch setting. (michi_cc)
rubidium
parents: 9775
diff changeset
  2001
			DrawGroundSprite(GetWaypointAxis(ti->tile) == AXIS_X ? rti->base_sprites.single_y : rti->base_sprites.single_x, PALETTE_CRASH);
2005c34d0811 (svn r13927) -Add [YAPP]: Draw reserved tracks darker, toggeld by a patch setting. (michi_cc)
rubidium
parents: 9775
diff changeset
  2002
		}
2005c34d0811 (svn r13927) -Add [YAPP]: Draw reserved tracks darker, toggeld by a patch setting. (michi_cc)
rubidium
parents: 9775
diff changeset
  2003
9154
2c042b567165 (svn r13016) -Codechange: unify the detection if rail catenary should be drawn
smatz
parents: 9111
diff changeset
  2004
		if (HasCatenaryDrawn(GetRailType(ti->tile))) DrawCatenary(ti);
3355
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3333
diff changeset
  2005
4225
88d760a6a4bf (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  2006
		foreach_draw_tile_seq(dtss, dts->seq) {
8570
f50de4804ff1 (svn r12148) -Codechange: Merge 'image' and 'pal' of DrawTileSeqStruct into one PalSpriteID
frosch
parents: 8567
diff changeset
  2007
			SpriteID image = dtss->image.sprite;
10355
8a930759b457 (svn r14606) -Codechange: Unify usage of PALETTE_MODIFIER_TRANSPARENT and PALETTE_MODIFIER_COLOR in spritelayout drawing.
frosch
parents: 10330
diff changeset
  2008
			SpriteID pal   = dtss->image.pal;
4225
88d760a6a4bf (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  2009
9549
41ec95418e84 (svn r13565) -Change [FS#2077]: when invisibility is set, sprite sequences are now drawn until first non-opaque sprite is found (bit 14 not set)
smatz
parents: 9504
diff changeset
  2010
			/* Stop drawing sprite sequence once we meet a sprite that doesn't have to be opaque */
41ec95418e84 (svn r13565) -Change [FS#2077]: when invisibility is set, sprite sequences are now drawn until first non-opaque sprite is found (bit 14 not set)
smatz
parents: 9504
diff changeset
  2011
			if (IsInvisibilitySet(TO_BUILDINGS) && !HasBit(image, SPRITE_MODIFIER_OPAQUE)) return;
41ec95418e84 (svn r13565) -Change [FS#2077]: when invisibility is set, sprite sequences are now drawn until first non-opaque sprite is found (bit 14 not set)
smatz
parents: 9504
diff changeset
  2012
5738
5e2281cf6258 (svn r8283) -Fix (r8128): Custom waypoint drawing used wrong bits since bitshuffling occurred. Also update with other station drawing changes (code duplication,
peter1138
parents: 5735
diff changeset
  2013
			/* Unlike stations, our default waypoint has no variation for
5e2281cf6258 (svn r8283) -Fix (r8128): Custom waypoint drawing used wrong bits since bitshuffling occurred. Also update with other station drawing changes (code duplication,
peter1138
parents: 5735
diff changeset
  2014
			 * different railtype, so don't use the railtype offset if
5e2281cf6258 (svn r8283) -Fix (r8128): Custom waypoint drawing used wrong bits since bitshuffling occurred. Also update with other station drawing changes (code duplication,
peter1138
parents: 5735
diff changeset
  2015
			 * no relocation is set */
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7882
diff changeset
  2016
			if (HasBit(image, SPRITE_MODIFIER_USE_OFFSET)) {
5738
5e2281cf6258 (svn r8283) -Fix (r8128): Custom waypoint drawing used wrong bits since bitshuffling occurred. Also update with other station drawing changes (code duplication,
peter1138
parents: 5735
diff changeset
  2017
				image += rti->total_offset;
5e2281cf6258 (svn r8283) -Fix (r8128): Custom waypoint drawing used wrong bits since bitshuffling occurred. Also update with other station drawing changes (code duplication,
peter1138
parents: 5735
diff changeset
  2018
			} else {
5e2281cf6258 (svn r8283) -Fix (r8128): Custom waypoint drawing used wrong bits since bitshuffling occurred. Also update with other station drawing changes (code duplication,
peter1138
parents: 5735
diff changeset
  2019
				image += relocation;
5e2281cf6258 (svn r8283) -Fix (r8128): Custom waypoint drawing used wrong bits since bitshuffling occurred. Also update with other station drawing changes (code duplication,
peter1138
parents: 5735
diff changeset
  2020
			}
5e2281cf6258 (svn r8283) -Fix (r8128): Custom waypoint drawing used wrong bits since bitshuffling occurred. Also update with other station drawing changes (code duplication,
peter1138
parents: 5735
diff changeset
  2021
10355
8a930759b457 (svn r14606) -Codechange: Unify usage of PALETTE_MODIFIER_TRANSPARENT and PALETTE_MODIFIER_COLOR in spritelayout drawing.
frosch
parents: 10330
diff changeset
  2022
			pal = SpriteLayoutPaletteTransform(image, pal, _drawtile_track_palette);
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5598
diff changeset
  2023
5738
5e2281cf6258 (svn r8283) -Fix (r8128): Custom waypoint drawing used wrong bits since bitshuffling occurred. Also update with other station drawing changes (code duplication,
peter1138
parents: 5735
diff changeset
  2024
			if ((byte)dtss->delta_z != 0x80) {
5e2281cf6258 (svn r8283) -Fix (r8128): Custom waypoint drawing used wrong bits since bitshuffling occurred. Also update with other station drawing changes (code duplication,
peter1138
parents: 5735
diff changeset
  2025
				AddSortableSpriteToDraw(
5e2281cf6258 (svn r8283) -Fix (r8128): Custom waypoint drawing used wrong bits since bitshuffling occurred. Also update with other station drawing changes (code duplication,
peter1138
parents: 5735
diff changeset
  2026
					image, pal,
5e2281cf6258 (svn r8283) -Fix (r8128): Custom waypoint drawing used wrong bits since bitshuffling occurred. Also update with other station drawing changes (code duplication,
peter1138
parents: 5735
diff changeset
  2027
					ti->x + dtss->delta_x, ti->y + dtss->delta_y,
5e2281cf6258 (svn r8283) -Fix (r8128): Custom waypoint drawing used wrong bits since bitshuffling occurred. Also update with other station drawing changes (code duplication,
peter1138
parents: 5735
diff changeset
  2028
					dtss->size_x, dtss->size_y,
7333
e48228e44be8 (svn r10696) -Codechange: remove duplication of the "make sprite transparent" code.
rubidium
parents: 7307
diff changeset
  2029
					dtss->size_z, ti->z + dtss->delta_z,
8158
2946a316540b (svn r11720) -Codechange: [NewGRF] Add support for bit 30 of station tile layouts; forcing a sprite to always be opaque.
peter1138
parents: 8157
diff changeset
  2030
					!HasBit(image, SPRITE_MODIFIER_OPAQUE) && IsTransparencySet(TO_BUILDINGS)
5738
5e2281cf6258 (svn r8283) -Fix (r8128): Custom waypoint drawing used wrong bits since bitshuffling occurred. Also update with other station drawing changes (code duplication,
peter1138
parents: 5735
diff changeset
  2031
				);
5e2281cf6258 (svn r8283) -Fix (r8128): Custom waypoint drawing used wrong bits since bitshuffling occurred. Also update with other station drawing changes (code duplication,
peter1138
parents: 5735
diff changeset
  2032
			} else {
10257
2c37b72eec95 (svn r14488) -Fix: Synchronize drawing of spritelayouts in DrawTileLayout (Houses), IndustryDrawTileLayout, DrawStationTile, DrawTile_Station and DrawTile_Track (Waypoint).
frosch
parents: 10236
diff changeset
  2033
				/* For stations and original spritelayouts delta_x and delta_y are signed */
2c37b72eec95 (svn r14488) -Fix: Synchronize drawing of spritelayouts in DrawTileLayout (Houses), IndustryDrawTileLayout, DrawStationTile, DrawTile_Station and DrawTile_Track (Waypoint).
frosch
parents: 10236
diff changeset
  2034
				AddChildSpriteScreen(image, pal, dtss->delta_x, dtss->delta_y, !HasBit(image, SPRITE_MODIFIER_OPAQUE) && IsTransparencySet(TO_BUILDINGS));
5738
5e2281cf6258 (svn r8283) -Fix (r8128): Custom waypoint drawing used wrong bits since bitshuffling occurred. Also update with other station drawing changes (code duplication,
peter1138
parents: 5735
diff changeset
  2035
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2036
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2037
	}
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  2038
	DrawBridgeMiddle(ti);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2039
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2040
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2041
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5598
diff changeset
  2042
static void DrawTileSequence(int x, int y, SpriteID ground, const DrawTileSeqStruct* dtss, uint32 offset)
4225
88d760a6a4bf (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  2043
{
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10172
diff changeset
  2044
	SpriteID palette = COMPANY_SPRITE_COLOR(_local_company);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2045
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5598
diff changeset
  2046
	DrawSprite(ground, PAL_NONE, x, y);
8570
f50de4804ff1 (svn r12148) -Codechange: Merge 'image' and 'pal' of DrawTileSeqStruct into one PalSpriteID
frosch
parents: 8567
diff changeset
  2047
	for (; dtss->image.sprite != 0; dtss++) {
4225
88d760a6a4bf (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  2048
		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: 8567
diff changeset
  2049
		SpriteID image = dtss->image.sprite + offset;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2050
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7882
diff changeset
  2051
		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
  2052
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2053
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2054
4225
88d760a6a4bf (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  2055
void DrawTrainDepotSprite(int x, int y, int dir, RailType railtype)
88d760a6a4bf (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  2056
{
88d760a6a4bf (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  2057
	const DrawTileSprites* dts = &_depot_gfx_table[dir];
8571
53c94d717e99 (svn r12149) -Codechange: Merge 'ground_sprite' and 'ground_pal' of DrawTileSprites into one PalSpriteID
frosch
parents: 8570
diff changeset
  2058
	SpriteID image = dts->ground.sprite;
4225
88d760a6a4bf (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  2059
	uint32 offset = GetRailTypeInfo(railtype)->total_offset;
88d760a6a4bf (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  2060
88d760a6a4bf (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  2061
	if (image != SPR_FLAT_GRASS_TILE) image += offset;
88d760a6a4bf (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  2062
	DrawTileSequence(x + 33, y + 17, image, dts->seq, offset);
88d760a6a4bf (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  2063
}
88d760a6a4bf (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  2064
2520
8a52362c4ada (svn r3049) Replace byte/int/uint by RailType where appropriate
tron
parents: 2502
diff changeset
  2065
void DrawDefaultWaypointSprite(int x, int y, RailType railtype)
2261
d3554e5d3e86 (svn r2781) Fix some of the issues with variables in .h files.
ludde
parents: 2254
diff changeset
  2066
{
4225
88d760a6a4bf (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  2067
	uint32 offset = GetRailTypeInfo(railtype)->total_offset;
88d760a6a4bf (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  2068
	const DrawTileSprites* dts = &_waypoint_gfx_table[AXIS_X];
2261
d3554e5d3e86 (svn r2781) Fix some of the issues with variables in .h files.
ludde
parents: 2254
diff changeset
  2069
8571
53c94d717e99 (svn r12149) -Codechange: Merge 'ground_sprite' and 'ground_pal' of DrawTileSprites into one PalSpriteID
frosch
parents: 8570
diff changeset
  2070
	DrawTileSequence(x, y, dts->ground.sprite + offset, dts->seq, 0);
2261
d3554e5d3e86 (svn r2781) Fix some of the issues with variables in .h files.
ludde
parents: 2254
diff changeset
  2071
}
d3554e5d3e86 (svn r2781) Fix some of the issues with variables in .h files.
ludde
parents: 2254
diff changeset
  2072
4231
2823b3643862 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4230
diff changeset
  2073
static uint GetSlopeZ_Track(TileIndex tile, uint x, uint y)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2074
{
4231
2823b3643862 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4230
diff changeset
  2075
	uint z;
2823b3643862 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4230
diff changeset
  2076
	Slope tileh = GetTileSlope(tile, &z);
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2934
diff changeset
  2077
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3575
diff changeset
  2078
	if (tileh == SLOPE_FLAT) return z;
4231
2823b3643862 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4230
diff changeset
  2079
	if (IsPlainRailTile(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
  2080
		z += ApplyFoundationToSlope(GetRailFoundation(tileh, GetTrackBits(tile)), &tileh);
4231
2823b3643862 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4230
diff changeset
  2081
		return z + GetPartialZ(x & 0xF, y & 0xF, tileh);
4182
48dba107ff43 (svn r5624) Use {IsPlainRailTile,IsRailDepot,IsRailWaypoint,HasSignals}() instead of GetRailTile{T,Subt}ype() - this is more concise and a bit more flexible if/when the rail tile encoding changes
tron
parents: 4180
diff changeset
  2082
	} else {
48dba107ff43 (svn r5624) Use {IsPlainRailTile,IsRailDepot,IsRailWaypoint,HasSignals}() instead of GetRailTile{T,Subt}ype() - this is more concise and a bit more flexible if/when the rail tile encoding changes
tron
parents: 4180
diff changeset
  2083
		return z + TILE_HEIGHT;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2084
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2085
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2086
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
  2087
static Foundation GetFoundation_Track(TileIndex tile, Slope tileh)
39
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 22
diff changeset
  2088
{
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
  2089
	return IsPlainRailTile(tile) ? GetRailFoundation(tileh, GetTrackBits(tile)) : FlatteningFoundation(tileh);
39
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 22
diff changeset
  2090
}
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 22
diff changeset
  2091
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1963
diff changeset
  2092
static void GetAcceptedCargo_Track(TileIndex tile, AcceptedCargo ac)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2093
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2094
	/* not used */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2095
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2096
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1963
diff changeset
  2097
static void AnimateTile_Track(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2098
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2099
	/* not used */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2100
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2101
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1963
diff changeset
  2102
static void TileLoop_Track(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2103
{
3523
549603ffba5d (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
  2104
	RailGroundType old_ground = GetRailGroundType(tile);
4483
286633eb42fc (svn r6268) Remove now pointless assignment (followup of r6267)
tron
parents: 4482
diff changeset
  2105
	RailGroundType new_ground;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2106
7771
a900b80b48f2 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 7770
diff changeset
  2107
	if (old_ground == RAIL_GROUND_WATER) {
a900b80b48f2 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 7770
diff changeset
  2108
		TileLoop_Water(tile);
a900b80b48f2 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 7770
diff changeset
  2109
		return;
a900b80b48f2 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 7770
diff changeset
  2110
	}
a900b80b48f2 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 7770
diff changeset
  2111
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
  2112
	switch (_settings_game.game_creation.landscape) {
8523
2ded162394a9 (svn r12098) -Fix: make snow appear on rail tiles dependant on track height, not on height of the lowest part of the tile
smatz
parents: 8519
diff changeset
  2113
		case LT_ARCTIC: {
2ded162394a9 (svn r12098) -Fix: make snow appear on rail tiles dependant on track height, not on height of the lowest part of the tile
smatz
parents: 8519
diff changeset
  2114
			uint z;
2ded162394a9 (svn r12098) -Fix: make snow appear on rail tiles dependant on track height, not on height of the lowest part of the tile
smatz
parents: 8519
diff changeset
  2115
			Slope slope = GetTileSlope(tile, &z);
2ded162394a9 (svn r12098) -Fix: make snow appear on rail tiles dependant on track height, not on height of the lowest part of the tile
smatz
parents: 8519
diff changeset
  2116
			bool half = false;
2ded162394a9 (svn r12098) -Fix: make snow appear on rail tiles dependant on track height, not on height of the lowest part of the tile
smatz
parents: 8519
diff changeset
  2117
2ded162394a9 (svn r12098) -Fix: make snow appear on rail tiles dependant on track height, not on height of the lowest part of the tile
smatz
parents: 8519
diff changeset
  2118
			/* for non-flat track, use lower part of track
2ded162394a9 (svn r12098) -Fix: make snow appear on rail tiles dependant on track height, not on height of the lowest part of the tile
smatz
parents: 8519
diff changeset
  2119
			 * in other cases, use the highest part with track */
2ded162394a9 (svn r12098) -Fix: make snow appear on rail tiles dependant on track height, not on height of the lowest part of the tile
smatz
parents: 8519
diff changeset
  2120
			if (IsPlainRailTile(tile)) {
2ded162394a9 (svn r12098) -Fix: make snow appear on rail tiles dependant on track height, not on height of the lowest part of the tile
smatz
parents: 8519
diff changeset
  2121
				TrackBits track = GetTrackBits(tile);
2ded162394a9 (svn r12098) -Fix: make snow appear on rail tiles dependant on track height, not on height of the lowest part of the tile
smatz
parents: 8519
diff changeset
  2122
				Foundation f = GetRailFoundation(slope, track);
2ded162394a9 (svn r12098) -Fix: make snow appear on rail tiles dependant on track height, not on height of the lowest part of the tile
smatz
parents: 8519
diff changeset
  2123
2ded162394a9 (svn r12098) -Fix: make snow appear on rail tiles dependant on track height, not on height of the lowest part of the tile
smatz
parents: 8519
diff changeset
  2124
				switch (f) {
2ded162394a9 (svn r12098) -Fix: make snow appear on rail tiles dependant on track height, not on height of the lowest part of the tile
smatz
parents: 8519
diff changeset
  2125
					case FOUNDATION_NONE:
2ded162394a9 (svn r12098) -Fix: make snow appear on rail tiles dependant on track height, not on height of the lowest part of the tile
smatz
parents: 8519
diff changeset
  2126
						/* no foundation - is the track on the upper side of three corners raised tile? */
2ded162394a9 (svn r12098) -Fix: make snow appear on rail tiles dependant on track height, not on height of the lowest part of the tile
smatz
parents: 8519
diff changeset
  2127
						if (IsSlopeWithThreeCornersRaised(slope)) z += TILE_HEIGHT;
2ded162394a9 (svn r12098) -Fix: make snow appear on rail tiles dependant on track height, not on height of the lowest part of the tile
smatz
parents: 8519
diff changeset
  2128
						break;
2ded162394a9 (svn r12098) -Fix: make snow appear on rail tiles dependant on track height, not on height of the lowest part of the tile
smatz
parents: 8519
diff changeset
  2129
2ded162394a9 (svn r12098) -Fix: make snow appear on rail tiles dependant on track height, not on height of the lowest part of the tile
smatz
parents: 8519
diff changeset
  2130
					case FOUNDATION_INCLINED_X:
2ded162394a9 (svn r12098) -Fix: make snow appear on rail tiles dependant on track height, not on height of the lowest part of the tile
smatz
parents: 8519
diff changeset
  2131
					case FOUNDATION_INCLINED_Y:
2ded162394a9 (svn r12098) -Fix: make snow appear on rail tiles dependant on track height, not on height of the lowest part of the tile
smatz
parents: 8519
diff changeset
  2132
						/* sloped track - is it on a steep slope? */
2ded162394a9 (svn r12098) -Fix: make snow appear on rail tiles dependant on track height, not on height of the lowest part of the tile
smatz
parents: 8519
diff changeset
  2133
						if (IsSteepSlope(slope)) z += TILE_HEIGHT;
2ded162394a9 (svn r12098) -Fix: make snow appear on rail tiles dependant on track height, not on height of the lowest part of the tile
smatz
parents: 8519
diff changeset
  2134
						break;
2ded162394a9 (svn r12098) -Fix: make snow appear on rail tiles dependant on track height, not on height of the lowest part of the tile
smatz
parents: 8519
diff changeset
  2135
2ded162394a9 (svn r12098) -Fix: make snow appear on rail tiles dependant on track height, not on height of the lowest part of the tile
smatz
parents: 8519
diff changeset
  2136
					case FOUNDATION_STEEP_LOWER:
2ded162394a9 (svn r12098) -Fix: make snow appear on rail tiles dependant on track height, not on height of the lowest part of the tile
smatz
parents: 8519
diff changeset
  2137
						/* only lower part of steep slope */
2ded162394a9 (svn r12098) -Fix: make snow appear on rail tiles dependant on track height, not on height of the lowest part of the tile
smatz
parents: 8519
diff changeset
  2138
						z += TILE_HEIGHT;
2ded162394a9 (svn r12098) -Fix: make snow appear on rail tiles dependant on track height, not on height of the lowest part of the tile
smatz
parents: 8519
diff changeset
  2139
						break;
2ded162394a9 (svn r12098) -Fix: make snow appear on rail tiles dependant on track height, not on height of the lowest part of the tile
smatz
parents: 8519
diff changeset
  2140
2ded162394a9 (svn r12098) -Fix: make snow appear on rail tiles dependant on track height, not on height of the lowest part of the tile
smatz
parents: 8519
diff changeset
  2141
					default:
2ded162394a9 (svn r12098) -Fix: make snow appear on rail tiles dependant on track height, not on height of the lowest part of the tile
smatz
parents: 8519
diff changeset
  2142
						/* if it is a steep slope, then there is a track on higher part */
2ded162394a9 (svn r12098) -Fix: make snow appear on rail tiles dependant on track height, not on height of the lowest part of the tile
smatz
parents: 8519
diff changeset
  2143
						if (IsSteepSlope(slope)) z += TILE_HEIGHT;
2ded162394a9 (svn r12098) -Fix: make snow appear on rail tiles dependant on track height, not on height of the lowest part of the tile
smatz
parents: 8519
diff changeset
  2144
						z += TILE_HEIGHT;
2ded162394a9 (svn r12098) -Fix: make snow appear on rail tiles dependant on track height, not on height of the lowest part of the tile
smatz
parents: 8519
diff changeset
  2145
						break;
2ded162394a9 (svn r12098) -Fix: make snow appear on rail tiles dependant on track height, not on height of the lowest part of the tile
smatz
parents: 8519
diff changeset
  2146
				}
2ded162394a9 (svn r12098) -Fix: make snow appear on rail tiles dependant on track height, not on height of the lowest part of the tile
smatz
parents: 8519
diff changeset
  2147
2ded162394a9 (svn r12098) -Fix: make snow appear on rail tiles dependant on track height, not on height of the lowest part of the tile
smatz
parents: 8519
diff changeset
  2148
				half = IsInsideMM(f, FOUNDATION_STEEP_BOTH, FOUNDATION_HALFTILE_N + 1);
2ded162394a9 (svn r12098) -Fix: make snow appear on rail tiles dependant on track height, not on height of the lowest part of the tile
smatz
parents: 8519
diff changeset
  2149
			} else {
2ded162394a9 (svn r12098) -Fix: make snow appear on rail tiles dependant on track height, not on height of the lowest part of the tile
smatz
parents: 8519
diff changeset
  2150
				/* is the depot on a non-flat tile? */
2ded162394a9 (svn r12098) -Fix: make snow appear on rail tiles dependant on track height, not on height of the lowest part of the tile
smatz
parents: 8519
diff changeset
  2151
				if (slope != SLOPE_FLAT) z += TILE_HEIGHT;
2ded162394a9 (svn r12098) -Fix: make snow appear on rail tiles dependant on track height, not on height of the lowest part of the tile
smatz
parents: 8519
diff changeset
  2152
			}
2ded162394a9 (svn r12098) -Fix: make snow appear on rail tiles dependant on track height, not on height of the lowest part of the tile
smatz
parents: 8519
diff changeset
  2153
2ded162394a9 (svn r12098) -Fix: make snow appear on rail tiles dependant on track height, not on height of the lowest part of the tile
smatz
parents: 8519
diff changeset
  2154
			/* 'z' is now the lowest part of the highest track bit -
2ded162394a9 (svn r12098) -Fix: make snow appear on rail tiles dependant on track height, not on height of the lowest part of the tile
smatz
parents: 8519
diff changeset
  2155
			 * for sloped track, it is 'z' of lower part
2ded162394a9 (svn r12098) -Fix: make snow appear on rail tiles dependant on track height, not on height of the lowest part of the tile
smatz
parents: 8519
diff changeset
  2156
			 * for two track bits, it is 'z' of higher track bit
2ded162394a9 (svn r12098) -Fix: make snow appear on rail tiles dependant on track height, not on height of the lowest part of the tile
smatz
parents: 8519
diff changeset
  2157
			 * For non-continuous foundations (and STEEP_BOTH), 'half' is set */
2ded162394a9 (svn r12098) -Fix: make snow appear on rail tiles dependant on track height, not on height of the lowest part of the tile
smatz
parents: 8519
diff changeset
  2158
			if (z > GetSnowLine()) {
2ded162394a9 (svn r12098) -Fix: make snow appear on rail tiles dependant on track height, not on height of the lowest part of the tile
smatz
parents: 8519
diff changeset
  2159
				if (half && z - GetSnowLine() == TILE_HEIGHT) {
2ded162394a9 (svn r12098) -Fix: make snow appear on rail tiles dependant on track height, not on height of the lowest part of the tile
smatz
parents: 8519
diff changeset
  2160
					/* track on non-continuous foundation, lower part is not under snow */
2ded162394a9 (svn r12098) -Fix: make snow appear on rail tiles dependant on track height, not on height of the lowest part of the tile
smatz
parents: 8519
diff changeset
  2161
					new_ground = RAIL_GROUND_HALF_SNOW;
2ded162394a9 (svn r12098) -Fix: make snow appear on rail tiles dependant on track height, not on height of the lowest part of the tile
smatz
parents: 8519
diff changeset
  2162
				} else {
2ded162394a9 (svn r12098) -Fix: make snow appear on rail tiles dependant on track height, not on height of the lowest part of the tile
smatz
parents: 8519
diff changeset
  2163
					new_ground = RAIL_GROUND_ICE_DESERT;
2ded162394a9 (svn r12098) -Fix: make snow appear on rail tiles dependant on track height, not on height of the lowest part of the tile
smatz
parents: 8519
diff changeset
  2164
				}
4482
5010275cab9e (svn r6267) Simplify the control flow in the rail tile loop by eliminating a bool flag and replacing it by a simple goto
tron
parents: 4479
diff changeset
  2165
				goto set_ground;
3562
83a833bbe9ac (svn r4440) - Fix: Yoyo-effect of rail in desert/snow introduced by r4379. When a special groundtype below the track is encountered in the tileloop, always return even if groundtype hasn't changed.
Darkvater
parents: 3549
diff changeset
  2166
			}
2631
2ed0eb408229 (svn r3173) Use the trinary operator and switch to improve readability
tron
parents: 2626
diff changeset
  2167
			break;
8523
2ded162394a9 (svn r12098) -Fix: make snow appear on rail tiles dependant on track height, not on height of the lowest part of the tile
smatz
parents: 8519
diff changeset
  2168
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2169
6357
f0f5e7d1713c (svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents: 6343
diff changeset
  2170
		case LT_TROPIC:
3562
83a833bbe9ac (svn r4440) - Fix: Yoyo-effect of rail in desert/snow introduced by r4379. When a special groundtype below the track is encountered in the tileloop, always return even if groundtype hasn't changed.
Darkvater
parents: 3549
diff changeset
  2171
			if (GetTropicZone(tile) == TROPICZONE_DESERT) {
83a833bbe9ac (svn r4440) - Fix: Yoyo-effect of rail in desert/snow introduced by r4379. When a special groundtype below the track is encountered in the tileloop, always return even if groundtype hasn't changed.
Darkvater
parents: 3549
diff changeset
  2172
				new_ground = RAIL_GROUND_ICE_DESERT;
4482
5010275cab9e (svn r6267) Simplify the control flow in the rail tile loop by eliminating a bool flag and replacing it by a simple goto
tron
parents: 4479
diff changeset
  2173
				goto set_ground;
3562
83a833bbe9ac (svn r4440) - Fix: Yoyo-effect of rail in desert/snow introduced by r4379. When a special groundtype below the track is encountered in the tileloop, always return even if groundtype hasn't changed.
Darkvater
parents: 3549
diff changeset
  2174
			}
3523
549603ffba5d (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
  2175
			break;
549603ffba5d (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
  2176
	}
549603ffba5d (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
  2177
4182
48dba107ff43 (svn r5624) Use {IsPlainRailTile,IsRailDepot,IsRailWaypoint,HasSignals}() instead of GetRailTile{T,Subt}ype() - this is more concise and a bit more flexible if/when the rail tile encoding changes
tron
parents: 4180
diff changeset
  2178
	if (!IsPlainRailTile(tile)) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2179
3523
549603ffba5d (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
  2180
	new_ground = RAIL_GROUND_GRASS;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2181
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6406
diff changeset
  2182
	if (old_ground != RAIL_GROUND_BARREN) { // wait until bottom is green
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2183
		/* determine direction of fence */
3267
feff95208a9f (svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents: 3265
diff changeset
  2184
		TrackBits rail = GetTrackBits(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2185
2839
a466d41923d8 (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2186
		switch (rail) {
a466d41923d8 (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2187
			case TRACK_BIT_UPPER: new_ground = RAIL_GROUND_FENCE_HORIZ1; break;
a466d41923d8 (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2188
			case TRACK_BIT_LOWER: new_ground = RAIL_GROUND_FENCE_HORIZ2; break;
a466d41923d8 (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2189
			case TRACK_BIT_LEFT:  new_ground = RAIL_GROUND_FENCE_VERT1;  break;
a466d41923d8 (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2190
			case TRACK_BIT_RIGHT: new_ground = RAIL_GROUND_FENCE_VERT2;  break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2191
2839
a466d41923d8 (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2192
			default: {
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10172
diff changeset
  2193
				Owner owner = GetTileOwner(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2194
2839
a466d41923d8 (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2195
				if (rail == (TRACK_BIT_LOWER | TRACK_BIT_RIGHT) || (
3258
1c079364726d (svn r3946) Add short hand names for common track combinations
tron
parents: 3254
diff changeset
  2196
							(rail & TRACK_BIT_3WAY_NW) == 0 &&
3102
f9ca4379db9d (svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron
parents: 3101
diff changeset
  2197
							(rail & TRACK_BIT_X)
2839
a466d41923d8 (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2198
						)) {
a466d41923d8 (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2199
					TileIndex n = tile + TileDiffXY(0, -1);
3524
0a5fa1095ff4 (svn r4380) -Codechange: Make use of GetTrackBits where appropriate
celestar
parents: 3523
diff changeset
  2200
					TrackBits nrail = GetTrackBits(n);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2201
2839
a466d41923d8 (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2202
					if (!IsTileType(n, MP_RAILWAY) ||
a466d41923d8 (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2203
							!IsTileOwner(n, owner) ||
3524
0a5fa1095ff4 (svn r4380) -Codechange: Make use of GetTrackBits where appropriate
celestar
parents: 3523
diff changeset
  2204
							nrail == TRACK_BIT_UPPER ||
0a5fa1095ff4 (svn r4380) -Codechange: Make use of GetTrackBits where appropriate
celestar
parents: 3523
diff changeset
  2205
							nrail == TRACK_BIT_LEFT) {
2839
a466d41923d8 (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2206
						new_ground = RAIL_GROUND_FENCE_NW;
a466d41923d8 (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2207
					}
a466d41923d8 (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2208
				}
a466d41923d8 (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2209
a466d41923d8 (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2210
				if (rail == (TRACK_BIT_UPPER | TRACK_BIT_LEFT) || (
3258
1c079364726d (svn r3946) Add short hand names for common track combinations
tron
parents: 3254
diff changeset
  2211
							(rail & TRACK_BIT_3WAY_SE) == 0 &&
3102
f9ca4379db9d (svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron
parents: 3101
diff changeset
  2212
							(rail & TRACK_BIT_X)
2839
a466d41923d8 (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2213
						)) {
a466d41923d8 (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2214
					TileIndex n = tile + TileDiffXY(0, 1);
3524
0a5fa1095ff4 (svn r4380) -Codechange: Make use of GetTrackBits where appropriate
celestar
parents: 3523
diff changeset
  2215
					TrackBits nrail = GetTrackBits(n);
2839
a466d41923d8 (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2216
a466d41923d8 (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2217
					if (!IsTileType(n, MP_RAILWAY) ||
a466d41923d8 (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2218
							!IsTileOwner(n, owner) ||
3524
0a5fa1095ff4 (svn r4380) -Codechange: Make use of GetTrackBits where appropriate
celestar
parents: 3523
diff changeset
  2219
							nrail == TRACK_BIT_LOWER ||
0a5fa1095ff4 (svn r4380) -Codechange: Make use of GetTrackBits where appropriate
celestar
parents: 3523
diff changeset
  2220
							nrail == TRACK_BIT_RIGHT) {
2839
a466d41923d8 (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2221
						new_ground = (new_ground == RAIL_GROUND_FENCE_NW) ?
a466d41923d8 (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2222
							RAIL_GROUND_FENCE_SENW : RAIL_GROUND_FENCE_SE;
a466d41923d8 (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2223
					}
a466d41923d8 (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2224
				}
a466d41923d8 (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2225
a466d41923d8 (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2226
				if (rail == (TRACK_BIT_LOWER | TRACK_BIT_LEFT) || (
3258
1c079364726d (svn r3946) Add short hand names for common track combinations
tron
parents: 3254
diff changeset
  2227
							(rail & TRACK_BIT_3WAY_NE) == 0 &&
3102
f9ca4379db9d (svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron
parents: 3101
diff changeset
  2228
							(rail & TRACK_BIT_Y)
2839
a466d41923d8 (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2229
						)) {
a466d41923d8 (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2230
					TileIndex n = tile + TileDiffXY(-1, 0);
3524
0a5fa1095ff4 (svn r4380) -Codechange: Make use of GetTrackBits where appropriate
celestar
parents: 3523
diff changeset
  2231
					TrackBits nrail = GetTrackBits(n);
2839
a466d41923d8 (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2232
a466d41923d8 (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2233
					if (!IsTileType(n, MP_RAILWAY) ||
a466d41923d8 (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2234
							!IsTileOwner(n, owner) ||
3524
0a5fa1095ff4 (svn r4380) -Codechange: Make use of GetTrackBits where appropriate
celestar
parents: 3523
diff changeset
  2235
							nrail == TRACK_BIT_UPPER ||
0a5fa1095ff4 (svn r4380) -Codechange: Make use of GetTrackBits where appropriate
celestar
parents: 3523
diff changeset
  2236
							nrail == TRACK_BIT_RIGHT) {
2839
a466d41923d8 (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2237
						new_ground = RAIL_GROUND_FENCE_NE;
a466d41923d8 (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2238
					}
a466d41923d8 (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2239
				}
a466d41923d8 (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2240
a466d41923d8 (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2241
				if (rail == (TRACK_BIT_UPPER | TRACK_BIT_RIGHT) || (
3265
a11459ae44a0 (svn r3976) Fix typo in r3946
tron
parents: 3258
diff changeset
  2242
							(rail & TRACK_BIT_3WAY_SW) == 0 &&
3102
f9ca4379db9d (svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron
parents: 3101
diff changeset
  2243
							(rail & TRACK_BIT_Y)
2839
a466d41923d8 (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2244
						)) {
a466d41923d8 (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2245
					TileIndex n = tile + TileDiffXY(1, 0);
3524
0a5fa1095ff4 (svn r4380) -Codechange: Make use of GetTrackBits where appropriate
celestar
parents: 3523
diff changeset
  2246
					TrackBits nrail = GetTrackBits(n);
2839
a466d41923d8 (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2247
a466d41923d8 (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2248
					if (!IsTileType(n, MP_RAILWAY) ||
a466d41923d8 (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2249
							!IsTileOwner(n, owner) ||
3524
0a5fa1095ff4 (svn r4380) -Codechange: Make use of GetTrackBits where appropriate
celestar
parents: 3523
diff changeset
  2250
							nrail == TRACK_BIT_LOWER ||
0a5fa1095ff4 (svn r4380) -Codechange: Make use of GetTrackBits where appropriate
celestar
parents: 3523
diff changeset
  2251
							nrail == TRACK_BIT_LEFT) {
2839
a466d41923d8 (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2252
						new_ground = (new_ground == RAIL_GROUND_FENCE_NE) ?
a466d41923d8 (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2253
							RAIL_GROUND_FENCE_NESW : RAIL_GROUND_FENCE_SW;
a466d41923d8 (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2254
					}
a466d41923d8 (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2255
				}
a466d41923d8 (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2256
				break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2257
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2258
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2259
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2260
4482
5010275cab9e (svn r6267) Simplify the control flow in the rail tile loop by eliminating a bool flag and replacing it by a simple goto
tron
parents: 4479
diff changeset
  2261
set_ground:
2667
f3ffefc784c5 (svn r3209) In TileLoop_Track(), use names based on function rather than their place in the map array.
peter1138
parents: 2645
diff changeset
  2262
	if (old_ground != new_ground) {
3523
549603ffba5d (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
  2263
		SetRailGroundType(tile, new_ground);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2264
		MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2265
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2266
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2267
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2268
8616
fd862a55c47f (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8598
diff changeset
  2269
static TrackStatus GetTileTrackStatus_Track(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: 1963
diff changeset
  2270
{
9503
231e0b6b5b54 (svn r13485) -Fix: let ships also navigate on half-tile sloped watery rail tiles.
rubidium
parents: 9413
diff changeset
  2271
	/* Case of half tile slope with water. */
231e0b6b5b54 (svn r13485) -Fix: let ships also navigate on half-tile sloped watery rail tiles.
rubidium
parents: 9413
diff changeset
  2272
	if (mode == TRANSPORT_WATER && IsPlainRailTile(tile) && GetRailGroundType(tile) == RAIL_GROUND_WATER) {
231e0b6b5b54 (svn r13485) -Fix: let ships also navigate on half-tile sloped watery rail tiles.
rubidium
parents: 9413
diff changeset
  2273
		TrackBits tb = GetTrackBits(tile);
231e0b6b5b54 (svn r13485) -Fix: let ships also navigate on half-tile sloped watery rail tiles.
rubidium
parents: 9413
diff changeset
  2274
		switch (tb) {
231e0b6b5b54 (svn r13485) -Fix: let ships also navigate on half-tile sloped watery rail tiles.
rubidium
parents: 9413
diff changeset
  2275
			default: NOT_REACHED();
231e0b6b5b54 (svn r13485) -Fix: let ships also navigate on half-tile sloped watery rail tiles.
rubidium
parents: 9413
diff changeset
  2276
			case TRACK_BIT_UPPER: tb = TRACK_BIT_LOWER; break;
231e0b6b5b54 (svn r13485) -Fix: let ships also navigate on half-tile sloped watery rail tiles.
rubidium
parents: 9413
diff changeset
  2277
			case TRACK_BIT_LOWER: tb = TRACK_BIT_UPPER; break;
231e0b6b5b54 (svn r13485) -Fix: let ships also navigate on half-tile sloped watery rail tiles.
rubidium
parents: 9413
diff changeset
  2278
			case TRACK_BIT_LEFT:  tb = TRACK_BIT_RIGHT; break;
231e0b6b5b54 (svn r13485) -Fix: let ships also navigate on half-tile sloped watery rail tiles.
rubidium
parents: 9413
diff changeset
  2279
			case TRACK_BIT_RIGHT: tb = TRACK_BIT_LEFT;  break;
231e0b6b5b54 (svn r13485) -Fix: let ships also navigate on half-tile sloped watery rail tiles.
rubidium
parents: 9413
diff changeset
  2280
		}
231e0b6b5b54 (svn r13485) -Fix: let ships also navigate on half-tile sloped watery rail tiles.
rubidium
parents: 9413
diff changeset
  2281
		return CombineTrackStatus(TrackBitsToTrackdirBits(tb), TRACKDIR_BIT_NONE);
231e0b6b5b54 (svn r13485) -Fix: let ships also navigate on half-tile sloped watery rail tiles.
rubidium
parents: 9413
diff changeset
  2282
	}
231e0b6b5b54 (svn r13485) -Fix: let ships also navigate on half-tile sloped watery rail tiles.
rubidium
parents: 9413
diff changeset
  2283
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  2284
	if (mode != TRANSPORT_RAIL) return 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2285
8616
fd862a55c47f (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8598
diff changeset
  2286
	TrackBits trackbits = TRACK_BIT_NONE;
fd862a55c47f (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8598
diff changeset
  2287
	TrackdirBits red_signals = TRACKDIR_BIT_NONE;
fd862a55c47f (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8598
diff changeset
  2288
6187
60fc283a1722 (svn r8966) -Codechange: replace some if-cascades by switches.
rubidium
parents: 6172
diff changeset
  2289
	switch (GetRailTileType(tile)) {
60fc283a1722 (svn r8966) -Codechange: replace some if-cascades by switches.
rubidium
parents: 6172
diff changeset
  2290
		default: NOT_REACHED();
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: 8571
diff changeset
  2291
		case RAIL_TILE_NORMAL:
8616
fd862a55c47f (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8598
diff changeset
  2292
			trackbits = GetTrackBits(tile);
fd862a55c47f (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8598
diff changeset
  2293
			break;
3267
feff95208a9f (svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents: 3265
diff changeset
  2294
6187
60fc283a1722 (svn r8966) -Codechange: replace some if-cascades by switches.
rubidium
parents: 6172
diff changeset
  2295
		case RAIL_TILE_SIGNALS: {
8616
fd862a55c47f (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8598
diff changeset
  2296
			trackbits = GetTrackBits(tile);
6753
c1013c837417 (svn r9988) -Codechange: remove the last direct map accesses, except the ones needed for the savegame saving/loading mechanisms.
rubidium
parents: 6728
diff changeset
  2297
			byte a = GetPresentSignals(tile);
c1013c837417 (svn r9988) -Codechange: remove the last direct map accesses, except the ones needed for the savegame saving/loading mechanisms.
rubidium
parents: 6728
diff changeset
  2298
			uint b = GetSignalStates(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2299
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2300
			b &= a;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2301
9791
7bcdf05e5e5b (svn r13933) -Codechange [YAPP]: Handle through and PBS signals correctly in the signal code. (michi_cc)
rubidium
parents: 9790
diff changeset
  2302
			/* When signals are not present (in neither direction),
7bcdf05e5e5b (svn r13933) -Codechange [YAPP]: Handle through and PBS signals correctly in the signal code. (michi_cc)
rubidium
parents: 9790
diff changeset
  2303
			 * we pretend them to be green. Otherwise, it depends on
7bcdf05e5e5b (svn r13933) -Codechange [YAPP]: Handle through and PBS signals correctly in the signal code. (michi_cc)
rubidium
parents: 9790
diff changeset
  2304
			 * the signal type. For signals that are only active from
7bcdf05e5e5b (svn r13933) -Codechange [YAPP]: Handle through and PBS signals correctly in the signal code. (michi_cc)
rubidium
parents: 9790
diff changeset
  2305
			 * one side, we set the missing signals explicitely to
7bcdf05e5e5b (svn r13933) -Codechange [YAPP]: Handle through and PBS signals correctly in the signal code. (michi_cc)
rubidium
parents: 9790
diff changeset
  2306
			 * `green'. Otherwise, they implicitely become `red'. */
7bcdf05e5e5b (svn r13933) -Codechange [YAPP]: Handle through and PBS signals correctly in the signal code. (michi_cc)
rubidium
parents: 9790
diff changeset
  2307
			if (!IsOnewaySignal(tile, TRACK_UPPER) || (a & SignalOnTrack(TRACK_UPPER)) == 0) b |= ~a & SignalOnTrack(TRACK_UPPER);
7bcdf05e5e5b (svn r13933) -Codechange [YAPP]: Handle through and PBS signals correctly in the signal code. (michi_cc)
rubidium
parents: 9790
diff changeset
  2308
			if (!IsOnewaySignal(tile, TRACK_LOWER) || (a & SignalOnTrack(TRACK_LOWER)) == 0) b |= ~a & SignalOnTrack(TRACK_LOWER);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2309
8616
fd862a55c47f (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8598
diff changeset
  2310
			if ((b & 0x8) == 0) red_signals |= (TRACKDIR_BIT_LEFT_N | TRACKDIR_BIT_X_NE | TRACKDIR_BIT_Y_SE | TRACKDIR_BIT_UPPER_E);
fd862a55c47f (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8598
diff changeset
  2311
			if ((b & 0x4) == 0) red_signals |= (TRACKDIR_BIT_LEFT_S | TRACKDIR_BIT_X_SW | TRACKDIR_BIT_Y_NW | TRACKDIR_BIT_UPPER_W);
fd862a55c47f (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8598
diff changeset
  2312
			if ((b & 0x2) == 0) red_signals |= (TRACKDIR_BIT_RIGHT_N | TRACKDIR_BIT_LOWER_E);
fd862a55c47f (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8598
diff changeset
  2313
			if ((b & 0x1) == 0) red_signals |= (TRACKDIR_BIT_RIGHT_S | TRACKDIR_BIT_LOWER_W);
6187
60fc283a1722 (svn r8966) -Codechange: replace some if-cascades by switches.
rubidium
parents: 6172
diff changeset
  2314
8616
fd862a55c47f (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8598
diff changeset
  2315
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2316
		}
6187
60fc283a1722 (svn r8966) -Codechange: replace some if-cascades by switches.
rubidium
parents: 6172
diff changeset
  2317
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: 8571
diff changeset
  2318
		case RAIL_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: 8571
diff changeset
  2319
			DiagDirection dir = GetRailDepotDirection(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: 8571
diff changeset
  2320
8616
fd862a55c47f (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8598
diff changeset
  2321
			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: 8571
diff changeset
  2322
9224
93528d9cb96d (svn r13090) -Codechange: add functions for direct conversion from DiagDirection to Track and Trackbits
smatz
parents: 9154
diff changeset
  2323
			trackbits = DiagDirToDiagTrackBits(dir);
8616
fd862a55c47f (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8598
diff changeset
  2324
			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: 8571
diff changeset
  2325
		}
c3404405f3f5 (svn r12177) -Codechange: use 'side' parameter in GetTileTrackStatus so there can be less checks in pathfinders for depots/stations/tunnels/bridges
smatz
parents: 8571
diff changeset
  2326
c3404405f3f5 (svn r12177) -Codechange: use 'side' parameter in GetTileTrackStatus so there can be less checks in pathfinders for depots/stations/tunnels/bridges
smatz
parents: 8571
diff changeset
  2327
		case RAIL_TILE_WAYPOINT:
8616
fd862a55c47f (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8598
diff changeset
  2328
			trackbits = GetRailWaypointBits(tile);
fd862a55c47f (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8598
diff changeset
  2329
			break;
3267
feff95208a9f (svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents: 3265
diff changeset
  2330
	}
8616
fd862a55c47f (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8598
diff changeset
  2331
fd862a55c47f (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8598
diff changeset
  2332
	return CombineTrackStatus(TrackBitsToTrackdirBits(trackbits), red_signals);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2333
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2334
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1963
diff changeset
  2335
static void ClickTile_Track(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2336
{
6187
60fc283a1722 (svn r8966) -Codechange: replace some if-cascades by switches.
rubidium
parents: 6172
diff changeset
  2337
	switch (GetRailTileType(tile)) {
9949
392998225bdd (svn r14104) -Feature: Add a window for waypoints, allowing to view all the trains having the selected waypoint in their orders.
belugas
parents: 9867
diff changeset
  2338
		case RAIL_TILE_DEPOT:    ShowDepotWindow(tile, VEH_TRAIN);            break;
392998225bdd (svn r14104) -Feature: Add a window for waypoints, allowing to view all the trains having the selected waypoint in their orders.
belugas
parents: 9867
diff changeset
  2339
		case RAIL_TILE_WAYPOINT: ShowWaypointWindow(GetWaypointByTile(tile)); break;
6187
60fc283a1722 (svn r8966) -Codechange: replace some if-cascades by switches.
rubidium
parents: 6172
diff changeset
  2340
		default: break;
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
  2341
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2342
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2343
1590
3351993cb1da (svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron
parents: 1555
diff changeset
  2344
static void GetTileDesc_Track(TileIndex tile, TileDesc *td)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2345
{
9322
cf7dc39f9576 (svn r13206) -Feature(ette): Display all owners of a tile in the tile-info-window.
frosch
parents: 9224
diff changeset
  2346
	td->owner[0] = GetTileOwner(tile);
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
  2347
	switch (GetRailTileType(tile)) {
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: 3778
diff changeset
  2348
		case RAIL_TILE_NORMAL:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2349
			td->str = STR_1021_RAILROAD_TRACK;
1590
3351993cb1da (svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron
parents: 1555
diff changeset
  2350
			break;
3351993cb1da (svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron
parents: 1555
diff changeset
  2351
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: 3778
diff changeset
  2352
		case RAIL_TILE_SIGNALS: {
9790
5d5c70e0334e (svn r13932) -Add [YAPP]: PBS signals added to the map array. The signals are drawn using the old Patch-like PBS sprites. (michi_cc)
rubidium
parents: 9788
diff changeset
  2353
			const StringID signal_type[6][6] = {
6770
408585d467f9 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 6753
diff changeset
  2354
				{
408585d467f9 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 6753
diff changeset
  2355
					STR_RAILROAD_TRACK_WITH_NORMAL_SIGNALS,
408585d467f9 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 6753
diff changeset
  2356
					STR_RAILROAD_TRACK_WITH_NORMAL_PRESIGNALS,
408585d467f9 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 6753
diff changeset
  2357
					STR_RAILROAD_TRACK_WITH_NORMAL_EXITSIGNALS,
9790
5d5c70e0334e (svn r13932) -Add [YAPP]: PBS signals added to the map array. The signals are drawn using the old Patch-like PBS sprites. (michi_cc)
rubidium
parents: 9788
diff changeset
  2358
					STR_RAILROAD_TRACK_WITH_NORMAL_COMBOSIGNALS,
5d5c70e0334e (svn r13932) -Add [YAPP]: PBS signals added to the map array. The signals are drawn using the old Patch-like PBS sprites. (michi_cc)
rubidium
parents: 9788
diff changeset
  2359
					STR_RAILROAD_TRACK_WITH_NORMAL_PBSSIGNALS,
5d5c70e0334e (svn r13932) -Add [YAPP]: PBS signals added to the map array. The signals are drawn using the old Patch-like PBS sprites. (michi_cc)
rubidium
parents: 9788
diff changeset
  2360
					STR_RAILROAD_TRACK_WITH_NORMAL_NOENTRYSIGNALS
6770
408585d467f9 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 6753
diff changeset
  2361
				},
408585d467f9 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 6753
diff changeset
  2362
				{
408585d467f9 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 6753
diff changeset
  2363
					STR_RAILROAD_TRACK_WITH_NORMAL_PRESIGNALS,
408585d467f9 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 6753
diff changeset
  2364
					STR_RAILROAD_TRACK_WITH_PRESIGNALS,
408585d467f9 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 6753
diff changeset
  2365
					STR_RAILROAD_TRACK_WITH_PRE_EXITSIGNALS,
9790
5d5c70e0334e (svn r13932) -Add [YAPP]: PBS signals added to the map array. The signals are drawn using the old Patch-like PBS sprites. (michi_cc)
rubidium
parents: 9788
diff changeset
  2366
					STR_RAILROAD_TRACK_WITH_PRE_COMBOSIGNALS,
5d5c70e0334e (svn r13932) -Add [YAPP]: PBS signals added to the map array. The signals are drawn using the old Patch-like PBS sprites. (michi_cc)
rubidium
parents: 9788
diff changeset
  2367
					STR_RAILROAD_TRACK_WITH_PRE_PBSSIGNALS,
5d5c70e0334e (svn r13932) -Add [YAPP]: PBS signals added to the map array. The signals are drawn using the old Patch-like PBS sprites. (michi_cc)
rubidium
parents: 9788
diff changeset
  2368
					STR_RAILROAD_TRACK_WITH_PRE_NOENTRYSIGNALS
6770
408585d467f9 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 6753
diff changeset
  2369
				},
408585d467f9 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 6753
diff changeset
  2370
				{
408585d467f9 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 6753
diff changeset
  2371
					STR_RAILROAD_TRACK_WITH_NORMAL_EXITSIGNALS,
408585d467f9 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 6753
diff changeset
  2372
					STR_RAILROAD_TRACK_WITH_PRE_EXITSIGNALS,
408585d467f9 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 6753
diff changeset
  2373
					STR_RAILROAD_TRACK_WITH_EXITSIGNALS,
9790
5d5c70e0334e (svn r13932) -Add [YAPP]: PBS signals added to the map array. The signals are drawn using the old Patch-like PBS sprites. (michi_cc)
rubidium
parents: 9788
diff changeset
  2374
					STR_RAILROAD_TRACK_WITH_EXIT_COMBOSIGNALS,
5d5c70e0334e (svn r13932) -Add [YAPP]: PBS signals added to the map array. The signals are drawn using the old Patch-like PBS sprites. (michi_cc)
rubidium
parents: 9788
diff changeset
  2375
					STR_RAILROAD_TRACK_WITH_EXIT_PBSSIGNALS,
5d5c70e0334e (svn r13932) -Add [YAPP]: PBS signals added to the map array. The signals are drawn using the old Patch-like PBS sprites. (michi_cc)
rubidium
parents: 9788
diff changeset
  2376
					STR_RAILROAD_TRACK_WITH_EXIT_NOENTRYSIGNALS
6770
408585d467f9 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 6753
diff changeset
  2377
				},
408585d467f9 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 6753
diff changeset
  2378
				{
408585d467f9 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 6753
diff changeset
  2379
					STR_RAILROAD_TRACK_WITH_NORMAL_COMBOSIGNALS,
408585d467f9 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 6753
diff changeset
  2380
					STR_RAILROAD_TRACK_WITH_PRE_COMBOSIGNALS,
408585d467f9 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 6753
diff changeset
  2381
					STR_RAILROAD_TRACK_WITH_EXIT_COMBOSIGNALS,
9790
5d5c70e0334e (svn r13932) -Add [YAPP]: PBS signals added to the map array. The signals are drawn using the old Patch-like PBS sprites. (michi_cc)
rubidium
parents: 9788
diff changeset
  2382
					STR_RAILROAD_TRACK_WITH_COMBOSIGNALS,
5d5c70e0334e (svn r13932) -Add [YAPP]: PBS signals added to the map array. The signals are drawn using the old Patch-like PBS sprites. (michi_cc)
rubidium
parents: 9788
diff changeset
  2383
					STR_RAILROAD_TRACK_WITH_COMBO_PBSSIGNALS,
5d5c70e0334e (svn r13932) -Add [YAPP]: PBS signals added to the map array. The signals are drawn using the old Patch-like PBS sprites. (michi_cc)
rubidium
parents: 9788
diff changeset
  2384
					STR_RAILROAD_TRACK_WITH_COMBO_NOENTRYSIGNALS
5d5c70e0334e (svn r13932) -Add [YAPP]: PBS signals added to the map array. The signals are drawn using the old Patch-like PBS sprites. (michi_cc)
rubidium
parents: 9788
diff changeset
  2385
				},
5d5c70e0334e (svn r13932) -Add [YAPP]: PBS signals added to the map array. The signals are drawn using the old Patch-like PBS sprites. (michi_cc)
rubidium
parents: 9788
diff changeset
  2386
				{
5d5c70e0334e (svn r13932) -Add [YAPP]: PBS signals added to the map array. The signals are drawn using the old Patch-like PBS sprites. (michi_cc)
rubidium
parents: 9788
diff changeset
  2387
					STR_RAILROAD_TRACK_WITH_NORMAL_PBSSIGNALS,
5d5c70e0334e (svn r13932) -Add [YAPP]: PBS signals added to the map array. The signals are drawn using the old Patch-like PBS sprites. (michi_cc)
rubidium
parents: 9788
diff changeset
  2388
					STR_RAILROAD_TRACK_WITH_PRE_PBSSIGNALS,
5d5c70e0334e (svn r13932) -Add [YAPP]: PBS signals added to the map array. The signals are drawn using the old Patch-like PBS sprites. (michi_cc)
rubidium
parents: 9788
diff changeset
  2389
					STR_RAILROAD_TRACK_WITH_EXIT_PBSSIGNALS,
5d5c70e0334e (svn r13932) -Add [YAPP]: PBS signals added to the map array. The signals are drawn using the old Patch-like PBS sprites. (michi_cc)
rubidium
parents: 9788
diff changeset
  2390
					STR_RAILROAD_TRACK_WITH_COMBO_PBSSIGNALS,
5d5c70e0334e (svn r13932) -Add [YAPP]: PBS signals added to the map array. The signals are drawn using the old Patch-like PBS sprites. (michi_cc)
rubidium
parents: 9788
diff changeset
  2391
					STR_RAILROAD_TRACK_WITH_PBSSIGNALS,
5d5c70e0334e (svn r13932) -Add [YAPP]: PBS signals added to the map array. The signals are drawn using the old Patch-like PBS sprites. (michi_cc)
rubidium
parents: 9788
diff changeset
  2392
					STR_RAILROAD_TRACK_WITH_PBS_NOENTRYSIGNALS
5d5c70e0334e (svn r13932) -Add [YAPP]: PBS signals added to the map array. The signals are drawn using the old Patch-like PBS sprites. (michi_cc)
rubidium
parents: 9788
diff changeset
  2393
				},
5d5c70e0334e (svn r13932) -Add [YAPP]: PBS signals added to the map array. The signals are drawn using the old Patch-like PBS sprites. (michi_cc)
rubidium
parents: 9788
diff changeset
  2394
				{
5d5c70e0334e (svn r13932) -Add [YAPP]: PBS signals added to the map array. The signals are drawn using the old Patch-like PBS sprites. (michi_cc)
rubidium
parents: 9788
diff changeset
  2395
					STR_RAILROAD_TRACK_WITH_NORMAL_NOENTRYSIGNALS,
5d5c70e0334e (svn r13932) -Add [YAPP]: PBS signals added to the map array. The signals are drawn using the old Patch-like PBS sprites. (michi_cc)
rubidium
parents: 9788
diff changeset
  2396
					STR_RAILROAD_TRACK_WITH_PRE_NOENTRYSIGNALS,
5d5c70e0334e (svn r13932) -Add [YAPP]: PBS signals added to the map array. The signals are drawn using the old Patch-like PBS sprites. (michi_cc)
rubidium
parents: 9788
diff changeset
  2397
					STR_RAILROAD_TRACK_WITH_EXIT_NOENTRYSIGNALS,
5d5c70e0334e (svn r13932) -Add [YAPP]: PBS signals added to the map array. The signals are drawn using the old Patch-like PBS sprites. (michi_cc)
rubidium
parents: 9788
diff changeset
  2398
					STR_RAILROAD_TRACK_WITH_COMBO_NOENTRYSIGNALS,
5d5c70e0334e (svn r13932) -Add [YAPP]: PBS signals added to the map array. The signals are drawn using the old Patch-like PBS sprites. (michi_cc)
rubidium
parents: 9788
diff changeset
  2399
					STR_RAILROAD_TRACK_WITH_PBS_NOENTRYSIGNALS,
5d5c70e0334e (svn r13932) -Add [YAPP]: PBS signals added to the map array. The signals are drawn using the old Patch-like PBS sprites. (michi_cc)
rubidium
parents: 9788
diff changeset
  2400
					STR_RAILROAD_TRACK_WITH_NOENTRYSIGNALS
6770
408585d467f9 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 6753
diff changeset
  2401
				}
1590
3351993cb1da (svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron
parents: 1555
diff changeset
  2402
			};
3351993cb1da (svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron
parents: 1555
diff changeset
  2403
10213
ebd3d874b820 (svn r14434) -Fix (r14432): compile warning.
rubidium
parents: 10212
diff changeset
  2404
			SignalType primary_signal;
ebd3d874b820 (svn r14434) -Fix (r14432): compile warning.
rubidium
parents: 10212
diff changeset
  2405
			SignalType secondary_signal;
10212
88638dba4eb9 (svn r14432) -Fix: tile description of tiles with only one signal that is not the normal signal showing "normal signal and <signal type on tile>".
rubidium
parents: 10207
diff changeset
  2406
			if (HasSignalOnTrack(tile, TRACK_UPPER)) {
88638dba4eb9 (svn r14432) -Fix: tile description of tiles with only one signal that is not the normal signal showing "normal signal and <signal type on tile>".
rubidium
parents: 10207
diff changeset
  2407
				primary_signal = GetSignalType(tile, TRACK_UPPER);
88638dba4eb9 (svn r14432) -Fix: tile description of tiles with only one signal that is not the normal signal showing "normal signal and <signal type on tile>".
rubidium
parents: 10207
diff changeset
  2408
				secondary_signal = HasSignalOnTrack(tile, TRACK_LOWER) ? GetSignalType(tile, TRACK_LOWER) : primary_signal;
88638dba4eb9 (svn r14432) -Fix: tile description of tiles with only one signal that is not the normal signal showing "normal signal and <signal type on tile>".
rubidium
parents: 10207
diff changeset
  2409
			} else {
88638dba4eb9 (svn r14432) -Fix: tile description of tiles with only one signal that is not the normal signal showing "normal signal and <signal type on tile>".
rubidium
parents: 10207
diff changeset
  2410
				secondary_signal = primary_signal = GetSignalType(tile, TRACK_LOWER);
88638dba4eb9 (svn r14432) -Fix: tile description of tiles with only one signal that is not the normal signal showing "normal signal and <signal type on tile>".
rubidium
parents: 10207
diff changeset
  2411
			}
88638dba4eb9 (svn r14432) -Fix: tile description of tiles with only one signal that is not the normal signal showing "normal signal and <signal type on tile>".
rubidium
parents: 10207
diff changeset
  2412
88638dba4eb9 (svn r14432) -Fix: tile description of tiles with only one signal that is not the normal signal showing "normal signal and <signal type on tile>".
rubidium
parents: 10207
diff changeset
  2413
			td->str = signal_type[secondary_signal][primary_signal];
1590
3351993cb1da (svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron
parents: 1555
diff changeset
  2414
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2415
		}
1590
3351993cb1da (svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron
parents: 1555
diff changeset
  2416
6172
e6d7a5b3d63f (svn r8935) -Codechange: unification of track type between road and rail tiles, unification of ground type between normal rail tiles and depots/waypoints and removing the need for RailTileSubType.
rubidium
parents: 6160
diff changeset
  2417
		case RAIL_TILE_DEPOT:
e6d7a5b3d63f (svn r8935) -Codechange: unification of track type between road and rail tiles, unification of ground type between normal rail tiles and depots/waypoints and removing the need for RailTileSubType.
rubidium
parents: 6160
diff changeset
  2418
			td->str = STR_1023_RAILROAD_TRAIN_DEPOT;
e6d7a5b3d63f (svn r8935) -Codechange: unification of track type between road and rail tiles, unification of ground type between normal rail tiles and depots/waypoints and removing the need for RailTileSubType.
rubidium
parents: 6160
diff changeset
  2419
			break;
e6d7a5b3d63f (svn r8935) -Codechange: unification of track type between road and rail tiles, unification of ground type between normal rail tiles and depots/waypoints and removing the need for RailTileSubType.
rubidium
parents: 6160
diff changeset
  2420
e6d7a5b3d63f (svn r8935) -Codechange: unification of track type between road and rail tiles, unification of ground type between normal rail tiles and depots/waypoints and removing the need for RailTileSubType.
rubidium
parents: 6160
diff changeset
  2421
		case RAIL_TILE_WAYPOINT:
1590
3351993cb1da (svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron
parents: 1555
diff changeset
  2422
		default:
6172
e6d7a5b3d63f (svn r8935) -Codechange: unification of track type between road and rail tiles, unification of ground type between normal rail tiles and depots/waypoints and removing the need for RailTileSubType.
rubidium
parents: 6160
diff changeset
  2423
			td->str = STR_LANDINFO_WAYPOINT;
1590
3351993cb1da (svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron
parents: 1555
diff changeset
  2424
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2425
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2426
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2427
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10172
diff changeset
  2428
static void ChangeTileOwner_Track(TileIndex tile, Owner old_owner, Owner new_owner)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2429
{
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10172
diff changeset
  2430
	if (!IsTileOwner(tile, old_owner)) return;
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10172
diff changeset
  2431
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10172
diff changeset
  2432
	if (new_owner != INVALID_OWNER) {
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10172
diff changeset
  2433
		SetTileOwner(tile, new_owner);
4434
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4388
diff changeset
  2434
	} else {
8519
fe61d7aa3053 (svn r12094) -Codechange: use DC_BANKRUPT command flag when removing player property to allow further fixes
smatz
parents: 8414
diff changeset
  2435
		DoCommand(tile, 0, 0, DC_EXEC | DC_BANKRUPT, CMD_LANDSCAPE_CLEAR);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2436
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2437
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2438
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2439
static const byte _fractcoords_behind[4] = { 0x8F, 0x8, 0x80, 0xF8 };
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2440
static const byte _fractcoords_enter[4] = { 0x8A, 0x48, 0x84, 0xA8 };
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
  2441
static const signed char _deltacoord_leaveoffset[8] = {
1922
bda6f85eefaa (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents: 1903
diff changeset
  2442
	-1,  0,  1,  0, /* x */
bda6f85eefaa (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents: 1903
diff changeset
  2443
	 0,  1,  0, -1  /* y */
bda6f85eefaa (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents: 1903
diff changeset
  2444
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2445
8712
be50475ea8fc (svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz
parents: 8676
diff changeset
  2446
be50475ea8fc (svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz
parents: 8676
diff changeset
  2447
/** Compute number of ticks when next wagon will leave a depot.
be50475ea8fc (svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz
parents: 8676
diff changeset
  2448
 * Negative means next wagon should have left depot n ticks before.
be50475ea8fc (svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz
parents: 8676
diff changeset
  2449
 * @param v vehicle outside (leaving) the depot
be50475ea8fc (svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz
parents: 8676
diff changeset
  2450
 * @return number of ticks when the next wagon will leave
be50475ea8fc (svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz
parents: 8676
diff changeset
  2451
 */
be50475ea8fc (svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz
parents: 8676
diff changeset
  2452
int TicksToLeaveDepot(const Vehicle *v)
be50475ea8fc (svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz
parents: 8676
diff changeset
  2453
{
be50475ea8fc (svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz
parents: 8676
diff changeset
  2454
	DiagDirection dir = GetRailDepotDirection(v->tile);
be50475ea8fc (svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz
parents: 8676
diff changeset
  2455
	int length = v->u.rail.cached_veh_length;
be50475ea8fc (svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz
parents: 8676
diff changeset
  2456
be50475ea8fc (svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz
parents: 8676
diff changeset
  2457
	switch (dir) {
be50475ea8fc (svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz
parents: 8676
diff changeset
  2458
		case DIAGDIR_NE: return  ((int)(v->x_pos & 0x0F) - ((_fractcoords_enter[dir] & 0x0F) - (length + 1)));
be50475ea8fc (svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz
parents: 8676
diff changeset
  2459
		case DIAGDIR_SE: return -((int)(v->y_pos & 0x0F) - ((_fractcoords_enter[dir] >> 4)   + (length + 1)));
be50475ea8fc (svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz
parents: 8676
diff changeset
  2460
		case DIAGDIR_SW: return -((int)(v->x_pos & 0x0F) - ((_fractcoords_enter[dir] & 0x0F) + (length + 1)));
be50475ea8fc (svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz
parents: 8676
diff changeset
  2461
		default:
be50475ea8fc (svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz
parents: 8676
diff changeset
  2462
		case DIAGDIR_NW: return  ((int)(v->y_pos & 0x0F) - ((_fractcoords_enter[dir] >> 4)   - (length + 1)));
be50475ea8fc (svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz
parents: 8676
diff changeset
  2463
	}
be50475ea8fc (svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz
parents: 8676
diff changeset
  2464
be50475ea8fc (svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz
parents: 8676
diff changeset
  2465
	return 0; // make compilers happy
be50475ea8fc (svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz
parents: 8676
diff changeset
  2466
}
be50475ea8fc (svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz
parents: 8676
diff changeset
  2467
10260
c6ec6b3c1b18 (svn r14491) -Documentation: updates/additions of doxygen docs (Alberth)
rubidium
parents: 10257
diff changeset
  2468
/** Tile callback routine when vehicle enters tile
c6ec6b3c1b18 (svn r14491) -Documentation: updates/additions of doxygen docs (Alberth)
rubidium
parents: 10257
diff changeset
  2469
 * @see vehicle_enter_tile_proc */
8119
52b48108425a (svn r11680) -Codechange: refactor more out of openttd.h and functions.h.
rubidium
parents: 8116
diff changeset
  2470
static VehicleEnterTileStatus VehicleEnter_Track(Vehicle *v, TileIndex tile, int x, int y)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2471
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2472
	byte fract_coord;
1922
bda6f85eefaa (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents: 1903
diff changeset
  2473
	byte fract_coord_leave;
3157
3f35e2d9c8e3 (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3154
diff changeset
  2474
	DiagDirection dir;
1922
bda6f85eefaa (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents: 1903
diff changeset
  2475
	int length;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  2476
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6406
diff changeset
  2477
	/* this routine applies only to trains in depot tiles */
8961
fb0848956387 (svn r12753) -Codechange: do not use IsDepotTypeTile() where simpler function can be used
smatz
parents: 8954
diff changeset
  2478
	if (v->type != VEH_TRAIN || !IsRailDepotTile(tile)) return VETSB_CONTINUE;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2479
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2480
	/* depot direction */
3185
a9d0cdff7b84 (svn r3831) Add and use GetRailDepotDirection()
tron
parents: 3184
diff changeset
  2481
	dir = GetRailDepotDirection(tile);
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  2482
1922
bda6f85eefaa (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents: 1903
diff changeset
  2483
	/* calculate the point where the following wagon should be activated */
bda6f85eefaa (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents: 1903
diff changeset
  2484
	/* this depends on the length of the current vehicle */
bda6f85eefaa (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents: 1903
diff changeset
  2485
	length = v->u.rail.cached_veh_length;
bda6f85eefaa (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents: 1903
diff changeset
  2486
bda6f85eefaa (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents: 1903
diff changeset
  2487
	fract_coord_leave =
4434
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4388
diff changeset
  2488
		((_fractcoords_enter[dir] & 0x0F) + // x
1922
bda6f85eefaa (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents: 1903
diff changeset
  2489
			(length + 1) * _deltacoord_leaveoffset[dir]) +
4434
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4388
diff changeset
  2490
		(((_fractcoords_enter[dir] >> 4) +  // y
1922
bda6f85eefaa (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents: 1903
diff changeset
  2491
			((length + 1) * _deltacoord_leaveoffset[dir+4])) << 4);
bda6f85eefaa (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents: 1903
diff changeset
  2492
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2493
	fract_coord = (x & 0xF) + ((y & 0xF) << 4);
1922
bda6f85eefaa (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents: 1903
diff changeset
  2494
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2495
	if (_fractcoords_behind[dir] == fract_coord) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2496
		/* make sure a train is not entering the tile from behind */
5991
ec2eebfe86de (svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents: 5738
diff changeset
  2497
		return VETSB_CANNOT_ENTER;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2498
	} else if (_fractcoords_enter[dir] == fract_coord) {
3157
3f35e2d9c8e3 (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3154
diff changeset
  2499
		if (DiagDirToDir(ReverseDiagDir(dir)) == v->direction) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2500
			/* enter the depot */
5993
956d341d930e (svn r8701) -Codechange: replace magic numbers with enums for u.rail.track.
rubidium
parents: 5991
diff changeset
  2501
			v->u.rail.track = TRACK_BIT_DEPOT,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2502
			v->vehstatus |= VS_HIDDEN; /* hide it */
3157
3f35e2d9c8e3 (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3154
diff changeset
  2503
			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: 7448
diff changeset
  2504
			if (v->Next() == NULL) VehicleEnterDepot(v);
5198
7046e5b0b5bc (svn r7313) -Codechange: Calling invalidate data on a window will surely warrant a redraw, so call
Darkvater
parents: 5116
diff changeset
  2505
			v->tile = tile;
7046e5b0b5bc (svn r7313) -Codechange: Calling invalidate data on a window will surely warrant a redraw, so call
Darkvater
parents: 5116
diff changeset
  2506
4739
e626ef1b522e (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4725
diff changeset
  2507
			InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile);
5991
ec2eebfe86de (svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents: 5738
diff changeset
  2508
			return VETSB_ENTERED_WORMHOLE;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2509
		}
1922
bda6f85eefaa (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents: 1903
diff changeset
  2510
	} else if (fract_coord_leave == fract_coord) {
3157
3f35e2d9c8e3 (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3154
diff changeset
  2511
		if (DiagDirToDir(dir) == v->direction) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2512
			/* leave the depot? */
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: 7448
diff changeset
  2513
			if ((v = v->Next()) != NULL) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2514
				v->vehstatus &= ~VS_HIDDEN;
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
  2515
				v->u.rail.track = (DiagDirToAxis(dir) == AXIS_X ? TRACK_BIT_X : TRACK_BIT_Y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2516
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2517
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2518
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2519
5991
ec2eebfe86de (svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents: 5738
diff changeset
  2520
	return VETSB_CONTINUE;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2521
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2522
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
  2523
/**
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
  2524
 * Tests if autoslope is allowed.
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
  2525
 *
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
  2526
 * @param tile The 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
  2527
 * @param flags Terraform command flags.
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
  2528
 * @param z_old Old TileZ.
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
  2529
 * @param tileh_old Old TileSlope.
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
  2530
 * @param z_new New TileZ.
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
  2531
 * @param tileh_new New TileSlope.
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
  2532
 * @param rail_bits Trackbits.
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
  2533
 */
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
  2534
static CommandCost TestAutoslopeOnRailTile(TileIndex tile, uint flags, uint z_old, Slope tileh_old, uint z_new, Slope tileh_new, TrackBits rail_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
  2535
{
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
  2536
	if (!_settings_game.construction.build_on_slopes || !AutoslopeEnabled()) return CMD_ERROR;
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
  2537
10017
c0eb11a864d7 (svn r14176) -Fix: better 'safe' than ... 'save'
smatz
parents: 10006
diff changeset
  2538
	/* Is the slope-rail_bits combination valid in general? I.e. is it safe to call GetRailFoundation() ? */
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
  2539
	if (CmdFailed(CheckRailSlope(tileh_new, rail_bits, TRACK_BIT_NONE, tile))) return CMD_ERROR;
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
  2540
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
  2541
	/* Get the slopes on top of the foundations */
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
  2542
	z_old += ApplyFoundationToSlope(GetRailFoundation(tileh_old, rail_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
  2543
	z_new += ApplyFoundationToSlope(GetRailFoundation(tileh_new, rail_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
  2544
7793
ee8954ca2477 (svn r11343) -Fix[FS#1368]: Autoslope did not work correctly for single track on higher part of steep slopes. (frosch)
belugas
parents: 7771
diff changeset
  2545
	Corner track_corner;
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
  2546
	switch (rail_bits) {
7793
ee8954ca2477 (svn r11343) -Fix[FS#1368]: Autoslope did not work correctly for single track on higher part of steep slopes. (frosch)
belugas
parents: 7771
diff changeset
  2547
		case TRACK_BIT_LEFT:  track_corner = CORNER_W; break;
ee8954ca2477 (svn r11343) -Fix[FS#1368]: Autoslope did not work correctly for single track on higher part of steep slopes. (frosch)
belugas
parents: 7771
diff changeset
  2548
		case TRACK_BIT_LOWER: track_corner = CORNER_S; break;
ee8954ca2477 (svn r11343) -Fix[FS#1368]: Autoslope did not work correctly for single track on higher part of steep slopes. (frosch)
belugas
parents: 7771
diff changeset
  2549
		case TRACK_BIT_RIGHT: track_corner = CORNER_E; break;
ee8954ca2477 (svn r11343) -Fix[FS#1368]: Autoslope did not work correctly for single track on higher part of steep slopes. (frosch)
belugas
parents: 7771
diff changeset
  2550
		case TRACK_BIT_UPPER: track_corner = CORNER_N; break;
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
  2551
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
  2552
		/* 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: 8228
diff changeset
  2553
		default: return (((z_old != z_new) || (tileh_old != tileh_new)) ? CMD_ERROR : 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
  2554
	}
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
  2555
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
  2556
	/* The height of the track_corner must not be changed. The rest ensures GetRailFoundation() already. */
8413
c7f3384330a3 (svn r11983) -Codechange: Add some helper functions for slopes and use them.
frosch
parents: 8398
diff changeset
  2557
	z_old += GetSlopeZInCorner(RemoveHalftileSlope(tileh_old), track_corner);
c7f3384330a3 (svn r11983) -Codechange: Add some helper functions for slopes and use them.
frosch
parents: 8398
diff changeset
  2558
	z_new += GetSlopeZInCorner(RemoveHalftileSlope(tileh_new), track_corner);
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
  2559
	if (z_old != z_new) return CMD_ERROR;
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
  2560
8230
64f28fe2d5c8 (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8228
diff changeset
  2561
	CommandCost cost = CommandCost(EXPENSES_CONSTRUCTION, _price.terraform);
7793
ee8954ca2477 (svn r11343) -Fix[FS#1368]: Autoslope did not work correctly for single track on higher part of steep slopes. (frosch)
belugas
parents: 7771
diff changeset
  2562
	/* Make the ground dirty, if surface slope has changed */
ee8954ca2477 (svn r11343) -Fix[FS#1368]: Autoslope did not work correctly for single track on higher part of steep slopes. (frosch)
belugas
parents: 7771
diff changeset
  2563
	if (tileh_old != tileh_new) {
8414
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
  2564
		/* If there is flat water on the lower halftile add the cost for clearing it */
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
  2565
		if (GetRailGroundType(tile) == RAIL_GROUND_WATER && IsSlopeWithOneCornerRaised(tileh_old)) cost.AddCost(_price.clear_water);
7793
ee8954ca2477 (svn r11343) -Fix[FS#1368]: Autoslope did not work correctly for single track on higher part of steep slopes. (frosch)
belugas
parents: 7771
diff changeset
  2566
		if ((flags & DC_EXEC) != 0) SetRailGroundType(tile, RAIL_GROUND_BARREN);
ee8954ca2477 (svn r11343) -Fix[FS#1368]: Autoslope did not work correctly for single track on higher part of steep slopes. (frosch)
belugas
parents: 7771
diff changeset
  2567
	}
7771
a900b80b48f2 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 7770
diff changeset
  2568
	return  cost;
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
  2569
}
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
  2570
7494
ab05bad37410 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7492
diff changeset
  2571
static CommandCost TerraformTile_Track(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
  2572
{
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
  2573
	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
  2574
	Slope tileh_old = GetTileSlope(tile, &z_old);
7494
ab05bad37410 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7492
diff changeset
  2575
	if (IsPlainRailTile(tile)) {
ab05bad37410 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7492
diff changeset
  2576
		TrackBits rail_bits = GetTrackBits(tile);
8414
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
  2577
		/* Is there flat water on the lower halftile, that must be cleared expensively? */
488721240c47 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8413
diff changeset
  2578
		bool was_water = (GetRailGroundType(tile) == RAIL_GROUND_WATER && IsSlopeWithOneCornerRaised(tileh_old));
7494
ab05bad37410 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7492
diff changeset
  2579
ab05bad37410 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7492
diff changeset
  2580
		_error_message = STR_1008_MUST_REMOVE_RAILROAD_TRACK;
ab05bad37410 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7492
diff changeset
  2581
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
  2582
		/* First test autoslope. However if it succeeds we still have to test the rest, because non-autoslope terraforming is cheaper. */
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
  2583
		CommandCost autoslope_result = TestAutoslopeOnRailTile(tile, flags, z_old, tileh_old, z_new, tileh_new, rail_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
  2584
7494
ab05bad37410 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7492
diff changeset
  2585
		/* When there is only a single horizontal/vertical track, one corner can be terraformed. */
7770
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
  2586
		Corner allowed_corner;
7494
ab05bad37410 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7492
diff changeset
  2587
		switch (rail_bits) {
7770
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
  2588
			case TRACK_BIT_RIGHT: allowed_corner = CORNER_W; break;
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
  2589
			case TRACK_BIT_UPPER: allowed_corner = CORNER_S; break;
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
  2590
			case TRACK_BIT_LEFT:  allowed_corner = CORNER_E; break;
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
  2591
			case TRACK_BIT_LOWER: allowed_corner = CORNER_N; break;
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
  2592
			default: return autoslope_result;
7494
ab05bad37410 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7492
diff changeset
  2593
		}
ab05bad37410 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7492
diff changeset
  2594
ab05bad37410 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7492
diff changeset
  2595
		Foundation f_old = GetRailFoundation(tileh_old, rail_bits);
ab05bad37410 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7492
diff changeset
  2596
7770
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
  2597
		/* Do not allow terraforming if allowed_corner is part of anti-zig-zag foundations */
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
  2598
		if (tileh_old != SLOPE_NS && tileh_old != SLOPE_EW && IsSpecialRailFoundation(f_old)) return autoslope_result;
7494
ab05bad37410 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7492
diff changeset
  2599
7770
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
  2600
		/* Everything is valid, which only changes allowed_corner */
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
  2601
		for (Corner corner = (Corner)0; corner < CORNER_END; corner = (Corner)(corner + 1)) {
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
  2602
			if (allowed_corner == corner) continue;
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7764
diff changeset
  2603
			if (z_old + GetSlopeZInCorner(tileh_old, corner) != z_new + GetSlopeZInCorner(tileh_new, corner)) return autoslope_result;
7494
ab05bad37410 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7492
diff changeset
  2604
		}
ab05bad37410 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7492
diff changeset
  2605
ab05bad37410 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7492
diff changeset
  2606
		/* Make the ground dirty */
ab05bad37410 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7492
diff changeset
  2607
		if ((flags & DC_EXEC) != 0) SetRailGroundType(tile, RAIL_GROUND_BARREN);
ab05bad37410 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7492
diff changeset
  2608
7771
a900b80b48f2 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 7770
diff changeset
  2609
		/* allow terraforming */
8230
64f28fe2d5c8 (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8228
diff changeset
  2610
		return CommandCost(EXPENSES_CONSTRUCTION, was_water ? _price.clear_water : (Money)0);
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
  2611
	} 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
  2612
		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
  2613
			switch (GetRailTileType(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
  2614
				case RAIL_TILE_WAYPOINT: {
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
  2615
					CommandCost cost = TestAutoslopeOnRailTile(tile, flags, z_old, tileh_old, z_new, tileh_new, GetRailWaypointBits(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
  2616
					if (!CmdFailed(cost)) return cost; // allow autoslope
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
  2617
					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
  2618
				}
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
  2619
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
  2620
				case RAIL_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: 8228
diff changeset
  2621
					if (AutoslopeCheckForEntranceEdge(tile, z_new, tileh_new, GetRailDepotDirection(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
  2622
					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
  2623
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
  2624
				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
  2625
			}
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
  2626
		}
7494
ab05bad37410 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7492
diff changeset
  2627
	}
ab05bad37410 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7492
diff changeset
  2628
	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
  2629
}
ab05bad37410 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7492
diff changeset
  2630
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2631
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
  2632
extern const TileTypeProcs _tile_type_rail_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: 4253
diff changeset
  2633
	DrawTile_Track,           /* 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: 4253
diff changeset
  2634
	GetSlopeZ_Track,          /* 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: 4253
diff changeset
  2635
	ClearTile_Track,          /* 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: 4253
diff changeset
  2636
	GetAcceptedCargo_Track,   /* 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: 4253
diff changeset
  2637
	GetTileDesc_Track,        /* 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: 4253
diff changeset
  2638
	GetTileTrackStatus_Track, /* 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: 4253
diff changeset
  2639
	ClickTile_Track,          /* 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: 4253
diff changeset
  2640
	AnimateTile_Track,        /* 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: 4253
diff changeset
  2641
	TileLoop_Track,           /* 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: 4253
diff changeset
  2642
	ChangeTileOwner_Track,    /* 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: 4253
diff changeset
  2643
	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: 4253
diff changeset
  2644
	VehicleEnter_Track,       /* 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
  2645
	GetFoundation_Track,      /* 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
  2646
	TerraformTile_Track,      /* terraform_tile_proc */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2647
};