src/rail_cmd.cpp
author rubidium
Tue, 20 May 2008 22:05:25 +0000
branch0.6
changeset 10659 2d983c15a049
parent 10323 57d8fd25473e
child 11129 72b8e47f86d8
permissions -rw-r--r--
(svn r13203) [0.6] -Prepare: for 0.6.1-RC2.
2186
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
6889
f7f6d9cb07a0 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6694
diff changeset
     3
/** @file rail_cmd.cpp */
f7f6d9cb07a0 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6694
diff changeset
     4
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
#include "stdafx.h"
1891
92a3b0aa0946 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1818
diff changeset
     6
#include "openttd.h"
3189
1af302c5abd0 (svn r3846) Add functions to set the type of stuff (clear, water, rail, road) under bridges
tron
parents: 3185
diff changeset
     7
#include "bridge_map.h"
6486
4f8af35b11eb (svn r8908) -Codechange: declaration of DrawBridgeMiddle does not belong in a map accessors header.
rubidium
parents: 6460
diff changeset
     8
#include "bridge.h"
6460
b3017e083031 (svn r8876) -Fix
tron
parents: 6459
diff changeset
     9
#include "cmd_helper.h"
1922
797081e56d13 (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"
8615
6b91ca653bad (svn r11680) -Codechange: refactor more out of openttd.h and functions.h.
rubidium
parents: 8612
diff changeset
    11
#include "tile_cmd.h"
3101
e2fdb8802c2f (svn r3696) Add functions to turn a tile into a normal rail tile/depot/waypoint. This is just a tiny step, the rail code needs way more love and caring
tron
parents: 3099
diff changeset
    12
#include "rail_map.h"
3144
426b825578f9 (svn r3763) Adapt to the new 'map accessors go in foo_map.h'-scheme
tron
parents: 3142
diff changeset
    13
#include "road_map.h"
6669
487ac09b95c4 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6585
diff changeset
    14
#include "landscape.h"
3319
7d04847e4689 (svn r4085) Add GetTown{Index,ByTile}() to get the town index resp. the town from a tile
tron
parents: 3286
diff changeset
    15
#include "town_map.h"
3154
a8fffb204d0e (svn r3777) Add some functions to handle tunnels
tron
parents: 3153
diff changeset
    16
#include "tunnel_map.h"
8720
4e60c30e2006 (svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents: 8707
diff changeset
    17
#include "viewport_func.h"
8612
6414fc21c2f3 (svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents: 8604
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"
1922
797081e56d13 (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents: 1903
diff changeset
    20
#include "engine.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    21
#include "town.h"
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 337
diff changeset
    22
#include "station.h"
405
6830ae7a0d5d (svn r602) -newgrf: Move DrawTileSeqStruct & co and struct SpriteGroup to sprite.h (pasky)
darkvater
parents: 403
diff changeset
    23
#include "sprite.h"
1313
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents: 1247
diff changeset
    24
#include "depot.h"
1542
2ca6d1624e6d (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1536
diff changeset
    25
#include "waypoint.h"
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
    26
#include "rail.h"
3638
6e0b43d905d4 (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
    27
#include "newgrf.h"
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3884
diff changeset
    28
#include "yapf/yapf.h"
8035
a0200ced6d9f (svn r11059) -Fix [FS#1182]: inconsistency between Rail<->ElRail conversions of different kinds of rail containing tiles (normal rail, stations, depots, etc). Patch by SmatZ.
rubidium
parents: 7990
diff changeset
    29
#include "newgrf_engine.h"
3757
a0bba34a94ba (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
    30
#include "newgrf_callbacks.h"
a0bba34a94ba (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_station.h"
4556
693f37c36c85 (svn r6395) -Fix: when converting a depot from/to elrail, update the power of trains that are in it
glx
parents: 4549
diff changeset
    32
#include "train.h"
8707
55835d8fbfcd (svn r11774) -Change: do not include variables.h in a header when it is not needed.
rubidium
parents: 8693
diff changeset
    33
#include "variables.h"
8078
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
    34
#include "autoslope.h"
8345
6caa3fdb972c (svn r11399) -Feature(ette): transparency settings can now be saved and thus remembered.
belugas
parents: 8329
diff changeset
    35
#include "transparency.h"
8444
9317090e9c8c (svn r11504) -Fix [FS#1467]: removing docks/ship depots could result in non-canal water where canals should have been build.
rubidium
parents: 8428
diff changeset
    36
#include "water.h"
8579
3efbb430092e (svn r11644) -Codechange: merge some functions from tunnel_map.h and bridge_map.h into tunnelbridge_map.h
smatz
parents: 8577
diff changeset
    37
#include "tunnelbridge_map.h"
8602
9e75e594a068 (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: 8592
diff changeset
    38
#include "window_func.h"
8640
1e93b81e96d2 (svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium
parents: 8635
diff changeset
    39
#include "vehicle_func.h"
8653
a83f7a536919 (svn r11719) -Codechange: split sound.h in a header with types and one with functions.
rubidium
parents: 8649
diff changeset
    40
#include "sound_func.h"
8734
b7fc8c6fd379 (svn r11802) -Fix [FS#716]: do not crash trains when leaving depot to a very long track
smatz
parents: 8732
diff changeset
    41
#include "signal_func.h"
8894
1e5b2d4380b8 (svn r11968) -Codechange: remove redundant FindLengthOfTunnel(), use GetTunnelBridgeLength() and/or GetOtherTunnelEnd() instead
smatz
parents: 8840
diff changeset
    42
#include "tunnelbridge.h"
8579
3efbb430092e (svn r11644) -Codechange: merge some functions from tunnel_map.h and bridge_map.h into tunnelbridge_map.h
smatz
parents: 8577
diff changeset
    43
8760
ce0891c412ce (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8734
diff changeset
    44
#include "table/sprites.h"
ce0891c412ce (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8734
diff changeset
    45
#include "table/strings.h"
ce0891c412ce (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8734
diff changeset
    46
#include "table/railtypes.h"
9063
71e5e4283b4b (svn r12145) -Codechange: includes should be at the top of the source file
belugas
parents: 9059
diff changeset
    47
#include "table/track_land.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    48
2261
3f78323707bb (svn r2781) Fix some of the issues with variables in .h files.
ludde
parents: 2254
diff changeset
    49
const byte _track_sloped_sprites[14] = {
3f78323707bb (svn r2781) Fix some of the issues with variables in .h files.
ludde
parents: 2254
diff changeset
    50
	14, 15, 22, 13,
3f78323707bb (svn r2781) Fix some of the issues with variables in .h files.
ludde
parents: 2254
diff changeset
    51
	 0, 21, 17, 12,
3f78323707bb (svn r2781) Fix some of the issues with variables in .h files.
ludde
parents: 2254
diff changeset
    52
	23,  0, 18, 20,
3f78323707bb (svn r2781) Fix some of the issues with variables in .h files.
ludde
parents: 2254
diff changeset
    53
	19, 16
3f78323707bb (svn r2781) Fix some of the issues with variables in .h files.
ludde
parents: 2254
diff changeset
    54
};
3f78323707bb (svn r2781) Fix some of the issues with variables in .h files.
ludde
parents: 2254
diff changeset
    55
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    56
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    57
/*         4
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    58
 *     ---------
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    59
 *    |\       /|
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    60
 *    | \    1/ |
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    61
 *    |  \   /  |
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    62
 *    |   \ /   |
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    63
 *  16|    \    |32
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
    64
 *    |   / \2  |
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    65
 *    |  /   \  |
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    66
 *    | /     \ |
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    67
 *    |/       \|
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    68
 *     ---------
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    69
 *         8
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    70
 */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    71
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    72
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    73
22
fe6f35cc987b (svn r23) -Some omments on the code (blathijs)
darkvater
parents: 13
diff changeset
    74
/* 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
    75
 * MAP3LO byte:  abcd???? => Signal Exists?
4434
4175805666a5 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4388
diff changeset
    76
 *               a and b are for diagonals, upper and left,
4175805666a5 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4388
diff changeset
    77
 *               one for each direction. (ie a == NE->SW, b ==
4175805666a5 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4388
diff changeset
    78
 *               SW->NE, or v.v., I don't know. b and c are
4175805666a5 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4388
diff changeset
    79
 *               similar for lower and right.
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    80
 * MAP2 byte:    ????abcd => Type of ground.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    81
 * MAP3LO byte:  ????abcd => Type of rail.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    82
 * MAP5:         00abcdef => rail
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    83
 *               01abcdef => rail w/ signals
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    84
 *               10uuuuuu => unused
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
    85
 *               11uuuudd => rail depot
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    86
 */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    87
7944
65c7c2e1bcb9 (svn r10922) -Codechange: Allow building and removing tracks and signals when there is a
maedhros
parents: 7885
diff changeset
    88
8734
b7fc8c6fd379 (svn r11802) -Fix [FS#716]: do not crash trains when leaving depot to a very long track
smatz
parents: 8732
diff changeset
    89
void *EnsureNoTrainOnTrackProc(Vehicle *v, void *data)
7944
65c7c2e1bcb9 (svn r10922) -Codechange: Allow building and removing tracks and signals when there is a
maedhros
parents: 7885
diff changeset
    90
{
8577
fc4b7dd34058 (svn r11642) -Codechange: VehicleFromPos does check for v->tile == tile, so remove useless checks
smatz
parents: 8573
diff changeset
    91
	TrackBits rail_bits = *(TrackBits *)data;
fc4b7dd34058 (svn r11642) -Codechange: VehicleFromPos does check for v->tile == tile, so remove useless checks
smatz
parents: 8573
diff changeset
    92
fc4b7dd34058 (svn r11642) -Codechange: VehicleFromPos does check for v->tile == tile, so remove useless checks
smatz
parents: 8573
diff changeset
    93
	if (v->type != VEH_TRAIN) return NULL;
fc4b7dd34058 (svn r11642) -Codechange: VehicleFromPos does check for v->tile == tile, so remove useless checks
smatz
parents: 8573
diff changeset
    94
fc4b7dd34058 (svn r11642) -Codechange: VehicleFromPos does check for v->tile == tile, so remove useless checks
smatz
parents: 8573
diff changeset
    95
	if ((v->u.rail.track != rail_bits) && !TracksOverlap(v->u.rail.track | rail_bits)) return NULL;
7944
65c7c2e1bcb9 (svn r10922) -Codechange: Allow building and removing tracks and signals when there is a
maedhros
parents: 7885
diff changeset
    96
65c7c2e1bcb9 (svn r10922) -Codechange: Allow building and removing tracks and signals when there is a
maedhros
parents: 7885
diff changeset
    97
	_error_message = VehicleInTheWayErrMsg(v);
65c7c2e1bcb9 (svn r10922) -Codechange: Allow building and removing tracks and signals when there is a
maedhros
parents: 7885
diff changeset
    98
	return v;
65c7c2e1bcb9 (svn r10922) -Codechange: Allow building and removing tracks and signals when there is a
maedhros
parents: 7885
diff changeset
    99
}
65c7c2e1bcb9 (svn r10922) -Codechange: Allow building and removing tracks and signals when there is a
maedhros
parents: 7885
diff changeset
   100
65c7c2e1bcb9 (svn r10922) -Codechange: Allow building and removing tracks and signals when there is a
maedhros
parents: 7885
diff changeset
   101
/**
65c7c2e1bcb9 (svn r10922) -Codechange: Allow building and removing tracks and signals when there is a
maedhros
parents: 7885
diff changeset
   102
 * Tests if a vehicle interacts with the specified track.
65c7c2e1bcb9 (svn r10922) -Codechange: Allow building and removing tracks and signals when there is a
maedhros
parents: 7885
diff changeset
   103
 * All track bits interact except parallel TRACK_BIT_HORZ or TRACK_BIT_VERT.
65c7c2e1bcb9 (svn r10922) -Codechange: Allow building and removing tracks and signals when there is a
maedhros
parents: 7885
diff changeset
   104
 *
65c7c2e1bcb9 (svn r10922) -Codechange: Allow building and removing tracks and signals when there is a
maedhros
parents: 7885
diff changeset
   105
 * @param tile The tile.
65c7c2e1bcb9 (svn r10922) -Codechange: Allow building and removing tracks and signals when there is a
maedhros
parents: 7885
diff changeset
   106
 * @param track The track.
65c7c2e1bcb9 (svn r10922) -Codechange: Allow building and removing tracks and signals when there is a
maedhros
parents: 7885
diff changeset
   107
 */
65c7c2e1bcb9 (svn r10922) -Codechange: Allow building and removing tracks and signals when there is a
maedhros
parents: 7885
diff changeset
   108
static bool EnsureNoTrainOnTrack(TileIndex tile, Track track)
65c7c2e1bcb9 (svn r10922) -Codechange: Allow building and removing tracks and signals when there is a
maedhros
parents: 7885
diff changeset
   109
{
8577
fc4b7dd34058 (svn r11642) -Codechange: VehicleFromPos does check for v->tile == tile, so remove useless checks
smatz
parents: 8573
diff changeset
   110
	TrackBits rail_bits = TrackToTrackBits(track);
fc4b7dd34058 (svn r11642) -Codechange: VehicleFromPos does check for v->tile == tile, so remove useless checks
smatz
parents: 8573
diff changeset
   111
fc4b7dd34058 (svn r11642) -Codechange: VehicleFromPos does check for v->tile == tile, so remove useless checks
smatz
parents: 8573
diff changeset
   112
	return VehicleFromPos(tile, &rail_bits, &EnsureNoTrainOnTrackProc) == NULL;
7944
65c7c2e1bcb9 (svn r10922) -Codechange: Allow building and removing tracks and signals when there is a
maedhros
parents: 7885
diff changeset
   113
}
65c7c2e1bcb9 (svn r10922) -Codechange: Allow building and removing tracks and signals when there is a
maedhros
parents: 7885
diff changeset
   114
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   115
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
   116
{
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6902
diff changeset
   117
	TrackBits current; // The current track layout
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6902
diff changeset
   118
	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
   119
	_error_message = STR_1001_IMPOSSIBLE_TRACK_COMBINATION;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   120
4182
20d711816338 (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
   121
	if (!IsPlainRailTile(tile)) return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   122
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   123
	/* So, we have a tile with tracks on it (and possibly signals). Let's see
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   124
	 * what tracks first */
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   125
	current = GetTrackBits(tile);
1946
68e7ee03016a (svn r2452) Fix defect in r2448 which caused building tracks unexpectedly fail or succeed
tron
parents: 1942
diff changeset
   126
	future = current | to_build;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   127
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   128
	/* Are we really building something new? */
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   129
	if (current == future) {
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   130
		/* Nothing new is being built */
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   131
		_error_message = STR_1007_ALREADY_BUILT;
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   132
		return false;
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   133
	}
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   134
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   135
	/* Let's see if we may build this */
4182
20d711816338 (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
   136
	if (flags & DC_NO_RAIL_OVERLAP || HasSignals(tile)) {
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   137
		/* If we are not allowed to overlap (flag is on for ai players or we have
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   138
		 * signals on the tile), check that */
3258
94a915e7485f (svn r3946) Add short hand names for common track combinations
tron
parents: 3254
diff changeset
   139
		return future == TRACK_BIT_HORZ || future == TRACK_BIT_VERT;
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   140
	} else {
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   141
		/* Normally, we may overlap and any combination is valid */
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   142
		return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   143
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   144
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   145
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   146
8199
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8138
diff changeset
   147
/** Valid TrackBits on a specific (non-steep)-slope without foundation */
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8138
diff changeset
   148
static const TrackBits _valid_tracks_without_foundation[15] = {
3258
94a915e7485f (svn r3946) Add short hand names for common track combinations
tron
parents: 3254
diff changeset
   149
	TRACK_BIT_ALL,
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   150
	TRACK_BIT_RIGHT,
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   151
	TRACK_BIT_UPPER,
3102
fde95020fc8e (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
   152
	TRACK_BIT_X,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   153
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   154
	TRACK_BIT_LEFT,
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   155
	TRACK_BIT_NONE,
3102
fde95020fc8e (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
   156
	TRACK_BIT_Y,
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   157
	TRACK_BIT_LOWER,
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   158
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   159
	TRACK_BIT_LOWER,
3102
fde95020fc8e (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
   160
	TRACK_BIT_Y,
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   161
	TRACK_BIT_NONE,
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   162
	TRACK_BIT_LEFT,
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   163
3102
fde95020fc8e (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
   164
	TRACK_BIT_X,
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   165
	TRACK_BIT_UPPER,
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   166
	TRACK_BIT_RIGHT,
8199
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8138
diff changeset
   167
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   168
8199
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8138
diff changeset
   169
/** Valid TrackBits on a specific (non-steep)-slope with leveled foundation */
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8138
diff changeset
   170
static const TrackBits _valid_tracks_on_leveled_foundation[15] = {
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   171
	TRACK_BIT_NONE,
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   172
	TRACK_BIT_LEFT,
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   173
	TRACK_BIT_LOWER,
3102
fde95020fc8e (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_Y | TRACK_BIT_LOWER | TRACK_BIT_LEFT,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   175
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   176
	TRACK_BIT_RIGHT,
3258
94a915e7485f (svn r3946) Add short hand names for common track combinations
tron
parents: 3254
diff changeset
   177
	TRACK_BIT_ALL,
3102
fde95020fc8e (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_X | TRACK_BIT_LOWER | TRACK_BIT_RIGHT,
3258
94a915e7485f (svn r3946) Add short hand names for common track combinations
tron
parents: 3254
diff changeset
   179
	TRACK_BIT_ALL,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   180
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   181
	TRACK_BIT_UPPER,
3102
fde95020fc8e (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_X | TRACK_BIT_UPPER | TRACK_BIT_LEFT,
3258
94a915e7485f (svn r3946) Add short hand names for common track combinations
tron
parents: 3254
diff changeset
   183
	TRACK_BIT_ALL,
94a915e7485f (svn r3946) Add short hand names for common track combinations
tron
parents: 3254
diff changeset
   184
	TRACK_BIT_ALL,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   185
3102
fde95020fc8e (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_Y | TRACK_BIT_UPPER | TRACK_BIT_RIGHT,
3258
94a915e7485f (svn r3946) Add short hand names for common track combinations
tron
parents: 3254
diff changeset
   187
	TRACK_BIT_ALL,
94a915e7485f (svn r3946) Add short hand names for common track combinations
tron
parents: 3254
diff changeset
   188
	TRACK_BIT_ALL
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   189
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   190
8199
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8138
diff changeset
   191
/**
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8138
diff changeset
   192
 * Checks if a track combination is valid on a specific slope and returns the needed foundation.
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8138
diff changeset
   193
 *
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8138
diff changeset
   194
 * @param tileh Tile slope.
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8138
diff changeset
   195
 * @param bits  Trackbits.
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8138
diff changeset
   196
 * @return Needed foundation or FOUNDATION_INVALID if track/slope combination is not allowed.
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8138
diff changeset
   197
 */
7831
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7829
diff changeset
   198
Foundation GetRailFoundation(Slope tileh, TrackBits bits)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   199
{
8199
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8138
diff changeset
   200
	if (bits == TRACK_BIT_NONE) return FOUNDATION_NONE;
3878
91a8b87f641e (svn r4927) Replace 3 big ifs (which regard foundations) by a bit less confusing code
tron
parents: 3869
diff changeset
   201
8199
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8138
diff changeset
   202
	if (IsSteepSlope(tileh)) {
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8138
diff changeset
   203
		/* Test for inclined foundations */
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8138
diff changeset
   204
		if (bits == TRACK_BIT_X) return FOUNDATION_INCLINED_X;
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8138
diff changeset
   205
		if (bits == TRACK_BIT_Y) return FOUNDATION_INCLINED_Y;
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8138
diff changeset
   206
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8138
diff changeset
   207
		/* Get higher track */
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8138
diff changeset
   208
		Corner highest_corner = GetHighestSlopeCorner(tileh);
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8138
diff changeset
   209
		TrackBits higher_track = CornerToTrackBits(highest_corner);
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8138
diff changeset
   210
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8138
diff changeset
   211
		/* Only higher track? */
8266
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   212
		if (bits == higher_track) return HalftileFoundation(highest_corner);
8199
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8138
diff changeset
   213
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8138
diff changeset
   214
		/* Overlap with higher track? */
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8138
diff changeset
   215
		if (TracksOverlap(bits | higher_track)) return FOUNDATION_INVALID;
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8138
diff changeset
   216
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8138
diff changeset
   217
		/* either lower track or both higher and lower track */
8266
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   218
		return ((bits & higher_track) != 0 ? FOUNDATION_STEEP_BOTH : FOUNDATION_STEEP_LOWER);
8199
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8138
diff changeset
   219
	} else {
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8138
diff changeset
   220
		if ((~_valid_tracks_without_foundation[tileh] & bits) == 0) return FOUNDATION_NONE;
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8138
diff changeset
   221
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8138
diff changeset
   222
		bool valid_on_leveled = ((~_valid_tracks_on_leveled_foundation[tileh] & bits) == 0);
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8138
diff changeset
   223
8266
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   224
		Corner track_corner;
8199
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8138
diff changeset
   225
		switch (bits) {
8266
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   226
			case TRACK_BIT_LEFT:  track_corner = CORNER_W; break;
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   227
			case TRACK_BIT_LOWER: track_corner = CORNER_S; break;
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   228
			case TRACK_BIT_RIGHT: track_corner = CORNER_E; break;
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   229
			case TRACK_BIT_UPPER: track_corner = CORNER_N; break;
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   230
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   231
			case TRACK_BIT_HORZ:
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   232
				if (tileh == SLOPE_N) return HalftileFoundation(CORNER_N);
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   233
				if (tileh == SLOPE_S) return HalftileFoundation(CORNER_S);
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   234
				return (valid_on_leveled ? FOUNDATION_LEVELED : FOUNDATION_INVALID);
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   235
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   236
			case TRACK_BIT_VERT:
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   237
				if (tileh == SLOPE_W) return HalftileFoundation(CORNER_W);
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   238
				if (tileh == SLOPE_E) return HalftileFoundation(CORNER_E);
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   239
				return (valid_on_leveled ? FOUNDATION_LEVELED : FOUNDATION_INVALID);
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   240
8199
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8138
diff changeset
   241
			case TRACK_BIT_X:
8909
fa15e9afad2f (svn r11983) -Codechange: Add some helper functions for slopes and use them.
frosch
parents: 8894
diff changeset
   242
				if (IsSlopeWithOneCornerRaised(tileh)) return FOUNDATION_INCLINED_X;
8199
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8138
diff changeset
   243
				return (valid_on_leveled ? FOUNDATION_LEVELED : FOUNDATION_INVALID);
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8138
diff changeset
   244
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8138
diff changeset
   245
			case TRACK_BIT_Y:
8909
fa15e9afad2f (svn r11983) -Codechange: Add some helper functions for slopes and use them.
frosch
parents: 8894
diff changeset
   246
				if (IsSlopeWithOneCornerRaised(tileh)) return FOUNDATION_INCLINED_Y;
8199
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8138
diff changeset
   247
				return (valid_on_leveled ? FOUNDATION_LEVELED : FOUNDATION_INVALID);
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8138
diff changeset
   248
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8138
diff changeset
   249
			default:
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8138
diff changeset
   250
				return (valid_on_leveled ? FOUNDATION_LEVELED : FOUNDATION_INVALID);
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8138
diff changeset
   251
		}
8266
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   252
		/* Single diagonal track */
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   253
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   254
		/* Track must be at least valid on leveled foundation */
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   255
		if (!valid_on_leveled) return FOUNDATION_INVALID;
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   256
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   257
		/* If slope has three raised corners, build leveled foundation */
8909
fa15e9afad2f (svn r11983) -Codechange: Add some helper functions for slopes and use them.
frosch
parents: 8894
diff changeset
   258
		if (IsSlopeWithThreeCornersRaised(tileh)) return FOUNDATION_LEVELED;
8266
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   259
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   260
		/* If neighboured corners of track_corner are lowered, build halftile foundation */
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   261
		if ((tileh & SlopeWithThreeCornersRaised(OppositeCorner(track_corner))) == SlopeWithOneCornerRaised(track_corner)) return HalftileFoundation(track_corner);
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   262
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   263
		/* else special anti-zig-zag foundation */
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   264
		return SpecialRailFoundation(track_corner);
2951
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2934
diff changeset
   265
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   266
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   267
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   268
8199
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8138
diff changeset
   269
/**
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8138
diff changeset
   270
 * Tests if a track can be build on a tile.
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8138
diff changeset
   271
 *
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8138
diff changeset
   272
 * @param tileh Tile slope.
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8138
diff changeset
   273
 * @param rail_bits Tracks to build.
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8138
diff changeset
   274
 * @param existing Tracks already built.
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8138
diff changeset
   275
 * @param tile Tile (used for water test)
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8138
diff changeset
   276
 * @return Error message or cost for foundation building.
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8138
diff changeset
   277
 */
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7287
diff changeset
   278
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
   279
{
8199
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8138
diff changeset
   280
	/* don't allow building on the lower side of a coast */
8267
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8266
diff changeset
   281
	if (IsTileType(tile, MP_WATER) || (IsTileType(tile, MP_RAILWAY) && (GetRailGroundType(tile) == RAIL_GROUND_WATER))) {
8199
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8138
diff changeset
   282
		if (!IsSteepSlope(tileh) && ((~_valid_tracks_on_leveled_foundation[tileh] & (rail_bits | existing)) != 0)) return_cmd_error(STR_3807_CAN_T_BUILD_ON_WATER);
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8138
diff changeset
   283
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   284
8199
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8138
diff changeset
   285
	Foundation f_new = GetRailFoundation(tileh, rail_bits | existing);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   286
8199
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8138
diff changeset
   287
	/* check track/slope combination */
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8138
diff changeset
   288
	if ((f_new == FOUNDATION_INVALID) ||
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8138
diff changeset
   289
	    ((f_new != FOUNDATION_NONE) && (!_patches.build_on_slopes || _is_old_ai_player))
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8138
diff changeset
   290
	   ) return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   291
8199
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8138
diff changeset
   292
	Foundation f_old = GetRailFoundation(tileh, existing);
8726
5ae45b46506b (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8724
diff changeset
   293
	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
   294
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   295
1775
08ff0f12ccdc (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
   296
/* Validate functions for rail building */
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   297
static inline bool ValParamTrackOrientation(Track track) {return IsValidTrack(track);}
1775
08ff0f12ccdc (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
   298
08ff0f12ccdc (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
   299
/** Build a single piece of rail
3491
4c8427796c64 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3486
diff changeset
   300
 * @param tile tile  to build on
6979
d194d25020e7 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6948
diff changeset
   301
 * @param flags operation to perform
1775
08ff0f12ccdc (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
   302
 * @param p1 railtype of being built piece (normal, mono, maglev)
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   303
 * @param p2 rail track to build
1775
08ff0f12ccdc (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
   304
 */
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7287
diff changeset
   305
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
   306
{
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3575
diff changeset
   307
	Slope tileh;
8732
b18f578f7c16 (svn r11800) -Codechange: move some functions to a more logical location + some type safety.
rubidium
parents: 8726
diff changeset
   308
	RailType railtype = (RailType)p1;
b18f578f7c16 (svn r11800) -Codechange: move some functions to a more logical location + some type safety.
rubidium
parents: 8726
diff changeset
   309
	Track track = (Track)p2;
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   310
	TrackBits trackbit;
8726
5ae45b46506b (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8724
diff changeset
   311
	CommandCost cost(EXPENSES_CONSTRUCTION);
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7287
diff changeset
   312
	CommandCost ret;
1627
d88508d9ced0 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   313
8732
b18f578f7c16 (svn r11800) -Codechange: move some functions to a more logical location + some type safety.
rubidium
parents: 8726
diff changeset
   314
	if (!ValParamRailtype(railtype) || !ValParamTrackOrientation(track)) return CMD_ERROR;
1627
d88508d9ced0 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   315
d88508d9ced0 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   316
	tileh = GetTileSlope(tile, NULL);
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   317
	trackbit = TrackToTrackBits(track);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   318
1627
d88508d9ced0 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   319
	switch (GetTileType(tile)) {
d88508d9ced0 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   320
		case MP_RAILWAY:
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   321
			if (!CheckTrackCombination(tile, trackbit, flags) ||
7944
65c7c2e1bcb9 (svn r10922) -Codechange: Allow building and removing tracks and signals when there is a
maedhros
parents: 7885
diff changeset
   322
					!EnsureNoTrainOnTrack(tile, track)) {
1627
d88508d9ced0 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   323
				return CMD_ERROR;
d88508d9ced0 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   324
			}
4180
72f8362401b6 (svn r5618) Remove a redundant check, CheckTrackCombination() a few lines above performs the same test
tron
parents: 4158
diff changeset
   325
			if (!IsTileOwner(tile, _current_player) ||
5582
0b1e6b9a1bdb (svn r7583) -Fix (r7573): Merging of bridge branch broke (partially reverted?) automatic railtype conversion when building track on existing rail.
peter1138
parents: 5573
diff changeset
   326
					!IsCompatibleRail(GetRailType(tile), railtype)) {
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6902
diff changeset
   327
				/* Get detailed error message */
3491
4c8427796c64 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3486
diff changeset
   328
				return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
1627
d88508d9ced0 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   329
			}
d88508d9ced0 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   330
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   331
			ret = CheckRailSlope(tileh, trackbit, GetTrackBits(tile), tile);
1691
fcd9fefaed02 (svn r2195) Add CmdFailed() as the One True Way(tm) to check if a command failed.
tron
parents: 1669
diff changeset
   332
			if (CmdFailed(ret)) return ret;
7446
1c4d469f986e (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 7442
diff changeset
   333
			cost.AddCost(ret);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   334
5059
dbded6ba1f91 (svn r7112) -Codechange (r7106): Improve the test for determining if the rail type should be converted
peter1138
parents: 5058
diff changeset
   335
			/* If the rail types don't match, try to convert only if engines of
dbded6ba1f91 (svn r7112) -Codechange (r7106): Improve the test for determining if the rail type should be converted
peter1138
parents: 5058
diff changeset
   336
			 * the present rail type are powered on the new rail type. */
dbded6ba1f91 (svn r7112) -Codechange (r7106): Improve the test for determining if the rail type should be converted
peter1138
parents: 5058
diff changeset
   337
			if (GetRailType(tile) != railtype && HasPowerOnRail(GetRailType(tile), railtype)) {
5058
81748e4f3e60 (svn r7111) After checking p1 in CmdBuildSingleRail() assign it to a variable railtype instead of using p1 in the function. Also assign p2 to track only after it has been checked for validity
tron
parents: 5055
diff changeset
   338
				ret = DoCommand(tile, tile, railtype, flags, CMD_CONVERT_RAIL);
5054
cf05383e4df5 (svn r7106) -Feature: Allow over-building of compatible railtypes, i.e. normal and
peter1138
parents: 5015
diff changeset
   339
				if (CmdFailed(ret)) return ret;
7446
1c4d469f986e (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 7442
diff changeset
   340
				cost.AddCost(ret);
5054
cf05383e4df5 (svn r7106) -Feature: Allow over-building of compatible railtypes, i.e. normal and
peter1138
parents: 5015
diff changeset
   341
			}
cf05383e4df5 (svn r7106) -Feature: Allow over-building of compatible railtypes, i.e. normal and
peter1138
parents: 5015
diff changeset
   342
1719
b428568cec03 (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
   343
			if (flags & DC_EXEC) {
3523
168ee460418b (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
   344
				SetRailGroundType(tile, RAIL_GROUND_BARREN);
5662
2dd848654f54 (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: 5582
diff changeset
   345
				SetTrackBits(tile, GetTrackBits(tile) | trackbit);
1719
b428568cec03 (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
   346
			}
1627
d88508d9ced0 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   347
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   348
7866
e19fda04e8d3 (svn r10733) -Codechange: change MP_STREET into MP_ROAD as we use the word "road" everywhere except in the tile type.
rubidium
parents: 7831
diff changeset
   349
		case MP_ROAD:
3142
00b67636048f (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
   350
#define M(x) (1 << (x))
00b67636048f (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
   351
			/* Level crossings may only be built on these slopes */
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8378
diff changeset
   352
			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
d88508d9ced0 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   353
				return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
3142
00b67636048f (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
   354
			}
00b67636048f (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
   355
#undef M
00b67636048f (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
   356
6902
9da0ee122fd5 (svn r9542) -Fix(FS# 712): When checking if a vehicle is on a given tile, and you are working on the ground tile, do not take aircrafts into account, as they do not pose any danger for the construction/destruction/conversion itself. Z stuff, in other words
belugas
parents: 6889
diff changeset
   357
			if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   358
9059
04edde3eb0c6 (svn r12141) -Codechange: Introduce IsNormalRoad[Tile](), IsRoadDepot[Tile]() and HasTileRoadType(); and use them.
frosch
parents: 9043
diff changeset
   359
			if (IsNormalRoad(tile)) {
4140
c294db895325 (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
   360
				if (HasRoadWorks(tile)) return_cmd_error(STR_ROAD_WORKS_IN_PROGRESS);
c294db895325 (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
   361
9160
e11f0a28e7f1 (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: 9112
diff changeset
   362
				if (GetDisallowedRoadDirections(tile) != DRD_NONE) return_cmd_error(STR_ERR_CROSSING_ON_ONEWAY_ROAD);
e11f0a28e7f1 (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: 9112
diff changeset
   363
7157
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 7087
diff changeset
   364
				RoadTypes roadtypes = GetRoadTypes(tile);
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 7087
diff changeset
   365
				RoadBits road = GetRoadBits(tile, ROADTYPE_ROAD);
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 7087
diff changeset
   366
				RoadBits tram = GetRoadBits(tile, ROADTYPE_TRAM);
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 7087
diff changeset
   367
				switch (roadtypes) {
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 7087
diff changeset
   368
					default: break;
7224
31699d7486ed (svn r9960) -Fix [FS#813]: road wasn't properly added when overbuilding a tram rails with normal rails to for a crossing.
rubidium
parents: 7179
diff changeset
   369
					case ROADTYPES_TRAM:
31699d7486ed (svn r9960) -Fix [FS#813]: road wasn't properly added when overbuilding a tram rails with normal rails to for a crossing.
rubidium
parents: 7179
diff changeset
   370
						/* Tram crossings must always have road. */
9165
765c4f60311c (svn r12334) -Codechange: Don't change road owner without DC_EXEC. Didn't affect anything in this case but is bad form.
peter1138
parents: 9160
diff changeset
   371
						if (flags & DC_EXEC) SetRoadOwner(tile, ROADTYPE_ROAD, _current_player);
7224
31699d7486ed (svn r9960) -Fix [FS#813]: road wasn't properly added when overbuilding a tram rails with normal rails to for a crossing.
rubidium
parents: 7179
diff changeset
   372
						roadtypes |= ROADTYPES_ROAD;
31699d7486ed (svn r9960) -Fix [FS#813]: road wasn't properly added when overbuilding a tram rails with normal rails to for a crossing.
rubidium
parents: 7179
diff changeset
   373
						break;
31699d7486ed (svn r9960) -Fix [FS#813]: road wasn't properly added when overbuilding a tram rails with normal rails to for a crossing.
rubidium
parents: 7179
diff changeset
   374
7157
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 7087
diff changeset
   375
					case ROADTYPES_ROADTRAM: if (road == tram) break;
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 7087
diff changeset
   376
						/* FALL THROUGH */
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 7087
diff changeset
   377
					case ROADTYPES_ROADHWAY: // Road and highway are incompatible in this case
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 7087
diff changeset
   378
					case ROADTYPES_TRAMHWAY: // Tram and highway are incompatible in this case
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 7087
diff changeset
   379
					case ROADTYPES_ALL:      // Also incompatible
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 7087
diff changeset
   380
						return CMD_ERROR;
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 7087
diff changeset
   381
				}
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 7087
diff changeset
   382
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 7087
diff changeset
   383
				road |= tram | GetRoadBits(tile, ROADTYPE_HWAY);
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 7087
diff changeset
   384
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 7087
diff changeset
   385
				if ((track == TRACK_X && road == ROAD_Y) ||
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 7087
diff changeset
   386
						(track == TRACK_Y && road == ROAD_X)) {
4140
c294db895325 (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
   387
					if (flags & DC_EXEC) {
7157
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 7087
diff changeset
   388
						MakeRoadCrossing(tile, GetRoadOwner(tile, ROADTYPE_ROAD), GetRoadOwner(tile, ROADTYPE_TRAM), GetRoadOwner(tile, ROADTYPE_HWAY), _current_player, (track == TRACK_X ? AXIS_Y : AXIS_X), railtype, roadtypes, GetTownIndex(tile));
8840
81cfba69eddd (svn r11910) -Fix: play 'ding-ding' crossing sound in more cases (except gameload and crossing construction)
smatz
parents: 8838
diff changeset
   389
						UpdateLevelCrossing(tile, false);
4140
c294db895325 (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
   390
					}
c294db895325 (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
   391
					break;
4139
e4acf9f12cb9 (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
   392
				}
1627
d88508d9ced0 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   393
			}
d88508d9ced0 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   394
3267
591027d10884 (svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents: 3265
diff changeset
   395
			if (IsLevelCrossing(tile) && GetCrossingRailBits(tile) == trackbit) {
1627
d88508d9ced0 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   396
				return_cmd_error(STR_1007_ALREADY_BUILT);
3267
591027d10884 (svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents: 3265
diff changeset
   397
			}
1627
d88508d9ced0 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   398
			/* FALLTHROUGH */
d88508d9ced0 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   399
d88508d9ced0 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   400
		default:
8910
b261b6cb9b21 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8909
diff changeset
   401
			/* Will there be flat water on the lower halftile? */
8909
fa15e9afad2f (svn r11983) -Codechange: Add some helper functions for slopes and use them.
frosch
parents: 8894
diff changeset
   402
			bool water_ground = IsTileType(tile, MP_WATER) && IsSlopeWithOneCornerRaised(tileh);
8267
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8266
diff changeset
   403
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   404
			ret = CheckRailSlope(tileh, trackbit, TRACK_BIT_NONE, tile);
1691
fcd9fefaed02 (svn r2195) Add CmdFailed() as the One True Way(tm) to check if a command failed.
tron
parents: 1669
diff changeset
   405
			if (CmdFailed(ret)) return ret;
7446
1c4d469f986e (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 7442
diff changeset
   406
			cost.AddCost(ret);
1627
d88508d9ced0 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   407
3491
4c8427796c64 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3486
diff changeset
   408
			ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
1691
fcd9fefaed02 (svn r2195) Add CmdFailed() as the One True Way(tm) to check if a command failed.
tron
parents: 1669
diff changeset
   409
			if (CmdFailed(ret)) return ret;
7446
1c4d469f986e (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 7442
diff changeset
   410
			cost.AddCost(ret);
1627
d88508d9ced0 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   411
8267
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8266
diff changeset
   412
			if (water_ground) {
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8266
diff changeset
   413
				cost.AddCost(-_price.clear_water);
8473
773b817b64d0 (svn r11533) -Codechange: Rename some unclear clear_x prices member names.
belugas
parents: 8444
diff changeset
   414
				cost.AddCost(_price.clear_roughland);
8267
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8266
diff changeset
   415
			}
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8266
diff changeset
   416
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8266
diff changeset
   417
			if (flags & DC_EXEC) {
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8266
diff changeset
   418
				MakeRailNormal(tile, _current_player, trackbit, railtype);
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8266
diff changeset
   419
				if (water_ground) SetRailGroundType(tile, RAIL_GROUND_WATER);
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8266
diff changeset
   420
			}
1627
d88508d9ced0 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   421
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   422
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   423
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   424
	if (flags & DC_EXEC) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   425
		MarkTileDirtyByTile(tile);
8802
e08824cdab46 (svn r11871) -Fix [FS#1074]: do not update signals after each tile when building/removing a large block of track/signals/station
smatz
parents: 8796
diff changeset
   426
		AddTrackToSignalBuffer(tile, track, _current_player);
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3884
diff changeset
   427
		YapfNotifyTrackLayoutChange(tile, track);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   428
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   429
8226
c66a40c8e9bf (svn r11265) -Feature: Make more advanced rail types more expensive to build.
maedhros
parents: 8199
diff changeset
   430
	return cost.AddCost(RailBuildCost(railtype));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   431
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   432
1775
08ff0f12ccdc (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
   433
/** Remove a single piece of track
3491
4c8427796c64 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3486
diff changeset
   434
 * @param tile tile to remove track from
6979
d194d25020e7 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6948
diff changeset
   435
 * @param flags operation to perform
1775
08ff0f12ccdc (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
   436
 * @param p1 unused
08ff0f12ccdc (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
   437
 * @param p2 rail orientation
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   438
 */
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7287
diff changeset
   439
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
   440
{
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   441
	Track track = (Track)p2;
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   442
	TrackBits trackbit;
8726
5ae45b46506b (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8724
diff changeset
   443
	CommandCost cost(EXPENSES_CONSTRUCTION, _price.remove_rail );
3284
fafe2ef7b809 (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
   444
	bool crossing = false;
1775
08ff0f12ccdc (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
   445
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   446
	if (!ValParamTrackOrientation((Track)p2)) return CMD_ERROR;
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   447
	trackbit = TrackToTrackBits(track);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   448
8814
5537156d6cc3 (svn r11883) -Fix (r11864): assert when trying to remove rail from a house or industry tile
smatz
parents: 8802
diff changeset
   449
	/* Need to read tile owner now because it may change when the rail is removed
5537156d6cc3 (svn r11883) -Fix (r11864): assert when trying to remove rail from a house or industry tile
smatz
parents: 8802
diff changeset
   450
	 * Also, in case of floods, _current_player != owner
5537156d6cc3 (svn r11883) -Fix (r11864): assert when trying to remove rail from a house or industry tile
smatz
parents: 8802
diff changeset
   451
	 * There may be invalid tiletype even in exec run (when removing long track),
5537156d6cc3 (svn r11883) -Fix (r11864): assert when trying to remove rail from a house or industry tile
smatz
parents: 8802
diff changeset
   452
	 * so do not call GetTileOwner(tile) in any case here */
5537156d6cc3 (svn r11883) -Fix (r11864): assert when trying to remove rail from a house or industry tile
smatz
parents: 8802
diff changeset
   453
	Owner owner = INVALID_OWNER;
8796
81b0d6b54a1f (svn r11864) -Codechange: pass owner whose signals we will update instead of complex detection later
smatz
parents: 8760
diff changeset
   454
3273
7303df652359 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents: 3271
diff changeset
   455
	switch (GetTileType(tile)) {
7866
e19fda04e8d3 (svn r10733) -Codechange: change MP_STREET into MP_ROAD as we use the word "road" everywhere except in the tile type.
rubidium
parents: 7831
diff changeset
   456
		case MP_ROAD: {
3273
7303df652359 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents: 3271
diff changeset
   457
			if (!IsLevelCrossing(tile) ||
7303df652359 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents: 3271
diff changeset
   458
					GetCrossingRailBits(tile) != trackbit ||
7303df652359 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents: 3271
diff changeset
   459
					(_current_player != OWNER_WATER && !CheckTileOwnership(tile)) ||
9015
4a44c6974ac1 (svn r12094) -Codechange: use DC_BANKRUPT command flag when removing player property to allow further fixes
smatz
parents: 8910
diff changeset
   460
					(!(flags & DC_BANKRUPT) && !EnsureNoVehicleOnGround(tile))) {
3273
7303df652359 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents: 3271
diff changeset
   461
				return CMD_ERROR;
7303df652359 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents: 3271
diff changeset
   462
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   463
3273
7303df652359 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents: 3271
diff changeset
   464
			if (flags & DC_EXEC) {
8814
5537156d6cc3 (svn r11883) -Fix (r11864): assert when trying to remove rail from a house or industry tile
smatz
parents: 8802
diff changeset
   465
				owner = GetTileOwner(tile);
7157
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 7087
diff changeset
   466
				MakeRoadNormal(tile, GetCrossingRoadBits(tile), GetRoadTypes(tile), GetTownIndex(tile), GetRoadOwner(tile, ROADTYPE_ROAD), GetRoadOwner(tile, ROADTYPE_TRAM), GetRoadOwner(tile, ROADTYPE_HWAY));
3273
7303df652359 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents: 3271
diff changeset
   467
			}
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   468
			break;
3071
a6acfe74e0a7 (svn r3660) Convert further road bits and type references to the functions/enums
tron
parents: 3069
diff changeset
   469
		}
2548
97ada3bd2702 (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2544
diff changeset
   470
3273
7303df652359 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents: 3271
diff changeset
   471
		case MP_RAILWAY: {
7303df652359 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents: 3271
diff changeset
   472
			TrackBits present;
7303df652359 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents: 3271
diff changeset
   473
7303df652359 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents: 3271
diff changeset
   474
			if (!IsPlainRailTile(tile) ||
7303df652359 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents: 3271
diff changeset
   475
					(_current_player != OWNER_WATER && !CheckTileOwnership(tile)) ||
7944
65c7c2e1bcb9 (svn r10922) -Codechange: Allow building and removing tracks and signals when there is a
maedhros
parents: 7885
diff changeset
   476
					!EnsureNoTrainOnTrack(tile, track)) {
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   477
				return CMD_ERROR;
3273
7303df652359 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents: 3271
diff changeset
   478
			}
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   479
3273
7303df652359 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents: 3271
diff changeset
   480
			present = GetTrackBits(tile);
7303df652359 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents: 3271
diff changeset
   481
			if ((present & trackbit) == 0) return CMD_ERROR;
3284
fafe2ef7b809 (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
   482
			if (present == (TRACK_BIT_X | TRACK_BIT_Y)) crossing = true;
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   483
1963
8a398139fb87 (svn r2469) - Add: When removing tracks with the 'remove' tool, have it automatically remove signals on the tracks.
hackykid
parents: 1954
diff changeset
   484
			/* Charge extra to remove signals on the track, if they are there */
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   485
			if (HasSignalOnTrack(tile, track))
7446
1c4d469f986e (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 7442
diff changeset
   486
				cost.AddCost(DoCommand(tile, track, 0, flags, CMD_REMOVE_SIGNALS));
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   487
3273
7303df652359 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents: 3271
diff changeset
   488
			if (flags & DC_EXEC) {
8814
5537156d6cc3 (svn r11883) -Fix (r11864): assert when trying to remove rail from a house or industry tile
smatz
parents: 8802
diff changeset
   489
				owner = GetTileOwner(tile);
3273
7303df652359 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents: 3271
diff changeset
   490
				present ^= trackbit;
7303df652359 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents: 3271
diff changeset
   491
				if (present == 0) {
8910
b261b6cb9b21 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8909
diff changeset
   492
					Slope tileh = GetTileSlope(tile, NULL);
b261b6cb9b21 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8909
diff changeset
   493
					/* If there is flat water on the lower halftile, convert the tile to shore so the water remains */
b261b6cb9b21 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8909
diff changeset
   494
					if (GetRailGroundType(tile) == RAIL_GROUND_WATER && IsSlopeWithOneCornerRaised(tileh)) {
8267
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8266
diff changeset
   495
						MakeShore(tile);
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8266
diff changeset
   496
					} else {
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8266
diff changeset
   497
						DoClearSquare(tile);
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8266
diff changeset
   498
					}
3273
7303df652359 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents: 3271
diff changeset
   499
				} else {
7303df652359 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents: 3271
diff changeset
   500
					SetTrackBits(tile, present);
7303df652359 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents: 3271
diff changeset
   501
				}
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   502
			}
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   503
			break;
3273
7303df652359 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents: 3271
diff changeset
   504
		}
2548
97ada3bd2702 (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2544
diff changeset
   505
3273
7303df652359 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents: 3271
diff changeset
   506
		default: return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   507
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   508
3273
7303df652359 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents: 3271
diff changeset
   509
	if (flags & DC_EXEC) {
8814
5537156d6cc3 (svn r11883) -Fix (r11864): assert when trying to remove rail from a house or industry tile
smatz
parents: 8802
diff changeset
   510
		/* if we got that far, 'owner' variable is set correctly */
5537156d6cc3 (svn r11883) -Fix (r11864): assert when trying to remove rail from a house or industry tile
smatz
parents: 8802
diff changeset
   511
		assert(IsValidPlayer(owner));
5537156d6cc3 (svn r11883) -Fix (r11864): assert when trying to remove rail from a house or industry tile
smatz
parents: 8802
diff changeset
   512
3273
7303df652359 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents: 3271
diff changeset
   513
		MarkTileDirtyByTile(tile);
3284
fafe2ef7b809 (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
   514
		if (crossing) {
fafe2ef7b809 (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
   515
			/* crossing is set when only TRACK_BIT_X and TRACK_BIT_Y are set. As we
fafe2ef7b809 (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
			 * are removing one of these pieces, we'll need to update signals for
fafe2ef7b809 (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
   517
			 * both directions explicitly, as after the track is removed it won't
fafe2ef7b809 (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
   518
			 * 'connect' with the other piece. */
8802
e08824cdab46 (svn r11871) -Fix [FS#1074]: do not update signals after each tile when building/removing a large block of track/signals/station
smatz
parents: 8796
diff changeset
   519
			AddTrackToSignalBuffer(tile, TRACK_X, owner);
e08824cdab46 (svn r11871) -Fix [FS#1074]: do not update signals after each tile when building/removing a large block of track/signals/station
smatz
parents: 8796
diff changeset
   520
			AddTrackToSignalBuffer(tile, TRACK_Y, owner);
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3884
diff changeset
   521
			YapfNotifyTrackLayoutChange(tile, TRACK_X);
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3884
diff changeset
   522
			YapfNotifyTrackLayoutChange(tile, TRACK_Y);
3284
fafe2ef7b809 (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
   523
		} else {
8802
e08824cdab46 (svn r11871) -Fix [FS#1074]: do not update signals after each tile when building/removing a large block of track/signals/station
smatz
parents: 8796
diff changeset
   524
			AddTrackToSignalBuffer(tile, track, owner);
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3884
diff changeset
   525
			YapfNotifyTrackLayoutChange(tile, track);
3284
fafe2ef7b809 (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
   526
		}
3273
7303df652359 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents: 3271
diff changeset
   527
	}
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   528
1963
8a398139fb87 (svn r2469) - Add: When removing tracks with the 'remove' tool, have it automatically remove signals on the tracks.
hackykid
parents: 1954
diff changeset
   529
	return cost;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   530
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   531
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   532
8267
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8266
diff changeset
   533
/**
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8266
diff changeset
   534
 * Called from water_cmd if a non-flat rail-tile gets flooded and should be converted to shore.
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8266
diff changeset
   535
 * The function floods the lower halftile, if the tile has a halftile foundation.
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8266
diff changeset
   536
 *
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8266
diff changeset
   537
 * @param t The tile to flood.
8828
3caed7db62de (svn r11898) -Fix: Update neighboured canals + signals when flooding non-flat tiles, too.
frosch
parents: 8814
diff changeset
   538
 * @return true if something was flooded.
8267
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8266
diff changeset
   539
 */
8828
3caed7db62de (svn r11898) -Fix: Update neighboured canals + signals when flooding non-flat tiles, too.
frosch
parents: 8814
diff changeset
   540
bool FloodHalftile(TileIndex t)
8267
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8266
diff changeset
   541
{
8828
3caed7db62de (svn r11898) -Fix: Update neighboured canals + signals when flooding non-flat tiles, too.
frosch
parents: 8814
diff changeset
   542
	bool flooded = false;
3caed7db62de (svn r11898) -Fix: Update neighboured canals + signals when flooding non-flat tiles, too.
frosch
parents: 8814
diff changeset
   543
	if (GetRailGroundType(t) == RAIL_GROUND_WATER) return flooded;
8267
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8266
diff changeset
   544
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8266
diff changeset
   545
	Slope tileh = GetTileSlope(t, NULL);
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8266
diff changeset
   546
	TrackBits rail_bits = GetTrackBits(t);
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8266
diff changeset
   547
8909
fa15e9afad2f (svn r11983) -Codechange: Add some helper functions for slopes and use them.
frosch
parents: 8894
diff changeset
   548
	if (IsSlopeWithOneCornerRaised(tileh)) {
8267
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8266
diff changeset
   549
		TrackBits lower_track = CornerToTrackBits(OppositeCorner(GetHighestSlopeCorner(tileh)));
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8266
diff changeset
   550
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8266
diff changeset
   551
		TrackBits to_remove = lower_track & rail_bits;
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8266
diff changeset
   552
		if (to_remove != 0) {
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8266
diff changeset
   553
			_current_player = OWNER_WATER;
8828
3caed7db62de (svn r11898) -Fix: Update neighboured canals + signals when flooding non-flat tiles, too.
frosch
parents: 8814
diff changeset
   554
			if (CmdFailed(DoCommand(t, 0, FIND_FIRST_BIT(to_remove), DC_EXEC, CMD_REMOVE_SINGLE_RAIL))) return flooded; // not yet floodable
3caed7db62de (svn r11898) -Fix: Update neighboured canals + signals when flooding non-flat tiles, too.
frosch
parents: 8814
diff changeset
   555
			flooded = true;
8267
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8266
diff changeset
   556
			rail_bits = rail_bits & ~to_remove;
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8266
diff changeset
   557
			if (rail_bits == 0) {
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8266
diff changeset
   558
				MakeShore(t);
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8266
diff changeset
   559
				MarkTileDirtyByTile(t);
8828
3caed7db62de (svn r11898) -Fix: Update neighboured canals + signals when flooding non-flat tiles, too.
frosch
parents: 8814
diff changeset
   560
				return flooded;
8267
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8266
diff changeset
   561
			}
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8266
diff changeset
   562
		}
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8266
diff changeset
   563
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8266
diff changeset
   564
		if (IsNonContinuousFoundation(GetRailFoundation(tileh, rail_bits))) {
8828
3caed7db62de (svn r11898) -Fix: Update neighboured canals + signals when flooding non-flat tiles, too.
frosch
parents: 8814
diff changeset
   565
			flooded = true;
8267
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8266
diff changeset
   566
			SetRailGroundType(t, RAIL_GROUND_WATER);
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8266
diff changeset
   567
			MarkTileDirtyByTile(t);
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8266
diff changeset
   568
		}
8910
b261b6cb9b21 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8909
diff changeset
   569
	} else {
b261b6cb9b21 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8909
diff changeset
   570
		/* Make shore on steep slopes and 'three-corners-raised'-slopes. */
b261b6cb9b21 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8909
diff changeset
   571
		if (ApplyFoundationToSlope(GetRailFoundation(tileh, rail_bits), &tileh) == 0) {
b261b6cb9b21 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8909
diff changeset
   572
			if (IsSteepSlope(tileh) || IsSlopeWithThreeCornersRaised(tileh)) {
b261b6cb9b21 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8909
diff changeset
   573
				flooded = true;
b261b6cb9b21 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8909
diff changeset
   574
				SetRailGroundType(t, RAIL_GROUND_WATER);
b261b6cb9b21 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8909
diff changeset
   575
				MarkTileDirtyByTile(t);
b261b6cb9b21 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8909
diff changeset
   576
			}
b261b6cb9b21 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8909
diff changeset
   577
		}
8267
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8266
diff changeset
   578
	}
8828
3caed7db62de (svn r11898) -Fix: Update neighboured canals + signals when flooding non-flat tiles, too.
frosch
parents: 8814
diff changeset
   579
	return flooded;
8267
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8266
diff changeset
   580
}
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8266
diff changeset
   581
3493
4d5830846ec2 (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   582
static const TileIndexDiffC _trackdelta[] = {
4d5830846ec2 (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   583
	{ -1,  0 }, {  0,  1 }, { -1,  0 }, {  0,  1 }, {  1,  0 }, {  0,  1 },
4d5830846ec2 (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   584
	{  0,  0 },
4d5830846ec2 (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   585
	{  0,  0 },
4d5830846ec2 (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   586
	{  1,  0 }, {  0, -1 }, {  0, -1 }, {  1,  0 }, {  0, -1 }, { -1,  0 },
4d5830846ec2 (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   587
	{  0,  0 },
4d5830846ec2 (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   588
	{  0,  0 }
4d5830846ec2 (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   589
};
4d5830846ec2 (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   590
4d5830846ec2 (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   591
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7287
diff changeset
   592
static CommandCost ValidateAutoDrag(Trackdir *trackdir, TileIndex start, TileIndex end)
1227
3552f20fcfcb (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
   593
{
3493
4d5830846ec2 (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   594
	int x = TileX(start);
4d5830846ec2 (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   595
	int y = TileY(start);
4d5830846ec2 (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   596
	int ex = TileX(end);
4d5830846ec2 (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   597
	int ey = TileY(end);
1227
3552f20fcfcb (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
   598
	int dx, dy, trdx, trdy;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   599
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   600
	if (!ValParamTrackOrientation(TrackdirToTrack(*trackdir))) return CMD_ERROR;
1227
3552f20fcfcb (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
   601
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6902
diff changeset
   602
	/* calculate delta x,y from start to end tile */
1227
3552f20fcfcb (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
   603
	dx = ex - x;
3552f20fcfcb (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
   604
	dy = ey - y;
3552f20fcfcb (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
   605
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6902
diff changeset
   606
	/* calculate delta x,y for the first direction */
3493
4d5830846ec2 (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   607
	trdx = _trackdelta[*trackdir].x;
4d5830846ec2 (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   608
	trdy = _trackdelta[*trackdir].y;
1227
3552f20fcfcb (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
   609
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   610
	if (!IsDiagonalTrackdir(*trackdir)) {
3493
4d5830846ec2 (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   611
		trdx += _trackdelta[*trackdir ^ 1].x;
4d5830846ec2 (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   612
		trdy += _trackdelta[*trackdir ^ 1].y;
1227
3552f20fcfcb (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
   613
	}
3552f20fcfcb (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
   614
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6902
diff changeset
   615
	/* validate the direction */
2951
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2934
diff changeset
   616
	while (
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2934
diff changeset
   617
		(trdx <= 0 && dx > 0) ||
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2934
diff changeset
   618
		(trdx >= 0 && dx < 0) ||
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2934
diff changeset
   619
		(trdy <= 0 && dy > 0) ||
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2934
diff changeset
   620
		(trdy >= 0 && dy < 0)
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2934
diff changeset
   621
	) {
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8378
diff changeset
   622
		if (!HasBit(*trackdir, 3)) { // first direction is invalid, try the other
8427
143b0be22af1 (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents: 8425
diff changeset
   623
			SetBit(*trackdir, 3); // reverse the direction
1227
3552f20fcfcb (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
   624
			trdx = -trdx;
3552f20fcfcb (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
   625
			trdy = -trdy;
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4067
diff changeset
   626
		} else { // other direction is invalid too, invalid drag
1227
3552f20fcfcb (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
   627
			return CMD_ERROR;
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4067
diff changeset
   628
		}
1227
3552f20fcfcb (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
   629
	}
3552f20fcfcb (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
   630
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6902
diff changeset
   631
	/* (for diagonal tracks, this is already made sure of by above test), but:
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6902
diff changeset
   632
	 * for non-diagonal tracks, check if the start and end tile are on 1 line */
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   633
	if (!IsDiagonalTrackdir(*trackdir)) {
3493
4d5830846ec2 (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   634
		trdx = _trackdelta[*trackdir].x;
4d5830846ec2 (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   635
		trdy = _trackdelta[*trackdir].y;
2951
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2934
diff changeset
   636
		if (abs(dx) != abs(dy) && abs(dx) + abs(trdy) != abs(dy) + abs(trdx))
1227
3552f20fcfcb (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
   637
			return CMD_ERROR;
3552f20fcfcb (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
   638
	}
3552f20fcfcb (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
7446
1c4d469f986e (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 7442
diff changeset
   640
	return CommandCost();
1227
3552f20fcfcb (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
   641
}
3552f20fcfcb (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
1775
08ff0f12ccdc (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
   643
/** Build a stretch of railroad tracks.
3491
4c8427796c64 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3486
diff changeset
   644
 * @param tile start tile of drag
6979
d194d25020e7 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6948
diff changeset
   645
 * @param flags operation to perform
1775
08ff0f12ccdc (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
   646
 * @param p1 end tile of drag
08ff0f12ccdc (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
   647
 * @param p2 various bitstuffed elements
08ff0f12ccdc (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
   648
 * - p2 = (bit 0-3) - railroad type normal/maglev (0 = normal, 1 = mono, 2 = maglev)
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   649
 * - p2 = (bit 4-6) - track-orientation, valid values: 0-5 (Track enum)
1775
08ff0f12ccdc (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
   650
 * - p2 = (bit 7)   - 0 = build, 1 = remove tracks
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   651
 */
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7287
diff changeset
   652
static CommandCost CmdRailTrackHelper(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
1227
3552f20fcfcb (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
   653
{
8726
5ae45b46506b (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8724
diff changeset
   654
	CommandCost ret, total_cost(EXPENSES_CONSTRUCTION);
2140
d708eb80ab8b (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
   655
	Track track = (Track)GB(p2, 4, 3);
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   656
	Trackdir trackdir;
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8378
diff changeset
   657
	byte mode = HasBit(p2, 7);
2604
901508f52c3d (svn r3141) Replace incorrect railtype bitmask in CmdRailTrackHelper with appropriate GB()
peter1138
parents: 2549
diff changeset
   658
	RailType railtype = (RailType)GB(p2, 0, 4);
3493
4d5830846ec2 (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   659
	TileIndex end_tile;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   660
2604
901508f52c3d (svn r3141) Replace incorrect railtype bitmask in CmdRailTrackHelper with appropriate GB()
peter1138
parents: 2549
diff changeset
   661
	if (!ValParamRailtype(railtype) || !ValParamTrackOrientation(track)) return CMD_ERROR;
2934
3b7eef9871f8 (svn r3490) -Fix: A bunch (10) of off-by-one errors when checking if a TileIndex points to a tile on the map
tron
parents: 2916
diff changeset
   662
	if (p1 >= MapSize()) return CMD_ERROR;
3493
4d5830846ec2 (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   663
	end_tile = p1;
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   664
	trackdir = TrackToTrackdir(track);
1775
08ff0f12ccdc (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
   665
3493
4d5830846ec2 (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   666
	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
   667
3493
4d5830846ec2 (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   668
	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
   669
2952
6a26eeda9679 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2951
diff changeset
   670
	for (;;) {
3493
4d5830846ec2 (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   671
		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
   672
1775
08ff0f12ccdc (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
   673
		if (CmdFailed(ret)) {
3671
6d3a34989d05 (svn r4586) - Codechange: Recursive commands that rely on _error_message to handle success/failure can fail if a recursive call fails but doesn't set the error message, thus resulting in an old, possibly erroneous being used (see FS#130 prior to r4585). Now properly reset the global variable _error_message in these cases.
Darkvater
parents: 3657
diff changeset
   674
			if ((_error_message != STR_1007_ALREADY_BUILT) && (mode == 0)) break;
6d3a34989d05 (svn r4586) - Codechange: Recursive commands that rely on _error_message to handle success/failure can fail if a recursive call fails but doesn't set the error message, thus resulting in an old, possibly erroneous being used (see FS#130 prior to r4585). Now properly reset the global variable _error_message in these cases.
Darkvater
parents: 3657
diff changeset
   675
			_error_message = INVALID_STRING_ID;
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4067
diff changeset
   676
		} else {
7446
1c4d469f986e (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 7442
diff changeset
   677
			total_cost.AddCost(ret);
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4067
diff changeset
   678
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   679
3493
4d5830846ec2 (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   680
		if (tile == end_tile) break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   681
3493
4d5830846ec2 (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   682
		tile += ToTileIndexDiff(_trackdelta[trackdir]);
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   683
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6902
diff changeset
   684
		/* toggle railbit for the non-diagonal tracks */
8428
f8300c908bd9 (svn r11485) -Codechange: Remove the doubled function ToggleBitT and rename the remaining to fit with the naming style
skidd13
parents: 8427
diff changeset
   685
		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
   686
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   687
7446
1c4d469f986e (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 7442
diff changeset
   688
	return (total_cost.GetCost() == 0) ? CMD_ERROR : total_cost;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   689
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   690
1796
cae31916ae54 (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
   691
/** Build rail on a stretch of track.
cae31916ae54 (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
   692
 * Stub for the unified rail builder/remover
6979
d194d25020e7 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6948
diff changeset
   693
 * @param tile start tile of drag
d194d25020e7 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6948
diff changeset
   694
 * @param flags operation to perform
d194d25020e7 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6948
diff changeset
   695
 * @param p1 end tile of drag
d194d25020e7 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6948
diff changeset
   696
 * @param p2 various bitstuffed elements
d194d25020e7 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6948
diff changeset
   697
 * - p2 = (bit 0-3) - railroad type normal/maglev (0 = normal, 1 = mono, 2 = maglev)
d194d25020e7 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6948
diff changeset
   698
 * - p2 = (bit 4-6) - track-orientation, valid values: 0-5 (Track enum)
d194d25020e7 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6948
diff changeset
   699
 * - p2 = (bit 7)   - 0 = build, 1 = remove tracks
1796
cae31916ae54 (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
   700
 * @see CmdRailTrackHelper
cae31916ae54 (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
   701
 */
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7287
diff changeset
   702
CommandCost CmdBuildRailroadTrack(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
1227
3552f20fcfcb (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
   703
{
8425
72a71d480c5f (svn r11482) -Codechange: Remove the doubled function ClrBitT and rename the remaining to fit with the naming style
skidd13
parents: 8424
diff changeset
   704
	return CmdRailTrackHelper(tile, flags, p1, ClrBit(p2, 7));
1227
3552f20fcfcb (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
   705
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   706
1796
cae31916ae54 (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
   707
/** Build rail on a stretch of track.
cae31916ae54 (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
   708
 * Stub for the unified rail builder/remover
6979
d194d25020e7 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6948
diff changeset
   709
 * @param tile start tile of drag
d194d25020e7 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6948
diff changeset
   710
 * @param flags operation to perform
d194d25020e7 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6948
diff changeset
   711
 * @param p1 end tile of drag
d194d25020e7 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6948
diff changeset
   712
 * @param p2 various bitstuffed elements
d194d25020e7 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6948
diff changeset
   713
 * - p2 = (bit 0-3) - railroad type normal/maglev (0 = normal, 1 = mono, 2 = maglev)
d194d25020e7 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6948
diff changeset
   714
 * - p2 = (bit 4-6) - track-orientation, valid values: 0-5 (Track enum)
d194d25020e7 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6948
diff changeset
   715
 * - p2 = (bit 7)   - 0 = build, 1 = remove tracks
1796
cae31916ae54 (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
   716
 * @see CmdRailTrackHelper
cae31916ae54 (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
   717
 */
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7287
diff changeset
   718
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
   719
{
8427
143b0be22af1 (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents: 8425
diff changeset
   720
	return CmdRailTrackHelper(tile, flags, p1, SetBit(p2, 7));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   721
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   722
1775
08ff0f12ccdc (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
   723
/** Build a train depot
3491
4c8427796c64 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3486
diff changeset
   724
 * @param tile position of the train depot
6979
d194d25020e7 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6948
diff changeset
   725
 * @param flags operation to perform
1775
08ff0f12ccdc (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
   726
 * @param p1 rail type
6460
b3017e083031 (svn r8876) -Fix
tron
parents: 6459
diff changeset
   727
 * @param p2 bit 0..1 entrance direction (DiagDirection)
2085
ae9e92ffe168 (svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents: 2049
diff changeset
   728
 *
ae9e92ffe168 (svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents: 2049
diff changeset
   729
 * @todo When checking for the tile slope,
ae9e92ffe168 (svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents: 2049
diff changeset
   730
 * 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
   731
 */
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7287
diff changeset
   732
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
   733
{
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3575
diff changeset
   734
	Slope tileh;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   735
1775
08ff0f12ccdc (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
   736
	/* check railtype and valid direction for depot (0 through 3), 4 in total */
8732
b18f578f7c16 (svn r11800) -Codechange: move some functions to a more logical location + some type safety.
rubidium
parents: 8726
diff changeset
   737
	if (!ValParamRailtype((RailType)p1)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   738
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   739
	tileh = GetTileSlope(tile, NULL);
2085
ae9e92ffe168 (svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents: 2049
diff changeset
   740
6460
b3017e083031 (svn r8876) -Fix
tron
parents: 6459
diff changeset
   741
	DiagDirection dir = Extract<DiagDirection, 0>(p2);
b3017e083031 (svn r8876) -Fix
tron
parents: 6459
diff changeset
   742
2085
ae9e92ffe168 (svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents: 2049
diff changeset
   743
	/* Prohibit construction if
4549
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4483
diff changeset
   744
	 * The tile is non-flat AND
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4483
diff changeset
   745
	 * 1) The AI is "old-school"
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4483
diff changeset
   746
	 * 2) build-on-slopes is disabled
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4483
diff changeset
   747
	 * 3) the tile is steep i.e. spans two height levels
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4483
diff changeset
   748
	 * 4) the exit points in the wrong direction
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4483
diff changeset
   749
	 */
2085
ae9e92ffe168 (svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents: 2049
diff changeset
   750
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3575
diff changeset
   751
	if (tileh != SLOPE_FLAT && (
2548
97ada3bd2702 (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2544
diff changeset
   752
				_is_old_ai_player ||
97ada3bd2702 (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2544
diff changeset
   753
				!_patches.build_on_slopes ||
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3575
diff changeset
   754
				IsSteepSlope(tileh) ||
6460
b3017e083031 (svn r8876) -Fix
tron
parents: 6459
diff changeset
   755
				!CanBuildDepotByTileh(dir, tileh)
2548
97ada3bd2702 (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2544
diff changeset
   756
			)) {
97ada3bd2702 (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2544
diff changeset
   757
		return_cmd_error(STR_0007_FLAT_LAND_REQUIRED);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   758
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   759
8726
5ae45b46506b (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8724
diff changeset
   760
	CommandCost cost = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
7446
1c4d469f986e (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 7442
diff changeset
   761
	if (CmdFailed(cost)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   762
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5568
diff changeset
   763
	if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST);
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5568
diff changeset
   764
10323
57d8fd25473e (svn r12864) [0.6] -Backport from trunk r12859, r12857, r12855, r12845, r12844:
rubidium
parents: 9208
diff changeset
   765
	if (!Depot::CanAllocateItem()) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   766
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   767
	if (flags & DC_EXEC) {
10323
57d8fd25473e (svn r12864) [0.6] -Backport from trunk r12859, r12857, r12855, r12845, r12844:
rubidium
parents: 9208
diff changeset
   768
		Depot *d = new Depot(tile);
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   769
		MakeRailDepot(tile, _current_player, dir, (RailType)p1);
3101
e2fdb8802c2f (svn r3696) Add functions to turn a tile into a normal rail tile/depot/waypoint. This is just a tiny step, the rail code needs way more love and caring
tron
parents: 3099
diff changeset
   770
		MarkTileDirtyByTile(tile);
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   771
1775
08ff0f12ccdc (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
   772
		d->town_index = ClosestTownFromTile(tile, (uint)-1)->index;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   773
8802
e08824cdab46 (svn r11871) -Fix [FS#1074]: do not update signals after each tile when building/removing a large block of track/signals/station
smatz
parents: 8796
diff changeset
   774
		AddSideToSignalBuffer(tile, INVALID_DIAGDIR, _current_player);
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   775
		YapfNotifyTrackLayoutChange(tile, TrackdirToTrack(DiagdirToDiagTrackdir(dir)));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   776
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   777
7446
1c4d469f986e (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 7442
diff changeset
   778
	return cost.AddCost(_price.build_train_depot);
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
1775
08ff0f12ccdc (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
   781
/** Build signals, alternate between double/single, signal/semaphore,
5982
54218ea5af1e (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: 5919
diff changeset
   782
 * pre/exit/combo-signals, and what-else not. If the rail piece does not
54218ea5af1e (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: 5919
diff changeset
   783
 * have any signals, bit 4 (cycle signal-type) is ignored
3491
4c8427796c64 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3486
diff changeset
   784
 * @param tile tile where to build the signals
6979
d194d25020e7 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6948
diff changeset
   785
 * @param flags operation to perform
1775
08ff0f12ccdc (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
   786
 * @param p1 various bitstuffed elements
5986
1b9ab9629d36 (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: 5982
diff changeset
   787
 * - p1 = (bit 0-2) - track-orientation, valid values: 0-5 (Track enum)
8487
bab0d066128b (svn r11547) -Add: signal selection GUI for the ones that really like to use that over CTRL. Patch by BigBB.
rubidium
parents: 8473
diff changeset
   788
 * - p1 = (bit 3)   - 1 = override signal/semaphore, or pre/exit/combo signal or (for bit 7) toggle variant (CTRL-toggle)
5986
1b9ab9629d36 (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: 5982
diff changeset
   789
 * - p1 = (bit 4)   - 0 = signals, 1 = semaphores
8487
bab0d066128b (svn r11547) -Add: signal selection GUI for the ones that really like to use that over CTRL. Patch by BigBB.
rubidium
parents: 8473
diff changeset
   790
 * - p1 = (bit 5-6) - type of the signal, for valid values see enum SignalType in rail_map.h
bab0d066128b (svn r11547) -Add: signal selection GUI for the ones that really like to use that over CTRL. Patch by BigBB.
rubidium
parents: 8473
diff changeset
   791
 * - p1 = (bit 7)   - convert the present signal type and variant
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   792
 * @param p2 used for CmdBuildManySignals() to copy direction of first signal
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   793
 * 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
   794
 */
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7287
diff changeset
   795
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
   796
{
5986
1b9ab9629d36 (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: 5982
diff changeset
   797
	Track track = (Track)GB(p1, 0, 3);
8487
bab0d066128b (svn r11547) -Add: signal selection GUI for the ones that really like to use that over CTRL. Patch by BigBB.
rubidium
parents: 8473
diff changeset
   798
	bool ctrl_pressed = HasBit(p1, 3); // was the CTRL button pressed
bab0d066128b (svn r11547) -Add: signal selection GUI for the ones that really like to use that over CTRL. Patch by BigBB.
rubidium
parents: 8473
diff changeset
   799
	SignalVariant sigvar = (ctrl_pressed ^ HasBit(p1, 4)) ? SIG_SEMAPHORE : SIG_ELECTRIC; // the signal variant of the new signal
bab0d066128b (svn r11547) -Add: signal selection GUI for the ones that really like to use that over CTRL. Patch by BigBB.
rubidium
parents: 8473
diff changeset
   800
	SignalType sigtype = (SignalType)GB(p1, 5, 2); // the signal type of the new signal
bab0d066128b (svn r11547) -Add: signal selection GUI for the ones that really like to use that over CTRL. Patch by BigBB.
rubidium
parents: 8473
diff changeset
   801
	bool convert_signal = HasBit(p1, 7); // convert button pressed
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7287
diff changeset
   802
	CommandCost cost;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   803
7944
65c7c2e1bcb9 (svn r10922) -Codechange: Allow building and removing tracks and signals when there is a
maedhros
parents: 7885
diff changeset
   804
	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
   805
		return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   806
1775
08ff0f12ccdc (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
   807
	/* Protect against invalid signal copying */
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   808
	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
   809
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   810
	/* You can only build signals on plain rail tiles, and the selected track must exist */
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   811
	if (!IsPlainRailTile(tile) || !HasTrack(tile, track)) return CMD_ERROR;
1084
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   812
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   813
	if (!CheckTileOwnership(tile)) return CMD_ERROR;
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   814
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   815
	{
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4067
diff changeset
   816
		/* See if this is a valid track combination for signals, (ie, no overlap) */
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4067
diff changeset
   817
		TrackBits trackbits = GetTrackBits(tile);
8329
77e50bd6ad67 (svn r11383) -Codechange: fixed all the mess around KillFirstBit (tnx to Rubidium and skidd13)
truelight
parents: 8289
diff changeset
   818
		if (KillFirstBit(trackbits) != TRACK_BIT_NONE && /* More than one track present */
3258
94a915e7485f (svn r3946) Add short hand names for common track combinations
tron
parents: 3254
diff changeset
   819
				trackbits != TRACK_BIT_HORZ &&
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4067
diff changeset
   820
				trackbits != TRACK_BIT_VERT) {
8487
bab0d066128b (svn r11547) -Add: signal selection GUI for the ones that really like to use that over CTRL. Patch by BigBB.
rubidium
parents: 8473
diff changeset
   821
			return_cmd_error(STR_1005_NO_SUITABLE_RAILROAD_TRACK);
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4067
diff changeset
   822
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   823
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   824
8487
bab0d066128b (svn r11547) -Add: signal selection GUI for the ones that really like to use that over CTRL. Patch by BigBB.
rubidium
parents: 8473
diff changeset
   825
	/* you can not convert a signal if no signal is on track */
bab0d066128b (svn r11547) -Add: signal selection GUI for the ones that really like to use that over CTRL. Patch by BigBB.
rubidium
parents: 8473
diff changeset
   826
	if (convert_signal && !HasSignalOnTrack(tile, track)) return CMD_ERROR;
bab0d066128b (svn r11547) -Add: signal selection GUI for the ones that really like to use that over CTRL. Patch by BigBB.
rubidium
parents: 8473
diff changeset
   827
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   828
	if (!HasSignalOnTrack(tile, track)) {
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6902
diff changeset
   829
		/* build new signals */
8726
5ae45b46506b (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8724
diff changeset
   830
		cost = CommandCost(EXPENSES_CONSTRUCTION, _price.build_signals);
1066
aad3c6ad147f (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
   831
	} else {
7266
4b75e7b9fa91 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 7249
diff changeset
   832
		if (p2 != 0 && sigvar != GetSignalVariant(tile, track)) {
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6902
diff changeset
   833
			/* convert signals <-> semaphores */
8726
5ae45b46506b (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8724
diff changeset
   834
			cost = CommandCost(EXPENSES_CONSTRUCTION, _price.build_signals + _price.remove_signals);
8487
bab0d066128b (svn r11547) -Add: signal selection GUI for the ones that really like to use that over CTRL. Patch by BigBB.
rubidium
parents: 8473
diff changeset
   835
bab0d066128b (svn r11547) -Add: signal selection GUI for the ones that really like to use that over CTRL. Patch by BigBB.
rubidium
parents: 8473
diff changeset
   836
		} else if (convert_signal) {
bab0d066128b (svn r11547) -Add: signal selection GUI for the ones that really like to use that over CTRL. Patch by BigBB.
rubidium
parents: 8473
diff changeset
   837
			/* convert button pressed */
bab0d066128b (svn r11547) -Add: signal selection GUI for the ones that really like to use that over CTRL. Patch by BigBB.
rubidium
parents: 8473
diff changeset
   838
			if (ctrl_pressed || GetSignalVariant(tile, track) != sigvar) {
bab0d066128b (svn r11547) -Add: signal selection GUI for the ones that really like to use that over CTRL. Patch by BigBB.
rubidium
parents: 8473
diff changeset
   839
				/* convert electric <-> semaphore */
8726
5ae45b46506b (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8724
diff changeset
   840
				cost = CommandCost(EXPENSES_CONSTRUCTION, _price.build_signals + _price.remove_signals);
8487
bab0d066128b (svn r11547) -Add: signal selection GUI for the ones that really like to use that over CTRL. Patch by BigBB.
rubidium
parents: 8473
diff changeset
   841
			} else {
bab0d066128b (svn r11547) -Add: signal selection GUI for the ones that really like to use that over CTRL. Patch by BigBB.
rubidium
parents: 8473
diff changeset
   842
				/* it is free to change signal type: normal-pre-exit-combo */
bab0d066128b (svn r11547) -Add: signal selection GUI for the ones that really like to use that over CTRL. Patch by BigBB.
rubidium
parents: 8473
diff changeset
   843
				cost = CommandCost();
bab0d066128b (svn r11547) -Add: signal selection GUI for the ones that really like to use that over CTRL. Patch by BigBB.
rubidium
parents: 8473
diff changeset
   844
			}
bab0d066128b (svn r11547) -Add: signal selection GUI for the ones that really like to use that over CTRL. Patch by BigBB.
rubidium
parents: 8473
diff changeset
   845
1084
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   846
		} else {
6928
44797333bcbf (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6923
diff changeset
   847
			/* it is free to change orientation/pre-exit-combo signals */
7446
1c4d469f986e (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 7442
diff changeset
   848
			cost = CommandCost();
1084
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   849
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   850
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   851
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   852
	if (flags & DC_EXEC) {
4182
20d711816338 (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
   853
		if (!HasSignals(tile)) {
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6902
diff changeset
   854
			/* there are no signals at all on this tile yet */
6498
aff910a05c6e (svn r8935) -Codechange: unification of track type between road and rail tiles, unification of ground type between normal rail tiles and depots/waypoints and removing the need for RailTileSubType.
rubidium
parents: 6486
diff changeset
   855
			SetHasSignals(tile, true);
7249
3e6c9df9794d (svn r9988) -Codechange: remove the last direct map accesses, except the ones needed for the savegame saving/loading mechanisms.
rubidium
parents: 7224
diff changeset
   856
			SetSignalStates(tile, 0xF); // all signals are on
3e6c9df9794d (svn r9988) -Codechange: remove the last direct map accesses, except the ones needed for the savegame saving/loading mechanisms.
rubidium
parents: 7224
diff changeset
   857
			SetPresentSignals(tile, 0); // no signals built by default
8487
bab0d066128b (svn r11547) -Add: signal selection GUI for the ones that really like to use that over CTRL. Patch by BigBB.
rubidium
parents: 8473
diff changeset
   858
			SetSignalType(tile, track, sigtype);
7266
4b75e7b9fa91 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 7249
diff changeset
   859
			SetSignalVariant(tile, track, sigvar);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   860
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   861
1084
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   862
		if (p2 == 0) {
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   863
			if (!HasSignalOnTrack(tile, track)) {
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6902
diff changeset
   864
				/* build new signals */
7249
3e6c9df9794d (svn r9988) -Codechange: remove the last direct map accesses, except the ones needed for the savegame saving/loading mechanisms.
rubidium
parents: 7224
diff changeset
   865
				SetPresentSignals(tile, GetPresentSignals(tile) | SignalOnTrack(track));
8487
bab0d066128b (svn r11547) -Add: signal selection GUI for the ones that really like to use that over CTRL. Patch by BigBB.
rubidium
parents: 8473
diff changeset
   866
				SetSignalType(tile, track, sigtype);
7266
4b75e7b9fa91 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 7249
diff changeset
   867
				SetSignalVariant(tile, track, sigvar);
1084
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   868
			} else {
8487
bab0d066128b (svn r11547) -Add: signal selection GUI for the ones that really like to use that over CTRL. Patch by BigBB.
rubidium
parents: 8473
diff changeset
   869
				if (convert_signal) {
bab0d066128b (svn r11547) -Add: signal selection GUI for the ones that really like to use that over CTRL. Patch by BigBB.
rubidium
parents: 8473
diff changeset
   870
					/* convert signal button pressed */
bab0d066128b (svn r11547) -Add: signal selection GUI for the ones that really like to use that over CTRL. Patch by BigBB.
rubidium
parents: 8473
diff changeset
   871
					if (ctrl_pressed) {
bab0d066128b (svn r11547) -Add: signal selection GUI for the ones that really like to use that over CTRL. Patch by BigBB.
rubidium
parents: 8473
diff changeset
   872
						/* toggle the pressent signal variant: SIG_ELECTRIC <-> SIG_SEMAPHORE */
bab0d066128b (svn r11547) -Add: signal selection GUI for the ones that really like to use that over CTRL. Patch by BigBB.
rubidium
parents: 8473
diff changeset
   873
						SetSignalVariant(tile, track, (GetSignalVariant(tile, track) == SIG_ELECTRIC) ? SIG_SEMAPHORE : SIG_ELECTRIC);
bab0d066128b (svn r11547) -Add: signal selection GUI for the ones that really like to use that over CTRL. Patch by BigBB.
rubidium
parents: 8473
diff changeset
   874
bab0d066128b (svn r11547) -Add: signal selection GUI for the ones that really like to use that over CTRL. Patch by BigBB.
rubidium
parents: 8473
diff changeset
   875
					} else {
bab0d066128b (svn r11547) -Add: signal selection GUI for the ones that really like to use that over CTRL. Patch by BigBB.
rubidium
parents: 8473
diff changeset
   876
						/* convert the present signal to the chosen type and variant */
bab0d066128b (svn r11547) -Add: signal selection GUI for the ones that really like to use that over CTRL. Patch by BigBB.
rubidium
parents: 8473
diff changeset
   877
						SetSignalType(tile, track, sigtype);
bab0d066128b (svn r11547) -Add: signal selection GUI for the ones that really like to use that over CTRL. Patch by BigBB.
rubidium
parents: 8473
diff changeset
   878
						SetSignalVariant(tile, track, sigvar);
bab0d066128b (svn r11547) -Add: signal selection GUI for the ones that really like to use that over CTRL. Patch by BigBB.
rubidium
parents: 8473
diff changeset
   879
					}
bab0d066128b (svn r11547) -Add: signal selection GUI for the ones that really like to use that over CTRL. Patch by BigBB.
rubidium
parents: 8473
diff changeset
   880
bab0d066128b (svn r11547) -Add: signal selection GUI for the ones that really like to use that over CTRL. Patch by BigBB.
rubidium
parents: 8473
diff changeset
   881
				} else if (ctrl_pressed) {
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6902
diff changeset
   882
					/* cycle between normal -> pre -> exit -> combo -> ... */
8487
bab0d066128b (svn r11547) -Add: signal selection GUI for the ones that really like to use that over CTRL. Patch by BigBB.
rubidium
parents: 8473
diff changeset
   883
					sigtype = GetSignalType(tile, track);
bab0d066128b (svn r11547) -Add: signal selection GUI for the ones that really like to use that over CTRL. Patch by BigBB.
rubidium
parents: 8473
diff changeset
   884
bab0d066128b (svn r11547) -Add: signal selection GUI for the ones that really like to use that over CTRL. Patch by BigBB.
rubidium
parents: 8473
diff changeset
   885
					SetSignalType(tile, track, sigtype == SIGTYPE_COMBO ? SIGTYPE_NORMAL : (SignalType)(sigtype + 1));
1084
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   886
				} else {
8487
bab0d066128b (svn r11547) -Add: signal selection GUI for the ones that really like to use that over CTRL. Patch by BigBB.
rubidium
parents: 8473
diff changeset
   887
					/* cycle the signal side: both -> left -> right -> both -> ... */
3522
25ce619b9a19 (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
   888
					CycleSignalSide(tile, track);
1084
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   889
				}
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   890
			}
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
   891
		} else {
1084
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   892
			/* If CmdBuildManySignals is called with copying signals, just copy the
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   893
			 * direction of the first signal given as parameter by CmdBuildManySignals */
7249
3e6c9df9794d (svn r9988) -Codechange: remove the last direct map accesses, except the ones needed for the savegame saving/loading mechanisms.
rubidium
parents: 7224
diff changeset
   894
			SetPresentSignals(tile, (GetPresentSignals(tile) & ~SignalOnTrack(track)) | (p2 & SignalOnTrack(track)));
7266
4b75e7b9fa91 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 7249
diff changeset
   895
			SetSignalVariant(tile, track, sigvar);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   896
		}
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   897
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   898
		MarkTileDirtyByTile(tile);
8802
e08824cdab46 (svn r11871) -Fix [FS#1074]: do not update signals after each tile when building/removing a large block of track/signals/station
smatz
parents: 8796
diff changeset
   899
		AddTrackToSignalBuffer(tile, track, _current_player);
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3884
diff changeset
   900
		YapfNotifyTrackLayoutChange(tile, track);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   901
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   902
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   903
	return cost;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   904
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   905
7659
5456fc83a700 (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: 7654
diff changeset
   906
static bool CheckSignalAutoFill(TileIndex &tile, Trackdir &trackdir, int &signal_ctr, bool remove)
5456fc83a700 (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: 7654
diff changeset
   907
{
5456fc83a700 (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: 7654
diff changeset
   908
	tile = AddTileIndexDiffCWrap(tile, _trackdelta[trackdir]);
5456fc83a700 (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: 7654
diff changeset
   909
	if (tile == INVALID_TILE) return false;
5456fc83a700 (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: 7654
diff changeset
   910
5456fc83a700 (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: 7654
diff changeset
   911
	/* Check for track bits on the new tile */
9112
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 9094
diff changeset
   912
	TrackdirBits trackdirbits = TrackStatusToTrackdirBits(GetTileTrackStatus(tile, TRANSPORT_RAIL, 0));
7659
5456fc83a700 (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: 7654
diff changeset
   913
5456fc83a700 (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: 7654
diff changeset
   914
	if (TracksOverlap(TrackdirBitsToTrackBits(trackdirbits))) return false;
5456fc83a700 (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: 7654
diff changeset
   915
	trackdirbits &= TrackdirReachesTrackdirs(trackdir);
5456fc83a700 (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: 7654
diff changeset
   916
5456fc83a700 (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: 7654
diff changeset
   917
	/* No track bits, must stop */
5456fc83a700 (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: 7654
diff changeset
   918
	if (trackdirbits == TRACKDIR_BIT_NONE) return false;
5456fc83a700 (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: 7654
diff changeset
   919
5456fc83a700 (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: 7654
diff changeset
   920
	/* Get the first track dir */
5456fc83a700 (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: 7654
diff changeset
   921
	trackdir = RemoveFirstTrackdir(&trackdirbits);
5456fc83a700 (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: 7654
diff changeset
   922
5456fc83a700 (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: 7654
diff changeset
   923
	/* Any left? It's a junction so we stop */
5456fc83a700 (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: 7654
diff changeset
   924
	if (trackdirbits != TRACKDIR_BIT_NONE) return false;
5456fc83a700 (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: 7654
diff changeset
   925
5456fc83a700 (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: 7654
diff changeset
   926
	switch (GetTileType(tile)) {
5456fc83a700 (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: 7654
diff changeset
   927
		case MP_RAILWAY:
5456fc83a700 (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: 7654
diff changeset
   928
			if (IsRailDepot(tile)) return false;
5456fc83a700 (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: 7654
diff changeset
   929
			if (!remove && HasSignalOnTrack(tile, TrackdirToTrack(trackdir))) return false;
5456fc83a700 (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: 7654
diff changeset
   930
			signal_ctr++;
5456fc83a700 (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: 7654
diff changeset
   931
			if (IsDiagonalTrackdir(trackdir)) {
5456fc83a700 (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: 7654
diff changeset
   932
				signal_ctr++;
5456fc83a700 (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: 7654
diff changeset
   933
				/* Ensure signal_ctr even so X and Y pieces get signals */
8425
72a71d480c5f (svn r11482) -Codechange: Remove the doubled function ClrBitT and rename the remaining to fit with the naming style
skidd13
parents: 8424
diff changeset
   934
				ClrBit(signal_ctr, 0);
7659
5456fc83a700 (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: 7654
diff changeset
   935
			}
5456fc83a700 (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: 7654
diff changeset
   936
			return true;
5456fc83a700 (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: 7654
diff changeset
   937
7866
e19fda04e8d3 (svn r10733) -Codechange: change MP_STREET into MP_ROAD as we use the word "road" everywhere except in the tile type.
rubidium
parents: 7831
diff changeset
   938
		case MP_ROAD:
7659
5456fc83a700 (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: 7654
diff changeset
   939
			if (!IsLevelCrossing(tile)) return false;
5456fc83a700 (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: 7654
diff changeset
   940
			signal_ctr += 2;
5456fc83a700 (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: 7654
diff changeset
   941
			return true;
5456fc83a700 (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: 7654
diff changeset
   942
5456fc83a700 (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: 7654
diff changeset
   943
		case MP_TUNNELBRIDGE: {
8584
a8b6dffead63 (svn r11649) -Codechange: some code can be simplified thanks to changes in r11642
smatz
parents: 8579
diff changeset
   944
			TileIndex orig_tile = tile; // backup old value
a8b6dffead63 (svn r11649) -Codechange: some code can be simplified thanks to changes in r11642
smatz
parents: 8579
diff changeset
   945
a8b6dffead63 (svn r11649) -Codechange: some code can be simplified thanks to changes in r11642
smatz
parents: 8579
diff changeset
   946
			if (GetTunnelBridgeTransportType(tile) != TRANSPORT_RAIL) return false;
a8b6dffead63 (svn r11649) -Codechange: some code can be simplified thanks to changes in r11642
smatz
parents: 8579
diff changeset
   947
			if (GetTunnelBridgeDirection(tile) != TrackdirToExitdir(trackdir)) return false;
a8b6dffead63 (svn r11649) -Codechange: some code can be simplified thanks to changes in r11642
smatz
parents: 8579
diff changeset
   948
a8b6dffead63 (svn r11649) -Codechange: some code can be simplified thanks to changes in r11642
smatz
parents: 8579
diff changeset
   949
			/* Skip to end of tunnel or bridge
a8b6dffead63 (svn r11649) -Codechange: some code can be simplified thanks to changes in r11642
smatz
parents: 8579
diff changeset
   950
			 * note that tile is a parameter by reference, so it must be updated */
8693
3d721429cc4f (svn r11760) -Codechange: unify the way how other end of a tunnel/bridge is determined at some places
smatz
parents: 8654
diff changeset
   951
			tile = GetOtherTunnelBridgeEnd(tile);
8584
a8b6dffead63 (svn r11649) -Codechange: some code can be simplified thanks to changes in r11642
smatz
parents: 8579
diff changeset
   952
8894
1e5b2d4380b8 (svn r11968) -Codechange: remove redundant FindLengthOfTunnel(), use GetTunnelBridgeLength() and/or GetOtherTunnelEnd() instead
smatz
parents: 8840
diff changeset
   953
			signal_ctr += (GetTunnelBridgeLength(orig_tile, tile) + 2) * 2;
7659
5456fc83a700 (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: 7654
diff changeset
   954
			return true;
5456fc83a700 (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: 7654
diff changeset
   955
		}
5456fc83a700 (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: 7654
diff changeset
   956
5456fc83a700 (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: 7654
diff changeset
   957
		default: return false;
5456fc83a700 (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: 7654
diff changeset
   958
	}
5456fc83a700 (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: 7654
diff changeset
   959
}
5456fc83a700 (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: 7654
diff changeset
   960
4434
4175805666a5 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4388
diff changeset
   961
/** Build many signals by dragging; AutoSignals
3491
4c8427796c64 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3486
diff changeset
   962
 * @param tile start tile of drag
6979
d194d25020e7 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6948
diff changeset
   963
 * @param flags operation to perform
1796
cae31916ae54 (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
   964
 * @param p1  end tile of drag
cae31916ae54 (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
   965
 * @param p2 various bitstuffed elements
5986
1b9ab9629d36 (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: 5982
diff changeset
   966
 * - p2 = (bit  0- 2) - track-orientation, valid values: 0-5 (Track enum)
1b9ab9629d36 (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: 5982
diff changeset
   967
 * - p2 = (bit  3)    - 1 = override signal/semaphore, or pre/exit/combo signal (CTRL-toggle)
1b9ab9629d36 (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: 5982
diff changeset
   968
 * - p2 = (bit  4)    - 0 = signals, 1 = semaphores
5982
54218ea5af1e (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: 5919
diff changeset
   969
 * - p2 = (bit  5)    - 0 = build, 1 = remove signals
7659
5456fc83a700 (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: 7654
diff changeset
   970
 * - p2 = (bit  6)    - 0 = selected stretch, 1 = auto fill
1796
cae31916ae54 (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
   971
 * - 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
   972
 */
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7287
diff changeset
   973
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
   974
{
8726
5ae45b46506b (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8724
diff changeset
   975
	CommandCost ret, total_cost(EXPENSES_CONSTRUCTION);
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7287
diff changeset
   976
	int signal_ctr;
1954
58fee2f9eb81 (svn r2460) - Fix: Prevent assertion failure when trying to drag signals starting from a non-rail tile.
hackykid
parents: 1946
diff changeset
   977
	byte signals;
1796
cae31916ae54 (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
   978
	bool error = true;
3493
4d5830846ec2 (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   979
	TileIndex end_tile;
7659
5456fc83a700 (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: 7654
diff changeset
   980
	TileIndex start_tile = tile;
1796
cae31916ae54 (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
   981
5986
1b9ab9629d36 (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: 5982
diff changeset
   982
	Track track = (Track)GB(p2, 0, 3);
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8378
diff changeset
   983
	bool mode = HasBit(p2, 3);
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8378
diff changeset
   984
	bool semaphores = HasBit(p2, 4);
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8378
diff changeset
   985
	bool remove = HasBit(p2, 5);
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8378
diff changeset
   986
	bool autofill = HasBit(p2, 6);
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   987
	Trackdir trackdir = TrackToTrackdir(track);
5982
54218ea5af1e (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: 5919
diff changeset
   988
	byte signal_density = GB(p2, 24, 8);
1796
cae31916ae54 (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
   989
2934
3b7eef9871f8 (svn r3490) -Fix: A bunch (10) of off-by-one errors when checking if a TileIndex points to a tile on the map
tron
parents: 2916
diff changeset
   990
	if (p1 >= MapSize()) return CMD_ERROR;
3493
4d5830846ec2 (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   991
	end_tile = p1;
1796
cae31916ae54 (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
   992
	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
   993
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   994
	if (!IsTileType(tile, MP_RAILWAY)) return CMD_ERROR;
1954
58fee2f9eb81 (svn r2460) - Fix: Prevent assertion failure when trying to drag signals starting from a non-rail tile.
hackykid
parents: 1946
diff changeset
   995
1796
cae31916ae54 (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
   996
	/* for vertical/horizontal tracks, double the given signals density
4549
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4483
diff changeset
   997
	 * since the original amount will be too dense (shorter tracks) */
7659
5456fc83a700 (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: 7654
diff changeset
   998
	signal_density *= 2;
1796
cae31916ae54 (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
   999
3493
4d5830846ec2 (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
  1000
	if (CmdFailed(ValidateAutoDrag(&trackdir, tile, end_tile))) return CMD_ERROR;
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
  1001
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
  1002
	track = TrackdirToTrack(trackdir); /* trackdir might have changed, keep track in sync */
7659
5456fc83a700 (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: 7654
diff changeset
  1003
	Trackdir start_trackdir = trackdir;
5456fc83a700 (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: 7654
diff changeset
  1004
5456fc83a700 (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: 7654
diff changeset
  1005
	/* Autofill must start on a valid track to be able to avoid loops */
5456fc83a700 (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: 7654
diff changeset
  1006
	if (autofill && !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
  1007
6928
44797333bcbf (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6923
diff changeset
  1008
	/* copy the signal-style of the first rail-piece if existing */
4182
20d711816338 (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
  1009
	if (HasSignals(tile)) {
7249
3e6c9df9794d (svn r9988) -Codechange: remove the last direct map accesses, except the ones needed for the savegame saving/loading mechanisms.
rubidium
parents: 7224
diff changeset
  1010
		signals = GetPresentSignals(tile) & SignalOnTrack(track);
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
  1011
		if (signals == 0) signals = SignalOnTrack(track); /* Can this actually occur? */
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
  1012
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6902
diff changeset
  1013
		/* copy signal/semaphores style (independent of CTRL) */
7266
4b75e7b9fa91 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 7249
diff changeset
  1014
		semaphores = GetSignalVariant(tile, track) != SIG_ELECTRIC;
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4067
diff changeset
  1015
	} else { // no signals exist, drag a two-way signal stretch
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
  1016
		signals = SignalOnTrack(track);
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4067
diff changeset
  1017
	}
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
  1018
7659
5456fc83a700 (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: 7654
diff changeset
  1019
	byte signal_dir = 0;
8427
143b0be22af1 (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents: 8425
diff changeset
  1020
	if (signals & SignalAlongTrackdir(trackdir))   SetBit(signal_dir, 0);
143b0be22af1 (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents: 8425
diff changeset
  1021
	if (signals & SignalAgainstTrackdir(trackdir)) SetBit(signal_dir, 1);
7659
5456fc83a700 (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: 7654
diff changeset
  1022
1954
58fee2f9eb81 (svn r2460) - Fix: Prevent assertion failure when trying to drag signals starting from a non-rail tile.
hackykid
parents: 1946
diff changeset
  1023
	/* signal_ctr         - amount of tiles already processed
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
  1024
	 * 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
  1025
	 **********
1954
58fee2f9eb81 (svn r2460) - Fix: Prevent assertion failure when trying to drag signals starting from a non-rail tile.
hackykid
parents: 1946
diff changeset
  1026
	 * trackdir   - trackdir to build with autorail
58fee2f9eb81 (svn r2460) - Fix: Prevent assertion failure when trying to drag signals starting from a non-rail tile.
hackykid
parents: 1946
diff changeset
  1027
	 * semaphores - semaphores or signals
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
  1028
	 * signals    - is there a signal/semaphore on the first tile, copy its style (two-way/single-way)
4549
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4483
diff changeset
  1029
	 *              and convert all others to semaphore/signal
5982
54218ea5af1e (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: 5919
diff changeset
  1030
	 * remove     - 1 remove signals, 0 build signals */
7446
1c4d469f986e (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 7442
diff changeset
  1031
	signal_ctr = 0;
1796
cae31916ae54 (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
  1032
	for (;;) {
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6902
diff changeset
  1033
		/* only build/remove signals with the specified density */
7659
5456fc83a700 (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: 7654
diff changeset
  1034
		if ((remove && autofill) || signal_ctr % signal_density == 0) {
5986
1b9ab9629d36 (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: 5982
diff changeset
  1035
			uint32 p1 = GB(TrackdirToTrack(trackdir), 0, 3);
1b9ab9629d36 (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: 5982
diff changeset
  1036
			SB(p1, 3, 1, mode);
1b9ab9629d36 (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: 5982
diff changeset
  1037
			SB(p1, 4, 1, semaphores);
7659
5456fc83a700 (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: 7654
diff changeset
  1038
5456fc83a700 (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: 7654
diff changeset
  1039
			/* Pick the correct orientation for the track direction */
5456fc83a700 (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: 7654
diff changeset
  1040
			signals = 0;
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8378
diff changeset
  1041
			if (HasBit(signal_dir, 0)) signals |= SignalAlongTrackdir(trackdir);
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8378
diff changeset
  1042
			if (HasBit(signal_dir, 1)) signals |= SignalAgainstTrackdir(trackdir);
7659
5456fc83a700 (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: 7654
diff changeset
  1043
5982
54218ea5af1e (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: 5919
diff changeset
  1044
			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
  1045
5069
8097cd4cd07a (svn r7127) -Codechange [FS#149]: Improve the usability of the signal-dragger, do not bail out
Darkvater
parents: 5059
diff changeset
  1046
			/* Be user-friendly and try placing signals as much as possible */
7442
a4f7989f27d4 (svn r10200) -Codechange: add "shortcut" for !CmdFailed (CmdSucceeded).
rubidium
parents: 7439
diff changeset
  1047
			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
  1048
				error = false;
7446
1c4d469f986e (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 7442
diff changeset
  1049
				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
  1050
			}
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
  1051
		}
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
7659
5456fc83a700 (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: 7654
diff changeset
  1053
		if (autofill) {
5456fc83a700 (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: 7654
diff changeset
  1054
			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
  1055
7659
5456fc83a700 (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: 7654
diff changeset
  1056
			/* Prevent possible loops */
5456fc83a700 (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: 7654
diff changeset
  1057
			if (tile == start_tile && trackdir == start_trackdir) break;
5456fc83a700 (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: 7654
diff changeset
  1058
		} else {
5456fc83a700 (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: 7654
diff changeset
  1059
			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
  1060
7659
5456fc83a700 (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: 7654
diff changeset
  1061
			tile += ToTileIndexDiff(_trackdelta[trackdir]);
5456fc83a700 (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: 7654
diff changeset
  1062
			signal_ctr++;
5456fc83a700 (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: 7654
diff changeset
  1063
5456fc83a700 (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: 7654
diff changeset
  1064
			/* toggle railbit for the non-diagonal tracks (|, -- tracks) */
5456fc83a700 (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: 7654
diff changeset
  1065
			if (IsDiagonalTrackdir(trackdir)) {
5456fc83a700 (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: 7654
diff changeset
  1066
				signal_ctr++;
5456fc83a700 (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: 7654
diff changeset
  1067
			} else {
8428
f8300c908bd9 (svn r11485) -Codechange: Remove the doubled function ToggleBitT and rename the remaining to fit with the naming style
skidd13
parents: 8427
diff changeset
  1068
				ToggleBit(trackdir, 0);
7659
5456fc83a700 (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: 7654
diff changeset
  1069
			}
5456fc83a700 (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: 7654
diff changeset
  1070
		}
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
	}
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
  1072
2951
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2934
diff changeset
  1073
	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
  1074
}
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
  1075
1796
cae31916ae54 (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
  1076
/** Build signals on a stretch of track.
cae31916ae54 (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
 * Stub for the unified signal builder/remover
6979
d194d25020e7 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6948
diff changeset
  1078
 * @param tile start tile of drag
d194d25020e7 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6948
diff changeset
  1079
 * @param flags operation to perform
d194d25020e7 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6948
diff changeset
  1080
 * @param p1  end tile of drag
d194d25020e7 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6948
diff changeset
  1081
 * @param p2 various bitstuffed elements
d194d25020e7 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6948
diff changeset
  1082
 * - p2 = (bit  0- 2) - track-orientation, valid values: 0-5 (Track enum)
d194d25020e7 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6948
diff changeset
  1083
 * - p2 = (bit  3)    - 1 = override signal/semaphore, or pre/exit/combo signal (CTRL-toggle)
d194d25020e7 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6948
diff changeset
  1084
 * - p2 = (bit  4)    - 0 = signals, 1 = semaphores
d194d25020e7 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6948
diff changeset
  1085
 * - p2 = (bit  5)    - 0 = build, 1 = remove signals
7659
5456fc83a700 (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: 7654
diff changeset
  1086
 * - p2 = (bit  6)    - 0 = selected stretch, 1 = auto fill
6979
d194d25020e7 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6948
diff changeset
  1087
 * - p2 = (bit 24-31) - user defined signals_density
1796
cae31916ae54 (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
  1088
 * @see CmdSignalTrackHelper
cae31916ae54 (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
  1089
 */
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7287
diff changeset
  1090
CommandCost CmdBuildSignalTrack(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
1227
3552f20fcfcb (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
  1091
{
3491
4c8427796c64 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3486
diff changeset
  1092
	return CmdSignalTrackHelper(tile, flags, p1, p2);
1227
3552f20fcfcb (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
  1093
}
3552f20fcfcb (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
  1094
1775
08ff0f12ccdc (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
  1095
/** Remove signals
3491
4c8427796c64 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3486
diff changeset
  1096
 * @param tile coordinates where signal is being deleted from
6979
d194d25020e7 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6948
diff changeset
  1097
 * @param flags operation to perform
6984
045168d13eef (svn r9669) -Documentation: some more doxygen fixes
belugas
parents: 6979
diff changeset
  1098
 * @param p1 various bitstuffed elements, only track information is used
045168d13eef (svn r9669) -Documentation: some more doxygen fixes
belugas
parents: 6979
diff changeset
  1099
 *           - (bit  0- 2) - track-orientation, valid values: 0-5 (Track enum)
045168d13eef (svn r9669) -Documentation: some more doxygen fixes
belugas
parents: 6979
diff changeset
  1100
 *           - (bit  3)    - override signal/semaphore, or pre/exit/combo signal (CTRL-toggle)
045168d13eef (svn r9669) -Documentation: some more doxygen fixes
belugas
parents: 6979
diff changeset
  1101
 *           - (bit  4)    - 0 = signals, 1 = semaphores
045168d13eef (svn r9669) -Documentation: some more doxygen fixes
belugas
parents: 6979
diff changeset
  1102
 * @param p2 unused
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1103
 */
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7287
diff changeset
  1104
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
  1105
{
5986
1b9ab9629d36 (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: 5982
diff changeset
  1106
	Track track = (Track)GB(p1, 0, 3);
1518
ade7a74ac31a (svn r2022) Revise CmdRemoveSingleSignal: Check parameters for validity and simplify the function
tron
parents: 1477
diff changeset
  1107
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4067
diff changeset
  1108
	if (!ValParamTrackOrientation(track) ||
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4067
diff changeset
  1109
			!IsTileType(tile, MP_RAILWAY) ||
7944
65c7c2e1bcb9 (svn r10922) -Codechange: Allow building and removing tracks and signals when there is a
maedhros
parents: 7885
diff changeset
  1110
			!EnsureNoTrainOnTrack(tile, track) ||
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4067
diff changeset
  1111
			!HasSignalOnTrack(tile, track)) {
1518
ade7a74ac31a (svn r2022) Revise CmdRemoveSingleSignal: Check parameters for validity and simplify the function
tron
parents: 1477
diff changeset
  1112
		return CMD_ERROR;
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4067
diff changeset
  1113
	}
1518
ade7a74ac31a (svn r2022) Revise CmdRemoveSingleSignal: Check parameters for validity and simplify the function
tron
parents: 1477
diff changeset
  1114
1775
08ff0f12ccdc (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
  1115
	/* Only water can remove signals from anyone */
08ff0f12ccdc (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
  1116
	if (_current_player != OWNER_WATER && !CheckTileOwnership(tile)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1117
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1118
	/* Do it? */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1119
	if (flags & DC_EXEC) {
7249
3e6c9df9794d (svn r9988) -Codechange: remove the last direct map accesses, except the ones needed for the savegame saving/loading mechanisms.
rubidium
parents: 7224
diff changeset
  1120
		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
  1121
1066
aad3c6ad147f (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
  1122
		/* removed last signal from tile? */
7249
3e6c9df9794d (svn r9988) -Codechange: remove the last direct map accesses, except the ones needed for the savegame saving/loading mechanisms.
rubidium
parents: 7224
diff changeset
  1123
		if (GetPresentSignals(tile) == 0) {
3e6c9df9794d (svn r9988) -Codechange: remove the last direct map accesses, except the ones needed for the savegame saving/loading mechanisms.
rubidium
parents: 7224
diff changeset
  1124
			SetSignalStates(tile, 0);
6498
aff910a05c6e (svn r8935) -Codechange: unification of track type between road and rail tiles, unification of ground type between normal rail tiles and depots/waypoints and removing the need for RailTileSubType.
rubidium
parents: 6486
diff changeset
  1125
			SetHasSignals(tile, false);
7266
4b75e7b9fa91 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 7249
diff changeset
  1126
			SetSignalVariant(tile, INVALID_TRACK, SIG_ELECTRIC); // remove any possible semaphores
1066
aad3c6ad147f (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
  1127
		}
1109
1bab892228cd (svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents: 1095
diff changeset
  1128
8802
e08824cdab46 (svn r11871) -Fix [FS#1074]: do not update signals after each tile when building/removing a large block of track/signals/station
smatz
parents: 8796
diff changeset
  1129
		AddTrackToSignalBuffer(tile, track, GetTileOwner(tile));
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3884
diff changeset
  1130
		YapfNotifyTrackLayoutChange(tile, track);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1131
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1132
		MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1133
	}
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1134
8726
5ae45b46506b (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8724
diff changeset
  1135
	return CommandCost(EXPENSES_CONSTRUCTION, _price.remove_signals);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1136
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1137
1796
cae31916ae54 (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
  1138
/** Remove signals on a stretch of track.
cae31916ae54 (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
  1139
 * Stub for the unified signal builder/remover
6979
d194d25020e7 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6948
diff changeset
  1140
 * @param tile start tile of drag
d194d25020e7 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6948
diff changeset
  1141
 * @param flags operation to perform
d194d25020e7 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6948
diff changeset
  1142
 * @param p1  end tile of drag
d194d25020e7 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6948
diff changeset
  1143
 * @param p2 various bitstuffed elements
d194d25020e7 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6948
diff changeset
  1144
 * - p2 = (bit  0- 2) - track-orientation, valid values: 0-5 (Track enum)
d194d25020e7 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6948
diff changeset
  1145
 * - p2 = (bit  3)    - 1 = override signal/semaphore, or pre/exit/combo signal (CTRL-toggle)
d194d25020e7 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6948
diff changeset
  1146
 * - p2 = (bit  4)    - 0 = signals, 1 = semaphores
d194d25020e7 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6948
diff changeset
  1147
 * - p2 = (bit  5)    - 0 = build, 1 = remove signals
7659
5456fc83a700 (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: 7654
diff changeset
  1148
 * - p2 = (bit  6)    - 0 = selected stretch, 1 = auto fill
6979
d194d25020e7 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6948
diff changeset
  1149
 * - p2 = (bit 24-31) - user defined signals_density
1796
cae31916ae54 (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
  1150
 * @see CmdSignalTrackHelper
cae31916ae54 (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
  1151
 */
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7287
diff changeset
  1152
CommandCost CmdRemoveSignalTrack(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
1227
3552f20fcfcb (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
  1153
{
8427
143b0be22af1 (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents: 8425
diff changeset
  1154
	return CmdSignalTrackHelper(tile, flags, p1, SetBit(p2, 5)); // bit 5 is remove bit
1227
3552f20fcfcb (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
  1155
}
3552f20fcfcb (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
  1156
8592
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1157
/** Update power of train under which is the railtype being converted */
8035
a0200ced6d9f (svn r11059) -Fix [FS#1182]: inconsistency between Rail<->ElRail conversions of different kinds of rail containing tiles (normal rail, stations, depots, etc). Patch by SmatZ.
rubidium
parents: 7990
diff changeset
  1158
void *UpdateTrainPowerProc(Vehicle *v, void *data)
a0200ced6d9f (svn r11059) -Fix [FS#1182]: inconsistency between Rail<->ElRail conversions of different kinds of rail containing tiles (normal rail, stations, depots, etc). Patch by SmatZ.
rubidium
parents: 7990
diff changeset
  1159
{
a0200ced6d9f (svn r11059) -Fix [FS#1182]: inconsistency between Rail<->ElRail conversions of different kinds of rail containing tiles (normal rail, stations, depots, etc). Patch by SmatZ.
rubidium
parents: 7990
diff changeset
  1160
	/* Similiar checks as in TrainPowerChanged() */
a0200ced6d9f (svn r11059) -Fix [FS#1182]: inconsistency between Rail<->ElRail conversions of different kinds of rail containing tiles (normal rail, stations, depots, etc). Patch by SmatZ.
rubidium
parents: 7990
diff changeset
  1161
8577
fc4b7dd34058 (svn r11642) -Codechange: VehicleFromPos does check for v->tile == tile, so remove useless checks
smatz
parents: 8573
diff changeset
  1162
	if (v->type == VEH_TRAIN && !IsArticulatedPart(v)) {
8035
a0200ced6d9f (svn r11059) -Fix [FS#1182]: inconsistency between Rail<->ElRail conversions of different kinds of rail containing tiles (normal rail, stations, depots, etc). Patch by SmatZ.
rubidium
parents: 7990
diff changeset
  1163
		const RailVehicleInfo *rvi = RailVehInfo(v->engine_type);
a0200ced6d9f (svn r11059) -Fix [FS#1182]: inconsistency between Rail<->ElRail conversions of different kinds of rail containing tiles (normal rail, stations, depots, etc). Patch by SmatZ.
rubidium
parents: 7990
diff changeset
  1164
		if (GetVehicleProperty(v, 0x0B, rvi->power) != 0) TrainPowerChanged(v->First());
a0200ced6d9f (svn r11059) -Fix [FS#1182]: inconsistency between Rail<->ElRail conversions of different kinds of rail containing tiles (normal rail, stations, depots, etc). Patch by SmatZ.
rubidium
parents: 7990
diff changeset
  1165
	}
a0200ced6d9f (svn r11059) -Fix [FS#1182]: inconsistency between Rail<->ElRail conversions of different kinds of rail containing tiles (normal rail, stations, depots, etc). Patch by SmatZ.
rubidium
parents: 7990
diff changeset
  1166
a0200ced6d9f (svn r11059) -Fix [FS#1182]: inconsistency between Rail<->ElRail conversions of different kinds of rail containing tiles (normal rail, stations, depots, etc). Patch by SmatZ.
rubidium
parents: 7990
diff changeset
  1167
	return NULL;
a0200ced6d9f (svn r11059) -Fix [FS#1182]: inconsistency between Rail<->ElRail conversions of different kinds of rail containing tiles (normal rail, stations, depots, etc). Patch by SmatZ.
rubidium
parents: 7990
diff changeset
  1168
}
a0200ced6d9f (svn r11059) -Fix [FS#1182]: inconsistency between Rail<->ElRail conversions of different kinds of rail containing tiles (normal rail, stations, depots, etc). Patch by SmatZ.
rubidium
parents: 7990
diff changeset
  1169
1782
0ac16ff36293 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1781
diff changeset
  1170
/** Convert one rail type to the other. You can convert normal rail to
0ac16ff36293 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1781
diff changeset
  1171
 * monorail/maglev easily or vice-versa.
3491
4c8427796c64 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3486
diff changeset
  1172
 * @param tile end tile of rail conversion drag
6979
d194d25020e7 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6948
diff changeset
  1173
 * @param flags operation to perform
1782
0ac16ff36293 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1781
diff changeset
  1174
 * @param p1 start tile of drag
0ac16ff36293 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1781
diff changeset
  1175
 * @param p2 new railtype to convert to
0ac16ff36293 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1781
diff changeset
  1176
 */
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7287
diff changeset
  1177
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
  1178
{
8726
5ae45b46506b (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8724
diff changeset
  1179
	CommandCost cost(EXPENSES_CONSTRUCTION);
8732
b18f578f7c16 (svn r11800) -Codechange: move some functions to a more logical location + some type safety.
rubidium
parents: 8726
diff changeset
  1180
	RailType totype = (RailType)p2;
b18f578f7c16 (svn r11800) -Codechange: move some functions to a more logical location + some type safety.
rubidium
parents: 8726
diff changeset
  1181
b18f578f7c16 (svn r11800) -Codechange: move some functions to a more logical location + some type safety.
rubidium
parents: 8726
diff changeset
  1182
	if (!ValParamRailtype(totype)) return CMD_ERROR;
2934
3b7eef9871f8 (svn r3490) -Fix: A bunch (10) of off-by-one errors when checking if a TileIndex points to a tile on the map
tron
parents: 2916
diff changeset
  1183
	if (p1 >= MapSize()) return CMD_ERROR;
1782
0ac16ff36293 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1781
diff changeset
  1184
8592
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1185
	uint ex = TileX(tile);
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1186
	uint ey = TileY(tile);
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1187
	uint sx = TileX(p1);
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1188
	uint sy = TileY(p1);
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1189
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6902
diff changeset
  1190
	/* make sure sx,sy are smaller than ex,ey */
6432
8fb778a7f2d7 (svn r8841) -Fix
tron
parents: 6319
diff changeset
  1191
	if (ex < sx) Swap(ex, sx);
8fb778a7f2d7 (svn r8841) -Fix
tron
parents: 6319
diff changeset
  1192
	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
  1193
8592
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1194
	_error_message = STR_1005_NO_SUITABLE_RAILROAD_TRACK; // by default, there is no track to convert
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1195
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1196
	for (uint x = sx; x <= ex; ++x) {
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1197
		for (uint y = sy; y <= ey; ++y) {
3493
4d5830846ec2 (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
  1198
			TileIndex tile = TileXY(x, y);
8592
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1199
			TileType tt = GetTileType(tile);
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1200
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1201
			/* Check if there is any track on tile */
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1202
			switch (tt) {
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1203
				case MP_RAILWAY:
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1204
					break;
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1205
				case MP_STATION:
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1206
					if (!IsRailwayStation(tile)) continue;
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1207
					break;
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1208
				case MP_ROAD:
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1209
					if (!IsLevelCrossing(tile)) continue;
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1210
					break;
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1211
				case MP_TUNNELBRIDGE:
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1212
					if (GetTunnelBridgeTransportType(tile) != TRANSPORT_RAIL) continue;
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1213
					break;
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1214
				default: continue;
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1215
			}
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1216
8592
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1217
			/* Original railtype we are converting from */
8035
a0200ced6d9f (svn r11059) -Fix [FS#1182]: inconsistency between Rail<->ElRail conversions of different kinds of rail containing tiles (normal rail, stations, depots, etc). Patch by SmatZ.
rubidium
parents: 7990
diff changeset
  1218
			RailType type = GetRailType(tile);
a0200ced6d9f (svn r11059) -Fix [FS#1182]: inconsistency between Rail<->ElRail conversions of different kinds of rail containing tiles (normal rail, stations, depots, etc). Patch by SmatZ.
rubidium
parents: 7990
diff changeset
  1219
8592
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1220
			/* Converting to the same type or converting 'hidden' elrail -> rail */
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1221
			if (type == totype || (_patches.disable_elrails && totype == RAILTYPE_RAIL && type == RAILTYPE_ELECTRIC)) continue;
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1222
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1223
			/* Trying to convert other's rail */
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1224
			if (!CheckTileOwnership(tile)) continue;
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1225
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1226
			/* Vehicle on the tile when not converting Rail <-> ElRail
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1227
			 * Tunnels and bridges have special check later */
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1228
			if (tt != MP_TUNNELBRIDGE) {
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1229
				if (!IsCompatibleRail(type, totype) && !EnsureNoVehicleOnGround(tile)) continue;
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1230
				if (flags & DC_EXEC) { // we can safely convert, too
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1231
					SetRailType(tile, totype);
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1232
					MarkTileDirtyByTile(tile);
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1233
					/* update power of train engines on this tile */
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1234
					VehicleFromPos(tile, NULL, &UpdateTrainPowerProc);
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1235
				}
8035
a0200ced6d9f (svn r11059) -Fix [FS#1182]: inconsistency between Rail<->ElRail conversions of different kinds of rail containing tiles (normal rail, stations, depots, etc). Patch by SmatZ.
rubidium
parents: 7990
diff changeset
  1236
			}
a0200ced6d9f (svn r11059) -Fix [FS#1182]: inconsistency between Rail<->ElRail conversions of different kinds of rail containing tiles (normal rail, stations, depots, etc). Patch by SmatZ.
rubidium
parents: 7990
diff changeset
  1237
8592
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1238
			switch (tt) {
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1239
				case MP_RAILWAY:
8649
36cda5a2e5e7 (svn r11715) -Fix: do not use GetTrackBits() for depots and waypoints while converting railtype
smatz
parents: 8640
diff changeset
  1240
					switch (GetRailTileType(tile)) {
36cda5a2e5e7 (svn r11715) -Fix: do not use GetTrackBits() for depots and waypoints while converting railtype
smatz
parents: 8640
diff changeset
  1241
						case RAIL_TILE_WAYPOINT:
36cda5a2e5e7 (svn r11715) -Fix: do not use GetTrackBits() for depots and waypoints while converting railtype
smatz
parents: 8640
diff changeset
  1242
							if (flags & DC_EXEC) {
36cda5a2e5e7 (svn r11715) -Fix: do not use GetTrackBits() for depots and waypoints while converting railtype
smatz
parents: 8640
diff changeset
  1243
								/* notify YAPF about the track layout change */
36cda5a2e5e7 (svn r11715) -Fix: do not use GetTrackBits() for depots and waypoints while converting railtype
smatz
parents: 8640
diff changeset
  1244
								YapfNotifyTrackLayoutChange(tile, AxisToTrack(GetWaypointAxis(tile)));
36cda5a2e5e7 (svn r11715) -Fix: do not use GetTrackBits() for depots and waypoints while converting railtype
smatz
parents: 8640
diff changeset
  1245
							}
36cda5a2e5e7 (svn r11715) -Fix: do not use GetTrackBits() for depots and waypoints while converting railtype
smatz
parents: 8640
diff changeset
  1246
							cost.AddCost(RailConvertCost(type, totype));
36cda5a2e5e7 (svn r11715) -Fix: do not use GetTrackBits() for depots and waypoints while converting railtype
smatz
parents: 8640
diff changeset
  1247
							break;
36cda5a2e5e7 (svn r11715) -Fix: do not use GetTrackBits() for depots and waypoints while converting railtype
smatz
parents: 8640
diff changeset
  1248
36cda5a2e5e7 (svn r11715) -Fix: do not use GetTrackBits() for depots and waypoints while converting railtype
smatz
parents: 8640
diff changeset
  1249
						case RAIL_TILE_DEPOT:
36cda5a2e5e7 (svn r11715) -Fix: do not use GetTrackBits() for depots and waypoints while converting railtype
smatz
parents: 8640
diff changeset
  1250
							if (flags & DC_EXEC) {
36cda5a2e5e7 (svn r11715) -Fix: do not use GetTrackBits() for depots and waypoints while converting railtype
smatz
parents: 8640
diff changeset
  1251
								/* notify YAPF about the track layout change */
36cda5a2e5e7 (svn r11715) -Fix: do not use GetTrackBits() for depots and waypoints while converting railtype
smatz
parents: 8640
diff changeset
  1252
								YapfNotifyTrackLayoutChange(tile, AxisToTrack(DiagDirToAxis(GetRailDepotDirection(tile))));
36cda5a2e5e7 (svn r11715) -Fix: do not use GetTrackBits() for depots and waypoints while converting railtype
smatz
parents: 8640
diff changeset
  1253
36cda5a2e5e7 (svn r11715) -Fix: do not use GetTrackBits() for depots and waypoints while converting railtype
smatz
parents: 8640
diff changeset
  1254
								/* Update build vehicle window related to this depot */
36cda5a2e5e7 (svn r11715) -Fix: do not use GetTrackBits() for depots and waypoints while converting railtype
smatz
parents: 8640
diff changeset
  1255
								InvalidateWindowData(WC_VEHICLE_DEPOT, tile);
36cda5a2e5e7 (svn r11715) -Fix: do not use GetTrackBits() for depots and waypoints while converting railtype
smatz
parents: 8640
diff changeset
  1256
								InvalidateWindowData(WC_BUILD_VEHICLE, tile);
36cda5a2e5e7 (svn r11715) -Fix: do not use GetTrackBits() for depots and waypoints while converting railtype
smatz
parents: 8640
diff changeset
  1257
							}
36cda5a2e5e7 (svn r11715) -Fix: do not use GetTrackBits() for depots and waypoints while converting railtype
smatz
parents: 8640
diff changeset
  1258
							cost.AddCost(RailConvertCost(type, totype));
36cda5a2e5e7 (svn r11715) -Fix: do not use GetTrackBits() for depots and waypoints while converting railtype
smatz
parents: 8640
diff changeset
  1259
							break;
36cda5a2e5e7 (svn r11715) -Fix: do not use GetTrackBits() for depots and waypoints while converting railtype
smatz
parents: 8640
diff changeset
  1260
36cda5a2e5e7 (svn r11715) -Fix: do not use GetTrackBits() for depots and waypoints while converting railtype
smatz
parents: 8640
diff changeset
  1261
						default: // RAIL_TILE_NORMAL, RAIL_TILE_SIGNALS
36cda5a2e5e7 (svn r11715) -Fix: do not use GetTrackBits() for depots and waypoints while converting railtype
smatz
parents: 8640
diff changeset
  1262
							if (flags & DC_EXEC) {
36cda5a2e5e7 (svn r11715) -Fix: do not use GetTrackBits() for depots and waypoints while converting railtype
smatz
parents: 8640
diff changeset
  1263
								/* notify YAPF about the track layout change */
36cda5a2e5e7 (svn r11715) -Fix: do not use GetTrackBits() for depots and waypoints while converting railtype
smatz
parents: 8640
diff changeset
  1264
								TrackBits tracks = GetTrackBits(tile);
36cda5a2e5e7 (svn r11715) -Fix: do not use GetTrackBits() for depots and waypoints while converting railtype
smatz
parents: 8640
diff changeset
  1265
								while (tracks != TRACK_BIT_NONE) {
36cda5a2e5e7 (svn r11715) -Fix: do not use GetTrackBits() for depots and waypoints while converting railtype
smatz
parents: 8640
diff changeset
  1266
									YapfNotifyTrackLayoutChange(tile, RemoveFirstTrack(&tracks));
36cda5a2e5e7 (svn r11715) -Fix: do not use GetTrackBits() for depots and waypoints while converting railtype
smatz
parents: 8640
diff changeset
  1267
								}
36cda5a2e5e7 (svn r11715) -Fix: do not use GetTrackBits() for depots and waypoints while converting railtype
smatz
parents: 8640
diff changeset
  1268
							}
36cda5a2e5e7 (svn r11715) -Fix: do not use GetTrackBits() for depots and waypoints while converting railtype
smatz
parents: 8640
diff changeset
  1269
							cost.AddCost(RailConvertCost(type, totype) * CountBits(GetTrackBits(tile)));
36cda5a2e5e7 (svn r11715) -Fix: do not use GetTrackBits() for depots and waypoints while converting railtype
smatz
parents: 8640
diff changeset
  1270
							break;
8592
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1271
					}
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1272
					break;
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1273
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1274
				case MP_TUNNELBRIDGE: {
8693
3d721429cc4f (svn r11760) -Codechange: unify the way how other end of a tunnel/bridge is determined at some places
smatz
parents: 8654
diff changeset
  1275
					TileIndex endtile = GetOtherTunnelBridgeEnd(tile);
8592
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1276
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1277
					/* If both ends of tunnel/bridge are in the range, do not try to convert twice -
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1278
					 * it would cause assert because of different test and exec runs */
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1279
					if (endtile < tile && TileX(endtile) >= sx && TileX(endtile) <= ex &&
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1280
							TileY(endtile) >= sy && TileY(endtile) <= ey) continue;
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1281
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1282
					/* When not coverting rail <-> el. rail, any vehicle cannot be in tunnel/bridge */
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1283
					if (!IsCompatibleRail(GetRailType(tile), totype) &&
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1284
							GetVehicleTunnelBridge(tile, endtile) != NULL) continue;
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1285
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1286
					if (flags & DC_EXEC) {
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1287
						SetRailType(tile, totype);
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1288
						SetRailType(endtile, totype);
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1289
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1290
						VehicleFromPos(tile, NULL, &UpdateTrainPowerProc);
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1291
						VehicleFromPos(endtile, NULL, &UpdateTrainPowerProc);
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1292
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1293
						Track track = AxisToTrack(DiagDirToAxis(GetTunnelBridgeDirection(tile)));
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1294
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1295
						YapfNotifyTrackLayoutChange(tile, track);
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1296
						YapfNotifyTrackLayoutChange(endtile, track);
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1297
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1298
						MarkTileDirtyByTile(tile);
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1299
						MarkTileDirtyByTile(endtile);
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1300
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1301
						if (IsBridge(tile)) {
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1302
							TileIndexDiff delta = TileOffsByDiagDir(GetTunnelBridgeDirection(tile));
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1303
							TileIndex t = tile + delta;
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1304
							for (; t != endtile; t += delta) MarkTileDirtyByTile(t); // TODO encapsulate this into a function
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1305
						}
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1306
					}
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1307
8894
1e5b2d4380b8 (svn r11968) -Codechange: remove redundant FindLengthOfTunnel(), use GetTunnelBridgeLength() and/or GetOtherTunnelEnd() instead
smatz
parents: 8840
diff changeset
  1308
					cost.AddCost((GetTunnelBridgeLength(tile, endtile) + 2) * RailConvertCost(type, totype));
8592
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1309
				} break;
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1310
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1311
				default: // MP_STATION, MP_ROAD
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1312
					if (flags & DC_EXEC) {
9094
58d1cddf1af6 (svn r12179) -Codechange: use GetCrossingRailTrack() and GetCrossingRailAxis() to improve code readability
smatz
parents: 9092
diff changeset
  1313
						Track track = ((tt == MP_STATION) ? GetRailStationTrack(tile) : GetCrossingRailTrack(tile));
8592
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1314
						YapfNotifyTrackLayoutChange(tile, track);
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1315
					}
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1316
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1317
					cost.AddCost(RailConvertCost(type, totype));
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1318
					break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1319
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1320
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1321
	}
1782
0ac16ff36293 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1781
diff changeset
  1322
8592
3b75a1a7ecd2 (svn r11657) -Fix: show better error message when trying to convert rail
smatz
parents: 8584
diff changeset
  1323
	return (cost.GetCost() == 0) ? CMD_ERROR : cost;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1324
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1325
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7287
diff changeset
  1326
static CommandCost RemoveTrainDepot(TileIndex tile, uint32 flags)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1327
{
149
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 84
diff changeset
  1328
	if (!CheckTileOwnership(tile) && _current_player != OWNER_WATER)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1329
		return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1330
6902
9da0ee122fd5 (svn r9542) -Fix(FS# 712): When checking if a vehicle is on a given tile, and you are working on the ground tile, do not take aircrafts into account, as they do not pose any danger for the construction/destruction/conversion itself. Z stuff, in other words
belugas
parents: 6889
diff changeset
  1331
	if (!EnsureNoVehicleOnGround(tile))
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1332
		return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1333
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1334
	if (flags & DC_EXEC) {
8796
81b0d6b54a1f (svn r11864) -Codechange: pass owner whose signals we will update instead of complex detection later
smatz
parents: 8760
diff changeset
  1335
		/* read variables before the depot is removed */
3191
d273bda0f5d4 (svn r3851) Rail depots only have an entrance at one side, therefore use UpdateSignalsOnSegment() instead of SetSignalsOnBothDir()
tron
parents: 3189
diff changeset
  1336
		DiagDirection dir = GetRailDepotDirection(tile);
8796
81b0d6b54a1f (svn r11864) -Codechange: pass owner whose signals we will update instead of complex detection later
smatz
parents: 8760
diff changeset
  1337
		Owner owner = GetTileOwner(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1338
7885
4eb9b01e37ff (svn r10758) -Codechange: make the depot struct use the pool item class as super class.
rubidium
parents: 7867
diff changeset
  1339
		DoClearSquare(tile);
4eb9b01e37ff (svn r10758) -Codechange: make the depot struct use the pool item class as super class.
rubidium
parents: 7867
diff changeset
  1340
		delete GetDepotByTile(tile);
8802
e08824cdab46 (svn r11871) -Fix [FS#1074]: do not update signals after each tile when building/removing a large block of track/signals/station
smatz
parents: 8796
diff changeset
  1341
		AddSideToSignalBuffer(tile, dir, owner);
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3884
diff changeset
  1342
		YapfNotifyTrackLayoutChange(tile, TrackdirToTrack(DiagdirToDiagTrackdir(dir)));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1343
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1344
8726
5ae45b46506b (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8724
diff changeset
  1345
	return CommandCost(EXPENSES_CONSTRUCTION, _price.remove_train_depot);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1346
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1347
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7287
diff changeset
  1348
static CommandCost ClearTile_Track(TileIndex tile, byte flags)
1534
2f7388d38291 (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
  1349
{
8726
5ae45b46506b (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8724
diff changeset
  1350
	CommandCost cost(EXPENSES_CONSTRUCTION);
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7287
diff changeset
  1351
	CommandCost ret;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1352
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1353
	if (flags & DC_AUTO) {
1901
fb05044cf5c3 (svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents: 1891
diff changeset
  1354
		if (!IsTileOwner(tile, _current_player))
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1355
			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
  1356
4182
20d711816338 (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
  1357
		if (IsPlainRailTile(tile)) {
20d711816338 (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
  1358
			return_cmd_error(STR_1008_MUST_REMOVE_RAILROAD_TRACK);
20d711816338 (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
  1359
		} else {
20d711816338 (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
  1360
			return_cmd_error(STR_2004_BUILDING_MUST_BE_DEMOLISHED);
20d711816338 (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
  1361
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1362
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1363
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
  1364
	switch (GetRailTileType(tile)) {
3792
2eb8388731bf (svn r4788) - Codechange: RAILTYPE_{NORMAL,ELECTRIC,...} and RAIL_TYPE_{NORMAL,SIGNAL,...} have nearly the same name, rename RAIL_TYPE_* to RAIL_TILE_* of extra clarity
rubidium
parents: 3778
diff changeset
  1365
		case RAIL_TILE_SIGNALS:
2eb8388731bf (svn r4788) - Codechange: RAILTYPE_{NORMAL,ELECTRIC,...} and RAIL_TYPE_{NORMAL,SIGNAL,...} have nearly the same name, rename RAIL_TYPE_* to RAIL_TILE_* of extra clarity
rubidium
parents: 3778
diff changeset
  1366
		case RAIL_TILE_NORMAL: {
8910
b261b6cb9b21 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8909
diff changeset
  1367
			Slope tileh = GetTileSlope(tile, NULL);
b261b6cb9b21 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8909
diff changeset
  1368
			/* Is there flat water on the lower halftile, that gets cleared expensively? */
b261b6cb9b21 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8909
diff changeset
  1369
			bool water_ground = (GetRailGroundType(tile) == RAIL_GROUND_WATER && IsSlopeWithOneCornerRaised(tileh));
8267
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8266
diff changeset
  1370
5665
9498578ecbf2 (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: 5662
diff changeset
  1371
			TrackBits tracks = GetTrackBits(tile);
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
  1372
			while (tracks != TRACK_BIT_NONE) {
5849
58039c9dc565 (svn r8052) - Codechange: RemoveFirstTrack() and RemoveFirstTrackdir() now accept pointer to TrackBits/TrackdirBits instead of reference.
KUDr
parents: 5838
diff changeset
  1373
				Track track = RemoveFirstTrack(&tracks);
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
  1374
				ret = DoCommand(tile, 0, track, flags, CMD_REMOVE_SINGLE_RAIL);
5662
2dd848654f54 (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: 5582
diff changeset
  1375
				if (CmdFailed(ret)) return CMD_ERROR;
7446
1c4d469f986e (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 7442
diff changeset
  1376
				cost.AddCost(ret);
1534
2f7388d38291 (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
  1377
			}
8267
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8266
diff changeset
  1378
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8266
diff changeset
  1379
			if (water_ground) {
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8266
diff changeset
  1380
				/* The track was removed, and left a coast tile. Now also clear the water. */
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8266
diff changeset
  1381
				if (flags & DC_EXEC) DoClearSquare(tile);
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8266
diff changeset
  1382
				cost.AddCost(_price.clear_water);
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8266
diff changeset
  1383
			}
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8266
diff changeset
  1384
1534
2f7388d38291 (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
  1385
			return cost;
2f7388d38291 (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
  1386
		}
2f7388d38291 (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
  1387
6498
aff910a05c6e (svn r8935) -Codechange: unification of track type between road and rail tiles, unification of ground type between normal rail tiles and depots/waypoints and removing the need for RailTileSubType.
rubidium
parents: 6486
diff changeset
  1388
		case RAIL_TILE_DEPOT:
aff910a05c6e (svn r8935) -Codechange: unification of track type between road and rail tiles, unification of ground type between normal rail tiles and depots/waypoints and removing the need for RailTileSubType.
rubidium
parents: 6486
diff changeset
  1389
			return RemoveTrainDepot(tile, flags);
aff910a05c6e (svn r8935) -Codechange: unification of track type between road and rail tiles, unification of ground type between normal rail tiles and depots/waypoints and removing the need for RailTileSubType.
rubidium
parents: 6486
diff changeset
  1390
aff910a05c6e (svn r8935) -Codechange: unification of track type between road and rail tiles, unification of ground type between normal rail tiles and depots/waypoints and removing the need for RailTileSubType.
rubidium
parents: 6486
diff changeset
  1391
		case RAIL_TILE_WAYPOINT:
aff910a05c6e (svn r8935) -Codechange: unification of track type between road and rail tiles, unification of ground type between normal rail tiles and depots/waypoints and removing the need for RailTileSubType.
rubidium
parents: 6486
diff changeset
  1392
			return RemoveTrainWaypoint(tile, flags, false);
1534
2f7388d38291 (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
  1393
2f7388d38291 (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
  1394
		default:
2f7388d38291 (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
  1395
			return CMD_ERROR;
2f7388d38291 (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
  1396
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1397
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1398
8260
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8259
diff changeset
  1399
/**
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8259
diff changeset
  1400
 * Get surface height in point (x,y)
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8259
diff changeset
  1401
 * On tiles with halftile foundations move (x,y) to a save point wrt. track
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8259
diff changeset
  1402
 */
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8259
diff changeset
  1403
static uint GetSaveSlopeZ(uint x, uint y, Track track)
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8259
diff changeset
  1404
{
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8259
diff changeset
  1405
	switch (track) {
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8259
diff changeset
  1406
		case TRACK_UPPER: x &= ~0xF; y &= ~0xF; break;
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8259
diff changeset
  1407
		case TRACK_LOWER: x |=  0xF; y |=  0xF; break;
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8259
diff changeset
  1408
		case TRACK_LEFT:  x |=  0xF; y &= ~0xF; break;
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8259
diff changeset
  1409
		case TRACK_RIGHT: x &= ~0xF; y |=  0xF; break;
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8259
diff changeset
  1410
		default: break;
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8259
diff changeset
  1411
	}
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8259
diff changeset
  1412
	return GetSlopeZ(x, y);
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8259
diff changeset
  1413
}
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8259
diff changeset
  1414
7266
4b75e7b9fa91 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 7249
diff changeset
  1415
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
  1416
{
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
  1417
	bool side = (_opt.road_side != 0) && _patches.signal_side;
3502
d41ccd2fb5c5 (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
  1418
	static const Point SignalPositions[2][12] = {
d41ccd2fb5c5 (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
  1419
		{      /* Signals on the left side */
d41ccd2fb5c5 (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
  1420
		/*  LEFT      LEFT      RIGHT     RIGHT     UPPER     UPPER */
d41ccd2fb5c5 (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
  1421
			{ 8,  5}, {14,  1}, { 1, 14}, { 9, 11}, { 1,  0}, { 3, 10},
d41ccd2fb5c5 (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
  1422
		/*  LOWER     LOWER     X         X         Y         Y     */
d41ccd2fb5c5 (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
  1423
			{11,  4}, {14, 14}, {11,  3}, { 4, 13}, { 3,  4}, {11, 13}
d41ccd2fb5c5 (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
  1424
		}, {   /* Signals on the right side */
d41ccd2fb5c5 (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
  1425
		/*  LEFT      LEFT      RIGHT     RIGHT     UPPER     UPPER */
d41ccd2fb5c5 (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
  1426
			{14,  1}, {12, 10}, { 4,  6}, { 1, 14}, {10,  4}, { 0,  1},
d41ccd2fb5c5 (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
  1427
		/*  LOWER     LOWER     X         X         Y         Y     */
d41ccd2fb5c5 (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
  1428
			{14, 14}, { 5, 12}, {11, 13}, { 4,  3}, {13,  4}, { 3, 11}
d41ccd2fb5c5 (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
  1429
		}
d41ccd2fb5c5 (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
  1430
	};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1431
3575
867df1ec208a (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
  1432
	uint x = TileX(tile) * TILE_SIZE + SignalPositions[side][pos].x;
867df1ec208a (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
  1433
	uint y = TileY(tile) * TILE_SIZE + SignalPositions[side][pos].y;
867df1ec208a (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
  1434
3638
6e0b43d905d4 (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
  1435
	SpriteID sprite;
6e0b43d905d4 (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
  1436
9043
dfcde0d0dc0a (svn r12125) -Codechange: Remove redundant signal lookup table, and document why normal electric signals are handled specially.
peter1138
parents: 9019
diff changeset
  1437
	SignalType type       = GetSignalType(tile, track);
dfcde0d0dc0a (svn r12125) -Codechange: Remove redundant signal lookup table, and document why normal electric signals are handled specially.
peter1138
parents: 9019
diff changeset
  1438
	SignalVariant variant = GetSignalVariant(tile, track);
dfcde0d0dc0a (svn r12125) -Codechange: Remove redundant signal lookup table, and document why normal electric signals are handled specially.
peter1138
parents: 9019
diff changeset
  1439
dfcde0d0dc0a (svn r12125) -Codechange: Remove redundant signal lookup table, and document why normal electric signals are handled specially.
peter1138
parents: 9019
diff changeset
  1440
	if (type == SIGTYPE_NORMAL && variant == SIG_ELECTRIC) {
dfcde0d0dc0a (svn r12125) -Codechange: Remove redundant signal lookup table, and document why normal electric signals are handled specially.
peter1138
parents: 9019
diff changeset
  1441
		/* Normal electric signals are picked from original sprites. */
dfcde0d0dc0a (svn r12125) -Codechange: Remove redundant signal lookup table, and document why normal electric signals are handled specially.
peter1138
parents: 9019
diff changeset
  1442
		sprite = SPR_ORIGINAL_SIGNALS_BASE + image + condition;
3638
6e0b43d905d4 (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
  1443
	} else {
9043
dfcde0d0dc0a (svn r12125) -Codechange: Remove redundant signal lookup table, and document why normal electric signals are handled specially.
peter1138
parents: 9019
diff changeset
  1444
		/* All other signals are picked from add on sprites. */
dfcde0d0dc0a (svn r12125) -Codechange: Remove redundant signal lookup table, and document why normal electric signals are handled specially.
peter1138
parents: 9019
diff changeset
  1445
		sprite = SPR_SIGNALS_BASE + (type - 1) * 16 + variant * 64 + image + condition;
3638
6e0b43d905d4 (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
  1446
	}
3575
867df1ec208a (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
  1447
8260
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8259
diff changeset
  1448
	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
  1449
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1450
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1451
static uint32 _drawtile_track_palette;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1452
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1453
2436
177cb6a8339f (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents: 2425
diff changeset
  1454
static void DrawTrackFence_NW(const TileInfo *ti)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1455
{
7803
07d4e0a7a9db (svn r10659) -Codechange: updated documentation around RAIL_GROUND_FENCE_VERT[12] (frosch)
truelight
parents: 7768
diff changeset
  1456
	SpriteID image = SPR_TRACK_FENCE_FLAT_X;
07d4e0a7a9db (svn r10659) -Codechange: updated documentation around RAIL_GROUND_FENCE_VERT[12] (frosch)
truelight
parents: 7768
diff changeset
  1457
	if (ti->tileh != SLOPE_FLAT) image = (ti->tileh & SLOPE_S) ? SPR_TRACK_FENCE_SLOPE_SW : SPR_TRACK_FENCE_SLOPE_NE;
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5849
diff changeset
  1458
	AddSortableSpriteToDraw(image, _drawtile_track_palette,
2951
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2934
diff changeset
  1459
		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
  1460
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1461
2436
177cb6a8339f (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents: 2425
diff changeset
  1462
static void DrawTrackFence_SE(const TileInfo *ti)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1463
{
7803
07d4e0a7a9db (svn r10659) -Codechange: updated documentation around RAIL_GROUND_FENCE_VERT[12] (frosch)
truelight
parents: 7768
diff changeset
  1464
	SpriteID image = SPR_TRACK_FENCE_FLAT_X;
07d4e0a7a9db (svn r10659) -Codechange: updated documentation around RAIL_GROUND_FENCE_VERT[12] (frosch)
truelight
parents: 7768
diff changeset
  1465
	if (ti->tileh != SLOPE_FLAT) image = (ti->tileh & SLOPE_S) ? SPR_TRACK_FENCE_SLOPE_SW : SPR_TRACK_FENCE_SLOPE_NE;
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5849
diff changeset
  1466
	AddSortableSpriteToDraw(image, _drawtile_track_palette,
3645
86af43f87885 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3638
diff changeset
  1467
		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
  1468
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1469
2436
177cb6a8339f (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents: 2425
diff changeset
  1470
static void DrawTrackFence_NW_SE(const TileInfo *ti)
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
	DrawTrackFence_NW(ti);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1473
	DrawTrackFence_SE(ti);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1474
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1475
2436
177cb6a8339f (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents: 2425
diff changeset
  1476
static void DrawTrackFence_NE(const TileInfo *ti)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1477
{
7803
07d4e0a7a9db (svn r10659) -Codechange: updated documentation around RAIL_GROUND_FENCE_VERT[12] (frosch)
truelight
parents: 7768
diff changeset
  1478
	SpriteID image = SPR_TRACK_FENCE_FLAT_Y;
07d4e0a7a9db (svn r10659) -Codechange: updated documentation around RAIL_GROUND_FENCE_VERT[12] (frosch)
truelight
parents: 7768
diff changeset
  1479
	if (ti->tileh != SLOPE_FLAT) image = (ti->tileh & SLOPE_S) ? SPR_TRACK_FENCE_SLOPE_SE : SPR_TRACK_FENCE_SLOPE_NW;
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5849
diff changeset
  1480
	AddSortableSpriteToDraw(image, _drawtile_track_palette,
2951
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2934
diff changeset
  1481
		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
  1482
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1483
2436
177cb6a8339f (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents: 2425
diff changeset
  1484
static void DrawTrackFence_SW(const TileInfo *ti)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1485
{
7803
07d4e0a7a9db (svn r10659) -Codechange: updated documentation around RAIL_GROUND_FENCE_VERT[12] (frosch)
truelight
parents: 7768
diff changeset
  1486
	SpriteID image = SPR_TRACK_FENCE_FLAT_Y;
07d4e0a7a9db (svn r10659) -Codechange: updated documentation around RAIL_GROUND_FENCE_VERT[12] (frosch)
truelight
parents: 7768
diff changeset
  1487
	if (ti->tileh != SLOPE_FLAT) image = (ti->tileh & SLOPE_S) ? SPR_TRACK_FENCE_SLOPE_SE : SPR_TRACK_FENCE_SLOPE_NW;
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5849
diff changeset
  1488
	AddSortableSpriteToDraw(image, _drawtile_track_palette,
3645
86af43f87885 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3638
diff changeset
  1489
		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
  1490
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1491
2436
177cb6a8339f (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents: 2425
diff changeset
  1492
static void DrawTrackFence_NE_SW(const TileInfo *ti)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1493
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1494
	DrawTrackFence_NE(ti);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1495
	DrawTrackFence_SW(ti);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1496
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1497
7803
07d4e0a7a9db (svn r10659) -Codechange: updated documentation around RAIL_GROUND_FENCE_VERT[12] (frosch)
truelight
parents: 7768
diff changeset
  1498
/**
07d4e0a7a9db (svn r10659) -Codechange: updated documentation around RAIL_GROUND_FENCE_VERT[12] (frosch)
truelight
parents: 7768
diff changeset
  1499
 * Draw fence at eastern side of track.
07d4e0a7a9db (svn r10659) -Codechange: updated documentation around RAIL_GROUND_FENCE_VERT[12] (frosch)
truelight
parents: 7768
diff changeset
  1500
 */
2436
177cb6a8339f (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents: 2425
diff changeset
  1501
static void DrawTrackFence_NS_1(const TileInfo *ti)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1502
{
8909
fa15e9afad2f (svn r11983) -Codechange: Add some helper functions for slopes and use them.
frosch
parents: 8894
diff changeset
  1503
	uint z = ti->z + GetSlopeZInCorner(RemoveHalftileSlope(ti->tileh), CORNER_W);
7803
07d4e0a7a9db (svn r10659) -Codechange: updated documentation around RAIL_GROUND_FENCE_VERT[12] (frosch)
truelight
parents: 7768
diff changeset
  1504
	AddSortableSpriteToDraw(SPR_TRACK_FENCE_FLAT_VERT, _drawtile_track_palette,
3645
86af43f87885 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3638
diff changeset
  1505
		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
  1506
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1507
7803
07d4e0a7a9db (svn r10659) -Codechange: updated documentation around RAIL_GROUND_FENCE_VERT[12] (frosch)
truelight
parents: 7768
diff changeset
  1508
/**
07d4e0a7a9db (svn r10659) -Codechange: updated documentation around RAIL_GROUND_FENCE_VERT[12] (frosch)
truelight
parents: 7768
diff changeset
  1509
 * Draw fence at western side of track.
07d4e0a7a9db (svn r10659) -Codechange: updated documentation around RAIL_GROUND_FENCE_VERT[12] (frosch)
truelight
parents: 7768
diff changeset
  1510
 */
2436
177cb6a8339f (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents: 2425
diff changeset
  1511
static void DrawTrackFence_NS_2(const TileInfo *ti)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1512
{
8909
fa15e9afad2f (svn r11983) -Codechange: Add some helper functions for slopes and use them.
frosch
parents: 8894
diff changeset
  1513
	uint z = ti->z + GetSlopeZInCorner(RemoveHalftileSlope(ti->tileh), CORNER_E);
7803
07d4e0a7a9db (svn r10659) -Codechange: updated documentation around RAIL_GROUND_FENCE_VERT[12] (frosch)
truelight
parents: 7768
diff changeset
  1514
	AddSortableSpriteToDraw(SPR_TRACK_FENCE_FLAT_VERT, _drawtile_track_palette,
3645
86af43f87885 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3638
diff changeset
  1515
		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
  1516
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1517
7803
07d4e0a7a9db (svn r10659) -Codechange: updated documentation around RAIL_GROUND_FENCE_VERT[12] (frosch)
truelight
parents: 7768
diff changeset
  1518
/**
07d4e0a7a9db (svn r10659) -Codechange: updated documentation around RAIL_GROUND_FENCE_VERT[12] (frosch)
truelight
parents: 7768
diff changeset
  1519
 * Draw fence at southern side of track.
07d4e0a7a9db (svn r10659) -Codechange: updated documentation around RAIL_GROUND_FENCE_VERT[12] (frosch)
truelight
parents: 7768
diff changeset
  1520
 */
2436
177cb6a8339f (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents: 2425
diff changeset
  1521
static void DrawTrackFence_WE_1(const TileInfo *ti)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1522
{
8909
fa15e9afad2f (svn r11983) -Codechange: Add some helper functions for slopes and use them.
frosch
parents: 8894
diff changeset
  1523
	uint z = ti->z + GetSlopeZInCorner(RemoveHalftileSlope(ti->tileh), CORNER_N);
7803
07d4e0a7a9db (svn r10659) -Codechange: updated documentation around RAIL_GROUND_FENCE_VERT[12] (frosch)
truelight
parents: 7768
diff changeset
  1524
	AddSortableSpriteToDraw(SPR_TRACK_FENCE_FLAT_HORZ, _drawtile_track_palette,
3645
86af43f87885 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3638
diff changeset
  1525
		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
  1526
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1527
7803
07d4e0a7a9db (svn r10659) -Codechange: updated documentation around RAIL_GROUND_FENCE_VERT[12] (frosch)
truelight
parents: 7768
diff changeset
  1528
/**
07d4e0a7a9db (svn r10659) -Codechange: updated documentation around RAIL_GROUND_FENCE_VERT[12] (frosch)
truelight
parents: 7768
diff changeset
  1529
 * Draw fence at northern side of track.
07d4e0a7a9db (svn r10659) -Codechange: updated documentation around RAIL_GROUND_FENCE_VERT[12] (frosch)
truelight
parents: 7768
diff changeset
  1530
 */
2436
177cb6a8339f (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents: 2425
diff changeset
  1531
static void DrawTrackFence_WE_2(const TileInfo *ti)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1532
{
8909
fa15e9afad2f (svn r11983) -Codechange: Add some helper functions for slopes and use them.
frosch
parents: 8894
diff changeset
  1533
	uint z = ti->z + GetSlopeZInCorner(RemoveHalftileSlope(ti->tileh), CORNER_S);
7803
07d4e0a7a9db (svn r10659) -Codechange: updated documentation around RAIL_GROUND_FENCE_VERT[12] (frosch)
truelight
parents: 7768
diff changeset
  1534
	AddSortableSpriteToDraw(SPR_TRACK_FENCE_FLAT_HORZ, _drawtile_track_palette,
3645
86af43f87885 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3638
diff changeset
  1535
		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
  1536
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1537
4040
3c5fc0aea78d (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
  1538
3c5fc0aea78d (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
  1539
static void DrawTrackDetails(const TileInfo* ti)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1540
{
4040
3c5fc0aea78d (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
  1541
	switch (GetRailGroundType(ti->tile)) {
3c5fc0aea78d (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
  1542
		case RAIL_GROUND_FENCE_NW:     DrawTrackFence_NW(ti);    break;
3c5fc0aea78d (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
  1543
		case RAIL_GROUND_FENCE_SE:     DrawTrackFence_SE(ti);    break;
3c5fc0aea78d (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
  1544
		case RAIL_GROUND_FENCE_SENW:   DrawTrackFence_NW_SE(ti); break;
3c5fc0aea78d (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
  1545
		case RAIL_GROUND_FENCE_NE:     DrawTrackFence_NE(ti);    break;
3c5fc0aea78d (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
  1546
		case RAIL_GROUND_FENCE_SW:     DrawTrackFence_SW(ti);    break;
3c5fc0aea78d (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
  1547
		case RAIL_GROUND_FENCE_NESW:   DrawTrackFence_NE_SW(ti); break;
3c5fc0aea78d (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
  1548
		case RAIL_GROUND_FENCE_VERT1:  DrawTrackFence_NS_1(ti);  break;
3c5fc0aea78d (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
  1549
		case RAIL_GROUND_FENCE_VERT2:  DrawTrackFence_NS_2(ti);  break;
3c5fc0aea78d (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
  1550
		case RAIL_GROUND_FENCE_HORIZ1: DrawTrackFence_WE_1(ti);  break;
3c5fc0aea78d (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
  1551
		case RAIL_GROUND_FENCE_HORIZ2: DrawTrackFence_WE_2(ti);  break;
8910
b261b6cb9b21 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8909
diff changeset
  1552
		case RAIL_GROUND_WATER: {
b261b6cb9b21 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8909
diff changeset
  1553
			Corner track_corner;
b261b6cb9b21 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8909
diff changeset
  1554
			if (IsHalftileSlope(ti->tileh)) {
b261b6cb9b21 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8909
diff changeset
  1555
				/* Steep slope or one-corner-raised slope with halftile foundation */
b261b6cb9b21 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8909
diff changeset
  1556
				track_corner = GetHalftileSlopeCorner(ti->tileh);
b261b6cb9b21 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8909
diff changeset
  1557
			} else {
b261b6cb9b21 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8909
diff changeset
  1558
				/* Three-corner-raised slope */
b261b6cb9b21 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8909
diff changeset
  1559
				track_corner = OppositeCorner(GetHighestSlopeCorner(ComplementSlope(ti->tileh)));
b261b6cb9b21 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8909
diff changeset
  1560
			}
b261b6cb9b21 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8909
diff changeset
  1561
			switch (track_corner) {
8267
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8266
diff changeset
  1562
				case CORNER_W: DrawTrackFence_NS_1(ti); break;
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8266
diff changeset
  1563
				case CORNER_S: DrawTrackFence_WE_2(ti); break;
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8266
diff changeset
  1564
				case CORNER_E: DrawTrackFence_NS_2(ti); break;
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8266
diff changeset
  1565
				case CORNER_N: DrawTrackFence_WE_1(ti); break;
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8266
diff changeset
  1566
				default: NOT_REACHED();
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8266
diff changeset
  1567
			}
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8266
diff changeset
  1568
			break;
8910
b261b6cb9b21 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8909
diff changeset
  1569
		}
4040
3c5fc0aea78d (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
  1570
		default: break;
3c5fc0aea78d (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
  1571
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1572
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1573
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1574
2472
60c843b7ea28 (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
  1575
/**
60c843b7ea28 (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
  1576
 * Draw ground sprite and track bits
60c843b7ea28 (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
  1577
 * @param ti TileInfo
60c843b7ea28 (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
  1578
 * @param track TrackBits to draw
60c843b7ea28 (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
  1579
 */
4081
8d4111a68f72 (svn r5396) - Remove two fixed parameters
tron
parents: 4077
diff changeset
  1580
static void DrawTrackBits(TileInfo* ti, TrackBits track)
2472
60c843b7ea28 (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
  1581
{
8910
b261b6cb9b21 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8909
diff changeset
  1582
	/* SubSprite for drawing the track halftile of 'three-corners-raised'-sloped rail sprites. */
b261b6cb9b21 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8909
diff changeset
  1583
	static const int INF = 1000; // big number compared to tilesprite size
b261b6cb9b21 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8909
diff changeset
  1584
	static const SubSprite _halftile_sub_sprite[4] = {
b261b6cb9b21 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8909
diff changeset
  1585
		{ -INF    , -INF  , 32 - 33, INF     }, // CORNER_W, clip 33 pixels from right
b261b6cb9b21 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8909
diff changeset
  1586
		{ -INF    ,  0 + 7, INF    , INF     }, // CORNER_S, clip 7 pixels from top
b261b6cb9b21 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8909
diff changeset
  1587
		{ -31 + 33, -INF  , INF    , INF     }, // CORNER_E, clip 33 pixels from left
b261b6cb9b21 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8909
diff changeset
  1588
		{ -INF    , -INF  , INF    , 30 - 23 }  // CORNER_N, clip 23 pixels from bottom
b261b6cb9b21 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8909
diff changeset
  1589
	};
b261b6cb9b21 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8909
diff changeset
  1590
2472
60c843b7ea28 (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
  1591
	const RailtypeInfo *rti = GetRailTypeInfo(GetRailType(ti->tile));
8266
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
  1592
	RailGroundType rgt = GetRailGroundType(ti->tile);
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
  1593
	Foundation f = GetRailFoundation(ti->tileh, track);
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
  1594
	Corner halftile_corner = CORNER_INVALID;
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
  1595
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
  1596
	if (IsNonContinuousFoundation(f)) {
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
  1597
		/* Save halftile corner */
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
  1598
		halftile_corner = (f == FOUNDATION_STEEP_BOTH ? GetHighestSlopeCorner(ti->tileh) : GetHalftileFoundationCorner(f));
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
  1599
		/* Draw lower part first */
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
  1600
		track &= ~CornerToTrackBits(halftile_corner);
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
  1601
		f = (f == FOUNDATION_STEEP_BOTH ? FOUNDATION_STEEP_LOWER : FOUNDATION_NONE);
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
  1602
	}
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
  1603
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
  1604
	DrawFoundation(ti, f);
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
  1605
	/* DrawFoundation modifies ti */
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
  1606
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5849
diff changeset
  1607
	SpriteID image;
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5849
diff changeset
  1608
	SpriteID pal = PAL_NONE;
8910
b261b6cb9b21 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8909
diff changeset
  1609
	const SubSprite *sub = NULL;
2472
60c843b7ea28 (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
  1610
	bool junction = false;
60c843b7ea28 (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
  1611
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6902
diff changeset
  1612
	/* Select the sprite to use. */
8266
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
  1613
	if (track == 0) {
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
  1614
		/* Clear ground (only track on halftile foundation) */
8267
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8266
diff changeset
  1615
		if (rgt == RAIL_GROUND_WATER) {
8910
b261b6cb9b21 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8909
diff changeset
  1616
			if (IsSteepSlope(ti->tileh)) {
b261b6cb9b21 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8909
diff changeset
  1617
				DrawShoreTile(ti->tileh);
b261b6cb9b21 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8909
diff changeset
  1618
				image = 0;
b261b6cb9b21 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8909
diff changeset
  1619
			} else {
b261b6cb9b21 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8909
diff changeset
  1620
				image = SPR_FLAT_WATER_TILE;
b261b6cb9b21 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8909
diff changeset
  1621
			}
8267
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8266
diff changeset
  1622
		} else {
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8266
diff changeset
  1623
			switch (rgt) {
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8266
diff changeset
  1624
				case RAIL_GROUND_BARREN:     image = SPR_FLAT_BARE_LAND;  break;
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8266
diff changeset
  1625
				case RAIL_GROUND_ICE_DESERT: image = SPR_FLAT_SNOWY_TILE; break;
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8266
diff changeset
  1626
				default:                     image = SPR_FLAT_GRASS_TILE; break;
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8266
diff changeset
  1627
			}
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8266
diff changeset
  1628
			image += _tileh_to_sprite[ti->tileh];
8266
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
  1629
		}
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
  1630
	} else {
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
  1631
		if (ti->tileh != SLOPE_FLAT) {
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
  1632
			/* track on non-flat ground */
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
  1633
			image = _track_sloped_sprites[ti->tileh - 1] + rti->base_sprites.track_y;
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
  1634
		} else {
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
  1635
			/* track on flat ground */
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
  1636
			(image = rti->base_sprites.track_y, track == TRACK_BIT_Y) ||
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
  1637
			(image++,                           track == TRACK_BIT_X) ||
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
  1638
			(image++,                           track == TRACK_BIT_UPPER) ||
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
  1639
			(image++,                           track == TRACK_BIT_LOWER) ||
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
  1640
			(image++,                           track == TRACK_BIT_RIGHT) ||
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
  1641
			(image++,                           track == TRACK_BIT_LEFT) ||
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
  1642
			(image++,                           track == TRACK_BIT_CROSS) ||
2472
60c843b7ea28 (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
  1643
8266
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
  1644
			(image = rti->base_sprites.track_ns, track == TRACK_BIT_HORZ) ||
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
  1645
			(image++,                            track == TRACK_BIT_VERT) ||
2472
60c843b7ea28 (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
  1646
8266
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
  1647
			(junction = true, false) ||
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
  1648
			(image = rti->base_sprites.ground, (track & TRACK_BIT_3WAY_NE) == 0) ||
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
  1649
			(image++,                          (track & TRACK_BIT_3WAY_SW) == 0) ||
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
  1650
			(image++,                          (track & TRACK_BIT_3WAY_NW) == 0) ||
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
  1651
			(image++,                          (track & TRACK_BIT_3WAY_SE) == 0) ||
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
  1652
			(image++, true);
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
  1653
		}
2472
60c843b7ea28 (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
  1654
8266
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
  1655
		switch (rgt) {
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
  1656
			case RAIL_GROUND_BARREN:     pal = PALETTE_TO_BARE_LAND; break;
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
  1657
			case RAIL_GROUND_ICE_DESERT: image += rti->snow_offset;  break;
8910
b261b6cb9b21 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8909
diff changeset
  1658
			case RAIL_GROUND_WATER: {
b261b6cb9b21 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8909
diff changeset
  1659
				/* three-corner-raised slope */
b261b6cb9b21 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8909
diff changeset
  1660
				DrawShoreTile(ti->tileh);
b261b6cb9b21 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8909
diff changeset
  1661
				Corner track_corner = OppositeCorner(GetHighestSlopeCorner(ComplementSlope(ti->tileh)));
b261b6cb9b21 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8909
diff changeset
  1662
				sub = &(_halftile_sub_sprite[track_corner]);
b261b6cb9b21 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8909
diff changeset
  1663
				break;
b261b6cb9b21 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8909
diff changeset
  1664
			}
8266
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
  1665
			default: break;
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
  1666
		}
2472
60c843b7ea28 (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
  1667
	}
60c843b7ea28 (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
  1668
8910
b261b6cb9b21 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8909
diff changeset
  1669
	if (image != 0) DrawGroundSprite(image, pal, sub);
2472
60c843b7ea28 (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
  1670
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6902
diff changeset
  1671
	/* Draw track pieces individually for junction tiles */
2472
60c843b7ea28 (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
  1672
	if (junction) {
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5849
diff changeset
  1673
		if (track & TRACK_BIT_X)     DrawGroundSprite(rti->base_sprites.single_y, PAL_NONE);
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5849
diff changeset
  1674
		if (track & TRACK_BIT_Y)     DrawGroundSprite(rti->base_sprites.single_x, PAL_NONE);
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5849
diff changeset
  1675
		if (track & TRACK_BIT_UPPER) DrawGroundSprite(rti->base_sprites.single_n, PAL_NONE);
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5849
diff changeset
  1676
		if (track & TRACK_BIT_LOWER) DrawGroundSprite(rti->base_sprites.single_s, PAL_NONE);
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5849
diff changeset
  1677
		if (track & TRACK_BIT_LEFT)  DrawGroundSprite(rti->base_sprites.single_w, PAL_NONE);
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5849
diff changeset
  1678
		if (track & TRACK_BIT_RIGHT) DrawGroundSprite(rti->base_sprites.single_e, PAL_NONE);
2472
60c843b7ea28 (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
  1679
	}
8266
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
  1680
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
  1681
	if (IsValidCorner(halftile_corner)) {
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
  1682
		DrawFoundation(ti, HalftileFoundation(halftile_corner));
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
  1683
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
  1684
		/* Draw higher halftile-overlay: Use the sloped sprites with three corners raised. They probably best fit the lightning. */
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
  1685
		Slope fake_slope = SlopeWithThreeCornersRaised(OppositeCorner(halftile_corner));
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
  1686
		image = _track_sloped_sprites[fake_slope - 1] + rti->base_sprites.track_y;
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
  1687
		pal = PAL_NONE;
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
  1688
		switch (rgt) {
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
  1689
			case RAIL_GROUND_BARREN:     pal = PALETTE_TO_BARE_LAND; break;
9019
de364e5be143 (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: 9015
diff changeset
  1690
			case RAIL_GROUND_ICE_DESERT:
de364e5be143 (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: 9015
diff changeset
  1691
			case RAIL_GROUND_HALF_SNOW:  image += rti->snow_offset;  break; // higher part has snow in this case too
8266
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
  1692
			default: break;
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
  1693
		}
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
  1694
		DrawGroundSprite(image, pal, &(_halftile_sub_sprite[halftile_corner]));
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
  1695
	}
2472
60c843b7ea28 (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
  1696
}
60c843b7ea28 (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
  1697
9170
16054a687f70 (svn r12340) -Codechange: Remove some magic numbers (sprite IDs here) with some more meaningful values.
belugas
parents: 9165
diff changeset
  1698
/** Enums holding the offsets from base signal sprite,
16054a687f70 (svn r12340) -Codechange: Remove some magic numbers (sprite IDs here) with some more meaningful values.
belugas
parents: 9165
diff changeset
  1699
 * according to the side it is representing.
16054a687f70 (svn r12340) -Codechange: Remove some magic numbers (sprite IDs here) with some more meaningful values.
belugas
parents: 9165
diff changeset
  1700
 * The addtion of 2 per enum is necessary in order to "jump" over the
16054a687f70 (svn r12340) -Codechange: Remove some magic numbers (sprite IDs here) with some more meaningful values.
belugas
parents: 9165
diff changeset
  1701
 * green state sprite, all signal sprites being in pair,
16054a687f70 (svn r12340) -Codechange: Remove some magic numbers (sprite IDs here) with some more meaningful values.
belugas
parents: 9165
diff changeset
  1702
 * starting with the off-red state */
16054a687f70 (svn r12340) -Codechange: Remove some magic numbers (sprite IDs here) with some more meaningful values.
belugas
parents: 9165
diff changeset
  1703
enum {
9172
1d5899edc499 (svn r12342) -Fix(r12340): In order to avoid confusion, SIGN should be used for signs and SIGNAL for signals :)
belugas
parents: 9170
diff changeset
  1704
	SIGNAL_TO_SOUTHWEST =  0,
1d5899edc499 (svn r12342) -Fix(r12340): In order to avoid confusion, SIGN should be used for signs and SIGNAL for signals :)
belugas
parents: 9170
diff changeset
  1705
	SIGNAL_TO_NORTHEAST =  2,
1d5899edc499 (svn r12342) -Fix(r12340): In order to avoid confusion, SIGN should be used for signs and SIGNAL for signals :)
belugas
parents: 9170
diff changeset
  1706
	SIGNAL_TO_SOUTHEAST =  4,
1d5899edc499 (svn r12342) -Fix(r12340): In order to avoid confusion, SIGN should be used for signs and SIGNAL for signals :)
belugas
parents: 9170
diff changeset
  1707
	SIGNAL_TO_NORTHWEST =  6,
1d5899edc499 (svn r12342) -Fix(r12340): In order to avoid confusion, SIGN should be used for signs and SIGNAL for signals :)
belugas
parents: 9170
diff changeset
  1708
	SIGNAL_TO_EAST      =  8,
1d5899edc499 (svn r12342) -Fix(r12340): In order to avoid confusion, SIGN should be used for signs and SIGNAL for signals :)
belugas
parents: 9170
diff changeset
  1709
	SIGNAL_TO_WEST      = 10,
1d5899edc499 (svn r12342) -Fix(r12340): In order to avoid confusion, SIGN should be used for signs and SIGNAL for signals :)
belugas
parents: 9170
diff changeset
  1710
	SIGNAL_TO_SOUTH     = 12,
1d5899edc499 (svn r12342) -Fix(r12340): In order to avoid confusion, SIGN should be used for signs and SIGNAL for signals :)
belugas
parents: 9170
diff changeset
  1711
	SIGNAL_TO_NORTH     = 14,
9170
16054a687f70 (svn r12340) -Codechange: Remove some magic numbers (sprite IDs here) with some more meaningful values.
belugas
parents: 9165
diff changeset
  1712
};
16054a687f70 (svn r12340) -Codechange: Remove some magic numbers (sprite IDs here) with some more meaningful values.
belugas
parents: 9165
diff changeset
  1713
3519
22391e5d1bbf (svn r4375) -Codechange: Move the signal drawing bit to an own function and rename DrawSignalHelper to DrawSingleSignal
celestar
parents: 3507
diff changeset
  1714
static void DrawSignals(TileIndex tile, TrackBits rails)
22391e5d1bbf (svn r4375) -Codechange: Move the signal drawing bit to an own function and rename DrawSignalHelper to DrawSingleSignal
celestar
parents: 3507
diff changeset
  1715
{
9170
16054a687f70 (svn r12340) -Codechange: Remove some magic numbers (sprite IDs here) with some more meaningful values.
belugas
parents: 9165
diff changeset
  1716
#define MAYBE_DRAW_SIGNAL(x,y,z,t) if (IsSignalPresent(tile, x)) DrawSingleSignal(tile, t, GetSingleSignalState(tile, x), y, z)
3519
22391e5d1bbf (svn r4375) -Codechange: Move the signal drawing bit to an own function and rename DrawSignalHelper to DrawSingleSignal
celestar
parents: 3507
diff changeset
  1717
22391e5d1bbf (svn r4375) -Codechange: Move the signal drawing bit to an own function and rename DrawSignalHelper to DrawSingleSignal
celestar
parents: 3507
diff changeset
  1718
	if (!(rails & TRACK_BIT_Y)) {
22391e5d1bbf (svn r4375) -Codechange: Move the signal drawing bit to an own function and rename DrawSignalHelper to DrawSingleSignal
celestar
parents: 3507
diff changeset
  1719
		if (!(rails & TRACK_BIT_X)) {
22391e5d1bbf (svn r4375) -Codechange: Move the signal drawing bit to an own function and rename DrawSignalHelper to DrawSingleSignal
celestar
parents: 3507
diff changeset
  1720
			if (rails & TRACK_BIT_LEFT) {
9172
1d5899edc499 (svn r12342) -Fix(r12340): In order to avoid confusion, SIGN should be used for signs and SIGNAL for signals :)
belugas
parents: 9170
diff changeset
  1721
				MAYBE_DRAW_SIGNAL(2, SIGNAL_TO_NORTH, 0, TRACK_LEFT);
1d5899edc499 (svn r12342) -Fix(r12340): In order to avoid confusion, SIGN should be used for signs and SIGNAL for signals :)
belugas
parents: 9170
diff changeset
  1722
				MAYBE_DRAW_SIGNAL(3, SIGNAL_TO_SOUTH, 1, TRACK_LEFT);
3519
22391e5d1bbf (svn r4375) -Codechange: Move the signal drawing bit to an own function and rename DrawSignalHelper to DrawSingleSignal
celestar
parents: 3507
diff changeset
  1723
			}
22391e5d1bbf (svn r4375) -Codechange: Move the signal drawing bit to an own function and rename DrawSignalHelper to DrawSingleSignal
celestar
parents: 3507
diff changeset
  1724
			if (rails & TRACK_BIT_RIGHT) {
9172
1d5899edc499 (svn r12342) -Fix(r12340): In order to avoid confusion, SIGN should be used for signs and SIGNAL for signals :)
belugas
parents: 9170
diff changeset
  1725
				MAYBE_DRAW_SIGNAL(0, SIGNAL_TO_NORTH, 2, TRACK_RIGHT);
1d5899edc499 (svn r12342) -Fix(r12340): In order to avoid confusion, SIGN should be used for signs and SIGNAL for signals :)
belugas
parents: 9170
diff changeset
  1726
				MAYBE_DRAW_SIGNAL(1, SIGNAL_TO_SOUTH, 3, TRACK_RIGHT);
3519
22391e5d1bbf (svn r4375) -Codechange: Move the signal drawing bit to an own function and rename DrawSignalHelper to DrawSingleSignal
celestar
parents: 3507
diff changeset
  1727
			}
22391e5d1bbf (svn r4375) -Codechange: Move the signal drawing bit to an own function and rename DrawSignalHelper to DrawSingleSignal
celestar
parents: 3507
diff changeset
  1728
			if (rails & TRACK_BIT_UPPER) {
9172
1d5899edc499 (svn r12342) -Fix(r12340): In order to avoid confusion, SIGN should be used for signs and SIGNAL for signals :)
belugas
parents: 9170
diff changeset
  1729
				MAYBE_DRAW_SIGNAL(3, SIGNAL_TO_WEST, 4, TRACK_UPPER);
1d5899edc499 (svn r12342) -Fix(r12340): In order to avoid confusion, SIGN should be used for signs and SIGNAL for signals :)
belugas
parents: 9170
diff changeset
  1730
				MAYBE_DRAW_SIGNAL(2, SIGNAL_TO_EAST, 5, TRACK_UPPER);
3519
22391e5d1bbf (svn r4375) -Codechange: Move the signal drawing bit to an own function and rename DrawSignalHelper to DrawSingleSignal
celestar
parents: 3507
diff changeset
  1731
			}
22391e5d1bbf (svn r4375) -Codechange: Move the signal drawing bit to an own function and rename DrawSignalHelper to DrawSingleSignal
celestar
parents: 3507
diff changeset
  1732
			if (rails & TRACK_BIT_LOWER) {
9172
1d5899edc499 (svn r12342) -Fix(r12340): In order to avoid confusion, SIGN should be used for signs and SIGNAL for signals :)
belugas
parents: 9170
diff changeset
  1733
				MAYBE_DRAW_SIGNAL(1, SIGNAL_TO_WEST, 6, TRACK_LOWER);
1d5899edc499 (svn r12342) -Fix(r12340): In order to avoid confusion, SIGN should be used for signs and SIGNAL for signals :)
belugas
parents: 9170
diff changeset
  1734
				MAYBE_DRAW_SIGNAL(0, SIGNAL_TO_EAST, 7, TRACK_LOWER);
3519
22391e5d1bbf (svn r4375) -Codechange: Move the signal drawing bit to an own function and rename DrawSignalHelper to DrawSingleSignal
celestar
parents: 3507
diff changeset
  1735
			}
22391e5d1bbf (svn r4375) -Codechange: Move the signal drawing bit to an own function and rename DrawSignalHelper to DrawSingleSignal
celestar
parents: 3507
diff changeset
  1736
		} else {
9172
1d5899edc499 (svn r12342) -Fix(r12340): In order to avoid confusion, SIGN should be used for signs and SIGNAL for signals :)
belugas
parents: 9170
diff changeset
  1737
			MAYBE_DRAW_SIGNAL(3, SIGNAL_TO_SOUTHWEST, 8, TRACK_X);
1d5899edc499 (svn r12342) -Fix(r12340): In order to avoid confusion, SIGN should be used for signs and SIGNAL for signals :)
belugas
parents: 9170
diff changeset
  1738
			MAYBE_DRAW_SIGNAL(2, SIGNAL_TO_NORTHEAST, 9, TRACK_X);
3519
22391e5d1bbf (svn r4375) -Codechange: Move the signal drawing bit to an own function and rename DrawSignalHelper to DrawSingleSignal
celestar
parents: 3507
diff changeset
  1739
		}
22391e5d1bbf (svn r4375) -Codechange: Move the signal drawing bit to an own function and rename DrawSignalHelper to DrawSingleSignal
celestar
parents: 3507
diff changeset
  1740
	} else {
9172
1d5899edc499 (svn r12342) -Fix(r12340): In order to avoid confusion, SIGN should be used for signs and SIGNAL for signals :)
belugas
parents: 9170
diff changeset
  1741
		MAYBE_DRAW_SIGNAL(3, SIGNAL_TO_SOUTHEAST, 10, TRACK_Y);
1d5899edc499 (svn r12342) -Fix(r12340): In order to avoid confusion, SIGN should be used for signs and SIGNAL for signals :)
belugas
parents: 9170
diff changeset
  1742
		MAYBE_DRAW_SIGNAL(2, SIGNAL_TO_NORTHWEST, 11, TRACK_Y);
3519
22391e5d1bbf (svn r4375) -Codechange: Move the signal drawing bit to an own function and rename DrawSignalHelper to DrawSingleSignal
celestar
parents: 3507
diff changeset
  1743
	}
22391e5d1bbf (svn r4375) -Codechange: Move the signal drawing bit to an own function and rename DrawSignalHelper to DrawSingleSignal
celestar
parents: 3507
diff changeset
  1744
}
22391e5d1bbf (svn r4375) -Codechange: Move the signal drawing bit to an own function and rename DrawSignalHelper to DrawSingleSignal
celestar
parents: 3507
diff changeset
  1745
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1746
static void DrawTile_Track(TileInfo *ti)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1747
{
2233
146e2e405ec1 (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
  1748
	const RailtypeInfo *rti = GetRailTypeInfo(GetRailType(ti->tile));
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5849
diff changeset
  1749
	SpriteID image;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1750
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5849
diff changeset
  1751
	_drawtile_track_palette = PLAYER_SPRITE_COLOR(GetTileOwner(ti->tile));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1752
4182
20d711816338 (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
  1753
	if (IsPlainRailTile(ti->tile)) {
3267
591027d10884 (svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents: 3265
diff changeset
  1754
		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
  1755
4081
8d4111a68f72 (svn r5396) - Remove two fixed parameters
tron
parents: 4077
diff changeset
  1756
		DrawTrackBits(ti, rails);
2008
c9d6585c96c8 (svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents: 2007
diff changeset
  1757
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8378
diff changeset
  1758
		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
  1759
7539
eea0981e7f1a (svn r10308) -Codechange: some "cleanup" chunks from B. N. SmatZ!' work on fixing FS#119.
rubidium
parents: 7486
diff changeset
  1760
		if (GetRailType(ti->tile) == RAILTYPE_ELECTRIC) DrawCatenary(ti);
eea0981e7f1a (svn r10308) -Codechange: some "cleanup" chunks from B. N. SmatZ!' work on fixing FS#119.
rubidium
parents: 7486
diff changeset
  1761
4182
20d711816338 (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
  1762
		if (HasSignals(ti->tile)) DrawSignals(ti->tile, rails);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1763
	} else {
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6902
diff changeset
  1764
		/* draw depot/waypoint */
4225
a14f76451e03 (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  1765
		const DrawTileSprites* dts;
a14f76451e03 (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  1766
		const DrawTileSeqStruct* dtss;
a14f76451e03 (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  1767
		uint32 relocation;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1768
7831
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7829
diff changeset
  1769
		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
  1770
6498
aff910a05c6e (svn r8935) -Codechange: unification of track type between road and rail tiles, unification of ground type between normal rail tiles and depots/waypoints and removing the need for RailTileSubType.
rubidium
parents: 6486
diff changeset
  1771
		if (IsRailDepot(ti->tile)) {
4225
a14f76451e03 (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  1772
			dts = &_depot_gfx_table[GetRailDepotDirection(ti->tile)];
a14f76451e03 (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  1773
a14f76451e03 (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  1774
			relocation = rti->total_offset;
a14f76451e03 (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  1775
9067
88f2bc991236 (svn r12149) -Codechange: Merge 'ground_sprite' and 'ground_pal' of DrawTileSprites into one PalSpriteID
frosch
parents: 9066
diff changeset
  1776
			image = dts->ground.sprite;
4225
a14f76451e03 (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  1777
			if (image != SPR_FLAT_GRASS_TILE) image += rti->total_offset;
a14f76451e03 (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  1778
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6902
diff changeset
  1779
			/* adjust ground tile for desert
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6902
diff changeset
  1780
			 * don't adjust for snow, because snow in depots looks weird */
6683
7ec558346172 (svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents: 6669
diff changeset
  1781
			if (IsSnowRailGround(ti->tile) && _opt.landscape == LT_TROPIC) {
4225
a14f76451e03 (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  1782
				if (image != SPR_FLAT_GRASS_TILE) {
a14f76451e03 (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  1783
					image += rti->snow_offset; // tile with tracks
a14f76451e03 (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  1784
				} else {
a14f76451e03 (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  1785
					image = SPR_FLAT_SNOWY_TILE; // flat ground
a14f76451e03 (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  1786
				}
a14f76451e03 (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  1787
			}
a14f76451e03 (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  1788
		} else {
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6902
diff changeset
  1789
			/* look for customization */
2670
34970983ef08 (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
  1790
			byte stat_id = GetWaypointByTile(ti->tile)->stat_id;
3676
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3671
diff changeset
  1791
			const StationSpec *statspec = GetCustomStationSpec(STAT_CLASS_WAYP, stat_id);
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 337
diff changeset
  1792
3676
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3671
diff changeset
  1793
			if (statspec != NULL) {
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6902
diff changeset
  1794
				/* emulate station tile - open with building */
4225
a14f76451e03 (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  1795
				const Station* st = ComposeWaypointStation(ti->tile);
a14f76451e03 (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  1796
				uint gfx = 2;
3757
a0bba34a94ba (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
  1797
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8378
diff changeset
  1798
				if (HasBit(statspec->callbackmask, CBM_STATION_SPRITE_LAYOUT)) {
3757
a0bba34a94ba (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
  1799
					uint16 callback = GetStationCallback(CBID_STATION_SPRITE_LAYOUT, 0, 0, statspec, st, ti->tile);
4225
a14f76451e03 (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  1800
					if (callback != CALLBACK_FAILED) gfx = callback;
3757
a0bba34a94ba (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
  1801
				}
a0bba34a94ba (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
  1802
3763
460bbb4a8154 (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
  1803
				if (statspec->renderdata == NULL) {
7768
2060e8d65a72 (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7659
diff changeset
  1804
					dts = GetStationTileLayout(STATION_RAIL, gfx);
3763
460bbb4a8154 (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
  1805
				} else {
4225
a14f76451e03 (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  1806
					dts = &statspec->renderdata[(gfx < statspec->tiles ? gfx : 0) + GetWaypointAxis(ti->tile)];
3763
460bbb4a8154 (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
  1807
				}
447
aaf1f59a8957 (svn r657) Do not touch 0x8000 bit in sprite index for custom waypoints. (pasky)
celestar
parents: 438
diff changeset
  1808
4225
a14f76451e03 (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  1809
				if (dts != NULL && dts->seq != NULL) {
a14f76451e03 (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  1810
					relocation = GetCustomStationRelocation(statspec, st, ti->tile);
a14f76451e03 (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  1811
9067
88f2bc991236 (svn r12149) -Codechange: Merge 'ground_sprite' and 'ground_pal' of DrawTileSprites into one PalSpriteID
frosch
parents: 9066
diff changeset
  1812
					image = dts->ground.sprite;
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8378
diff changeset
  1813
					if (HasBit(image, SPRITE_MODIFIER_USE_OFFSET)) {
3775
f3f1ba3111fa (svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents: 3763
diff changeset
  1814
						image += GetCustomStationGroundRelocation(statspec, st, ti->tile);
f3f1ba3111fa (svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents: 3763
diff changeset
  1815
						image += rti->custom_ground_offset;
f3f1ba3111fa (svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents: 3763
diff changeset
  1816
					} else {
f3f1ba3111fa (svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents: 3763
diff changeset
  1817
						image += rti->total_offset;
f3f1ba3111fa (svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents: 3763
diff changeset
  1818
					}
4225
a14f76451e03 (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  1819
				} else {
a14f76451e03 (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  1820
					goto default_waypoint;
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 337
diff changeset
  1821
				}
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1822
			} else {
4225
a14f76451e03 (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  1823
default_waypoint:
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6902
diff changeset
  1824
				/* There is no custom layout, fall back to the default graphics */
4225
a14f76451e03 (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  1825
				dts = &_waypoint_gfx_table[GetWaypointAxis(ti->tile)];
a14f76451e03 (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  1826
				relocation = 0;
9067
88f2bc991236 (svn r12149) -Codechange: Merge 'ground_sprite' and 'ground_pal' of DrawTileSprites into one PalSpriteID
frosch
parents: 9066
diff changeset
  1827
				image = dts->ground.sprite + rti->total_offset;
4225
a14f76451e03 (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  1828
				if (IsSnowRailGround(ti->tile)) image += rti->snow_offset;
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1829
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1830
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1831
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5849
diff changeset
  1832
		DrawGroundSprite(image, PAL_NONE);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1833
3355
a653b8e47f27 (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
  1834
		if (GetRailType(ti->tile) == RAILTYPE_ELECTRIC) DrawCatenary(ti);
a653b8e47f27 (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
  1835
4225
a14f76451e03 (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  1836
		foreach_draw_tile_seq(dtss, dts->seq) {
9066
29d5a0dfc329 (svn r12148) -Codechange: Merge 'image' and 'pal' of DrawTileSeqStruct into one PalSpriteID
frosch
parents: 9063
diff changeset
  1837
			SpriteID image = dtss->image.sprite;
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5849
diff changeset
  1838
			SpriteID pal;
4225
a14f76451e03 (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  1839
5989
88540735bad4 (svn r8283) -Fix (r8128): Custom waypoint drawing used wrong bits since bitshuffling occurred. Also update with other station drawing changes (code duplication,
peter1138
parents: 5986
diff changeset
  1840
			/* Unlike stations, our default waypoint has no variation for
88540735bad4 (svn r8283) -Fix (r8128): Custom waypoint drawing used wrong bits since bitshuffling occurred. Also update with other station drawing changes (code duplication,
peter1138
parents: 5986
diff changeset
  1841
			 * different railtype, so don't use the railtype offset if
88540735bad4 (svn r8283) -Fix (r8128): Custom waypoint drawing used wrong bits since bitshuffling occurred. Also update with other station drawing changes (code duplication,
peter1138
parents: 5986
diff changeset
  1842
			 * no relocation is set */
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8378
diff changeset
  1843
			if (HasBit(image, SPRITE_MODIFIER_USE_OFFSET)) {
5989
88540735bad4 (svn r8283) -Fix (r8128): Custom waypoint drawing used wrong bits since bitshuffling occurred. Also update with other station drawing changes (code duplication,
peter1138
parents: 5986
diff changeset
  1844
				image += rti->total_offset;
88540735bad4 (svn r8283) -Fix (r8128): Custom waypoint drawing used wrong bits since bitshuffling occurred. Also update with other station drawing changes (code duplication,
peter1138
parents: 5986
diff changeset
  1845
			} else {
88540735bad4 (svn r8283) -Fix (r8128): Custom waypoint drawing used wrong bits since bitshuffling occurred. Also update with other station drawing changes (code duplication,
peter1138
parents: 5986
diff changeset
  1846
				image += relocation;
88540735bad4 (svn r8283) -Fix (r8128): Custom waypoint drawing used wrong bits since bitshuffling occurred. Also update with other station drawing changes (code duplication,
peter1138
parents: 5986
diff changeset
  1847
			}
88540735bad4 (svn r8283) -Fix (r8128): Custom waypoint drawing used wrong bits since bitshuffling occurred. Also update with other station drawing changes (code duplication,
peter1138
parents: 5986
diff changeset
  1848
8654
83dc418497a9 (svn r11720) -Codechange: [NewGRF] Add support for bit 30 of station tile layouts; forcing a sprite to always be opaque.
peter1138
parents: 8653
diff changeset
  1849
			if (!(!HasBit(image, SPRITE_MODIFIER_OPAQUE) && IsTransparencySet(TO_BUILDINGS)) && HasBit(image, PALETTE_MODIFIER_COLOR)) {
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5849
diff changeset
  1850
				pal = _drawtile_track_palette;
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5849
diff changeset
  1851
			} else {
9066
29d5a0dfc329 (svn r12148) -Codechange: Merge 'image' and 'pal' of DrawTileSeqStruct into one PalSpriteID
frosch
parents: 9063
diff changeset
  1852
				pal = dtss->image.pal;
4225
a14f76451e03 (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  1853
			}
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5849
diff changeset
  1854
5989
88540735bad4 (svn r8283) -Fix (r8128): Custom waypoint drawing used wrong bits since bitshuffling occurred. Also update with other station drawing changes (code duplication,
peter1138
parents: 5986
diff changeset
  1855
			if ((byte)dtss->delta_z != 0x80) {
88540735bad4 (svn r8283) -Fix (r8128): Custom waypoint drawing used wrong bits since bitshuffling occurred. Also update with other station drawing changes (code duplication,
peter1138
parents: 5986
diff changeset
  1856
				AddSortableSpriteToDraw(
88540735bad4 (svn r8283) -Fix (r8128): Custom waypoint drawing used wrong bits since bitshuffling occurred. Also update with other station drawing changes (code duplication,
peter1138
parents: 5986
diff changeset
  1857
					image, pal,
88540735bad4 (svn r8283) -Fix (r8128): Custom waypoint drawing used wrong bits since bitshuffling occurred. Also update with other station drawing changes (code duplication,
peter1138
parents: 5986
diff changeset
  1858
					ti->x + dtss->delta_x, ti->y + dtss->delta_y,
88540735bad4 (svn r8283) -Fix (r8128): Custom waypoint drawing used wrong bits since bitshuffling occurred. Also update with other station drawing changes (code duplication,
peter1138
parents: 5986
diff changeset
  1859
					dtss->size_x, dtss->size_y,
7829
88883899c9e6 (svn r10696) -Codechange: remove duplication of the "make sprite transparent" code.
rubidium
parents: 7803
diff changeset
  1860
					dtss->size_z, ti->z + dtss->delta_z,
8654
83dc418497a9 (svn r11720) -Codechange: [NewGRF] Add support for bit 30 of station tile layouts; forcing a sprite to always be opaque.
peter1138
parents: 8653
diff changeset
  1861
					!HasBit(image, SPRITE_MODIFIER_OPAQUE) && IsTransparencySet(TO_BUILDINGS)
5989
88540735bad4 (svn r8283) -Fix (r8128): Custom waypoint drawing used wrong bits since bitshuffling occurred. Also update with other station drawing changes (code duplication,
peter1138
parents: 5986
diff changeset
  1862
				);
88540735bad4 (svn r8283) -Fix (r8128): Custom waypoint drawing used wrong bits since bitshuffling occurred. Also update with other station drawing changes (code duplication,
peter1138
parents: 5986
diff changeset
  1863
			} else {
88540735bad4 (svn r8283) -Fix (r8128): Custom waypoint drawing used wrong bits since bitshuffling occurred. Also update with other station drawing changes (code duplication,
peter1138
parents: 5986
diff changeset
  1864
				AddChildSpriteScreen(image, pal, dtss->delta_x, dtss->delta_y);
88540735bad4 (svn r8283) -Fix (r8128): Custom waypoint drawing used wrong bits since bitshuffling occurred. Also update with other station drawing changes (code duplication,
peter1138
parents: 5986
diff changeset
  1865
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1866
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1867
	}
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5568
diff changeset
  1868
	DrawBridgeMiddle(ti);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1869
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1870
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1871
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5849
diff changeset
  1872
static void DrawTileSequence(int x, int y, SpriteID ground, const DrawTileSeqStruct* dtss, uint32 offset)
4225
a14f76451e03 (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  1873
{
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5849
diff changeset
  1874
	SpriteID palette = PLAYER_SPRITE_COLOR(_local_player);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1875
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5849
diff changeset
  1876
	DrawSprite(ground, PAL_NONE, x, y);
9066
29d5a0dfc329 (svn r12148) -Codechange: Merge 'image' and 'pal' of DrawTileSeqStruct into one PalSpriteID
frosch
parents: 9063
diff changeset
  1877
	for (; dtss->image.sprite != 0; dtss++) {
4225
a14f76451e03 (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  1878
		Point pt = RemapCoords(dtss->delta_x, dtss->delta_y, dtss->delta_z);
9066
29d5a0dfc329 (svn r12148) -Codechange: Merge 'image' and 'pal' of DrawTileSeqStruct into one PalSpriteID
frosch
parents: 9063
diff changeset
  1879
		SpriteID image = dtss->image.sprite + offset;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1880
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8378
diff changeset
  1881
		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
  1882
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1883
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1884
4225
a14f76451e03 (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  1885
void DrawTrainDepotSprite(int x, int y, int dir, RailType railtype)
a14f76451e03 (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  1886
{
a14f76451e03 (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  1887
	const DrawTileSprites* dts = &_depot_gfx_table[dir];
9067
88f2bc991236 (svn r12149) -Codechange: Merge 'ground_sprite' and 'ground_pal' of DrawTileSprites into one PalSpriteID
frosch
parents: 9066
diff changeset
  1888
	SpriteID image = dts->ground.sprite;
4225
a14f76451e03 (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  1889
	uint32 offset = GetRailTypeInfo(railtype)->total_offset;
a14f76451e03 (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  1890
a14f76451e03 (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  1891
	if (image != SPR_FLAT_GRASS_TILE) image += offset;
a14f76451e03 (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  1892
	DrawTileSequence(x + 33, y + 17, image, dts->seq, offset);
a14f76451e03 (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  1893
}
a14f76451e03 (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  1894
2520
75eb66d6e371 (svn r3049) Replace byte/int/uint by RailType where appropriate
tron
parents: 2502
diff changeset
  1895
void DrawDefaultWaypointSprite(int x, int y, RailType railtype)
2261
3f78323707bb (svn r2781) Fix some of the issues with variables in .h files.
ludde
parents: 2254
diff changeset
  1896
{
4225
a14f76451e03 (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  1897
	uint32 offset = GetRailTypeInfo(railtype)->total_offset;
a14f76451e03 (svn r5771) Unify several code paths and data structures for drawing train depots and waypoints
tron
parents: 4182
diff changeset
  1898
	const DrawTileSprites* dts = &_waypoint_gfx_table[AXIS_X];
2261
3f78323707bb (svn r2781) Fix some of the issues with variables in .h files.
ludde
parents: 2254
diff changeset
  1899
9067
88f2bc991236 (svn r12149) -Codechange: Merge 'ground_sprite' and 'ground_pal' of DrawTileSprites into one PalSpriteID
frosch
parents: 9066
diff changeset
  1900
	DrawTileSequence(x, y, dts->ground.sprite + offset, dts->seq, 0);
2261
3f78323707bb (svn r2781) Fix some of the issues with variables in .h files.
ludde
parents: 2254
diff changeset
  1901
}
3f78323707bb (svn r2781) Fix some of the issues with variables in .h files.
ludde
parents: 2254
diff changeset
  1902
4231
dea6a63dd058 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4230
diff changeset
  1903
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
  1904
{
4231
dea6a63dd058 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4230
diff changeset
  1905
	uint z;
dea6a63dd058 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4230
diff changeset
  1906
	Slope tileh = GetTileSlope(tile, &z);
2951
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2934
diff changeset
  1907
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3575
diff changeset
  1908
	if (tileh == SLOPE_FLAT) return z;
4231
dea6a63dd058 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4230
diff changeset
  1909
	if (IsPlainRailTile(tile)) {
7831
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7829
diff changeset
  1910
		z += ApplyFoundationToSlope(GetRailFoundation(tileh, GetTrackBits(tile)), &tileh);
4231
dea6a63dd058 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4230
diff changeset
  1911
		return z + GetPartialZ(x & 0xF, y & 0xF, tileh);
4182
20d711816338 (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
  1912
	} else {
20d711816338 (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
  1913
		return z + TILE_HEIGHT;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1914
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1915
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1916
7831
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7829
diff changeset
  1917
static Foundation GetFoundation_Track(TileIndex tile, Slope tileh)
39
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 22
diff changeset
  1918
{
7831
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7829
diff changeset
  1919
	return IsPlainRailTile(tile) ? GetRailFoundation(tileh, GetTrackBits(tile)) : FlatteningFoundation(tileh);
39
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 22
diff changeset
  1920
}
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 22
diff changeset
  1921
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1963
diff changeset
  1922
static void GetAcceptedCargo_Track(TileIndex tile, AcceptedCargo ac)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1923
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1924
	/* not used */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1925
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1926
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1963
diff changeset
  1927
static void AnimateTile_Track(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1928
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1929
	/* not used */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1930
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1931
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1963
diff changeset
  1932
static void TileLoop_Track(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1933
{
3523
168ee460418b (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
  1934
	RailGroundType old_ground = GetRailGroundType(tile);
4483
939db99bddb9 (svn r6268) Remove now pointless assignment (followup of r6267)
tron
parents: 4482
diff changeset
  1935
	RailGroundType new_ground;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1936
8267
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8266
diff changeset
  1937
	if (old_ground == RAIL_GROUND_WATER) {
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8266
diff changeset
  1938
		TileLoop_Water(tile);
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8266
diff changeset
  1939
		return;
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8266
diff changeset
  1940
	}
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8266
diff changeset
  1941
2631
13daba67f217 (svn r3173) Use the trinary operator and switch to improve readability
tron
parents: 2626
diff changeset
  1942
	switch (_opt.landscape) {
9019
de364e5be143 (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: 9015
diff changeset
  1943
		case LT_ARCTIC: {
de364e5be143 (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: 9015
diff changeset
  1944
			uint z;
de364e5be143 (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: 9015
diff changeset
  1945
			Slope slope = GetTileSlope(tile, &z);
de364e5be143 (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: 9015
diff changeset
  1946
			bool half = false;
de364e5be143 (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: 9015
diff changeset
  1947
de364e5be143 (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: 9015
diff changeset
  1948
			/* for non-flat track, use lower part of track
de364e5be143 (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: 9015
diff changeset
  1949
			 * in other cases, use the highest part with track */
de364e5be143 (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: 9015
diff changeset
  1950
			if (IsPlainRailTile(tile)) {
de364e5be143 (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: 9015
diff changeset
  1951
				TrackBits track = GetTrackBits(tile);
de364e5be143 (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: 9015
diff changeset
  1952
				Foundation f = GetRailFoundation(slope, track);
de364e5be143 (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: 9015
diff changeset
  1953
de364e5be143 (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: 9015
diff changeset
  1954
				switch (f) {
de364e5be143 (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: 9015
diff changeset
  1955
					case FOUNDATION_NONE:
de364e5be143 (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: 9015
diff changeset
  1956
						/* no foundation - is the track on the upper side of three corners raised tile? */
de364e5be143 (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: 9015
diff changeset
  1957
						if (IsSlopeWithThreeCornersRaised(slope)) z += TILE_HEIGHT;
de364e5be143 (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: 9015
diff changeset
  1958
						break;
de364e5be143 (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: 9015
diff changeset
  1959
de364e5be143 (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: 9015
diff changeset
  1960
					case FOUNDATION_INCLINED_X:
de364e5be143 (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: 9015
diff changeset
  1961
					case FOUNDATION_INCLINED_Y:
de364e5be143 (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: 9015
diff changeset
  1962
						/* sloped track - is it on a steep slope? */
de364e5be143 (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: 9015
diff changeset
  1963
						if (IsSteepSlope(slope)) z += TILE_HEIGHT;
de364e5be143 (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: 9015
diff changeset
  1964
						break;
de364e5be143 (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: 9015
diff changeset
  1965
de364e5be143 (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: 9015
diff changeset
  1966
					case FOUNDATION_STEEP_LOWER:
de364e5be143 (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: 9015
diff changeset
  1967
						/* only lower part of steep slope */
de364e5be143 (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: 9015
diff changeset
  1968
						z += TILE_HEIGHT;
de364e5be143 (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: 9015
diff changeset
  1969
						break;
de364e5be143 (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: 9015
diff changeset
  1970
de364e5be143 (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: 9015
diff changeset
  1971
					default:
de364e5be143 (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: 9015
diff changeset
  1972
						/* if it is a steep slope, then there is a track on higher part */
de364e5be143 (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: 9015
diff changeset
  1973
						if (IsSteepSlope(slope)) z += TILE_HEIGHT;
de364e5be143 (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: 9015
diff changeset
  1974
						z += TILE_HEIGHT;
de364e5be143 (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: 9015
diff changeset
  1975
						break;
de364e5be143 (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: 9015
diff changeset
  1976
				}
de364e5be143 (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: 9015
diff changeset
  1977
de364e5be143 (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: 9015
diff changeset
  1978
				half = IsInsideMM(f, FOUNDATION_STEEP_BOTH, FOUNDATION_HALFTILE_N + 1);
de364e5be143 (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: 9015
diff changeset
  1979
			} else {
de364e5be143 (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: 9015
diff changeset
  1980
				/* is the depot on a non-flat tile? */
de364e5be143 (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: 9015
diff changeset
  1981
				if (slope != SLOPE_FLAT) z += TILE_HEIGHT;
de364e5be143 (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: 9015
diff changeset
  1982
			}
de364e5be143 (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: 9015
diff changeset
  1983
de364e5be143 (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: 9015
diff changeset
  1984
			/* 'z' is now the lowest part of the highest track bit -
de364e5be143 (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: 9015
diff changeset
  1985
			 * for sloped track, it is 'z' of lower part
de364e5be143 (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: 9015
diff changeset
  1986
			 * for two track bits, it is 'z' of higher track bit
de364e5be143 (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: 9015
diff changeset
  1987
			 * For non-continuous foundations (and STEEP_BOTH), 'half' is set */
de364e5be143 (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: 9015
diff changeset
  1988
			if (z > GetSnowLine()) {
de364e5be143 (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: 9015
diff changeset
  1989
				if (half && z - GetSnowLine() == TILE_HEIGHT) {
de364e5be143 (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: 9015
diff changeset
  1990
					/* track on non-continuous foundation, lower part is not under snow */
de364e5be143 (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: 9015
diff changeset
  1991
					new_ground = RAIL_GROUND_HALF_SNOW;
de364e5be143 (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: 9015
diff changeset
  1992
				} else {
de364e5be143 (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: 9015
diff changeset
  1993
					new_ground = RAIL_GROUND_ICE_DESERT;
de364e5be143 (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: 9015
diff changeset
  1994
				}
4482
4532293483d6 (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
  1995
				goto set_ground;
3562
c308f20e8388 (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
  1996
			}
2631
13daba67f217 (svn r3173) Use the trinary operator and switch to improve readability
tron
parents: 2626
diff changeset
  1997
			break;
9019
de364e5be143 (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: 9015
diff changeset
  1998
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1999
6683
7ec558346172 (svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents: 6669
diff changeset
  2000
		case LT_TROPIC:
3562
c308f20e8388 (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
  2001
			if (GetTropicZone(tile) == TROPICZONE_DESERT) {
c308f20e8388 (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
  2002
				new_ground = RAIL_GROUND_ICE_DESERT;
4482
4532293483d6 (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
  2003
				goto set_ground;
3562
c308f20e8388 (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
  2004
			}
3523
168ee460418b (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
  2005
			break;
168ee460418b (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
  2006
	}
168ee460418b (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
  2007
4182
20d711816338 (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
  2008
	if (!IsPlainRailTile(tile)) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2009
3523
168ee460418b (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
  2010
	new_ground = RAIL_GROUND_GRASS;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2011
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6902
diff changeset
  2012
	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
  2013
		/* determine direction of fence */
3267
591027d10884 (svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents: 3265
diff changeset
  2014
		TrackBits rail = GetTrackBits(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2015
2839
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2016
		switch (rail) {
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2017
			case TRACK_BIT_UPPER: new_ground = RAIL_GROUND_FENCE_HORIZ1; break;
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2018
			case TRACK_BIT_LOWER: new_ground = RAIL_GROUND_FENCE_HORIZ2; break;
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2019
			case TRACK_BIT_LEFT:  new_ground = RAIL_GROUND_FENCE_VERT1;  break;
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2020
			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
  2021
2839
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2022
			default: {
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2023
				PlayerID owner = GetTileOwner(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2024
2839
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2025
				if (rail == (TRACK_BIT_LOWER | TRACK_BIT_RIGHT) || (
3258
94a915e7485f (svn r3946) Add short hand names for common track combinations
tron
parents: 3254
diff changeset
  2026
							(rail & TRACK_BIT_3WAY_NW) == 0 &&
3102
fde95020fc8e (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
  2027
							(rail & TRACK_BIT_X)
2839
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2028
						)) {
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2029
					TileIndex n = tile + TileDiffXY(0, -1);
3524
be2b44204623 (svn r4380) -Codechange: Make use of GetTrackBits where appropriate
celestar
parents: 3523
diff changeset
  2030
					TrackBits nrail = GetTrackBits(n);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2031
2839
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2032
					if (!IsTileType(n, MP_RAILWAY) ||
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2033
							!IsTileOwner(n, owner) ||
3524
be2b44204623 (svn r4380) -Codechange: Make use of GetTrackBits where appropriate
celestar
parents: 3523
diff changeset
  2034
							nrail == TRACK_BIT_UPPER ||
be2b44204623 (svn r4380) -Codechange: Make use of GetTrackBits where appropriate
celestar
parents: 3523
diff changeset
  2035
							nrail == TRACK_BIT_LEFT) {
2839
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2036
						new_ground = RAIL_GROUND_FENCE_NW;
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2037
					}
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2038
				}
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2039
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2040
				if (rail == (TRACK_BIT_UPPER | TRACK_BIT_LEFT) || (
3258
94a915e7485f (svn r3946) Add short hand names for common track combinations
tron
parents: 3254
diff changeset
  2041
							(rail & TRACK_BIT_3WAY_SE) == 0 &&
3102
fde95020fc8e (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
  2042
							(rail & TRACK_BIT_X)
2839
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2043
						)) {
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2044
					TileIndex n = tile + TileDiffXY(0, 1);
3524
be2b44204623 (svn r4380) -Codechange: Make use of GetTrackBits where appropriate
celestar
parents: 3523
diff changeset
  2045
					TrackBits nrail = GetTrackBits(n);
2839
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2046
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2047
					if (!IsTileType(n, MP_RAILWAY) ||
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2048
							!IsTileOwner(n, owner) ||
3524
be2b44204623 (svn r4380) -Codechange: Make use of GetTrackBits where appropriate
celestar
parents: 3523
diff changeset
  2049
							nrail == TRACK_BIT_LOWER ||
be2b44204623 (svn r4380) -Codechange: Make use of GetTrackBits where appropriate
celestar
parents: 3523
diff changeset
  2050
							nrail == TRACK_BIT_RIGHT) {
2839
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2051
						new_ground = (new_ground == RAIL_GROUND_FENCE_NW) ?
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2052
							RAIL_GROUND_FENCE_SENW : RAIL_GROUND_FENCE_SE;
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2053
					}
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2054
				}
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2055
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2056
				if (rail == (TRACK_BIT_LOWER | TRACK_BIT_LEFT) || (
3258
94a915e7485f (svn r3946) Add short hand names for common track combinations
tron
parents: 3254
diff changeset
  2057
							(rail & TRACK_BIT_3WAY_NE) == 0 &&
3102
fde95020fc8e (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
  2058
							(rail & TRACK_BIT_Y)
2839
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2059
						)) {
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2060
					TileIndex n = tile + TileDiffXY(-1, 0);
3524
be2b44204623 (svn r4380) -Codechange: Make use of GetTrackBits where appropriate
celestar
parents: 3523
diff changeset
  2061
					TrackBits nrail = GetTrackBits(n);
2839
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2062
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2063
					if (!IsTileType(n, MP_RAILWAY) ||
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2064
							!IsTileOwner(n, owner) ||
3524
be2b44204623 (svn r4380) -Codechange: Make use of GetTrackBits where appropriate
celestar
parents: 3523
diff changeset
  2065
							nrail == TRACK_BIT_UPPER ||
be2b44204623 (svn r4380) -Codechange: Make use of GetTrackBits where appropriate
celestar
parents: 3523
diff changeset
  2066
							nrail == TRACK_BIT_RIGHT) {
2839
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2067
						new_ground = RAIL_GROUND_FENCE_NE;
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2068
					}
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2069
				}
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2070
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2071
				if (rail == (TRACK_BIT_UPPER | TRACK_BIT_RIGHT) || (
3265
33ca0ed9ed7d (svn r3976) Fix typo in r3946
tron
parents: 3258
diff changeset
  2072
							(rail & TRACK_BIT_3WAY_SW) == 0 &&
3102
fde95020fc8e (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
  2073
							(rail & TRACK_BIT_Y)
2839
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2074
						)) {
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2075
					TileIndex n = tile + TileDiffXY(1, 0);
3524
be2b44204623 (svn r4380) -Codechange: Make use of GetTrackBits where appropriate
celestar
parents: 3523
diff changeset
  2076
					TrackBits nrail = GetTrackBits(n);
2839
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2077
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2078
					if (!IsTileType(n, MP_RAILWAY) ||
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2079
							!IsTileOwner(n, owner) ||
3524
be2b44204623 (svn r4380) -Codechange: Make use of GetTrackBits where appropriate
celestar
parents: 3523
diff changeset
  2080
							nrail == TRACK_BIT_LOWER ||
be2b44204623 (svn r4380) -Codechange: Make use of GetTrackBits where appropriate
celestar
parents: 3523
diff changeset
  2081
							nrail == TRACK_BIT_LEFT) {
2839
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2082
						new_ground = (new_ground == RAIL_GROUND_FENCE_NE) ?
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2083
							RAIL_GROUND_FENCE_NESW : RAIL_GROUND_FENCE_SW;
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2084
					}
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2085
				}
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  2086
				break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2087
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2088
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2089
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2090
4482
4532293483d6 (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
  2091
set_ground:
2667
78b3c154afa4 (svn r3209) In TileLoop_Track(), use names based on function rather than their place in the map array.
peter1138
parents: 2645
diff changeset
  2092
	if (old_ground != new_ground) {
3523
168ee460418b (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
  2093
		SetRailGroundType(tile, new_ground);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2094
		MarkTileDirtyByTile(tile);
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
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2097
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2098
9112
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 9094
diff changeset
  2099
static TrackStatus GetTileTrackStatus_Track(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1963
diff changeset
  2100
{
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  2101
	if (mode != TRANSPORT_RAIL) return 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2102
9112
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 9094
diff changeset
  2103
	TrackBits trackbits = TRACK_BIT_NONE;
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 9094
diff changeset
  2104
	TrackdirBits red_signals = TRACKDIR_BIT_NONE;
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 9094
diff changeset
  2105
6513
8342666220ae (svn r8966) -Codechange: replace some if-cascades by switches.
rubidium
parents: 6498
diff changeset
  2106
	switch (GetRailTileType(tile)) {
8342666220ae (svn r8966) -Codechange: replace some if-cascades by switches.
rubidium
parents: 6498
diff changeset
  2107
		default: NOT_REACHED();
9092
383a632de666 (svn r12177) -Codechange: use 'side' parameter in GetTileTrackStatus so there can be less checks in pathfinders for depots/stations/tunnels/bridges
smatz
parents: 9067
diff changeset
  2108
		case RAIL_TILE_NORMAL:
9112
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 9094
diff changeset
  2109
			trackbits = GetTrackBits(tile);
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 9094
diff changeset
  2110
			break;
3267
591027d10884 (svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents: 3265
diff changeset
  2111
6513
8342666220ae (svn r8966) -Codechange: replace some if-cascades by switches.
rubidium
parents: 6498
diff changeset
  2112
		case RAIL_TILE_SIGNALS: {
9112
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 9094
diff changeset
  2113
			trackbits = GetTrackBits(tile);
7249
3e6c9df9794d (svn r9988) -Codechange: remove the last direct map accesses, except the ones needed for the savegame saving/loading mechanisms.
rubidium
parents: 7224
diff changeset
  2114
			byte a = GetPresentSignals(tile);
3e6c9df9794d (svn r9988) -Codechange: remove the last direct map accesses, except the ones needed for the savegame saving/loading mechanisms.
rubidium
parents: 7224
diff changeset
  2115
			uint b = GetSignalStates(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2116
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2117
			b &= a;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2118
22
fe6f35cc987b (svn r23) -Some omments on the code (blathijs)
darkvater
parents: 13
diff changeset
  2119
			/* When signals are not present (in neither
fe6f35cc987b (svn r23) -Some omments on the code (blathijs)
darkvater
parents: 13
diff changeset
  2120
			 * direction), we pretend them to be green. (So if
fe6f35cc987b (svn r23) -Some omments on the code (blathijs)
darkvater
parents: 13
diff changeset
  2121
			 * signals are only one way, the other way will
fe6f35cc987b (svn r23) -Some omments on the code (blathijs)
darkvater
parents: 13
diff changeset
  2122
			 * implicitely become `red' */
7249
3e6c9df9794d (svn r9988) -Codechange: remove the last direct map accesses, except the ones needed for the savegame saving/loading mechanisms.
rubidium
parents: 7224
diff changeset
  2123
			if ((a & 0xC) == 0) b |= 0xC;
3e6c9df9794d (svn r9988) -Codechange: remove the last direct map accesses, except the ones needed for the savegame saving/loading mechanisms.
rubidium
parents: 7224
diff changeset
  2124
			if ((a & 0x3) == 0) b |= 0x3;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2125
9112
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 9094
diff changeset
  2126
			if ((b & 0x8) == 0) red_signals |= (TRACKDIR_BIT_LEFT_N | TRACKDIR_BIT_X_NE | TRACKDIR_BIT_Y_SE | TRACKDIR_BIT_UPPER_E);
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 9094
diff changeset
  2127
			if ((b & 0x4) == 0) red_signals |= (TRACKDIR_BIT_LEFT_S | TRACKDIR_BIT_X_SW | TRACKDIR_BIT_Y_NW | TRACKDIR_BIT_UPPER_W);
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 9094
diff changeset
  2128
			if ((b & 0x2) == 0) red_signals |= (TRACKDIR_BIT_RIGHT_N | TRACKDIR_BIT_LOWER_E);
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 9094
diff changeset
  2129
			if ((b & 0x1) == 0) red_signals |= (TRACKDIR_BIT_RIGHT_S | TRACKDIR_BIT_LOWER_W);
6513
8342666220ae (svn r8966) -Codechange: replace some if-cascades by switches.
rubidium
parents: 6498
diff changeset
  2130
9112
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 9094
diff changeset
  2131
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2132
		}
6513
8342666220ae (svn r8966) -Codechange: replace some if-cascades by switches.
rubidium
parents: 6498
diff changeset
  2133
9092
383a632de666 (svn r12177) -Codechange: use 'side' parameter in GetTileTrackStatus so there can be less checks in pathfinders for depots/stations/tunnels/bridges
smatz
parents: 9067
diff changeset
  2134
		case RAIL_TILE_DEPOT: {
383a632de666 (svn r12177) -Codechange: use 'side' parameter in GetTileTrackStatus so there can be less checks in pathfinders for depots/stations/tunnels/bridges
smatz
parents: 9067
diff changeset
  2135
			DiagDirection dir = GetRailDepotDirection(tile);
383a632de666 (svn r12177) -Codechange: use 'side' parameter in GetTileTrackStatus so there can be less checks in pathfinders for depots/stations/tunnels/bridges
smatz
parents: 9067
diff changeset
  2136
9112
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 9094
diff changeset
  2137
			if (side != INVALID_DIAGDIR && side != dir) break;
9092
383a632de666 (svn r12177) -Codechange: use 'side' parameter in GetTileTrackStatus so there can be less checks in pathfinders for depots/stations/tunnels/bridges
smatz
parents: 9067
diff changeset
  2138
9112
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 9094
diff changeset
  2139
			trackbits = AxisToTrackBits(DiagDirToAxis(dir));
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 9094
diff changeset
  2140
			break;
9092
383a632de666 (svn r12177) -Codechange: use 'side' parameter in GetTileTrackStatus so there can be less checks in pathfinders for depots/stations/tunnels/bridges
smatz
parents: 9067
diff changeset
  2141
		}
383a632de666 (svn r12177) -Codechange: use 'side' parameter in GetTileTrackStatus so there can be less checks in pathfinders for depots/stations/tunnels/bridges
smatz
parents: 9067
diff changeset
  2142
383a632de666 (svn r12177) -Codechange: use 'side' parameter in GetTileTrackStatus so there can be less checks in pathfinders for depots/stations/tunnels/bridges
smatz
parents: 9067
diff changeset
  2143
		case RAIL_TILE_WAYPOINT:
9112
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 9094
diff changeset
  2144
			trackbits = GetRailWaypointBits(tile);
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 9094
diff changeset
  2145
			break;
3267
591027d10884 (svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents: 3265
diff changeset
  2146
	}
9112
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 9094
diff changeset
  2147
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 9094
diff changeset
  2148
	return CombineTrackStatus(TrackBitsToTrackdirBits(trackbits), red_signals);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2149
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2150
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1963
diff changeset
  2151
static void ClickTile_Track(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2152
{
6513
8342666220ae (svn r8966) -Codechange: replace some if-cascades by switches.
rubidium
parents: 6498
diff changeset
  2153
	switch (GetRailTileType(tile)) {
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
  2154
		case RAIL_TILE_DEPOT:    ShowDepotWindow(tile, VEH_TRAIN);                  break;
6513
8342666220ae (svn r8966) -Codechange: replace some if-cascades by switches.
rubidium
parents: 6498
diff changeset
  2155
		case RAIL_TILE_WAYPOINT: ShowRenameWaypointWindow(GetWaypointByTile(tile)); break;
8342666220ae (svn r8966) -Codechange: replace some if-cascades by switches.
rubidium
parents: 6498
diff changeset
  2156
		default: break;
2548
97ada3bd2702 (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2544
diff changeset
  2157
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2158
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2159
1590
4e39d1da10c7 (svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron
parents: 1555
diff changeset
  2160
static void GetTileDesc_Track(TileIndex tile, TileDesc *td)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2161
{
1901
fb05044cf5c3 (svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents: 1891
diff changeset
  2162
	td->owner = GetTileOwner(tile);
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
  2163
	switch (GetRailTileType(tile)) {
3792
2eb8388731bf (svn r4788) - Codechange: RAILTYPE_{NORMAL,ELECTRIC,...} and RAIL_TYPE_{NORMAL,SIGNAL,...} have nearly the same name, rename RAIL_TYPE_* to RAIL_TILE_* of extra clarity
rubidium
parents: 3778
diff changeset
  2164
		case RAIL_TILE_NORMAL:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2165
			td->str = STR_1021_RAILROAD_TRACK;
1590
4e39d1da10c7 (svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron
parents: 1555
diff changeset
  2166
			break;
4e39d1da10c7 (svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron
parents: 1555
diff changeset
  2167
3792
2eb8388731bf (svn r4788) - Codechange: RAILTYPE_{NORMAL,ELECTRIC,...} and RAIL_TYPE_{NORMAL,SIGNAL,...} have nearly the same name, rename RAIL_TYPE_* to RAIL_TILE_* of extra clarity
rubidium
parents: 3778
diff changeset
  2168
		case RAIL_TILE_SIGNALS: {
7266
4b75e7b9fa91 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 7249
diff changeset
  2169
			const StringID signal_type[4][4] = {
4b75e7b9fa91 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 7249
diff changeset
  2170
				{
4b75e7b9fa91 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 7249
diff changeset
  2171
					STR_RAILROAD_TRACK_WITH_NORMAL_SIGNALS,
4b75e7b9fa91 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 7249
diff changeset
  2172
					STR_RAILROAD_TRACK_WITH_NORMAL_PRESIGNALS,
4b75e7b9fa91 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 7249
diff changeset
  2173
					STR_RAILROAD_TRACK_WITH_NORMAL_EXITSIGNALS,
4b75e7b9fa91 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 7249
diff changeset
  2174
					STR_RAILROAD_TRACK_WITH_NORMAL_COMBOSIGNALS
4b75e7b9fa91 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 7249
diff changeset
  2175
				},
4b75e7b9fa91 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 7249
diff changeset
  2176
				{
4b75e7b9fa91 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 7249
diff changeset
  2177
					STR_RAILROAD_TRACK_WITH_NORMAL_PRESIGNALS,
4b75e7b9fa91 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 7249
diff changeset
  2178
					STR_RAILROAD_TRACK_WITH_PRESIGNALS,
4b75e7b9fa91 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 7249
diff changeset
  2179
					STR_RAILROAD_TRACK_WITH_PRE_EXITSIGNALS,
4b75e7b9fa91 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 7249
diff changeset
  2180
					STR_RAILROAD_TRACK_WITH_PRE_COMBOSIGNALS
4b75e7b9fa91 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 7249
diff changeset
  2181
				},
4b75e7b9fa91 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 7249
diff changeset
  2182
				{
4b75e7b9fa91 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 7249
diff changeset
  2183
					STR_RAILROAD_TRACK_WITH_NORMAL_EXITSIGNALS,
4b75e7b9fa91 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 7249
diff changeset
  2184
					STR_RAILROAD_TRACK_WITH_PRE_EXITSIGNALS,
4b75e7b9fa91 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 7249
diff changeset
  2185
					STR_RAILROAD_TRACK_WITH_EXITSIGNALS,
4b75e7b9fa91 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 7249
diff changeset
  2186
					STR_RAILROAD_TRACK_WITH_EXIT_COMBOSIGNALS
4b75e7b9fa91 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 7249
diff changeset
  2187
				},
4b75e7b9fa91 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 7249
diff changeset
  2188
				{
4b75e7b9fa91 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 7249
diff changeset
  2189
					STR_RAILROAD_TRACK_WITH_NORMAL_COMBOSIGNALS,
4b75e7b9fa91 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 7249
diff changeset
  2190
					STR_RAILROAD_TRACK_WITH_PRE_COMBOSIGNALS,
4b75e7b9fa91 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 7249
diff changeset
  2191
					STR_RAILROAD_TRACK_WITH_EXIT_COMBOSIGNALS,
4b75e7b9fa91 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 7249
diff changeset
  2192
					STR_RAILROAD_TRACK_WITH_COMBOSIGNALS
4b75e7b9fa91 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 7249
diff changeset
  2193
				}
1590
4e39d1da10c7 (svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron
parents: 1555
diff changeset
  2194
			};
4e39d1da10c7 (svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron
parents: 1555
diff changeset
  2195
7266
4b75e7b9fa91 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 7249
diff changeset
  2196
			td->str = signal_type[GetSignalType(tile, TRACK_UPPER)][GetSignalType(tile, TRACK_LOWER)];
1590
4e39d1da10c7 (svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron
parents: 1555
diff changeset
  2197
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2198
		}
1590
4e39d1da10c7 (svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron
parents: 1555
diff changeset
  2199
6498
aff910a05c6e (svn r8935) -Codechange: unification of track type between road and rail tiles, unification of ground type between normal rail tiles and depots/waypoints and removing the need for RailTileSubType.
rubidium
parents: 6486
diff changeset
  2200
		case RAIL_TILE_DEPOT:
aff910a05c6e (svn r8935) -Codechange: unification of track type between road and rail tiles, unification of ground type between normal rail tiles and depots/waypoints and removing the need for RailTileSubType.
rubidium
parents: 6486
diff changeset
  2201
			td->str = STR_1023_RAILROAD_TRAIN_DEPOT;
aff910a05c6e (svn r8935) -Codechange: unification of track type between road and rail tiles, unification of ground type between normal rail tiles and depots/waypoints and removing the need for RailTileSubType.
rubidium
parents: 6486
diff changeset
  2202
			break;
aff910a05c6e (svn r8935) -Codechange: unification of track type between road and rail tiles, unification of ground type between normal rail tiles and depots/waypoints and removing the need for RailTileSubType.
rubidium
parents: 6486
diff changeset
  2203
aff910a05c6e (svn r8935) -Codechange: unification of track type between road and rail tiles, unification of ground type between normal rail tiles and depots/waypoints and removing the need for RailTileSubType.
rubidium
parents: 6486
diff changeset
  2204
		case RAIL_TILE_WAYPOINT:
1590
4e39d1da10c7 (svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron
parents: 1555
diff changeset
  2205
		default:
6498
aff910a05c6e (svn r8935) -Codechange: unification of track type between road and rail tiles, unification of ground type between normal rail tiles and depots/waypoints and removing the need for RailTileSubType.
rubidium
parents: 6486
diff changeset
  2206
			td->str = STR_LANDINFO_WAYPOINT;
1590
4e39d1da10c7 (svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron
parents: 1555
diff changeset
  2207
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2208
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2209
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2210
2436
177cb6a8339f (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents: 2425
diff changeset
  2211
static void ChangeTileOwner_Track(TileIndex tile, PlayerID old_player, PlayerID new_player)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2212
{
1901
fb05044cf5c3 (svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents: 1891
diff changeset
  2213
	if (!IsTileOwner(tile, old_player)) return;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  2214
4848
56549aa3e234 (svn r6774) -Codechange: Rename the badly named OWNER_SPECTATOR to PLAYER_SPECTATOR and
Darkvater
parents: 4792
diff changeset
  2215
	if (new_player != PLAYER_SPECTATOR) {
1902
5d653da1abb7 (svn r2408) Introduce SetTileOwner() and use it
tron
parents: 1901
diff changeset
  2216
		SetTileOwner(tile, new_player);
4434
4175805666a5 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4388
diff changeset
  2217
	} else {
9015
4a44c6974ac1 (svn r12094) -Codechange: use DC_BANKRUPT command flag when removing player property to allow further fixes
smatz
parents: 8910
diff changeset
  2218
		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
  2219
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2220
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2221
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2222
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
  2223
static const byte _fractcoords_enter[4] = { 0x8A, 0x48, 0x84, 0xA8 };
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
  2224
static const signed char _deltacoord_leaveoffset[8] = {
1922
797081e56d13 (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents: 1903
diff changeset
  2225
	-1,  0,  1,  0, /* x */
797081e56d13 (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents: 1903
diff changeset
  2226
	 0,  1,  0, -1  /* y */
797081e56d13 (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents: 1903
diff changeset
  2227
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2228
9208
f376b12acb1b (svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz
parents: 9172
diff changeset
  2229
f376b12acb1b (svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz
parents: 9172
diff changeset
  2230
/** Compute number of ticks when next wagon will leave a depot.
f376b12acb1b (svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz
parents: 9172
diff changeset
  2231
 * Negative means next wagon should have left depot n ticks before.
f376b12acb1b (svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz
parents: 9172
diff changeset
  2232
 * @param v vehicle outside (leaving) the depot
f376b12acb1b (svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz
parents: 9172
diff changeset
  2233
 * @return number of ticks when the next wagon will leave
f376b12acb1b (svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz
parents: 9172
diff changeset
  2234
 */
f376b12acb1b (svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz
parents: 9172
diff changeset
  2235
int TicksToLeaveDepot(const Vehicle *v)
f376b12acb1b (svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz
parents: 9172
diff changeset
  2236
{
f376b12acb1b (svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz
parents: 9172
diff changeset
  2237
	DiagDirection dir = GetRailDepotDirection(v->tile);
f376b12acb1b (svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz
parents: 9172
diff changeset
  2238
	int length = v->u.rail.cached_veh_length;
f376b12acb1b (svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz
parents: 9172
diff changeset
  2239
f376b12acb1b (svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz
parents: 9172
diff changeset
  2240
	switch (dir) {
f376b12acb1b (svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz
parents: 9172
diff changeset
  2241
		case DIAGDIR_NE: return  ((int)(v->x_pos & 0x0F) - ((_fractcoords_enter[dir] & 0x0F) - (length + 1)));
f376b12acb1b (svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz
parents: 9172
diff changeset
  2242
		case DIAGDIR_SE: return -((int)(v->y_pos & 0x0F) - ((_fractcoords_enter[dir] >> 4)   + (length + 1)));
f376b12acb1b (svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz
parents: 9172
diff changeset
  2243
		case DIAGDIR_SW: return -((int)(v->x_pos & 0x0F) - ((_fractcoords_enter[dir] & 0x0F) + (length + 1)));
f376b12acb1b (svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz
parents: 9172
diff changeset
  2244
		default:
f376b12acb1b (svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz
parents: 9172
diff changeset
  2245
		case DIAGDIR_NW: return  ((int)(v->y_pos & 0x0F) - ((_fractcoords_enter[dir] >> 4)   - (length + 1)));
f376b12acb1b (svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz
parents: 9172
diff changeset
  2246
	}
f376b12acb1b (svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz
parents: 9172
diff changeset
  2247
f376b12acb1b (svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz
parents: 9172
diff changeset
  2248
	return 0; // make compilers happy
f376b12acb1b (svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz
parents: 9172
diff changeset
  2249
}
f376b12acb1b (svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz
parents: 9172
diff changeset
  2250
f376b12acb1b (svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz
parents: 9172
diff changeset
  2251
8615
6b91ca653bad (svn r11680) -Codechange: refactor more out of openttd.h and functions.h.
rubidium
parents: 8612
diff changeset
  2252
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
  2253
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2254
	byte fract_coord;
1922
797081e56d13 (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents: 1903
diff changeset
  2255
	byte fract_coord_leave;
3157
40de8616c04c (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3154
diff changeset
  2256
	DiagDirection dir;
1922
797081e56d13 (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents: 1903
diff changeset
  2257
	int length;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  2258
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6902
diff changeset
  2259
	/* this routine applies only to trains in depot tiles */
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
  2260
	if (v->type != VEH_TRAIN || !IsTileDepotType(tile, TRANSPORT_RAIL)) return VETSB_CONTINUE;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2261
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2262
	/* depot direction */
3185
c0ef161f700f (svn r3831) Add and use GetRailDepotDirection()
tron
parents: 3184
diff changeset
  2263
	dir = GetRailDepotDirection(tile);
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  2264
1922
797081e56d13 (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents: 1903
diff changeset
  2265
	/* calculate the point where the following wagon should be activated */
797081e56d13 (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents: 1903
diff changeset
  2266
	/* this depends on the length of the current vehicle */
797081e56d13 (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents: 1903
diff changeset
  2267
	length = v->u.rail.cached_veh_length;
797081e56d13 (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents: 1903
diff changeset
  2268
797081e56d13 (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents: 1903
diff changeset
  2269
	fract_coord_leave =
4434
4175805666a5 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4388
diff changeset
  2270
		((_fractcoords_enter[dir] & 0x0F) + // x
1922
797081e56d13 (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents: 1903
diff changeset
  2271
			(length + 1) * _deltacoord_leaveoffset[dir]) +
4434
4175805666a5 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4388
diff changeset
  2272
		(((_fractcoords_enter[dir] >> 4) +  // y
1922
797081e56d13 (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents: 1903
diff changeset
  2273
			((length + 1) * _deltacoord_leaveoffset[dir+4])) << 4);
797081e56d13 (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents: 1903
diff changeset
  2274
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2275
	fract_coord = (x & 0xF) + ((y & 0xF) << 4);
1922
797081e56d13 (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents: 1903
diff changeset
  2276
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2277
	if (_fractcoords_behind[dir] == fract_coord) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2278
		/* make sure a train is not entering the tile from behind */
6317
c73bda71ac16 (svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents: 5989
diff changeset
  2279
		return VETSB_CANNOT_ENTER;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2280
	} else if (_fractcoords_enter[dir] == fract_coord) {
3157
40de8616c04c (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3154
diff changeset
  2281
		if (DiagDirToDir(ReverseDiagDir(dir)) == v->direction) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2282
			/* enter the depot */
6319
27e68b914d3d (svn r8701) -Codechange: replace magic numbers with enums for u.rail.track.
rubidium
parents: 6317
diff changeset
  2283
			v->u.rail.track = TRACK_BIT_DEPOT,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2284
			v->vehstatus |= VS_HIDDEN; /* hide it */
3157
40de8616c04c (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3154
diff changeset
  2285
			v->direction = ReverseDir(v->direction);
7988
6075538f6111 (svn r11003) -Codechange: replace Vehicle->next to Vehicle->Next() and Vehicle->SetNext() so we can trap instances that change a next pointer and (in the future) update the first/previous pointers based on that.
rubidium
parents: 7944
diff changeset
  2286
			if (v->Next() == NULL) VehicleEnterDepot(v);
5198
2547d72f2db4 (svn r7313) -Codechange: Calling invalidate data on a window will surely warrant a redraw, so call
Darkvater
parents: 5116
diff changeset
  2287
			v->tile = tile;
2547d72f2db4 (svn r7313) -Codechange: Calling invalidate data on a window will surely warrant a redraw, so call
Darkvater
parents: 5116
diff changeset
  2288
4739
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4725
diff changeset
  2289
			InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile);
6317
c73bda71ac16 (svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents: 5989
diff changeset
  2290
			return VETSB_ENTERED_WORMHOLE;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2291
		}
1922
797081e56d13 (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents: 1903
diff changeset
  2292
	} else if (fract_coord_leave == fract_coord) {
3157
40de8616c04c (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3154
diff changeset
  2293
		if (DiagDirToDir(dir) == v->direction) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2294
			/* leave the depot? */
7988
6075538f6111 (svn r11003) -Codechange: replace Vehicle->next to Vehicle->Next() and Vehicle->SetNext() so we can trap instances that change a next pointer and (in the future) update the first/previous pointers based on that.
rubidium
parents: 7944
diff changeset
  2295
			if ((v = v->Next()) != NULL) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2296
				v->vehstatus &= ~VS_HIDDEN;
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
  2297
				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
  2298
			}
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
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2301
6317
c73bda71ac16 (svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents: 5989
diff changeset
  2302
	return VETSB_CONTINUE;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2303
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2304
8078
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  2305
/**
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  2306
 * Tests if autoslope is allowed.
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  2307
 *
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  2308
 * @param tile The tile.
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  2309
 * @param flags Terraform command flags.
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  2310
 * @param z_old Old TileZ.
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  2311
 * @param tileh_old Old TileSlope.
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  2312
 * @param z_new New TileZ.
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  2313
 * @param tileh_new New TileSlope.
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  2314
 * @param rail_bits Trackbits.
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  2315
 */
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  2316
static CommandCost TestAutoslopeOnRailTile(TileIndex tile, uint flags, uint z_old, Slope tileh_old, uint z_new, Slope tileh_new, TrackBits rail_bits)
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  2317
{
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  2318
	if (!_patches.build_on_slopes || !AutoslopeEnabled()) return CMD_ERROR;
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  2319
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  2320
	/* Is the slope-rail_bits combination valid in general? I.e. is it save to call GetRailFoundation() ? */
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  2321
	if (CmdFailed(CheckRailSlope(tileh_new, rail_bits, TRACK_BIT_NONE, tile))) return CMD_ERROR;
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  2322
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  2323
	/* Get the slopes on top of the foundations */
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  2324
	z_old += ApplyFoundationToSlope(GetRailFoundation(tileh_old, rail_bits), &tileh_old);
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  2325
	z_new += ApplyFoundationToSlope(GetRailFoundation(tileh_new, rail_bits), &tileh_new);
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  2326
8289
c78c7fb5cebf (svn r11343) -Fix[FS#1368]: Autoslope did not work correctly for single track on higher part of steep slopes. (frosch)
belugas
parents: 8267
diff changeset
  2327
	Corner track_corner;
8078
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  2328
	switch (rail_bits) {
8289
c78c7fb5cebf (svn r11343) -Fix[FS#1368]: Autoslope did not work correctly for single track on higher part of steep slopes. (frosch)
belugas
parents: 8267
diff changeset
  2329
		case TRACK_BIT_LEFT:  track_corner = CORNER_W; break;
c78c7fb5cebf (svn r11343) -Fix[FS#1368]: Autoslope did not work correctly for single track on higher part of steep slopes. (frosch)
belugas
parents: 8267
diff changeset
  2330
		case TRACK_BIT_LOWER: track_corner = CORNER_S; break;
c78c7fb5cebf (svn r11343) -Fix[FS#1368]: Autoslope did not work correctly for single track on higher part of steep slopes. (frosch)
belugas
parents: 8267
diff changeset
  2331
		case TRACK_BIT_RIGHT: track_corner = CORNER_E; break;
c78c7fb5cebf (svn r11343) -Fix[FS#1368]: Autoslope did not work correctly for single track on higher part of steep slopes. (frosch)
belugas
parents: 8267
diff changeset
  2332
		case TRACK_BIT_UPPER: track_corner = CORNER_N; break;
8078
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  2333
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  2334
		/* Surface slope must not be changed */
8726
5ae45b46506b (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8724
diff changeset
  2335
		default: return (((z_old != z_new) || (tileh_old != tileh_new)) ? CMD_ERROR : CommandCost(EXPENSES_CONSTRUCTION, _price.terraform));
8078
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  2336
	}
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  2337
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  2338
	/* The height of the track_corner must not be changed. The rest ensures GetRailFoundation() already. */
8909
fa15e9afad2f (svn r11983) -Codechange: Add some helper functions for slopes and use them.
frosch
parents: 8894
diff changeset
  2339
	z_old += GetSlopeZInCorner(RemoveHalftileSlope(tileh_old), track_corner);
fa15e9afad2f (svn r11983) -Codechange: Add some helper functions for slopes and use them.
frosch
parents: 8894
diff changeset
  2340
	z_new += GetSlopeZInCorner(RemoveHalftileSlope(tileh_new), track_corner);
8078
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  2341
	if (z_old != z_new) return CMD_ERROR;
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  2342
8726
5ae45b46506b (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8724
diff changeset
  2343
	CommandCost cost = CommandCost(EXPENSES_CONSTRUCTION, _price.terraform);
8289
c78c7fb5cebf (svn r11343) -Fix[FS#1368]: Autoslope did not work correctly for single track on higher part of steep slopes. (frosch)
belugas
parents: 8267
diff changeset
  2344
	/* Make the ground dirty, if surface slope has changed */
c78c7fb5cebf (svn r11343) -Fix[FS#1368]: Autoslope did not work correctly for single track on higher part of steep slopes. (frosch)
belugas
parents: 8267
diff changeset
  2345
	if (tileh_old != tileh_new) {
8910
b261b6cb9b21 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8909
diff changeset
  2346
		/* If there is flat water on the lower halftile add the cost for clearing it */
b261b6cb9b21 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8909
diff changeset
  2347
		if (GetRailGroundType(tile) == RAIL_GROUND_WATER && IsSlopeWithOneCornerRaised(tileh_old)) cost.AddCost(_price.clear_water);
8289
c78c7fb5cebf (svn r11343) -Fix[FS#1368]: Autoslope did not work correctly for single track on higher part of steep slopes. (frosch)
belugas
parents: 8267
diff changeset
  2348
		if ((flags & DC_EXEC) != 0) SetRailGroundType(tile, RAIL_GROUND_BARREN);
c78c7fb5cebf (svn r11343) -Fix[FS#1368]: Autoslope did not work correctly for single track on higher part of steep slopes. (frosch)
belugas
parents: 8267
diff changeset
  2349
	}
8267
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8266
diff changeset
  2350
	return  cost;
8078
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  2351
}
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  2352
7990
70039e33e893 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7988
diff changeset
  2353
static CommandCost TerraformTile_Track(TileIndex tile, uint32 flags, uint z_new, Slope tileh_new)
70039e33e893 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7988
diff changeset
  2354
{
8078
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  2355
	uint z_old;
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  2356
	Slope tileh_old = GetTileSlope(tile, &z_old);
7990
70039e33e893 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7988
diff changeset
  2357
	if (IsPlainRailTile(tile)) {
70039e33e893 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7988
diff changeset
  2358
		TrackBits rail_bits = GetTrackBits(tile);
8910
b261b6cb9b21 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8909
diff changeset
  2359
		/* Is there flat water on the lower halftile, that must be cleared expensively? */
b261b6cb9b21 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8909
diff changeset
  2360
		bool was_water = (GetRailGroundType(tile) == RAIL_GROUND_WATER && IsSlopeWithOneCornerRaised(tileh_old));
7990
70039e33e893 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7988
diff changeset
  2361
70039e33e893 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7988
diff changeset
  2362
		_error_message = STR_1008_MUST_REMOVE_RAILROAD_TRACK;
70039e33e893 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7988
diff changeset
  2363
8078
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  2364
		/* First test autoslope. However if it succeeds we still have to test the rest, because non-autoslope terraforming is cheaper. */
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  2365
		CommandCost autoslope_result = TestAutoslopeOnRailTile(tile, flags, z_old, tileh_old, z_new, tileh_new, rail_bits);
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  2366
7990
70039e33e893 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7988
diff changeset
  2367
		/* When there is only a single horizontal/vertical track, one corner can be terraformed. */
8266
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
  2368
		Corner allowed_corner;
7990
70039e33e893 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7988
diff changeset
  2369
		switch (rail_bits) {
8266
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
  2370
			case TRACK_BIT_RIGHT: allowed_corner = CORNER_W; break;
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
  2371
			case TRACK_BIT_UPPER: allowed_corner = CORNER_S; break;
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
  2372
			case TRACK_BIT_LEFT:  allowed_corner = CORNER_E; break;
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
  2373
			case TRACK_BIT_LOWER: allowed_corner = CORNER_N; break;
8078
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  2374
			default: return autoslope_result;
7990
70039e33e893 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7988
diff changeset
  2375
		}
70039e33e893 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7988
diff changeset
  2376
70039e33e893 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7988
diff changeset
  2377
		Foundation f_old = GetRailFoundation(tileh_old, rail_bits);
70039e33e893 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7988
diff changeset
  2378
8266
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
  2379
		/* Do not allow terraforming if allowed_corner is part of anti-zig-zag foundations */
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
  2380
		if (tileh_old != SLOPE_NS && tileh_old != SLOPE_EW && IsSpecialRailFoundation(f_old)) return autoslope_result;
7990
70039e33e893 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7988
diff changeset
  2381
8266
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
  2382
		/* Everything is valid, which only changes allowed_corner */
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
  2383
		for (Corner corner = (Corner)0; corner < CORNER_END; corner = (Corner)(corner + 1)) {
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
  2384
			if (allowed_corner == corner) continue;
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
  2385
			if (z_old + GetSlopeZInCorner(tileh_old, corner) != z_new + GetSlopeZInCorner(tileh_new, corner)) return autoslope_result;
7990
70039e33e893 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7988
diff changeset
  2386
		}
70039e33e893 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7988
diff changeset
  2387
70039e33e893 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7988
diff changeset
  2388
		/* Make the ground dirty */
70039e33e893 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7988
diff changeset
  2389
		if ((flags & DC_EXEC) != 0) SetRailGroundType(tile, RAIL_GROUND_BARREN);
70039e33e893 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7988
diff changeset
  2390
8267
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8266
diff changeset
  2391
		/* allow terraforming */
8726
5ae45b46506b (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8724
diff changeset
  2392
		return CommandCost(EXPENSES_CONSTRUCTION, was_water ? _price.clear_water : (Money)0);
8078
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  2393
	} else {
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  2394
		if (_patches.build_on_slopes && AutoslopeEnabled()) {
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  2395
			switch (GetRailTileType(tile)) {
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  2396
				case RAIL_TILE_WAYPOINT: {
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  2397
					CommandCost cost = TestAutoslopeOnRailTile(tile, flags, z_old, tileh_old, z_new, tileh_new, GetRailWaypointBits(tile));
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  2398
					if (!CmdFailed(cost)) return cost; // allow autoslope
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  2399
					break;
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  2400
				}
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  2401
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  2402
				case RAIL_TILE_DEPOT:
8726
5ae45b46506b (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8724
diff changeset
  2403
					if (AutoslopeCheckForEntranceEdge(tile, z_new, tileh_new, GetRailDepotDirection(tile))) return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform);
8078
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  2404
					break;
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  2405
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  2406
				default: NOT_REACHED();
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  2407
			}
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8035
diff changeset
  2408
		}
7990
70039e33e893 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7988
diff changeset
  2409
	}
70039e33e893 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7988
diff changeset
  2410
	return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
70039e33e893 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7988
diff changeset
  2411
}
70039e33e893 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7988
diff changeset
  2412
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2413
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
  2414
extern const TileTypeProcs _tile_type_rail_procs = {
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4253
diff changeset
  2415
	DrawTile_Track,           /* draw_tile_proc */
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4253
diff changeset
  2416
	GetSlopeZ_Track,          /* get_slope_z_proc */
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4253
diff changeset
  2417
	ClearTile_Track,          /* clear_tile_proc */
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4253
diff changeset
  2418
	GetAcceptedCargo_Track,   /* get_accepted_cargo_proc */
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4253
diff changeset
  2419
	GetTileDesc_Track,        /* get_tile_desc_proc */
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4253
diff changeset
  2420
	GetTileTrackStatus_Track, /* get_tile_track_status_proc */
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4253
diff changeset
  2421
	ClickTile_Track,          /* click_tile_proc */
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4253
diff changeset
  2422
	AnimateTile_Track,        /* animate_tile_proc */
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4253
diff changeset
  2423
	TileLoop_Track,           /* tile_loop_clear */
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4253
diff changeset
  2424
	ChangeTileOwner_Track,    /* change_tile_owner_clear */
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4253
diff changeset
  2425
	NULL,                     /* get_produced_cargo_proc */
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4253
diff changeset
  2426
	VehicleEnter_Track,       /* vehicle_enter_tile_proc */
7831
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7829
diff changeset
  2427
	GetFoundation_Track,      /* get_foundation_proc */
7990
70039e33e893 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7988
diff changeset
  2428
	TerraformTile_Track,      /* terraform_tile_proc */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2429
};