rail_cmd.c
author matthijs
Wed, 22 Mar 2006 22:26:16 +0000
branch0.4.5
changeset 9958 bed516c67d61
parent 9946 d3cb7e05c5a6
permissions -rw-r--r--
(svn r4041) [Debian] Change next version number to 0.4.6 instead of 0.4.5.1.
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
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     3
#include "stdafx.h"
1891
92a3b0aa0946 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1818
diff changeset
     4
#include "openttd.h"
1922
797081e56d13 (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents: 1903
diff changeset
     5
#include "debug.h"
2163
637ec3c361f5 (svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents: 2148
diff changeset
     6
#include "functions.h"
1363
01d3de5d8039 (svn r1867) Include tables/sprites.h only in files which need it
tron
parents: 1330
diff changeset
     7
#include "table/sprites.h"
507
8aa8100b0b22 (svn r815) Include strings.h only in the files which need it.
tron
parents: 497
diff changeset
     8
#include "table/strings.h"
679
e959706a3e4d (svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents: 555
diff changeset
     9
#include "map.h"
1209
a1ac96655b79 (svn r1713) Split off several functions which query/set information about a single tile from map.h and put them into a seperate file tile.h
tron
parents: 1123
diff changeset
    10
#include "tile.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    11
#include "vehicle.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    12
#include "viewport.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    13
#include "command.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    14
#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
    15
#include "engine.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    16
#include "town.h"
337
66647f97e7c0 (svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents: 283
diff changeset
    17
#include "sound.h"
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 337
diff changeset
    18
#include "station.h"
405
6830ae7a0d5d (svn r602) -newgrf: Move DrawTileSeqStruct & co and struct SpriteGroup to sprite.h (pasky)
darkvater
parents: 403
diff changeset
    19
#include "sprite.h"
1313
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents: 1247
diff changeset
    20
#include "depot.h"
1542
2ca6d1624e6d (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1536
diff changeset
    21
#include "waypoint.h"
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
    22
#include "rail.h"
2236
55f4d7353f52 (svn r2756) Renamed railtypes into _railtypes
ludde
parents: 2233
diff changeset
    23
#include "railtypes.h" // include table for railtypes
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    24
415
423de36034b8 (svn r612) [newgrf] Fix: custom waypoints on monorail/maglev are displayed correctly
dominik
parents: 413
diff changeset
    25
extern uint16 _custom_sprites_base;
423de36034b8 (svn r612) [newgrf] Fix: custom waypoints on monorail/maglev are displayed correctly
dominik
parents: 413
diff changeset
    26
2261
3f78323707bb (svn r2781) Fix some of the issues with variables in .h files.
ludde
parents: 2254
diff changeset
    27
const byte _track_sloped_sprites[14] = {
3f78323707bb (svn r2781) Fix some of the issues with variables in .h files.
ludde
parents: 2254
diff changeset
    28
	14, 15, 22, 13,
3f78323707bb (svn r2781) Fix some of the issues with variables in .h files.
ludde
parents: 2254
diff changeset
    29
	 0, 21, 17, 12,
3f78323707bb (svn r2781) Fix some of the issues with variables in .h files.
ludde
parents: 2254
diff changeset
    30
	23,  0, 18, 20,
3f78323707bb (svn r2781) Fix some of the issues with variables in .h files.
ludde
parents: 2254
diff changeset
    31
	19, 16
3f78323707bb (svn r2781) Fix some of the issues with variables in .h files.
ludde
parents: 2254
diff changeset
    32
};
3f78323707bb (svn r2781) Fix some of the issues with variables in .h files.
ludde
parents: 2254
diff changeset
    33
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1963
diff changeset
    34
void ShowTrainDepotWindow(TileIndex tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    35
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    36
/* Format of rail map5 byte.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    37
 * 00 abcdef  => Normal rail
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    38
 * 01 abcdef  => Rail with signals
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    39
 * 10 ??????  => Unused
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    40
 * 11 ????dd  => Depot
22
fe6f35cc987b (svn r23) -Some omments on the code (blathijs)
darkvater
parents: 13
diff changeset
    41
 *
fe6f35cc987b (svn r23) -Some omments on the code (blathijs)
darkvater
parents: 13
diff changeset
    42
 * abcdef is a bitmask, which contains ones for all present tracks. Below the
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
    43
 * value for each track is given.
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    44
 */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    45
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    46
/*         4
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    47
 *     ---------
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    48
 *    |\       /|
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    49
 *    | \    1/ |
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    50
 *    |  \   /  |
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    51
 *    |   \ /   |
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    52
 *  16|    \    |32
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
    53
 *    |   / \2  |
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    54
 *    |  /   \  |
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    55
 *    | /     \ |
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
 *     ---------
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    58
 *         8
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
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
// Constants for lower part of Map2 byte.
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
    63
enum RailMap2Lower4 {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    64
	RAIL_MAP2LO_GROUND_MASK = 0xF,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    65
	RAIL_GROUND_BROWN = 0,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    66
	RAIL_GROUND_GREEN = 1,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    67
	RAIL_GROUND_FENCE_NW = 2,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    68
	RAIL_GROUND_FENCE_SE = 3,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    69
	RAIL_GROUND_FENCE_SENW = 4,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    70
	RAIL_GROUND_FENCE_NE = 5,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    71
	RAIL_GROUND_FENCE_SW = 6,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    72
	RAIL_GROUND_FENCE_NESW = 7,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    73
	RAIL_GROUND_FENCE_VERT1 = 8,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    74
	RAIL_GROUND_FENCE_VERT2 = 9,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    75
	RAIL_GROUND_FENCE_HORIZ1 = 10,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    76
	RAIL_GROUND_FENCE_HORIZ2 = 11,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    77
	RAIL_GROUND_ICE_DESERT = 12,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    78
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    79
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    80
22
fe6f35cc987b (svn r23) -Some omments on the code (blathijs)
darkvater
parents: 13
diff changeset
    81
/* 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
    82
 * MAP3LO byte:  abcd???? => Signal Exists?
22
fe6f35cc987b (svn r23) -Some omments on the code (blathijs)
darkvater
parents: 13
diff changeset
    83
 *				 a and b are for diagonals, upper and left,
fe6f35cc987b (svn r23) -Some omments on the code (blathijs)
darkvater
parents: 13
diff changeset
    84
 *				 one for each direction. (ie a == NE->SW, b ==
fe6f35cc987b (svn r23) -Some omments on the code (blathijs)
darkvater
parents: 13
diff changeset
    85
 *				 SW->NE, or v.v., I don't know. b and c are
fe6f35cc987b (svn r23) -Some omments on the code (blathijs)
darkvater
parents: 13
diff changeset
    86
 *				 similar for lower and right.
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    87
 * MAP2 byte:    ????abcd => Type of ground.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    88
 * MAP3LO byte:  ????abcd => Type of rail.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    89
 * MAP5:         00abcdef => rail
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    90
 *               01abcdef => rail w/ signals
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    91
 *               10uuuuuu => unused
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
    92
 *               11uuuudd => rail depot
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    93
 */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    94
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
    95
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
    96
{
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
    97
	RailTileType type = GetRailTileType(tile);
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
    98
	TrackBits current; /* The current track layout */
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
    99
	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
   100
	_error_message = STR_1001_IMPOSSIBLE_TRACK_COMBINATION;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   101
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   102
	if (type != RAIL_TYPE_NORMAL && type != RAIL_TYPE_SIGNALS)
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   103
		return false; /* Cannot build anything on depots and checkpoints */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   104
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   105
	/* 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
   106
	 * what tracks first */
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   107
	current = GetTrackBits(tile);
1946
68e7ee03016a (svn r2452) Fix defect in r2448 which caused building tracks unexpectedly fail or succeed
tron
parents: 1942
diff changeset
   108
	future = current | to_build;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   109
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   110
	/* Are we really building something new? */
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   111
	if (current == future) {
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   112
		/* Nothing new is being built */
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   113
		_error_message = STR_1007_ALREADY_BUILT;
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   114
		return false;
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   115
	}
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   116
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   117
	/* Let's see if we may build this */
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   118
	if ((flags & DC_NO_RAIL_OVERLAP) || type == RAIL_TYPE_SIGNALS) {
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   119
		/* 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
   120
		 * signals on the tile), check that */
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   121
		return
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   122
			future == (TRACK_BIT_UPPER | TRACK_BIT_LOWER) ||
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   123
			future == (TRACK_BIT_LEFT  | TRACK_BIT_RIGHT);
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   124
	} else {
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   125
		/* 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
   126
		return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   127
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   128
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   129
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   130
9942
56446313309e (svn r4012) -Backport from trunk (3992, 3995): Rewrote the code to determine whether a rail-tile can be terraformed.
celestar
parents: 9936
diff changeset
   131
const TrackBits _valid_tileh_slopes[4][15] = {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   132
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   133
// set of normal ones
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   134
{
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   135
	TRACK_BIT_DIAG1|TRACK_BIT_DIAG2|TRACK_BIT_UPPER|TRACK_BIT_LOWER|TRACK_BIT_LEFT|TRACK_BIT_RIGHT,
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   136
	TRACK_BIT_RIGHT,
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   137
	TRACK_BIT_UPPER,
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   138
	TRACK_BIT_DIAG1,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   139
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   140
	TRACK_BIT_LEFT,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   141
	0,
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   142
	TRACK_BIT_DIAG2,
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   143
	TRACK_BIT_LOWER,
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   144
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   145
	TRACK_BIT_LOWER,
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   146
	TRACK_BIT_DIAG2,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   147
	0,
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   148
	TRACK_BIT_LEFT,
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   149
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   150
	TRACK_BIT_DIAG1,
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   151
	TRACK_BIT_UPPER,
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   152
	TRACK_BIT_RIGHT,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   153
},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   154
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   155
// allowed rail for an evenly raised platform
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   156
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   157
	0,
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   158
	TRACK_BIT_LEFT,
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   159
	TRACK_BIT_LOWER,
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   160
	TRACK_BIT_DIAG2 | TRACK_BIT_LOWER | TRACK_BIT_LEFT,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   161
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   162
	TRACK_BIT_RIGHT,
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   163
	TRACK_BIT_DIAG1|TRACK_BIT_DIAG2|TRACK_BIT_UPPER|TRACK_BIT_LOWER|TRACK_BIT_LEFT|TRACK_BIT_RIGHT,
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   164
	TRACK_BIT_DIAG1 | TRACK_BIT_LOWER | TRACK_BIT_RIGHT,
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   165
	TRACK_BIT_DIAG1|TRACK_BIT_DIAG2|TRACK_BIT_UPPER|TRACK_BIT_LOWER|TRACK_BIT_LEFT|TRACK_BIT_RIGHT,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   166
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   167
	TRACK_BIT_UPPER,
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   168
	TRACK_BIT_DIAG1 | TRACK_BIT_UPPER | TRACK_BIT_LEFT,
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   169
	TRACK_BIT_DIAG1|TRACK_BIT_DIAG2|TRACK_BIT_UPPER|TRACK_BIT_LOWER|TRACK_BIT_LEFT|TRACK_BIT_RIGHT,
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   170
	TRACK_BIT_DIAG1|TRACK_BIT_DIAG2|TRACK_BIT_UPPER|TRACK_BIT_LOWER|TRACK_BIT_LEFT|TRACK_BIT_RIGHT,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   171
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   172
	TRACK_BIT_DIAG2 | TRACK_BIT_UPPER | TRACK_BIT_RIGHT,
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   173
	TRACK_BIT_DIAG1|TRACK_BIT_DIAG2|TRACK_BIT_UPPER|TRACK_BIT_LOWER|TRACK_BIT_LEFT|TRACK_BIT_RIGHT,
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   174
	TRACK_BIT_DIAG1|TRACK_BIT_DIAG2|TRACK_BIT_UPPER|TRACK_BIT_LOWER|TRACK_BIT_LEFT|TRACK_BIT_RIGHT,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   175
},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   176
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   177
// allowed rail on coast tile
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   178
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   179
	0,
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   180
	TRACK_BIT_LEFT,
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   181
	TRACK_BIT_LOWER,
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   182
	TRACK_BIT_DIAG2|TRACK_BIT_LEFT|TRACK_BIT_LOWER,
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   183
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   184
	TRACK_BIT_RIGHT,
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   185
	TRACK_BIT_DIAG1|TRACK_BIT_DIAG2|TRACK_BIT_UPPER|TRACK_BIT_LOWER|TRACK_BIT_LEFT|TRACK_BIT_RIGHT,
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   186
	TRACK_BIT_DIAG1|TRACK_BIT_RIGHT|TRACK_BIT_LOWER,
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   187
	TRACK_BIT_DIAG1|TRACK_BIT_DIAG2|TRACK_BIT_UPPER|TRACK_BIT_LOWER|TRACK_BIT_LEFT|TRACK_BIT_RIGHT,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   188
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   189
	TRACK_BIT_UPPER,
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   190
	TRACK_BIT_DIAG1|TRACK_BIT_LEFT|TRACK_BIT_UPPER,
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   191
	TRACK_BIT_DIAG1|TRACK_BIT_DIAG2|TRACK_BIT_UPPER|TRACK_BIT_LOWER|TRACK_BIT_LEFT|TRACK_BIT_RIGHT,
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   192
	TRACK_BIT_DIAG1|TRACK_BIT_DIAG2|TRACK_BIT_UPPER|TRACK_BIT_LOWER|TRACK_BIT_LEFT|TRACK_BIT_RIGHT,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   193
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   194
	TRACK_BIT_DIAG2|TRACK_BIT_RIGHT|TRACK_BIT_UPPER,
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   195
	TRACK_BIT_DIAG1|TRACK_BIT_DIAG2|TRACK_BIT_UPPER|TRACK_BIT_LOWER|TRACK_BIT_LEFT|TRACK_BIT_RIGHT,
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   196
	TRACK_BIT_DIAG1|TRACK_BIT_DIAG2|TRACK_BIT_UPPER|TRACK_BIT_LOWER|TRACK_BIT_LEFT|TRACK_BIT_RIGHT,
13
3e7c1f74a996 (svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents: 0
diff changeset
   197
	},
3e7c1f74a996 (svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents: 0
diff changeset
   198
3e7c1f74a996 (svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents: 0
diff changeset
   199
	// valid railway crossings on slopes
3e7c1f74a996 (svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents: 0
diff changeset
   200
	{
3e7c1f74a996 (svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents: 0
diff changeset
   201
		1, 0, 0, // 0, 1, 2
3e7c1f74a996 (svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents: 0
diff changeset
   202
		0, 0, 1, // 3, 4, 5
3e7c1f74a996 (svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents: 0
diff changeset
   203
		0, 1, 0, // 6, 7, 8
3e7c1f74a996 (svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents: 0
diff changeset
   204
		0, 1, 1, // 9, 10, 11
3e7c1f74a996 (svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents: 0
diff changeset
   205
		0, 1, 1, // 12, 13, 14
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   206
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   207
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   208
84
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents: 59
diff changeset
   209
uint GetRailFoundation(uint tileh, uint bits)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   210
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   211
	int i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   212
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   213
	if ((~_valid_tileh_slopes[0][tileh] & bits) == 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   214
		return 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   215
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   216
	if ((~_valid_tileh_slopes[1][tileh] & bits) == 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   217
		return tileh;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   218
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   219
	if ( ((i=0, tileh == 1) || (i+=2, tileh == 2) || (i+=2, tileh == 4) || (i+=2, tileh == 8)) && (bits == TRACK_BIT_DIAG1 || (i++, bits == TRACK_BIT_DIAG2)))
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   220
		return i + 15;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   221
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   222
	return 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   223
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   224
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   225
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   226
static uint32 CheckRailSlope(uint tileh, TrackBits rail_bits, TrackBits existing, TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   227
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   228
	// never allow building on top of steep tiles
2085
ae9e92ffe168 (svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents: 2049
diff changeset
   229
	if (!IsSteepTileh(tileh)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   230
		rail_bits |= existing;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   231
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   232
		// don't allow building on the lower side of a coast
1627
d88508d9ced0 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   233
		if (IsTileType(tile, MP_WATER) &&
d88508d9ced0 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   234
				~_valid_tileh_slopes[2][tileh] & rail_bits) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   235
			return_cmd_error(STR_3807_CAN_T_BUILD_ON_WATER);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   236
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   237
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   238
		// no special foundation
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   239
		if ((~_valid_tileh_slopes[0][tileh] & rail_bits) == 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   240
			return 0;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   241
1627
d88508d9ced0 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   242
		if ((~_valid_tileh_slopes[1][tileh] & rail_bits) == 0 || ( // whole tile is leveled up
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   243
					(rail_bits == TRACK_BIT_DIAG1 || rail_bits == TRACK_BIT_DIAG2) &&
1627
d88508d9ced0 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   244
					(tileh == 1 || tileh == 2 || tileh == 4 || tileh == 8)
d88508d9ced0 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   245
				)) { // partly up
d88508d9ced0 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   246
			if (existing != 0) {
d88508d9ced0 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   247
				return 0;
2422
914a12dee832 (svn r2948) -Fix: the old AI needs a special flag that triggers all kind of special
truelight
parents: 2364
diff changeset
   248
			} else if (!_patches.build_on_slopes || _is_old_ai_player) {
1627
d88508d9ced0 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   249
				return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
d88508d9ced0 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   250
			} else {
d88508d9ced0 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   251
				return _price.terraform;
d88508d9ced0 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   252
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   253
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   254
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   255
	return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   256
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   257
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
   258
/* Validate functions for rail building */
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   259
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
   260
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
   261
/** Build a single piece of rail
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
   262
 * @param x,y coordinates on where to build
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
   263
 * @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
   264
 * @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
   265
 */
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
   266
int32 CmdBuildSingleRail(int x, int y, uint32 flags, uint32 p1, uint32 p2)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   267
{
1627
d88508d9ced0 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   268
	TileIndex tile;
d88508d9ced0 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   269
	uint tileh;
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   270
	uint m5; /* XXX: Used only as a cache, should probably be removed? */
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   271
	Track track = (Track)p2;
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   272
	TrackBits trackbit;
1627
d88508d9ced0 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   273
	int32 cost = 0;
d88508d9ced0 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   274
	int32 ret;
d88508d9ced0 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   275
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   276
	if (!ValParamRailtype(p1) || !ValParamTrackOrientation(track)) return CMD_ERROR;
1627
d88508d9ced0 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   277
1980
9ea0c89fbb58 (svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents: 1977
diff changeset
   278
	tile = TileVirtXY(x, y);
1627
d88508d9ced0 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   279
	tileh = GetTileSlope(tile, NULL);
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2020
diff changeset
   280
	m5 = _m[tile].m5;
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   281
	trackbit = TrackToTrackBits(track);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   282
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   283
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   284
1627
d88508d9ced0 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   285
	switch (GetTileType(tile)) {
d88508d9ced0 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   286
		case MP_TUNNELBRIDGE:
d88508d9ced0 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   287
			if ((m5 & 0xC0) != 0xC0 || // not bridge middle part?
2364
5ac6c8d6e031 (svn r2890) Fix some signed/unsigned comparison warnings (tokai)
tron
parents: 2261
diff changeset
   288
					(m5 & 0x01 ? TRACK_BIT_DIAG1 : TRACK_BIT_DIAG2) != trackbit) { // wrong direction?
1627
d88508d9ced0 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   289
				// Get detailed error message
d88508d9ced0 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   290
				return DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
d88508d9ced0 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   291
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   292
1630
15a88bda48fd (svn r2134) Return the correct error message if rail is already under a bridge, fix for r2131
tron
parents: 1628
diff changeset
   293
			switch (m5 & 0x38) { // what's under the bridge?
15a88bda48fd (svn r2134) Return the correct error message if rail is already under a bridge, fix for r2131
tron
parents: 1628
diff changeset
   294
				case 0x00: // clear land
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   295
					ret = CheckRailSlope(tileh, trackbit, 0, tile);
1691
fcd9fefaed02 (svn r2195) Add CmdFailed() as the One True Way(tm) to check if a command failed.
tron
parents: 1669
diff changeset
   296
					if (CmdFailed(ret)) return ret;
1630
15a88bda48fd (svn r2134) Return the correct error message if rail is already under a bridge, fix for r2131
tron
parents: 1628
diff changeset
   297
					cost += ret;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   298
1630
15a88bda48fd (svn r2134) Return the correct error message if rail is already under a bridge, fix for r2131
tron
parents: 1628
diff changeset
   299
					if (flags & DC_EXEC) {
1902
5d653da1abb7 (svn r2408) Introduce SetTileOwner() and use it
tron
parents: 1901
diff changeset
   300
						SetTileOwner(tile, _current_player);
2493
d834d0c1502a (svn r3019) -Codechange: Replace explicit shifting/anding/oring with GB and SB
tron
parents: 2472
diff changeset
   301
						SB(_m[tile].m3, 0, 4, p1);
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2020
diff changeset
   302
						_m[tile].m5 = (m5 & 0xC7) | 0x20; // railroad under bridge
1630
15a88bda48fd (svn r2134) Return the correct error message if rail is already under a bridge, fix for r2131
tron
parents: 1628
diff changeset
   303
					}
15a88bda48fd (svn r2134) Return the correct error message if rail is already under a bridge, fix for r2131
tron
parents: 1628
diff changeset
   304
					break;
15a88bda48fd (svn r2134) Return the correct error message if rail is already under a bridge, fix for r2131
tron
parents: 1628
diff changeset
   305
15a88bda48fd (svn r2134) Return the correct error message if rail is already under a bridge, fix for r2131
tron
parents: 1628
diff changeset
   306
				case 0x20: // rail already there
15a88bda48fd (svn r2134) Return the correct error message if rail is already under a bridge, fix for r2131
tron
parents: 1628
diff changeset
   307
					return_cmd_error(STR_1007_ALREADY_BUILT);
15a88bda48fd (svn r2134) Return the correct error message if rail is already under a bridge, fix for r2131
tron
parents: 1628
diff changeset
   308
15a88bda48fd (svn r2134) Return the correct error message if rail is already under a bridge, fix for r2131
tron
parents: 1628
diff changeset
   309
				default:
15a88bda48fd (svn r2134) Return the correct error message if rail is already under a bridge, fix for r2131
tron
parents: 1628
diff changeset
   310
					// Get detailed error message
15a88bda48fd (svn r2134) Return the correct error message if rail is already under a bridge, fix for r2131
tron
parents: 1628
diff changeset
   311
					return DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
1627
d88508d9ced0 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   312
			}
d88508d9ced0 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   313
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   314
1627
d88508d9ced0 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   315
		case MP_RAILWAY:
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   316
			if (!CheckTrackCombination(tile, trackbit, flags) ||
1627
d88508d9ced0 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   317
					!EnsureNoVehicle(tile)) {
d88508d9ced0 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   318
				return CMD_ERROR;
d88508d9ced0 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   319
			}
d88508d9ced0 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   320
			if (m5 & RAIL_TYPE_SPECIAL ||
1903
725cdd1ec467 (svn r2409) Missed one _map_owner -> IsTileOwner()
tron
parents: 1902
diff changeset
   321
					!IsTileOwner(tile, _current_player) ||
2493
d834d0c1502a (svn r3019) -Codechange: Replace explicit shifting/anding/oring with GB and SB
tron
parents: 2472
diff changeset
   322
					GB(_m[tile].m3, 0, 4) != p1) {
1627
d88508d9ced0 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   323
				// Get detailed error message
d88508d9ced0 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   324
				return DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
d88508d9ced0 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   325
			}
d88508d9ced0 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   326
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   327
			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
   328
			if (CmdFailed(ret)) return ret;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   329
			cost += ret;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   330
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
   331
			if (flags & DC_EXEC) {
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2020
diff changeset
   332
				_m[tile].m2 &= ~RAIL_MAP2LO_GROUND_MASK; // Bare land
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2020
diff changeset
   333
				_m[tile].m5 = m5 | 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
   334
			}
1627
d88508d9ced0 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   335
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   336
1627
d88508d9ced0 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   337
		case MP_STREET:
d88508d9ced0 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   338
			if (!_valid_tileh_slopes[3][tileh]) // prevent certain slopes
d88508d9ced0 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   339
				return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
d88508d9ced0 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   340
			if (!EnsureNoVehicle(tile)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   341
1627
d88508d9ced0 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   342
			if ((m5 & 0xF0) == 0 && ( // normal road?
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   343
						(track == TRACK_DIAG1 && m5 == 0x05) ||
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   344
						(track == TRACK_DIAG2 && m5 == 0x0A) // correct direction?
1627
d88508d9ced0 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   345
					)) {
d88508d9ced0 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   346
				if (flags & DC_EXEC) {
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2020
diff changeset
   347
					_m[tile].m3 = GetTileOwner(tile);
1902
5d653da1abb7 (svn r2408) Introduce SetTileOwner() and use it
tron
parents: 1901
diff changeset
   348
					SetTileOwner(tile, _current_player);
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2020
diff changeset
   349
					_m[tile].m4 = p1;
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2020
diff changeset
   350
					_m[tile].m5 = 0x10 | (track == TRACK_DIAG1 ? 0x08 : 0x00); // level crossing
1627
d88508d9ced0 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   351
				}
d88508d9ced0 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   352
				break;
d88508d9ced0 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   353
			}
d88508d9ced0 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   354
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   355
			if (IsLevelCrossing(tile) && (m5 & 0x08 ? TRACK_DIAG1 : TRACK_DIAG2) == track)
1627
d88508d9ced0 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   356
				return_cmd_error(STR_1007_ALREADY_BUILT);
d88508d9ced0 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   357
			/* FALLTHROUGH */
d88508d9ced0 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   358
d88508d9ced0 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   359
		default:
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   360
			ret = CheckRailSlope(tileh, trackbit, 0, tile);
1691
fcd9fefaed02 (svn r2195) Add CmdFailed() as the One True Way(tm) to check if a command failed.
tron
parents: 1669
diff changeset
   361
			if (CmdFailed(ret)) return ret;
1627
d88508d9ced0 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   362
			cost += ret;
d88508d9ced0 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   363
d88508d9ced0 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   364
			ret = DoCommandByTile(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
   365
			if (CmdFailed(ret)) return ret;
1627
d88508d9ced0 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   366
			cost += ret;
d88508d9ced0 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   367
d88508d9ced0 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   368
			if (flags & DC_EXEC) {
d88508d9ced0 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   369
				SetTileType(tile, MP_RAILWAY);
1902
5d653da1abb7 (svn r2408) Introduce SetTileOwner() and use it
tron
parents: 1901
diff changeset
   370
				SetTileOwner(tile, _current_player);
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2020
diff changeset
   371
				_m[tile].m2 = 0; // Bare land
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2020
diff changeset
   372
				_m[tile].m3 = p1; // No signals, rail type
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2020
diff changeset
   373
				_m[tile].m5 = trackbit;
1627
d88508d9ced0 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   374
			}
d88508d9ced0 (svn r2131) -Fix: Rewrite CmdBuildSingleRail(), this addresses several issues:
tron
parents: 1609
diff changeset
   375
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   376
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   377
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   378
	if (flags & DC_EXEC) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   379
		MarkTileDirtyByTile(tile);
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   380
		SetSignalsOnBothDir(tile, track);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   381
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   382
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   383
	return cost + _price.build_rail;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   384
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   385
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
   386
/** Remove a single piece of track
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
   387
 * @param x,y coordinates for removal of track
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
   388
 * @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
   389
 * @param p2 rail orientation
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   390
 */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   391
int32 CmdRemoveSingleRail(int x, int y, uint32 flags, uint32 p1, uint32 p2)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   392
{
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   393
	Track track = (Track)p2;
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   394
	TrackBits trackbit;
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
   395
	TileIndex tile;
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   396
	byte m5;
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
   397
	int32 cost = _price.remove_rail;
9946
d3cb7e05c5a6 (svn r4016) -Backport from trunk (3998): When removing rail track from a tile where only X and Y pieces exist, explicitly update signals in both directions.
celestar
parents: 9942
diff changeset
   398
	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
   399
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
   400
	if (!ValParamTrackOrientation(p2)) return CMD_ERROR;
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   401
	trackbit = TrackToTrackBits(track);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   402
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   403
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   404
1980
9ea0c89fbb58 (svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents: 1977
diff changeset
   405
	tile = TileVirtXY(x, y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   406
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   407
	if (!IsTileType(tile, MP_TUNNELBRIDGE) && !IsTileType(tile, MP_STREET) && !IsTileType(tile, MP_RAILWAY))
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   408
		return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   409
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   410
	if (_current_player != OWNER_WATER && !CheckTileOwnership(tile))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   411
		return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   412
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   413
	// allow building rail under bridge
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   414
	if (!IsTileType(tile, MP_TUNNELBRIDGE) && !EnsureNoVehicle(tile))
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   415
		return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   416
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   417
	switch(GetTileType(tile))
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   418
	{
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   419
		case MP_TUNNELBRIDGE:
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   420
			if (!EnsureNoVehicleZ(tile, TilePixelHeight(tile)))
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   421
				return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   422
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2020
diff changeset
   423
			if ((_m[tile].m5 & 0xF8) != 0xE0)
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   424
				return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   425
2364
5ac6c8d6e031 (svn r2890) Fix some signed/unsigned comparison warnings (tokai)
tron
parents: 2261
diff changeset
   426
			if ((_m[tile].m5 & 1 ? TRACK_BIT_DIAG1 : TRACK_BIT_DIAG2) != trackbit)
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   427
				return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   428
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   429
			if (!(flags & DC_EXEC))
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   430
				return _price.remove_rail;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   431
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
   432
			SetTileOwner(tile, OWNER_NONE);
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2020
diff changeset
   433
			_m[tile].m5 = _m[tile].m5 & 0xC7;
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   434
			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
   435
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   436
		case MP_STREET:
2493
d834d0c1502a (svn r3019) -Codechange: Replace explicit shifting/anding/oring with GB and SB
tron
parents: 2472
diff changeset
   437
			if (!IsLevelCrossing(tile)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   438
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   439
			/* This is a crossing, let's check if the direction is correct */
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2020
diff changeset
   440
			if (_m[tile].m5 & 8) {
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   441
				m5 = 5;
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   442
				if (track != TRACK_DIAG1)
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   443
					return CMD_ERROR;
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   444
			} else {
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   445
				m5 = 10;
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   446
				if (track != TRACK_DIAG2)
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   447
					return CMD_ERROR;
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   448
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   449
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   450
			if (!(flags & DC_EXEC))
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   451
				return _price.remove_rail;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   452
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2020
diff changeset
   453
			_m[tile].m5 = m5;
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2020
diff changeset
   454
			SetTileOwner(tile, _m[tile].m3);
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   455
			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
   456
9946
d3cb7e05c5a6 (svn r4016) -Backport from trunk (3998): When removing rail track from a tile where only X and Y pieces exist, explicitly update signals in both directions.
celestar
parents: 9942
diff changeset
   457
		case MP_RAILWAY: {
d3cb7e05c5a6 (svn r4016) -Backport from trunk (3998): When removing rail track from a tile where only X and Y pieces exist, explicitly update signals in both directions.
celestar
parents: 9942
diff changeset
   458
			TrackBits present;
d3cb7e05c5a6 (svn r4016) -Backport from trunk (3998): When removing rail track from a tile where only X and Y pieces exist, explicitly update signals in both directions.
celestar
parents: 9942
diff changeset
   459
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   460
			if (!IsPlainRailTile(tile))
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   461
				return CMD_ERROR;
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   462
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   463
			/* See if the track to remove is actually there */
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   464
			if (!(GetTrackBits(tile) & trackbit))
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   465
				return CMD_ERROR;
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   466
9946
d3cb7e05c5a6 (svn r4016) -Backport from trunk (3998): When removing rail track from a tile where only X and Y pieces exist, explicitly update signals in both directions.
celestar
parents: 9942
diff changeset
   467
			present = GetTrackBits(tile);
d3cb7e05c5a6 (svn r4016) -Backport from trunk (3998): When removing rail track from a tile where only X and Y pieces exist, explicitly update signals in both directions.
celestar
parents: 9942
diff changeset
   468
			if ((present & trackbit) == 0) return CMD_ERROR;
d3cb7e05c5a6 (svn r4016) -Backport from trunk (3998): When removing rail track from a tile where only X and Y pieces exist, explicitly update signals in both directions.
celestar
parents: 9942
diff changeset
   469
			if (present == (TRACK_BIT_DIAG1 | TRACK_BIT_DIAG2)) crossing = true;
d3cb7e05c5a6 (svn r4016) -Backport from trunk (3998): When removing rail track from a tile where only X and Y pieces exist, explicitly update signals in both directions.
celestar
parents: 9942
diff changeset
   470
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
   471
			/* 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
   472
			if (HasSignalOnTrack(tile, track))
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
   473
				cost += DoCommand(x, y, track, 0, flags, CMD_REMOVE_SIGNALS);
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   474
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   475
			if (!(flags & DC_EXEC))
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
   476
				return cost;
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   477
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   478
			/* We remove the trackbit here. */
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2020
diff changeset
   479
			_m[tile].m5 &= ~trackbit;
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   480
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   481
			if (GetTrackBits(tile)  == 0) {
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   482
				/* The tile has no tracks left, it is no longer a rail tile */
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   483
				DoClearSquare(tile);
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   484
				/* XXX: This is an optimisation, right? Is it really worth the ugly goto? */
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   485
				goto skip_mark_dirty;
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   486
			}
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   487
			break;
9946
d3cb7e05c5a6 (svn r4016) -Backport from trunk (3998): When removing rail track from a tile where only X and Y pieces exist, explicitly update signals in both directions.
celestar
parents: 9942
diff changeset
   488
		}
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
   489
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   490
		default:
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   491
			assert(0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   492
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   493
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   494
	/* mark_dirty */
9946
d3cb7e05c5a6 (svn r4016) -Backport from trunk (3998): When removing rail track from a tile where only X and Y pieces exist, explicitly update signals in both directions.
celestar
parents: 9942
diff changeset
   495
	if (flags & DC_EXEC) {
d3cb7e05c5a6 (svn r4016) -Backport from trunk (3998): When removing rail track from a tile where only X and Y pieces exist, explicitly update signals in both directions.
celestar
parents: 9942
diff changeset
   496
		MarkTileDirtyByTile(tile);
d3cb7e05c5a6 (svn r4016) -Backport from trunk (3998): When removing rail track from a tile where only X and Y pieces exist, explicitly update signals in both directions.
celestar
parents: 9942
diff changeset
   497
		if (crossing) {
d3cb7e05c5a6 (svn r4016) -Backport from trunk (3998): When removing rail track from a tile where only X and Y pieces exist, explicitly update signals in both directions.
celestar
parents: 9942
diff changeset
   498
			/* crossing is set when only TRACK_BIT_X and TRACK_BIT_Y are set. As we
d3cb7e05c5a6 (svn r4016) -Backport from trunk (3998): When removing rail track from a tile where only X and Y pieces exist, explicitly update signals in both directions.
celestar
parents: 9942
diff changeset
   499
			 * are removing one of these pieces, we'll need to update signals for
d3cb7e05c5a6 (svn r4016) -Backport from trunk (3998): When removing rail track from a tile where only X and Y pieces exist, explicitly update signals in both directions.
celestar
parents: 9942
diff changeset
   500
			 * both directions explicitly, as after the track is removed it won't
d3cb7e05c5a6 (svn r4016) -Backport from trunk (3998): When removing rail track from a tile where only X and Y pieces exist, explicitly update signals in both directions.
celestar
parents: 9942
diff changeset
   501
			 * 'connect' with the other piece. */
d3cb7e05c5a6 (svn r4016) -Backport from trunk (3998): When removing rail track from a tile where only X and Y pieces exist, explicitly update signals in both directions.
celestar
parents: 9942
diff changeset
   502
			SetSignalsOnBothDir(tile, TRACK_DIAG1);
d3cb7e05c5a6 (svn r4016) -Backport from trunk (3998): When removing rail track from a tile where only X and Y pieces exist, explicitly update signals in both directions.
celestar
parents: 9942
diff changeset
   503
			SetSignalsOnBothDir(tile, TRACK_DIAG2);
d3cb7e05c5a6 (svn r4016) -Backport from trunk (3998): When removing rail track from a tile where only X and Y pieces exist, explicitly update signals in both directions.
celestar
parents: 9942
diff changeset
   504
		} else {
d3cb7e05c5a6 (svn r4016) -Backport from trunk (3998): When removing rail track from a tile where only X and Y pieces exist, explicitly update signals in both directions.
celestar
parents: 9942
diff changeset
   505
			SetSignalsOnBothDir(tile, track);
d3cb7e05c5a6 (svn r4016) -Backport from trunk (3998): When removing rail track from a tile where only X and Y pieces exist, explicitly update signals in both directions.
celestar
parents: 9942
diff changeset
   506
		}
d3cb7e05c5a6 (svn r4016) -Backport from trunk (3998): When removing rail track from a tile where only X and Y pieces exist, explicitly update signals in both directions.
celestar
parents: 9942
diff changeset
   507
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   508
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   509
skip_mark_dirty:;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   510
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   511
	SetSignalsOnBothDir(tile, track);
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   512
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
   513
	return cost;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   514
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   515
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   516
static const struct {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   517
	int8 xinc[16];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   518
	int8 yinc[16];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   519
} _railbit = {{
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
   520
//  0   1   2   3   4   5
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
   521
	-16,  0,-16,  0, 16,  0,    0,  0,
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
   522
	 16,  0,  0, 16,  0,-16,    0,  0,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   523
},{
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
   524
	  0, 16,  0, 16,  0, 16,    0,  0,
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
   525
	  0,-16,-16,  0,-16,  0,    0,  0,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   526
}};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   527
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   528
static int32 ValidateAutoDrag(Trackdir *trackdir, int x, int y, int ex, int ey)
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
   529
{
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
   530
	int dx, dy, trdx, trdy;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   531
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   532
	if (!ValParamTrackOrientation(*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
   533
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
   534
	// calculate delta x,y from start to end tile
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
   535
	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
   536
	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
   537
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
   538
	// calculate delta x,y for the first direction
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   539
	trdx = _railbit.xinc[*trackdir];
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   540
	trdy = _railbit.yinc[*trackdir];
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
   541
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   542
	if (!IsDiagonalTrackdir(*trackdir)) {
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   543
		trdx += _railbit.xinc[*trackdir ^ 1];
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   544
		trdy += _railbit.yinc[*trackdir ^ 1];
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
   545
	}
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
   546
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
   547
	// validate the direction
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
   548
	while (((trdx <= 0) && (dx > 0)) || ((trdx >= 0) && (dx < 0)) ||
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
   549
	       ((trdy <= 0) && (dy > 0)) || ((trdy >= 0) && (dy < 0))) {
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   550
		if (!HASBIT(*trackdir, 3)) { // first direction is invalid, try the other
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   551
			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
   552
			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
   553
			trdy = -trdy;
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
   554
		} else // other direction is invalid too, invalid drag
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
   555
			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
   556
	}
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
   557
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
   558
	// (for diagonal tracks, this is already made sure of by above test), but:
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
   559
	// 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
   560
	if (!IsDiagonalTrackdir(*trackdir)) {
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   561
		trdx = _railbit.xinc[*trackdir];
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   562
		trdy = _railbit.yinc[*trackdir];
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
   563
		if ((abs(dx) != abs(dy)) && (abs(dx) + abs(trdy) != abs(dy) + abs(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
   564
			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
   565
	}
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
   566
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
   567
	return 0;
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
   568
}
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
   569
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
   570
/** Build a stretch of railroad tracks.
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
   571
 * @param x,y start 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
   572
 * @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
   573
 * @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
   574
 * - 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
   575
 * - 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
   576
 * - p2 = (bit 7)   - 0 = build, 1 = remove tracks
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   577
 */
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
   578
static int32 CmdRailTrackHelper(int x, int y, uint32 flags, uint32 p1, uint32 p2)
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
   579
{
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
   580
	int ex, ey;
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
   581
	int32 ret, total_cost = 0;
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
   582
	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
   583
	Trackdir trackdir;
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
   584
	byte mode = HASBIT(p2, 7);
2604
901508f52c3d (svn r3141) Replace incorrect railtype bitmask in CmdRailTrackHelper with appropriate GB()
peter1138
parents: 2549
diff changeset
   585
	RailType railtype = (RailType)GB(p2, 0, 4);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   586
2604
901508f52c3d (svn r3141) Replace incorrect railtype bitmask in CmdRailTrackHelper with appropriate GB()
peter1138
parents: 2549
diff changeset
   587
	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
   588
	if (p1 >= MapSize()) return CMD_ERROR;
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   589
	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
   590
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
   591
	/* unpack end point */
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   592
	ex = TileX(p1) * TILE_SIZE;
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   593
	ey = TileY(p1) * TILE_SIZE;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   594
889
7f8630bfea41 (svn r1375) -Fix: [1050990] Buying trains sometimes accounted for incorrectly. Was the result of the cost getting reset in a recursive call of docommand. That is fixed. In addition all cost-commands are typed explicitely. Please do not forget to do so or your costs will be credited to construction if you are unlucky.
darkvater
parents: 826
diff changeset
   595
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
7f8630bfea41 (svn r1375) -Fix: [1050990] Buying trains sometimes accounted for incorrectly. Was the result of the cost getting reset in a recursive call of docommand. That is fixed. In addition all cost-commands are typed explicitely. Please do not forget to do so or your costs will be credited to construction if you are unlucky.
darkvater
parents: 826
diff changeset
   596
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   597
	if (CmdFailed(ValidateAutoDrag(&trackdir, x, y, ex, ey))) return CMD_ERROR;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   598
1980
9ea0c89fbb58 (svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents: 1977
diff changeset
   599
	if (flags & DC_EXEC) SndPlayTileFx(SND_20_SPLAT_2, TileVirtXY(x, y));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   600
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   601
	for(;;) {
2604
901508f52c3d (svn r3141) Replace incorrect railtype bitmask in CmdRailTrackHelper with appropriate GB()
peter1138
parents: 2549
diff changeset
   602
		ret = DoCommand(x, y, 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
   603
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
   604
		if (CmdFailed(ret)) {
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
   605
			if ((_error_message != STR_1007_ALREADY_BUILT) && (mode == 0))
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   606
				break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   607
		} else
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   608
			total_cost += ret;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   609
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
   610
		if (x == ex && y == ey)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   611
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   612
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   613
		x += _railbit.xinc[trackdir];
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   614
		y += _railbit.yinc[trackdir];
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   615
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
   616
		// toggle railbit for the non-diagonal tracks
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   617
		if (!IsDiagonalTrackdir(trackdir)) trackdir ^= 1;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   618
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   619
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
   620
	return (total_cost == 0) ? CMD_ERROR : total_cost;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   621
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   622
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
   623
/** 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
   624
 * Stub for the unified rail builder/remover
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
   625
 * @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
   626
 */
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
int32 CmdBuildRailroadTrack(int x, int y, uint32 flags, uint32 p1, uint32 p2)
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
   628
{
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
   629
	return CmdRailTrackHelper(x, y, 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
   630
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   631
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
   632
/** 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
   633
 * Stub for the unified rail builder/remover
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
   634
 * @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
   635
 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   636
int32 CmdRemoveRailroadTrack(int x, int y, uint32 flags, uint32 p1, uint32 p2)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   637
{
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
   638
	return CmdRailTrackHelper(x, y, flags, p1, SETBIT(p2, 7));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   639
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   640
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
   641
/** Build a train depot
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
   642
 * @param x,y position of the train depot
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
 * @param p1 rail type
2085
ae9e92ffe168 (svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents: 2049
diff changeset
   644
 * @param p2 depot direction (0 through 3), where 0 is NE, 1 is SE, 2 is SW, 3 is NW
ae9e92ffe168 (svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents: 2049
diff changeset
   645
 *
ae9e92ffe168 (svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents: 2049
diff changeset
   646
 * @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
   647
 * 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
   648
 */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   649
int32 CmdBuildTrainDepot(int x, int y, uint32 flags, uint32 p1, uint32 p2)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   650
{
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
   651
	Depot *d;
1980
9ea0c89fbb58 (svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents: 1977
diff changeset
   652
	TileIndex tile = TileVirtXY(x, y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   653
	int32 cost, ret;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   654
	uint tileh;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   655
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   656
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   657
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   658
	if (!EnsureNoVehicle(tile)) return CMD_ERROR;
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
   659
	/* check railtype and valid direction for depot (0 through 3), 4 in total */
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
   660
	if (!ValParamRailtype(p1) || p2 > 3) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   661
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   662
	tileh = GetTileSlope(tile, NULL);
2085
ae9e92ffe168 (svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents: 2049
diff changeset
   663
ae9e92ffe168 (svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents: 2049
diff changeset
   664
	/* Prohibit construction if
ae9e92ffe168 (svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents: 2049
diff changeset
   665
		The tile is non-flat AND
ae9e92ffe168 (svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents: 2049
diff changeset
   666
		1) The AI is "old-school"
ae9e92ffe168 (svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents: 2049
diff changeset
   667
		2) build-on-slopes is disabled
ae9e92ffe168 (svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents: 2049
diff changeset
   668
		3) the tile is steep i.e. spans two height levels
ae9e92ffe168 (svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents: 2049
diff changeset
   669
		4) the exit points in the wrong direction
ae9e92ffe168 (svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents: 2049
diff changeset
   670
ae9e92ffe168 (svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents: 2049
diff changeset
   671
	*/
ae9e92ffe168 (svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents: 2049
diff changeset
   672
ae9e92ffe168 (svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents: 2049
diff changeset
   673
	if (tileh != 0 && (
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
   674
				_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
   675
				!_patches.build_on_slopes ||
97ada3bd2702 (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2544
diff changeset
   676
				IsSteepTileh(tileh) ||
97ada3bd2702 (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2544
diff changeset
   677
				!CanBuildDepotByTileh(p2, tileh)
97ada3bd2702 (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2544
diff changeset
   678
			)) {
97ada3bd2702 (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2544
diff changeset
   679
		return_cmd_error(STR_0007_FLAT_LAND_REQUIRED);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   680
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   681
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   682
	ret = DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
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
   683
	if (CmdFailed(ret)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   684
	cost = ret;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   685
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
   686
	d = AllocateDepot();
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   687
	if (d == NULL) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   688
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   689
	if (flags & DC_EXEC) {
2425
99e1e8430a28 (svn r2951) - Fix: [ 1259345 ] Changing engine in netgame opens train window for everyone
Darkvater
parents: 2422
diff changeset
   690
		if (IsLocalPlayer()) _last_built_train_depot_tile = tile;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   691
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   692
		ModifyTile(tile,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   693
			MP_SETTYPE(MP_RAILWAY) |
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   694
			MP_MAP3LO | MP_MAPOWNER_CURRENT | MP_MAP5,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   695
			p1, /* map3_lo */
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   696
			p2 | RAIL_TYPE_DEPOT_WAYPOINT /* map5 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   697
		);
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   698
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
   699
		d->xy = tile;
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
   700
		d->town_index = ClosestTownFromTile(tile, (uint)-1)->index;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   701
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   702
		SetSignalsOnBothDir(tile, (p2&1) ? 2 : 1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   703
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   704
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   705
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   706
	return cost + _price.build_train_depot;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   707
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   708
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
   709
/** Build signals, alternate between double/single, signal/semaphore,
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
   710
 * pre/exit/combo-signals, and what-else not
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
   711
 * @param x,y coordinates where signals is being built
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
   712
 * @param p1 various bitstuffed elements
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   713
 * - p1 = (bit 0-2) - 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
   714
 * - p1 = (bit 3)   - choose semaphores/signals or cycle normal/pre/exit/combo depending on context
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   715
 * @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
   716
 * 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
   717
 */
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
   718
int32 CmdBuildSingleSignal(int x, int y, uint32 flags, uint32 p1, uint32 p2)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   719
{
1980
9ea0c89fbb58 (svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents: 1977
diff changeset
   720
	TileIndex tile = TileVirtXY(x, y);
1084
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   721
	bool semaphore;
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   722
	bool pre_signal;
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   723
	Track track = (Track)(p1 & 0x7);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   724
	int32 cost;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   725
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   726
	// Same bit, used in different contexts
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   727
	semaphore = pre_signal = HASBIT(p1, 3);
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   728
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
   729
	if (!ValParamTrackOrientation(track) || !IsTileType(tile, MP_RAILWAY) || !EnsureNoVehicle(tile))
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   730
		return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   731
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
   732
	/* Protect against invalid signal copying */
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   733
	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
   734
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   735
	/* 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
   736
	if (!IsPlainRailTile(tile) || !HasTrack(tile, track)) return CMD_ERROR;
1084
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   737
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   738
	if (!CheckTileOwnership(tile)) return CMD_ERROR;
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   739
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
   740
	_error_message = STR_1005_NO_SUITABLE_RAILROAD_TRACK;
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
   741
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   742
	{
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   743
 		/* See if this is a valid track combination for signals, (ie, no overlap) */
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   744
 		TrackBits trackbits = GetTrackBits(tile);
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   745
		if (KILL_FIRST_BIT(trackbits) != 0 && /* More than one track present */
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   746
				trackbits != (TRACK_BIT_UPPER | TRACK_BIT_LOWER) && /* Horizontal parallel, non-intersecting tracks */
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   747
				trackbits != (TRACK_BIT_LEFT | TRACK_BIT_RIGHT) /* Vertical parallel, non-intersecting tracks */
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   748
		)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   749
			return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   750
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   751
1084
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   752
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   753
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   754
	if (!HasSignalOnTrack(tile, track)) {
1084
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   755
		// build new signals
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   756
		cost = _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
   757
	} else {
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   758
		if (p2 != 0 && semaphore != HasSemaphores(tile, track)) {
1084
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   759
			// convert signals <-> semaphores
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   760
			cost = _price.build_signals + _price.remove_signals;
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   761
		} else {
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   762
			// it is free to change orientation/pre-exit-combo signals
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   763
			cost = 0;
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   764
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   765
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   766
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   767
	if (flags & DC_EXEC) {
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   768
		if (GetRailTileType(tile) != RAIL_TYPE_SIGNALS) {
1084
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   769
			// there are no signals at all on this tile yet
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2020
diff changeset
   770
			_m[tile].m5 |= RAIL_TYPE_SIGNALS; // change into signals
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2020
diff changeset
   771
			_m[tile].m2 |= 0xF0;              // all signals are on
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2020
diff changeset
   772
			_m[tile].m3 &= ~0xF0;          // no signals built by default
2911
592a60af08a7 (svn r3466) - Codechange: Some changes to increase readability of signals code.
Darkvater
parents: 2841
diff changeset
   773
			_m[tile].m4 = semaphore ? SIG_SEMAPHORE_MASK : 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   774
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   775
1084
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   776
		if (p2 == 0) {
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   777
			if (!HasSignalOnTrack(tile, track)) {
1084
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   778
				// build new signals
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2020
diff changeset
   779
				_m[tile].m3 |= SignalOnTrack(track);
1084
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   780
			} else {
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   781
				if (pre_signal) {
2916
8f1aa489701f (svn r3472) - [PBS] Remove from trunk. Anyone interested can still find it in branch/pbs. This reverts revisions r3158, r3140, r3075, r2977, r2674, r2625, r2621, r2529, r2528, r2525, r2524, r2519, r2517, r2516, r2507, r2499. (in conjunction with Tron)
Darkvater
parents: 2911
diff changeset
   782
					// cycle between normal -> pre -> exit -> combo -> ...
2911
592a60af08a7 (svn r3466) - Codechange: Some changes to increase readability of signals code.
Darkvater
parents: 2841
diff changeset
   783
					byte type = (GetSignalType(tile, track) + 1) % SIGTYPE_END;
2916
8f1aa489701f (svn r3472) - [PBS] Remove from trunk. Anyone interested can still find it in branch/pbs. This reverts revisions r3158, r3140, r3075, r2977, r2674, r2625, r2621, r2529, r2528, r2525, r2524, r2519, r2517, r2516, r2507, r2499. (in conjunction with Tron)
Darkvater
parents: 2911
diff changeset
   784
					SB(_m[tile].m4, 0, 2, type);
1084
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   785
				} else {
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   786
					// cycle between two-way -> one-way -> one-way -> ...
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   787
					/* TODO: Rewrite switch into something more general */
1084
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   788
					switch (track) {
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   789
						case TRACK_LOWER:
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   790
						case TRACK_RIGHT: {
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2020
diff changeset
   791
							byte signal = (_m[tile].m3 - 0x10) & 0x30;
1084
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   792
							if (signal == 0) signal = 0x30;
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2020
diff changeset
   793
							_m[tile].m3 &= ~0x30;
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2020
diff changeset
   794
							_m[tile].m3 |= signal;
1084
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   795
							break;
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   796
						}
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
   797
1084
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   798
						default: {
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2020
diff changeset
   799
							byte signal = (_m[tile].m3 - 0x40) & 0xC0;
1084
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   800
							if (signal == 0) signal = 0xC0;
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2020
diff changeset
   801
							_m[tile].m3 &= ~0xC0;
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2020
diff changeset
   802
							_m[tile].m3 |= signal;
1084
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   803
							break;
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   804
						}
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   805
					}
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   806
				}
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   807
			}
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
   808
		} else {
1084
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   809
			/* 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
   810
			 * direction of the first signal given as parameter by CmdBuildManySignals */
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2020
diff changeset
   811
			_m[tile].m3 &= ~SignalOnTrack(track);
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2020
diff changeset
   812
			_m[tile].m3 |= p2 & SignalOnTrack(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
   813
			// convert between signal<->semaphores when dragging
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   814
			if (semaphore) {
2916
8f1aa489701f (svn r3472) - [PBS] Remove from trunk. Anyone interested can still find it in branch/pbs. This reverts revisions r3158, r3140, r3075, r2977, r2674, r2625, r2621, r2529, r2528, r2525, r2524, r2519, r2517, r2516, r2507, r2499. (in conjunction with Tron)
Darkvater
parents: 2911
diff changeset
   815
				SETBIT(_m[tile].m4, 2);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   816
			} else {
2916
8f1aa489701f (svn r3472) - [PBS] Remove from trunk. Anyone interested can still find it in branch/pbs. This reverts revisions r3158, r3140, r3075, r2977, r2674, r2625, r2621, r2529, r2528, r2525, r2524, r2519, r2517, r2516, r2507, r2499. (in conjunction with Tron)
Darkvater
parents: 2911
diff changeset
   817
				CLRBIT(_m[tile].m4, 2);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   818
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   819
		}
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   820
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   821
		MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   822
		SetSignalsOnBothDir(tile, track);
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   825
	return cost;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   826
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   827
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
   828
/**	Build many signals by dragging; AutoSignals
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
   829
 * @param x,y start 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
   830
 * @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
   831
 * @param p2 various bitstuffed elements
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
   832
 * - p2 = (bit  0)    - 0 = build, 1 = remove signals
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
   833
 * - p2 = (bit  3)    - 0 = signals, 1 = semaphores
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   834
 * - p2 = (bit  4- 6) - track-orientation, valid values: 0-5 (Track enum)
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
   835
 * - 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
   836
 */
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
   837
static int32 CmdSignalTrackHelper(int x, int y, 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
   838
{
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
   839
	int ex, ey;
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
   840
	int32 ret, total_cost, 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
   841
	byte signals;
1980
9ea0c89fbb58 (svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents: 1977
diff changeset
   842
	TileIndex tile = TileVirtXY(x, y);
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
   843
	bool error = true;
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
   844
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
   845
	int mode = p2 & 0x1;
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
   846
	Track track = GB(p2, 4, 3);
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   847
	Trackdir trackdir = TrackToTrackdir(track);
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
   848
	byte semaphores = (HASBIT(p2, 3)) ? 8 : 0;
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
   849
	byte signal_density = (p2 >> 24);
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
   850
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
   851
	if (p1 >= MapSize()) return CMD_ERROR;
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
   852
	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
   853
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   854
	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
   855
889
7f8630bfea41 (svn r1375) -Fix: [1050990] Buying trains sometimes accounted for incorrectly. Was the result of the cost getting reset in a recursive call of docommand. That is fixed. In addition all cost-commands are typed explicitely. Please do not forget to do so or your costs will be credited to construction if you are unlucky.
darkvater
parents: 826
diff changeset
   856
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
7f8630bfea41 (svn r1375) -Fix: [1050990] Buying trains sometimes accounted for incorrectly. Was the result of the cost getting reset in a recursive call of docommand. That is fixed. In addition all cost-commands are typed explicitely. Please do not forget to do so or your costs will be credited to construction if you are unlucky.
darkvater
parents: 826
diff changeset
   857
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
   858
	/* for vertical/horizontal tracks, double the given signals density
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
   859
	* since the original amount will be too dense (shorter tracks) */
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   860
	if (!IsDiagonalTrack(track))
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   861
		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
   862
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
   863
	// unpack end tile
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   864
	ex = TileX(p1) * TILE_SIZE;
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   865
	ey = TileY(p1) * TILE_SIZE;
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
   866
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   867
	if (CmdFailed(ValidateAutoDrag(&trackdir, x, y, ex, ey))) return CMD_ERROR;
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   868
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   869
	track = TrackdirToTrack(trackdir); /* trackdir might have changed, keep track in sync */
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
   870
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
   871
	// copy the signal-style of the first rail-piece if existing
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   872
	if (GetRailTileType(tile) == RAIL_TYPE_SIGNALS && GetTrackBits(tile) != 0) { /* XXX: GetTrackBits check useless? */
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2020
diff changeset
   873
		signals = _m[tile].m3 & SignalOnTrack(track);
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   874
		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
   875
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   876
		semaphores = (HasSemaphores(tile, track) ? 8 : 0); // copy signal/semaphores style (independent of CTRL)
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
   877
	} 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
   878
		signals = SignalOnTrack(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
   879
1954
58fee2f9eb81 (svn r2460) - Fix: Prevent assertion failure when trying to drag signals starting from a non-rail tile.
hackykid
parents: 1946
diff changeset
   880
	/* 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
   881
	 * 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
   882
	 **********
1954
58fee2f9eb81 (svn r2460) - Fix: Prevent assertion failure when trying to drag signals starting from a non-rail tile.
hackykid
parents: 1946
diff changeset
   883
	 * 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
   884
	 * semaphores - semaphores or signals
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   885
	 * signals    - is there a signal/semaphore on the first tile, copy its style (two-way/single-way)
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   886
	                and convert all others to semaphore/signal
1954
58fee2f9eb81 (svn r2460) - Fix: Prevent assertion failure when trying to drag signals starting from a non-rail tile.
hackykid
parents: 1946
diff changeset
   887
	 * mode       - 1 remove signals, 0 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
   888
	signal_ctr = total_cost = 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
   889
	for (;;) {
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
   890
		// only build/remove signals with the specified density
1954
58fee2f9eb81 (svn r2460) - Fix: Prevent assertion failure when trying to drag signals starting from a non-rail tile.
hackykid
parents: 1946
diff changeset
   891
		if ((signal_ctr % signal_density) == 0 ) {
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   892
			ret = DoCommand(x, y, TrackdirToTrack(trackdir) | semaphores, signals, flags, (mode == 1) ? 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
   893
826
0e2b569b737b (svn r1297) Language fixes in the source.. (ln-)
miham
parents: 817
diff changeset
   894
			/* Abort placement for any other error than NOT_SUITABLE_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
   895
			 * This includes vehicles on track, competitor's tracks, etc. */
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
   896
			if (CmdFailed(ret)) {
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
   897
				if (_error_message != STR_1005_NO_SUITABLE_RAILROAD_TRACK && mode != 1) 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
   898
			} else {
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
   899
				error = false;
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
   900
				total_cost += ret;
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
   901
			}
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
   902
		}
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
   903
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
   904
		if (ex == x && ey == y) break; // reached end of drag
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
   905
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   906
		x += _railbit.xinc[trackdir];
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   907
		y += _railbit.yinc[trackdir];
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
   908
		signal_ctr++;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   909
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
   910
		// toggle railbit for the non-diagonal tracks (|, -- tracks)
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   911
		if (!IsDiagonalTrackdir(trackdir)) trackdir ^= 1;
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
   912
	}
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
   913
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
   914
	return (error) ? CMD_ERROR : total_cost;
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
   915
}
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
   916
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
   917
/** 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
   918
 * Stub for the unified signal builder/remover
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
   919
 * @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
   920
 */
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
   921
int32 CmdBuildSignalTrack(int x, int y, uint32 flags, uint32 p1, uint32 p2)
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
   922
{
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
   923
	return CmdSignalTrackHelper(x, y, flags, p1, p2);
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
   924
}
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
   925
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
   926
/** Remove signals
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
   927
 * @param x,y coordinates where signal is being deleted from
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   928
 * @param p1 track to remove signal from (Track enum)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   929
 */
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
   930
int32 CmdRemoveSingleSignal(int x, int y, uint32 flags, uint32 p1, uint32 p2)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   931
{
1980
9ea0c89fbb58 (svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents: 1977
diff changeset
   932
	TileIndex tile = TileVirtXY(x, y);
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   933
	Track track = (Track)(p1 & 0x7);
1518
ade7a74ac31a (svn r2022) Revise CmdRemoveSingleSignal: Check parameters for validity and simplify the function
tron
parents: 1477
diff changeset
   934
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
   935
	if (!ValParamTrackOrientation(track) || !IsTileType(tile, MP_RAILWAY) || !EnsureNoVehicle(tile))
1518
ade7a74ac31a (svn r2022) Revise CmdRemoveSingleSignal: Check parameters for validity and simplify the function
tron
parents: 1477
diff changeset
   936
		return CMD_ERROR;
ade7a74ac31a (svn r2022) Revise CmdRemoveSingleSignal: Check parameters for validity and simplify the function
tron
parents: 1477
diff changeset
   937
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   938
	if (!HasSignalOnTrack(tile, track)) // no signals on track?
1518
ade7a74ac31a (svn r2022) Revise CmdRemoveSingleSignal: Check parameters for validity and simplify the function
tron
parents: 1477
diff changeset
   939
		return CMD_ERROR;
ade7a74ac31a (svn r2022) Revise CmdRemoveSingleSignal: Check parameters for validity and simplify the function
tron
parents: 1477
diff changeset
   940
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
   941
	/* 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
   942
	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
   943
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   944
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   945
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   946
	/* Do it? */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   947
	if (flags & DC_EXEC) {
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2020
diff changeset
   948
		_m[tile].m3 &= ~SignalOnTrack(track);
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   949
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
   950
		/* removed last signal from tile? */
2493
d834d0c1502a (svn r3019) -Codechange: Replace explicit shifting/anding/oring with GB and SB
tron
parents: 2472
diff changeset
   951
		if (GB(_m[tile].m3, 4, 4) == 0) {
d834d0c1502a (svn r3019) -Codechange: Replace explicit shifting/anding/oring with GB and SB
tron
parents: 2472
diff changeset
   952
			SB(_m[tile].m2, 4, 4, 0);
d834d0c1502a (svn r3019) -Codechange: Replace explicit shifting/anding/oring with GB and SB
tron
parents: 2472
diff changeset
   953
			SB(_m[tile].m5, 6, 2, RAIL_TYPE_NORMAL >> 6); // XXX >> because the constant is meant for direct application, not use with SB
2916
8f1aa489701f (svn r3472) - [PBS] Remove from trunk. Anyone interested can still find it in branch/pbs. This reverts revisions r3158, r3140, r3075, r2977, r2674, r2625, r2621, r2529, r2528, r2525, r2524, r2519, r2517, r2516, r2507, r2499. (in conjunction with Tron)
Darkvater
parents: 2911
diff changeset
   954
			CLRBIT(_m[tile].m4, 2); // 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
   955
		}
1109
1bab892228cd (svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents: 1095
diff changeset
   956
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
   957
		SetSignalsOnBothDir(tile, track);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   958
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   959
		MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   960
	}
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   961
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   962
	return _price.remove_signals;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   963
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   964
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
   965
/** 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
   966
 * Stub for the unified signal builder/remover
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
   967
 * @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
   968
 */
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
   969
int32 CmdRemoveSignalTrack(int x, int y, uint32 flags, uint32 p1, uint32 p2)
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
   970
{
1229
4c965ad79a0b (svn r1733) - Fix: oops "| 1" is SETBIT(x, 0), not 1 :(. Now you can remove signals again
darkvater
parents: 1227
diff changeset
   971
	return CmdSignalTrackHelper(x, y, flags, p1, SETBIT(p2, 0));
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
   972
}
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
   973
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1963
diff changeset
   974
typedef int32 DoConvertRailProc(TileIndex tile, uint totype, bool exec);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   975
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1963
diff changeset
   976
static int32 DoConvertRail(TileIndex tile, uint totype, bool exec)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   977
{
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
   978
	if (!CheckTileOwnership(tile) || !EnsureNoVehicle(tile)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   979
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   980
	// tile is already of requested type?
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
   981
	if (GetRailType(tile) == totype) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   982
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   983
	// change type.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   984
	if (exec) {
2499
bf819c473e13 (svn r3025) -Fix: Rail convert issue introduced in r3019
Darkvater
parents: 2493
diff changeset
   985
		SB(_m[tile].m3, 0, 4, totype);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   986
		MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   987
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   988
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
   989
	return _price.build_rail / 2;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   990
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   991
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1963
diff changeset
   992
extern int32 DoConvertStationRail(TileIndex tile, uint totype, bool exec);
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1963
diff changeset
   993
extern int32 DoConvertStreetRail(TileIndex tile, uint totype, bool exec);
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1963
diff changeset
   994
extern int32 DoConvertTunnelBridgeRail(TileIndex tile, uint totype, bool exec);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   995
1782
0ac16ff36293 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1781
diff changeset
   996
/** 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
   997
 * monorail/maglev easily or vice-versa.
0ac16ff36293 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1781
diff changeset
   998
 * @param ex,ey end tile of rail conversion drag
0ac16ff36293 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1781
diff changeset
   999
 * @param p1 start tile of drag
0ac16ff36293 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1781
diff changeset
  1000
 * @param p2 new railtype to convert to
0ac16ff36293 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1781
diff changeset
  1001
 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1002
int32 CmdConvertRail(int ex, int ey, uint32 flags, uint32 p1, uint32 p2)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1003
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1004
	int32 ret, cost, money;
1782
0ac16ff36293 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1781
diff changeset
  1005
	int sx, sy, x, y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1006
889
7f8630bfea41 (svn r1375) -Fix: [1050990] Buying trains sometimes accounted for incorrectly. Was the result of the cost getting reset in a recursive call of docommand. That is fixed. In addition all cost-commands are typed explicitely. Please do not forget to do so or your costs will be credited to construction if you are unlucky.
darkvater
parents: 826
diff changeset
  1007
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
7f8630bfea41 (svn r1375) -Fix: [1050990] Buying trains sometimes accounted for incorrectly. Was the result of the cost getting reset in a recursive call of docommand. That is fixed. In addition all cost-commands are typed explicitely. Please do not forget to do so or your costs will be credited to construction if you are unlucky.
darkvater
parents: 826
diff changeset
  1008
1782
0ac16ff36293 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1781
diff changeset
  1009
	if (!ValParamRailtype(p2)) 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
  1010
	if (p1 >= MapSize()) return CMD_ERROR;
1782
0ac16ff36293 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1781
diff changeset
  1011
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1012
	// make sure sx,sy are smaller than ex,ey
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
  1013
	sx = TileX(p1) * TILE_SIZE;
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
  1014
	sy = TileY(p1) * TILE_SIZE;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1015
	if (ex < sx) intswap(ex, sx);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1016
	if (ey < sy) intswap(ey, sy);
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1017
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1018
	money = GetAvailableMoneyForCommand();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1019
	cost = 0;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1020
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
  1021
	for (x = sx; x <= ex; x += TILE_SIZE) {
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
  1022
		for (y = sy; y <= ey; y += TILE_SIZE) {
1980
9ea0c89fbb58 (svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents: 1977
diff changeset
  1023
			TileIndex tile = TileVirtXY(x, y);
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1024
			DoConvertRailProc* proc;
1782
0ac16ff36293 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1781
diff changeset
  1025
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1026
			switch (GetTileType(tile)) {
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1027
				case MP_RAILWAY:      proc = DoConvertRail;             break;
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1028
				case MP_STATION:      proc = DoConvertStationRail;      break;
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1029
				case MP_STREET:       proc = DoConvertStreetRail;       break;
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1030
				case MP_TUNNELBRIDGE: proc = DoConvertTunnelBridgeRail; break;
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1031
				default: continue;
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1032
			}
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1033
1782
0ac16ff36293 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1781
diff changeset
  1034
			ret = proc(tile, p2, false);
0ac16ff36293 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1781
diff changeset
  1035
			if (CmdFailed(ret)) continue;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1036
			cost += ret;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1037
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1038
			if (flags & DC_EXEC) {
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1039
				money -= ret;
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1040
				if (money < 0) {
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1041
					_additional_cash_required = ret;
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1042
					return cost - ret;
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1043
				}
1782
0ac16ff36293 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1781
diff changeset
  1044
				proc(tile, p2, true);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1045
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1046
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1047
	}
1782
0ac16ff36293 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1781
diff changeset
  1048
0ac16ff36293 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1781
diff changeset
  1049
	return (cost == 0) ? CMD_ERROR : cost;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1050
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1051
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1963
diff changeset
  1052
static int32 RemoveTrainDepot(TileIndex tile, uint32 flags)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1053
{
149
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 84
diff changeset
  1054
	if (!CheckTileOwnership(tile) && _current_player != OWNER_WATER)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1055
		return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1056
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1057
	if (!EnsureNoVehicle(tile))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1058
		return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1059
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1060
	if (flags & DC_EXEC) {
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1061
		Track track = TrackdirToTrack(DiagdirToDiagTrackdir(GetDepotDirection(tile, TRANSPORT_RAIL)));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1062
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1063
		DoDeleteDepot(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1064
		SetSignalsOnBothDir(tile, track);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1065
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1066
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1067
	return _price.remove_train_depot;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1068
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1069
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
  1070
static int32 ClearTile_Track(TileIndex tile, byte flags)
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
  1071
{
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
  1072
	int32 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
  1073
	int32 ret;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1074
	byte m5;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1075
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2020
diff changeset
  1076
	m5 = _m[tile].m5;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1077
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1078
	if (flags & DC_AUTO) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1079
		if (m5 & RAIL_TYPE_SPECIAL)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1080
			return_cmd_error(STR_2004_BUILDING_MUST_BE_DEMOLISHED);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1081
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
  1082
		if (!IsTileOwner(tile, _current_player))
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1083
			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
  1084
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1085
		return_cmd_error(STR_1008_MUST_REMOVE_RAILROAD_TRACK);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1086
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1087
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1088
	cost = 0;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1089
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
  1090
	switch (GetRailTileType(tile)) {
2821
ba75b5f98725 (svn r3369) - Codechange: Replace tables _signals_table, _signals_table_other and _signals_table_both by the equivalent calls to rail.h functions.
matthijs
parents: 2817
diff changeset
  1091
		/* XXX: Why the fuck do we remove these thow signals first? */
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
  1092
		case RAIL_TYPE_SIGNALS:
2821
ba75b5f98725 (svn r3369) - Codechange: Replace tables _signals_table, _signals_table_other and _signals_table_both by the equivalent calls to rail.h functions.
matthijs
parents: 2817
diff changeset
  1093
			if(HasSignalOnTrack(tile, TRACK_DIAG1)) {
ba75b5f98725 (svn r3369) - Codechange: Replace tables _signals_table, _signals_table_other and _signals_table_both by the equivalent calls to rail.h functions.
matthijs
parents: 2817
diff changeset
  1094
				ret = DoCommandByTile(tile, TRACK_DIAG1, 0, flags, CMD_REMOVE_SIGNALS);
2737
f16e0a808897 (svn r3282) - Codechange: Replace tests against CMD_ERROR with CmdFailed()
peter1138
parents: 2670
diff changeset
  1095
				if (CmdFailed(ret)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1096
				cost += ret;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1097
			}
2821
ba75b5f98725 (svn r3369) - Codechange: Replace tables _signals_table, _signals_table_other and _signals_table_both by the equivalent calls to rail.h functions.
matthijs
parents: 2817
diff changeset
  1098
			if(HasSignalOnTrack(tile, TRACK_LOWER)) {
ba75b5f98725 (svn r3369) - Codechange: Replace tables _signals_table, _signals_table_other and _signals_table_both by the equivalent calls to rail.h functions.
matthijs
parents: 2817
diff changeset
  1099
				ret = DoCommandByTile(tile, TRACK_LOWER, 0, flags, CMD_REMOVE_SIGNALS);
2737
f16e0a808897 (svn r3282) - Codechange: Replace tests against CMD_ERROR with CmdFailed()
peter1138
parents: 2670
diff changeset
  1100
				if (CmdFailed(ret)) return CMD_ERROR;
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
  1101
				cost += ret;
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
  1102
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1103
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
  1104
			m5 &= TRACK_BIT_MASK;
1598
4425f756c19b (svn r2102) Fix bug introduced in r2038, which gave you money for clearing occupied railway tiles ([1171926])
tron
parents: 1591
diff changeset
  1105
			if (!(flags & DC_EXEC)) {
4425f756c19b (svn r2102) Fix bug introduced in r2038, which gave you money for clearing occupied railway tiles ([1171926])
tron
parents: 1591
diff changeset
  1106
				for (; m5 != 0; m5 >>= 1) if (m5 & 1) cost += _price.remove_rail;
4425f756c19b (svn r2102) Fix bug introduced in r2038, which gave you money for clearing occupied railway tiles ([1171926])
tron
parents: 1591
diff changeset
  1107
				return cost;
4425f756c19b (svn r2102) Fix bug introduced in r2038, which gave you money for clearing occupied railway tiles ([1171926])
tron
parents: 1591
diff changeset
  1108
			}
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
  1109
			/* FALLTHROUGH */
1109
1bab892228cd (svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents: 1095
diff changeset
  1110
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
  1111
		case RAIL_TYPE_NORMAL: {
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
  1112
			uint i;
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
  1113
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
  1114
			for (i = 0; m5 != 0; i++, m5 >>= 1) {
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
  1115
				if (m5 & 1) {
1598
4425f756c19b (svn r2102) Fix bug introduced in r2038, which gave you money for clearing occupied railway tiles ([1171926])
tron
parents: 1591
diff changeset
  1116
					ret = DoCommandByTile(tile, 0, i, flags, CMD_REMOVE_SINGLE_RAIL);
2737
f16e0a808897 (svn r3282) - Codechange: Replace tests against CMD_ERROR with CmdFailed()
peter1138
parents: 2670
diff changeset
  1117
					if (CmdFailed(ret)) return CMD_ERROR;
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
  1118
					cost += ret;
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
  1119
				}
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
  1120
			}
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
  1121
			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
  1122
		}
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
  1123
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
  1124
		case RAIL_TYPE_DEPOT_WAYPOINT:
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
  1125
			switch (m5 & RAIL_SUBTYPE_MASK) {
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
  1126
				case RAIL_SUBTYPE_DEPOT:
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
  1127
					return RemoveTrainDepot(tile, flags);
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
  1128
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
  1129
				case RAIL_SUBTYPE_WAYPOINT:
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
  1130
					return RemoveTrainWaypoint(tile, flags, false);
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
  1131
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
  1132
				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
  1133
					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
  1134
			}
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
  1135
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
  1136
		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
  1137
			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
  1138
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1139
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1140
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1141
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1142
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1143
#include "table/track_land.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1144
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1145
// used for presignals
2916
8f1aa489701f (svn r3472) - [PBS] Remove from trunk. Anyone interested can still find it in branch/pbs. This reverts revisions r3158, r3140, r3075, r2977, r2674, r2625, r2621, r2529, r2528, r2525, r2524, r2519, r2517, r2516, r2507, r2499. (in conjunction with Tron)
Darkvater
parents: 2911
diff changeset
  1146
static const SpriteID _signal_base_sprites[16] = {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1147
	0x4FB,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1148
	0x1323,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1149
	0x1333,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1150
	0x1343,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1151
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
  1152
	// semaphores
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1153
	0x1353,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1154
	0x1363,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1155
	0x1373,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1156
	0x1383,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1157
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1158
	// mirrored versions
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1159
	0x4FB,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1160
	0x1323,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1161
	0x1333,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1162
	0x1343,
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1163
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
  1164
	// semaphores
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
  1165
	0x1446,
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
  1166
	0x1456,
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
  1167
	0x1466,
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
  1168
	0x1476,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1169
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1170
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1171
// used to determine the side of the road for the signal
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1172
static const byte _signal_position[24] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1173
	/* original: left side position */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1174
	0x58,0x1E,0xE1,0xB9,0x01,0xA3,0x4B,0xEE,0x3B,0xD4,0x43,0xBD,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1175
	/* patch: ride side position */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1176
	0x1E,0xAC,0x64,0xE1,0x4A,0x10,0xEE,0xC5,0xDB,0x34,0x4D,0xB3
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1177
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1178
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
  1179
static void DrawSignalHelper(const TileInfo *ti, byte condition, uint32 image_and_pos)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1180
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1181
	bool otherside = _opt.road_side & _patches.signal_side;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1182
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1183
	uint v = _signal_position[(image_and_pos & 0xF) + (otherside ? 12 : 0)];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1184
	uint x = ti->x | (v&0xF);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1185
	uint y = ti->y | (v>>4);
2916
8f1aa489701f (svn r3472) - [PBS] Remove from trunk. Anyone interested can still find it in branch/pbs. This reverts revisions r3158, r3140, r3075, r2977, r2674, r2625, r2621, r2529, r2528, r2525, r2524, r2519, r2517, r2516, r2507, r2499. (in conjunction with Tron)
Darkvater
parents: 2911
diff changeset
  1186
	uint sprite = _signal_base_sprites[(_m[ti->tile].m4 & 0x7) + (otherside ? 8 : 0)] + (image_and_pos>>4) + ((condition != 0) ? 1 : 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1187
	AddSortableSpriteToDraw(sprite, x, y, 1, 1, 10, GetSlopeZ(x,y));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1188
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1189
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1190
static uint32 _drawtile_track_palette;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1191
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1192
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
  1193
static void DrawTrackFence_NW(const TileInfo *ti)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1194
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1195
	uint32 image = 0x515;
2645
964bd8fe3ce2 (svn r3187) Simplify overly complicated ifs, especially if (foo) return false; else return true; is confusing
tron
parents: 2642
diff changeset
  1196
	if (ti->tileh != 0) image = (ti->tileh & 2) ? 0x519 : 0x51B;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1197
	AddSortableSpriteToDraw(image | _drawtile_track_palette,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1198
		ti->x, ti->y+1, 16, 1, 4, ti->z);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1199
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1200
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
  1201
static void DrawTrackFence_SE(const TileInfo *ti)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1202
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1203
	uint32 image = 0x515;
2645
964bd8fe3ce2 (svn r3187) Simplify overly complicated ifs, especially if (foo) return false; else return true; is confusing
tron
parents: 2642
diff changeset
  1204
	if (ti->tileh != 0) image = (ti->tileh & 2) ? 0x519 : 0x51B;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1205
	AddSortableSpriteToDraw(image | _drawtile_track_palette,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1206
		ti->x, ti->y+15, 16, 1, 4, ti->z);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1207
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1208
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
  1209
static void DrawTrackFence_NW_SE(const TileInfo *ti)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1210
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1211
	DrawTrackFence_NW(ti);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1212
	DrawTrackFence_SE(ti);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1213
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1214
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
  1215
static void DrawTrackFence_NE(const TileInfo *ti)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1216
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1217
	uint32 image = 0x516;
2645
964bd8fe3ce2 (svn r3187) Simplify overly complicated ifs, especially if (foo) return false; else return true; is confusing
tron
parents: 2642
diff changeset
  1218
	if (ti->tileh != 0) image = (ti->tileh & 2) ? 0x51A : 0x51C;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1219
	AddSortableSpriteToDraw(image | _drawtile_track_palette,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1220
		ti->x+1, ti->y, 1, 16, 4, ti->z);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1221
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1222
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
  1223
static void DrawTrackFence_SW(const TileInfo *ti)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1224
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1225
	uint32 image = 0x516;
2645
964bd8fe3ce2 (svn r3187) Simplify overly complicated ifs, especially if (foo) return false; else return true; is confusing
tron
parents: 2642
diff changeset
  1226
	if (ti->tileh != 0) image = (ti->tileh & 2) ? 0x51A : 0x51C;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1227
	AddSortableSpriteToDraw(image | _drawtile_track_palette,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1228
		ti->x+15, ti->y, 1, 16, 4, ti->z);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1229
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1230
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
  1231
static void DrawTrackFence_NE_SW(const TileInfo *ti)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1232
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1233
	DrawTrackFence_NE(ti);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1234
	DrawTrackFence_SW(ti);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1235
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1236
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
  1237
static void DrawTrackFence_NS_1(const TileInfo *ti)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1238
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1239
	int z = ti->z;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1240
	if (ti->tileh & 1) z += 8;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1241
	AddSortableSpriteToDraw(0x517 | _drawtile_track_palette,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1242
		ti->x + 8, ti->y + 8, 1, 1, 4, z);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1243
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1244
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
  1245
static void DrawTrackFence_NS_2(const TileInfo *ti)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1246
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1247
	int z = ti->z;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1248
	if (ti->tileh & 4) z += 8;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1249
	AddSortableSpriteToDraw(0x517 | _drawtile_track_palette,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1250
		ti->x + 8, ti->y + 8, 1, 1, 4, z);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1251
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1252
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
  1253
static void DrawTrackFence_WE_1(const TileInfo *ti)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1254
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1255
	int z = ti->z;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1256
	if (ti->tileh & 8) z += 8;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1257
	AddSortableSpriteToDraw(0x518 | _drawtile_track_palette,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1258
		ti->x + 8, ti->y + 8, 1, 1, 4, z);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1259
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1260
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
  1261
static void DrawTrackFence_WE_2(const TileInfo *ti)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1262
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1263
	int z = ti->z;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1264
	if (ti->tileh & 2) z += 8;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1265
	AddSortableSpriteToDraw(0x518 | _drawtile_track_palette,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1266
		ti->x + 8, ti->y + 8, 1, 1, 4, z);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1267
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1268
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
  1269
static void DetTrackDrawProc_Null(const TileInfo *ti)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1270
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1271
	/* nothing should be here */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1272
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1273
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
  1274
typedef void DetailedTrackProc(const TileInfo *ti);
2752
b5fe5a7e6282 (svn r3297) Staticise
tron
parents: 2737
diff changeset
  1275
static DetailedTrackProc* const _detailed_track_proc[] = {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1276
	DetTrackDrawProc_Null,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1277
	DetTrackDrawProc_Null,
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1278
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1279
	DrawTrackFence_NW,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1280
	DrawTrackFence_SE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1281
	DrawTrackFence_NW_SE,
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1282
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1283
	DrawTrackFence_NE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1284
	DrawTrackFence_SW,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1285
	DrawTrackFence_NE_SW,
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1286
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1287
	DrawTrackFence_NS_1,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1288
	DrawTrackFence_NS_2,
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1289
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1290
	DrawTrackFence_WE_1,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1291
	DrawTrackFence_WE_2,
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1292
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1293
	DetTrackDrawProc_Null,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1294
	DetTrackDrawProc_Null,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1295
	DetTrackDrawProc_Null,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1296
	DetTrackDrawProc_Null,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1297
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1298
2254
72f8883ff3ac (svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents: 2236
diff changeset
  1299
static void DrawSpecialBuilding(uint32 image, uint32 offset,
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1300
                                const TileInfo* ti,
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 337
diff changeset
  1301
                                byte x, byte y, byte z,
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 337
diff changeset
  1302
                                byte xsize, byte ysize, byte zsize)
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 337
diff changeset
  1303
{
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1304
	if (image & PALETTE_MODIFIER_COLOR) image |= _drawtile_track_palette;
2254
72f8883ff3ac (svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents: 2236
diff changeset
  1305
	image += offset;
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1306
	if (_display_opt & DO_TRANS_BUILDINGS) MAKE_TRANSPARENT(image);
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 337
diff changeset
  1307
	AddSortableSpriteToDraw(image, ti->x + x, ti->y + y, xsize, ysize, zsize, ti->z + z);
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 337
diff changeset
  1308
}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 337
diff changeset
  1309
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
  1310
/**
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
  1311
 * 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
  1312
 * @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
  1313
 * @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
  1314
 * @param earth Draw as earth
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
  1315
 * @param snow Draw as snow
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
  1316
 * @param flat Always draw foundation
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
  1317
 */
2817
58dcead3f545 (svn r3365) Staticise 36 functions
tron
parents: 2753
diff changeset
  1318
static void DrawTrackBits(TileInfo* ti, TrackBits track, bool earth, bool snow, bool flat)
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
  1319
{
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
  1320
	const RailtypeInfo *rti = GetRailTypeInfo(GetRailType(ti->tile));
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
  1321
	PalSpriteID image;
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
  1322
	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
  1323
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
  1324
	// Select the sprite to use.
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
  1325
	(image = rti->base_sprites.track_y, track == TRACK_BIT_DIAG2) ||
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
  1326
	(image++,                           track == TRACK_BIT_DIAG1) ||
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
  1327
	(image++,                           track == TRACK_BIT_UPPER) ||
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
  1328
	(image++,                           track == TRACK_BIT_LOWER) ||
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
  1329
	(image++,                           track == TRACK_BIT_RIGHT) ||
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
  1330
	(image++,                           track == TRACK_BIT_LEFT) ||
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
  1331
	(image++,                           track == (TRACK_BIT_DIAG1 | TRACK_BIT_DIAG2)) ||
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
  1332
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
  1333
	(image = rti->base_sprites.track_ns, track == (TRACK_BIT_UPPER | TRACK_BIT_LOWER)) ||
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
  1334
	(image++,                            track == (TRACK_BIT_LEFT | TRACK_BIT_RIGHT)) ||
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
  1335
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
  1336
	(junction = true, 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
  1337
	(image = rti->base_sprites.ground, !(track & (TRACK_BIT_RIGHT | TRACK_BIT_UPPER | TRACK_BIT_DIAG1))) ||
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
  1338
	(image++,                          !(track & (TRACK_BIT_LEFT | TRACK_BIT_LOWER | TRACK_BIT_DIAG1))) ||
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
  1339
	(image++,                          !(track & (TRACK_BIT_LEFT | TRACK_BIT_UPPER | TRACK_BIT_DIAG2))) ||
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
  1340
	(image++,                          !(track & (TRACK_BIT_RIGHT | TRACK_BIT_LOWER | TRACK_BIT_DIAG2))) ||
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
  1341
	(image++, true);
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
  1342
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
  1343
	if (ti->tileh != 0) {
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
  1344
		int foundation;
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
  1345
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
  1346
		if (flat) {
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
  1347
			foundation = ti->tileh;
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
  1348
		} else {
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
  1349
			foundation = GetRailFoundation(ti->tileh, track);
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
  1350
		}
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
  1351
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
  1352
		if (foundation != 0)
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
  1353
			DrawFoundation(ti, foundation);
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
  1354
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
  1355
		// DrawFoundation() modifies ti.
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
  1356
		// Default sloped sprites..
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
  1357
		if (ti->tileh != 0)
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
  1358
			image = _track_sloped_sprites[ti->tileh - 1] + rti->base_sprites.track_y;
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
  1359
	}
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
  1360
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
  1361
	if (earth) {
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
  1362
		image = (image & SPRITE_MASK) | PALETTE_TO_BARE_LAND; // Use brown palette
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
  1363
	} else if (snow) {
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
  1364
		image += rti->snow_offset;
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
  1365
	}
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
  1366
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
  1367
	DrawGroundSprite(image);
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
  1368
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
  1369
	// Draw track pieces individually for junction tiles
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
  1370
	if (junction) {
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
  1371
		if (track & TRACK_BIT_DIAG1) DrawGroundSprite(rti->base_sprites.single_y);
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
  1372
		if (track & TRACK_BIT_DIAG2) DrawGroundSprite(rti->base_sprites.single_x);
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
  1373
		if (track & TRACK_BIT_UPPER) DrawGroundSprite(rti->base_sprites.single_n);
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
  1374
		if (track & TRACK_BIT_LOWER) DrawGroundSprite(rti->base_sprites.single_s);
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
  1375
		if (track & TRACK_BIT_LEFT)  DrawGroundSprite(rti->base_sprites.single_w);
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
  1376
		if (track & TRACK_BIT_RIGHT) DrawGroundSprite(rti->base_sprites.single_e);
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
  1377
	}
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
  1378
}
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
  1379
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1380
static void DrawTile_Track(TileInfo *ti)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1381
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1382
	byte m5;
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
  1383
	const RailtypeInfo *rti = GetRailTypeInfo(GetRailType(ti->tile));
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
  1384
	PalSpriteID image;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1385
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
  1386
	_drawtile_track_palette = SPRITE_PALETTE(PLAYER_SPRITE_COLOR(GetTileOwner(ti->tile)));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1387
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1388
	m5 = (byte)ti->map5;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1389
	if (!(m5 & RAIL_TYPE_SPECIAL)) {
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
  1390
		bool earth = (_m[ti->tile].m2 & RAIL_MAP2LO_GROUND_MASK) == RAIL_GROUND_BROWN;
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
  1391
		bool snow = (_m[ti->tile].m2 & RAIL_MAP2LO_GROUND_MASK) == RAIL_GROUND_ICE_DESERT;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1392
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
  1393
		DrawTrackBits(ti, m5 & TRACK_BIT_MASK, earth, snow, false);
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
  1394
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1395
		if (_display_opt & DO_FULL_DETAIL) {
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2020
diff changeset
  1396
			_detailed_track_proc[_m[ti->tile].m2 & RAIL_MAP2LO_GROUND_MASK](ti);
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1399
		/* draw signals also? */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1400
		if (!(ti->map5 & RAIL_TYPE_SIGNALS))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1401
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1402
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1403
		{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1404
			byte m23;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1405
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2020
diff changeset
  1406
			m23 = (_m[ti->tile].m3 >> 4) | (_m[ti->tile].m2 & 0xF0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1407
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1408
#define HAS_SIGNAL(x) (m23 & (byte)(0x1 << (x)))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1409
#define ISON_SIGNAL(x) (m23 & (byte)(0x10 << (x)))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1410
#define MAYBE_DRAW_SIGNAL(x,y,z) if (HAS_SIGNAL(x)) DrawSignalHelper(ti, ISON_SIGNAL(x), ((y-0x4FB) << 4)|(z))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1411
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
  1412
		if (!(m5 & TRACK_BIT_DIAG2)) {
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
  1413
			if (!(m5 & TRACK_BIT_DIAG1)) {
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
  1414
				if (m5 & TRACK_BIT_LEFT) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1415
					MAYBE_DRAW_SIGNAL(2, 0x509, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1416
					MAYBE_DRAW_SIGNAL(3, 0x507, 1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1417
				}
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
  1418
				if (m5 & TRACK_BIT_RIGHT) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1419
					MAYBE_DRAW_SIGNAL(0, 0x509, 2);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1420
					MAYBE_DRAW_SIGNAL(1, 0x507, 3);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1421
				}
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
  1422
				if (m5 & TRACK_BIT_UPPER) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1423
					MAYBE_DRAW_SIGNAL(3, 0x505, 4);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1424
					MAYBE_DRAW_SIGNAL(2, 0x503, 5);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1425
				}
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
  1426
				if (m5 & TRACK_BIT_LOWER) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1427
					MAYBE_DRAW_SIGNAL(1, 0x505, 6);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1428
					MAYBE_DRAW_SIGNAL(0, 0x503, 7);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1429
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1430
			} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1431
				MAYBE_DRAW_SIGNAL(3, 0x4FB, 8);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1432
				MAYBE_DRAW_SIGNAL(2, 0x4FD, 9);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1433
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1434
		} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1435
			MAYBE_DRAW_SIGNAL(3, 0x4FF, 10);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1436
			MAYBE_DRAW_SIGNAL(2, 0x501, 11);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1437
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1438
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1439
	} else {
395
4c990f33dab7 (svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents: 393
diff changeset
  1440
		/* draw depots / waypoints */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1441
		const DrawTrackSeqStruct *drss;
395
4c990f33dab7 (svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents: 393
diff changeset
  1442
		byte type = m5 & 0x3F; // 0-3: depots, 4-5: waypoints
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1443
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
  1444
		if (!(m5 & (RAIL_TILE_TYPE_MASK&~RAIL_TYPE_SPECIAL)))
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
  1445
			/* XXX: There used to be "return;" here, but since I could not find out
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
  1446
			 * why this would ever occur, I put assert(0) here. Let's see if someone
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
  1447
			 * complains about it. If not, we'll remove this check. (Matthijs). */
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
  1448
			 assert(0);
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1449
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1450
		if (ti->tileh != 0) DrawFoundation(ti, ti->tileh);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1451
2668
54d9f9d4dca3 (svn r3210) -Codechange: use IsRailWaypoint where possible (instead of magicnumbers)
truelight
parents: 2667
diff changeset
  1452
		if (IsRailWaypoint(ti->tile) && HASBIT(_m[ti->tile].m3, 4)) {
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 337
diff changeset
  1453
			// 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
  1454
			byte stat_id = GetWaypointByTile(ti->tile)->stat_id;
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
  1455
			const StationSpec *stat = GetCustomStation(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
  1456
2624
47d7768c6dca (svn r3166) Constify read-only accesses of custom stations
peter1138
parents: 2604
diff changeset
  1457
			if (stat != NULL) {
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 337
diff changeset
  1458
				DrawTileSeqStruct const *seq;
403
bfb365c74e80 (svn r600) -newgrf: Relocation offset for custom station sprites is now stored separately, making it possible to show different sprites in waypoint selection dialog (pasky).
darkvater
parents: 399
diff changeset
  1459
				// emulate station tile - open with building
2624
47d7768c6dca (svn r3166) Constify read-only accesses of custom stations
peter1138
parents: 2604
diff changeset
  1460
				const DrawTileSprites *cust = &stat->renderdata[2 + (m5 & 0x1)];
413
36afcda97345 (svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents: 412
diff changeset
  1461
				uint32 relocation = GetCustomStationRelocation(stat, ComposeWaypointStation(ti->tile), 0);
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 337
diff changeset
  1462
447
aaf1f59a8957 (svn r657) Do not touch 0x8000 bit in sprite index for custom waypoints. (pasky)
celestar
parents: 438
diff changeset
  1463
				/* We don't touch the 0x8000 bit. In all this
aaf1f59a8957 (svn r657) Do not touch 0x8000 bit in sprite index for custom waypoints. (pasky)
celestar
parents: 438
diff changeset
  1464
				 * waypoint code, it is used to indicate that
aaf1f59a8957 (svn r657) Do not touch 0x8000 bit in sprite index for custom waypoints. (pasky)
celestar
parents: 438
diff changeset
  1465
				 * we should offset by railtype, but we always
aaf1f59a8957 (svn r657) Do not touch 0x8000 bit in sprite index for custom waypoints. (pasky)
celestar
parents: 438
diff changeset
  1466
				 * do that for custom ground sprites and never
aaf1f59a8957 (svn r657) Do not touch 0x8000 bit in sprite index for custom waypoints. (pasky)
celestar
parents: 438
diff changeset
  1467
				 * for station sprites. And in the drawing
aaf1f59a8957 (svn r657) Do not touch 0x8000 bit in sprite index for custom waypoints. (pasky)
celestar
parents: 438
diff changeset
  1468
				 * code, it is used to indicate that the sprite
aaf1f59a8957 (svn r657) Do not touch 0x8000 bit in sprite index for custom waypoints. (pasky)
celestar
parents: 438
diff changeset
  1469
				 * should be drawn in company colors, and it's
aaf1f59a8957 (svn r657) Do not touch 0x8000 bit in sprite index for custom waypoints. (pasky)
celestar
parents: 438
diff changeset
  1470
				 * up to the GRF file to decide that. */
aaf1f59a8957 (svn r657) Do not touch 0x8000 bit in sprite index for custom waypoints. (pasky)
celestar
parents: 438
diff changeset
  1471
417
0c63a94557a5 (svn r614) [newgrf] Some minor code fixes
dominik
parents: 415
diff changeset
  1472
				image = cust->ground_sprite;
2254
72f8883ff3ac (svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents: 2236
diff changeset
  1473
				image += (image < _custom_sprites_base) ? rti->total_offset : GetRailType(ti->tile);
415
423de36034b8 (svn r612) [newgrf] Fix: custom waypoints on monorail/maglev are displayed correctly
dominik
parents: 413
diff changeset
  1474
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 337
diff changeset
  1475
				DrawGroundSprite(image);
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 337
diff changeset
  1476
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 337
diff changeset
  1477
				foreach_draw_tile_seq(seq, cust->seq) {
403
bfb365c74e80 (svn r600) -newgrf: Relocation offset for custom station sprites is now stored separately, making it possible to show different sprites in waypoint selection dialog (pasky).
darkvater
parents: 399
diff changeset
  1478
					uint32 image = seq->image + relocation;
447
aaf1f59a8957 (svn r657) Do not touch 0x8000 bit in sprite index for custom waypoints. (pasky)
celestar
parents: 438
diff changeset
  1479
					DrawSpecialBuilding(image, 0, ti,
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 337
diff changeset
  1480
					                    seq->delta_x, seq->delta_y, seq->delta_z,
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 337
diff changeset
  1481
					                    seq->width, seq->height, seq->unk);
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 337
diff changeset
  1482
				}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 337
diff changeset
  1483
				return;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 337
diff changeset
  1484
			}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 337
diff changeset
  1485
		}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 337
diff changeset
  1486
1399
4503bd2bfb82 (svn r1903) Replace some casts and macro magic with proper typing, similar to r1902
tron
parents: 1363
diff changeset
  1487
		drss = _track_depot_layout_table[type];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1488
1399
4503bd2bfb82 (svn r1903) Replace some casts and macro magic with proper typing, similar to r1902
tron
parents: 1363
diff changeset
  1489
		image = drss++->image;
2254
72f8883ff3ac (svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents: 2236
diff changeset
  1490
		/* @note This is kind of an ugly hack, as the PALETTE_MODIFIER_COLOR indicates
72f8883ff3ac (svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents: 2236
diff changeset
  1491
	 	 * whether the sprite is railtype dependent. Rewrite this asap */
72f8883ff3ac (svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents: 2236
diff changeset
  1492
		if (image & PALETTE_MODIFIER_COLOR) image = (image & SPRITE_MASK) + rti->total_offset;
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
		// adjust ground tile for desert
283
c1a99d78e5a3 (svn r289) Fix: Checkpoints on snow have correct ground now
dominik
parents: 282
diff changeset
  1495
		// (don't adjust for arctic depots, because snow in depots looks weird)
2254
72f8883ff3ac (svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents: 2236
diff changeset
  1496
		// type >= 4 means waypoints
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
  1497
		if ((_m[ti->tile].m4 & RAIL_MAP2LO_GROUND_MASK) == RAIL_GROUND_ICE_DESERT && (_opt.landscape == LT_DESERT || type >= 4)) {
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1498
			if (image != SPR_FLAT_GRASS_TILE) {
2254
72f8883ff3ac (svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents: 2236
diff changeset
  1499
				image += rti->snow_offset; // tile with tracks
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1500
			} else {
2254
72f8883ff3ac (svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents: 2236
diff changeset
  1501
				image = SPR_FLAT_SNOWY_TILE; // flat ground
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1502
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1503
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1504
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1505
		DrawGroundSprite(image);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1506
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1507
		for (; drss->image != 0; drss++) {
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1508
			DrawSpecialBuilding(drss->image, type < 4 ? rti->total_offset : 0, ti,
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 337
diff changeset
  1509
			                    drss->subcoord_x, drss->subcoord_y, 0,
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 337
diff changeset
  1510
			                    drss->width, drss->height, 0x17);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1511
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1512
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1513
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1514
2520
75eb66d6e371 (svn r3049) Replace byte/int/uint by RailType where appropriate
tron
parents: 2502
diff changeset
  1515
void DrawTrainDepotSprite(int x, int y, int image, RailType railtype)
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
	uint32 ormod, img;
2254
72f8883ff3ac (svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents: 2236
diff changeset
  1518
	const RailtypeInfo *rti = GetRailTypeInfo(railtype);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1519
	const DrawTrackSeqStruct *dtss;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1520
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1521
	ormod = PLAYER_SPRITE_COLOR(_local_player);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1522
1399
4503bd2bfb82 (svn r1903) Replace some casts and macro magic with proper typing, similar to r1902
tron
parents: 1363
diff changeset
  1523
	dtss = _track_depot_layout_table[image];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1524
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1525
	x += 33;
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1526
	y += 17;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1527
1399
4503bd2bfb82 (svn r1903) Replace some casts and macro magic with proper typing, similar to r1902
tron
parents: 1363
diff changeset
  1528
	img = dtss++->image;
2254
72f8883ff3ac (svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents: 2236
diff changeset
  1529
	/* @note This is kind of an ugly hack, as the PALETTE_MODIFIER_COLOR indicates
72f8883ff3ac (svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents: 2236
diff changeset
  1530
	 * whether the sprite is railtype dependent. Rewrite this asap */
72f8883ff3ac (svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents: 2236
diff changeset
  1531
	if (img & PALETTE_MODIFIER_COLOR) img = (img & SPRITE_MASK) + rti->total_offset;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1532
	DrawSprite(img, x, y);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1533
1399
4503bd2bfb82 (svn r1903) Replace some casts and macro magic with proper typing, similar to r1902
tron
parents: 1363
diff changeset
  1534
	for (; dtss->image != 0; dtss++) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1535
		Point pt = RemapCoords(dtss->subcoord_x, dtss->subcoord_y, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1536
		image = dtss->image;
2187
2a51f8925eeb (svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents: 2186
diff changeset
  1537
		if (image & PALETTE_MODIFIER_COLOR) image |= ormod;
2254
72f8883ff3ac (svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents: 2236
diff changeset
  1538
		DrawSprite(image + rti->total_offset, x + pt.x, y + pt.y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1539
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1540
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1541
2520
75eb66d6e371 (svn r3049) Replace byte/int/uint by RailType where appropriate
tron
parents: 2502
diff changeset
  1542
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
  1543
{
3f78323707bb (svn r2781) Fix some of the issues with variables in .h files.
ludde
parents: 2254
diff changeset
  1544
	const DrawTrackSeqStruct *dtss = _track_depot_layout_table[4];
3f78323707bb (svn r2781) Fix some of the issues with variables in .h files.
ludde
parents: 2254
diff changeset
  1545
	const RailtypeInfo *rti = GetRailTypeInfo(railtype);
3f78323707bb (svn r2781) Fix some of the issues with variables in .h files.
ludde
parents: 2254
diff changeset
  1546
	uint32 img;
3f78323707bb (svn r2781) Fix some of the issues with variables in .h files.
ludde
parents: 2254
diff changeset
  1547
3f78323707bb (svn r2781) Fix some of the issues with variables in .h files.
ludde
parents: 2254
diff changeset
  1548
	img = dtss++->image;
3f78323707bb (svn r2781) Fix some of the issues with variables in .h files.
ludde
parents: 2254
diff changeset
  1549
	if (img & PALETTE_MODIFIER_COLOR) img = (img & SPRITE_MASK) + rti->total_offset;
3f78323707bb (svn r2781) Fix some of the issues with variables in .h files.
ludde
parents: 2254
diff changeset
  1550
	DrawSprite(img, x, y);
3f78323707bb (svn r2781) Fix some of the issues with variables in .h files.
ludde
parents: 2254
diff changeset
  1551
3f78323707bb (svn r2781) Fix some of the issues with variables in .h files.
ludde
parents: 2254
diff changeset
  1552
	for (; dtss->image != 0; dtss++) {
3f78323707bb (svn r2781) Fix some of the issues with variables in .h files.
ludde
parents: 2254
diff changeset
  1553
		Point pt = RemapCoords(dtss->subcoord_x, dtss->subcoord_y, 0);
3f78323707bb (svn r2781) Fix some of the issues with variables in .h files.
ludde
parents: 2254
diff changeset
  1554
		img = dtss->image;
3f78323707bb (svn r2781) Fix some of the issues with variables in .h files.
ludde
parents: 2254
diff changeset
  1555
		if (img & PALETTE_MODIFIER_COLOR) img |= PLAYER_SPRITE_COLOR(_local_player);
3f78323707bb (svn r2781) Fix some of the issues with variables in .h files.
ludde
parents: 2254
diff changeset
  1556
		DrawSprite(img, x + pt.x, y + pt.y);
3f78323707bb (svn r2781) Fix some of the issues with variables in .h files.
ludde
parents: 2254
diff changeset
  1557
	}
3f78323707bb (svn r2781) Fix some of the issues with variables in .h files.
ludde
parents: 2254
diff changeset
  1558
}
3f78323707bb (svn r2781) Fix some of the issues with variables in .h files.
ludde
parents: 2254
diff changeset
  1559
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1560
typedef struct SetSignalsData {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1561
	int cur;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1562
	int cur_stack;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1563
	bool stop;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1564
	bool has_presignal;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1565
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1566
	// presignal info
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1567
	int presignal_exits;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1568
	int presignal_exits_free;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1569
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1570
	// these are used to keep track of the signals that change.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1571
	byte bit[NUM_SSD_ENTRY];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1572
	TileIndex tile[NUM_SSD_ENTRY];
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
	// these are used to keep track of the stack that modifies presignals recursively
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1575
	TileIndex next_tile[NUM_SSD_STACK];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1576
	byte next_dir[NUM_SSD_STACK];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1577
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1578
} SetSignalsData;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1579
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1963
diff changeset
  1580
static bool SetSignalsEnumProc(TileIndex tile, SetSignalsData *ssd, int track, uint length, byte *state)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1581
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1582
	// the tile has signals?
1035
0a170deb6e33 (svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents: 1024
diff changeset
  1583
	if (IsTileType(tile, MP_RAILWAY)) {
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
  1584
		if (HasSignalOnTrack(tile, TrackdirToTrack(track))) {
2821
ba75b5f98725 (svn r3369) - Codechange: Replace tables _signals_table, _signals_table_other and _signals_table_both by the equivalent calls to rail.h functions.
matthijs
parents: 2817
diff changeset
  1585
			if (HasSignalOnTrackdir(tile, ReverseTrackdir(track))) {
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
  1586
				// yes, add the signal to the list of signals
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
  1587
				if (ssd->cur != NUM_SSD_ENTRY) {
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
  1588
					ssd->tile[ssd->cur] = tile; // remember the tile index
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
  1589
					ssd->bit[ssd->cur] = track; // and the controlling bit number
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
  1590
					ssd->cur++;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1591
				}
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1592
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
  1593
				// remember if this block has a presignal.
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2020
diff changeset
  1594
				ssd->has_presignal |= (_m[tile].m4&1);
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
  1595
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1596
2916
8f1aa489701f (svn r3472) - [PBS] Remove from trunk. Anyone interested can still find it in branch/pbs. This reverts revisions r3158, r3140, r3075, r2977, r2674, r2625, r2621, r2529, r2528, r2525, r2524, r2519, r2517, r2516, r2507, r2499. (in conjunction with Tron)
Darkvater
parents: 2911
diff changeset
  1597
			if (HasSignalOnTrackdir(tile, track) && (_m[tile].m4 & 2)) {
8f1aa489701f (svn r3472) - [PBS] Remove from trunk. Anyone interested can still find it in branch/pbs. This reverts revisions r3158, r3140, r3075, r2977, r2674, r2625, r2621, r2529, r2528, r2525, r2524, r2519, r2517, r2516, r2507, r2499. (in conjunction with Tron)
Darkvater
parents: 2911
diff changeset
  1598
				// this is an exit signal that points out from the segment
8f1aa489701f (svn r3472) - [PBS] Remove from trunk. Anyone interested can still find it in branch/pbs. This reverts revisions r3158, r3140, r3075, r2977, r2674, r2625, r2621, r2529, r2528, r2525, r2524, r2519, r2517, r2516, r2507, r2499. (in conjunction with Tron)
Darkvater
parents: 2911
diff changeset
  1599
				ssd->presignal_exits++;
8f1aa489701f (svn r3472) - [PBS] Remove from trunk. Anyone interested can still find it in branch/pbs. This reverts revisions r3158, r3140, r3075, r2977, r2674, r2625, r2621, r2529, r2528, r2525, r2524, r2519, r2517, r2516, r2507, r2499. (in conjunction with Tron)
Darkvater
parents: 2911
diff changeset
  1600
				if (GetSignalState(tile, track) != SIGNAL_STATE_RED)
8f1aa489701f (svn r3472) - [PBS] Remove from trunk. Anyone interested can still find it in branch/pbs. This reverts revisions r3158, r3140, r3075, r2977, r2674, r2625, r2621, r2529, r2528, r2525, r2524, r2519, r2517, r2516, r2507, r2499. (in conjunction with Tron)
Darkvater
parents: 2911
diff changeset
  1601
					ssd->presignal_exits_free++;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1602
			}
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
  1603
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
  1604
			return true;
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1605
		} else if (IsTileDepotType(tile, TRANSPORT_RAIL)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1606
			return true; // don't look further if the tile is a depot
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1607
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1608
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1609
	return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1610
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1611
1555
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1612
/* Struct to parse data from VehicleFromPos to SignalVehicleCheckProc */
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1613
typedef struct SignalVehicleCheckStruct {
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1614
	TileIndex tile;
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1615
	uint track;
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1616
} SignalVehicleCheckStruct;
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1617
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1618
static void *SignalVehicleCheckProc(Vehicle *v, void *data)
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1619
{
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1620
	const SignalVehicleCheckStruct* dest = data;
1555
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1621
	TileIndex tile;
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1622
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1623
	if (v->type != VEH_Train) return NULL;
1609
b4d11170cbb5 (svn r2113) -Fix: first check if a vehicle is a train, before accessing u.rail
truelight
parents: 1598
diff changeset
  1624
1555
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1625
	/* Find the tile outside the tunnel, for signalling */
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1626
	if (v->u.rail.track == 0x40) {
1555
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1627
		tile = GetVehicleOutOfTunnelTile(v);
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1628
	} else {
1555
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1629
		tile = v->tile;
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1630
	}
1555
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1631
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1632
	/* Wrong tile, or no train? Not a match */
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1633
	if (tile != dest->tile) return NULL;
1555
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1634
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1635
	/* Are we on the same piece of track? */
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1636
	if (dest->track & (v->u.rail.track + (v->u.rail.track << 8))) return v;
1555
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1637
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1638
	return NULL;
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1639
}
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1640
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1641
/* Special check for SetSignalsAfterProc, to see if there is a vehicle on this tile */
2752
b5fe5a7e6282 (svn r3297) Staticise
tron
parents: 2737
diff changeset
  1642
static bool SignalVehicleCheck(TileIndex tile, uint track)
1555
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1643
{
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1644
	SignalVehicleCheckStruct dest;
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1645
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1646
	dest.tile = tile;
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1647
	dest.track = track;
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1648
1818
88ab405a9dfc (svn r2322) - CodeChange: doxygen commented the tunnel-crash fix. Also if (bla) {return;} else {return;} is not proper code. It's if (bla) {return;} return; ;)
Darkvater
parents: 1816
diff changeset
  1649
	/** @todo "Hackish" fix for the tunnel problems. This is needed because a tunnel
88ab405a9dfc (svn r2322) - CodeChange: doxygen commented the tunnel-crash fix. Also if (bla) {return;} else {return;} is not proper code. It's if (bla) {return;} return; ;)
Darkvater
parents: 1816
diff changeset
  1650
	 * is some kind of invisible black hole, and there is some special magic going
88ab405a9dfc (svn r2322) - CodeChange: doxygen commented the tunnel-crash fix. Also if (bla) {return;} else {return;} is not proper code. It's if (bla) {return;} return; ;)
Darkvater
parents: 1816
diff changeset
  1651
	 * on in there. This 'workaround' can be removed once the maprewrite is done.
88ab405a9dfc (svn r2322) - CodeChange: doxygen commented the tunnel-crash fix. Also if (bla) {return;} else {return;} is not proper code. It's if (bla) {return;} return; ;)
Darkvater
parents: 1816
diff changeset
  1652
	 */
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1653
	if (IsTileType(tile, MP_TUNNELBRIDGE) && GB(_m[tile].m5, 4, 4) == 0) {
1816
e96c4a8136bf (svn r2320) - Fix: [ 1185176 ] Train in tunnel is not properly detected by signal code (Hackykid)
matthijs
parents: 1813
diff changeset
  1654
		// It is a tunnel we're checking, we need to do some special stuff
e96c4a8136bf (svn r2320) - Fix: [ 1185176 ] Train in tunnel is not properly detected by signal code (Hackykid)
matthijs
parents: 1813
diff changeset
  1655
		// because VehicleFromPos will not find the vihicle otherwise
2493
d834d0c1502a (svn r3019) -Codechange: Replace explicit shifting/anding/oring with GB and SB
tron
parents: 2472
diff changeset
  1656
		byte direction = GB(_m[tile].m5, 0, 2);
1816
e96c4a8136bf (svn r2320) - Fix: [ 1185176 ] Train in tunnel is not properly detected by signal code (Hackykid)
matthijs
parents: 1813
diff changeset
  1657
		FindLengthOfTunnelResult flotr;
e96c4a8136bf (svn r2320) - Fix: [ 1185176 ] Train in tunnel is not properly detected by signal code (Hackykid)
matthijs
parents: 1813
diff changeset
  1658
		flotr = FindLengthOfTunnel(tile, direction);
e96c4a8136bf (svn r2320) - Fix: [ 1185176 ] Train in tunnel is not properly detected by signal code (Hackykid)
matthijs
parents: 1813
diff changeset
  1659
		dest.track = 1 << (direction & 1); // get the trackbit the vehicle would have if it has not entered the tunnel yet (ie is still visible)
e96c4a8136bf (svn r2320) - Fix: [ 1185176 ] Train in tunnel is not properly detected by signal code (Hackykid)
matthijs
parents: 1813
diff changeset
  1660
e96c4a8136bf (svn r2320) - Fix: [ 1185176 ] Train in tunnel is not properly detected by signal code (Hackykid)
matthijs
parents: 1813
diff changeset
  1661
		// check for a vehicle with that trackdir on the start tile of the tunnel
1818
88ab405a9dfc (svn r2322) - CodeChange: doxygen commented the tunnel-crash fix. Also if (bla) {return;} else {return;} is not proper code. It's if (bla) {return;} return; ;)
Darkvater
parents: 1816
diff changeset
  1662
		if (VehicleFromPos(tile, &dest, SignalVehicleCheckProc) != NULL) return true;
1816
e96c4a8136bf (svn r2320) - Fix: [ 1185176 ] Train in tunnel is not properly detected by signal code (Hackykid)
matthijs
parents: 1813
diff changeset
  1663
e96c4a8136bf (svn r2320) - Fix: [ 1185176 ] Train in tunnel is not properly detected by signal code (Hackykid)
matthijs
parents: 1813
diff changeset
  1664
		// check for a vehicle with that trackdir on the end tile of the tunnel
1818
88ab405a9dfc (svn r2322) - CodeChange: doxygen commented the tunnel-crash fix. Also if (bla) {return;} else {return;} is not proper code. It's if (bla) {return;} return; ;)
Darkvater
parents: 1816
diff changeset
  1665
		if (VehicleFromPos(flotr.tile, &dest, SignalVehicleCheckProc) != NULL) return true;
1816
e96c4a8136bf (svn r2320) - Fix: [ 1185176 ] Train in tunnel is not properly detected by signal code (Hackykid)
matthijs
parents: 1813
diff changeset
  1666
e96c4a8136bf (svn r2320) - Fix: [ 1185176 ] Train in tunnel is not properly detected by signal code (Hackykid)
matthijs
parents: 1813
diff changeset
  1667
		// now check all tiles from start to end for a "hidden" vehicle
e96c4a8136bf (svn r2320) - Fix: [ 1185176 ] Train in tunnel is not properly detected by signal code (Hackykid)
matthijs
parents: 1813
diff changeset
  1668
		// NOTE: the hashes for tiles may overlap, so this could maybe be optimised a bit by not checking every tile?
e96c4a8136bf (svn r2320) - Fix: [ 1185176 ] Train in tunnel is not properly detected by signal code (Hackykid)
matthijs
parents: 1813
diff changeset
  1669
		dest.track = 0x40; // trackbit for vehicles "hidden" inside a tunnel
e96c4a8136bf (svn r2320) - Fix: [ 1185176 ] Train in tunnel is not properly detected by signal code (Hackykid)
matthijs
parents: 1813
diff changeset
  1670
		for (; tile != flotr.tile; tile += TileOffsByDir(direction)) {
e96c4a8136bf (svn r2320) - Fix: [ 1185176 ] Train in tunnel is not properly detected by signal code (Hackykid)
matthijs
parents: 1813
diff changeset
  1671
			if (VehicleFromPos(tile, &dest, SignalVehicleCheckProc) != NULL)
e96c4a8136bf (svn r2320) - Fix: [ 1185176 ] Train in tunnel is not properly detected by signal code (Hackykid)
matthijs
parents: 1813
diff changeset
  1672
				return true;
e96c4a8136bf (svn r2320) - Fix: [ 1185176 ] Train in tunnel is not properly detected by signal code (Hackykid)
matthijs
parents: 1813
diff changeset
  1673
		}
e96c4a8136bf (svn r2320) - Fix: [ 1185176 ] Train in tunnel is not properly detected by signal code (Hackykid)
matthijs
parents: 1813
diff changeset
  1674
e96c4a8136bf (svn r2320) - Fix: [ 1185176 ] Train in tunnel is not properly detected by signal code (Hackykid)
matthijs
parents: 1813
diff changeset
  1675
		// no vehicle found
e96c4a8136bf (svn r2320) - Fix: [ 1185176 ] Train in tunnel is not properly detected by signal code (Hackykid)
matthijs
parents: 1813
diff changeset
  1676
		return false;
1818
88ab405a9dfc (svn r2322) - CodeChange: doxygen commented the tunnel-crash fix. Also if (bla) {return;} else {return;} is not proper code. It's if (bla) {return;} return; ;)
Darkvater
parents: 1816
diff changeset
  1677
	}
88ab405a9dfc (svn r2322) - CodeChange: doxygen commented the tunnel-crash fix. Also if (bla) {return;} else {return;} is not proper code. It's if (bla) {return;} return; ;)
Darkvater
parents: 1816
diff changeset
  1678
88ab405a9dfc (svn r2322) - CodeChange: doxygen commented the tunnel-crash fix. Also if (bla) {return;} else {return;} is not proper code. It's if (bla) {return;} return; ;)
Darkvater
parents: 1816
diff changeset
  1679
	return VehicleFromPos(tile, &dest, SignalVehicleCheckProc) != NULL;
1555
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1680
}
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1681
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1682
static void SetSignalsAfterProc(TrackPathFinder *tpf)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1683
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1684
	SetSignalsData *ssd = tpf->userdata;
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
  1685
	const TrackPathFinderLink* link;
1555
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1686
	uint offs;
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1687
	uint i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1688
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1689
	ssd->stop = false;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1690
1555
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1691
	/* Go through all the PF tiles */
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1692
	for (i = 0; i < lengthof(tpf->hash_head); i++) {
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1693
		/* Empty hash item */
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1694
		if (tpf->hash_head[i] == 0) continue;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1695
1555
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1696
		/* If 0x8000 is not set, there is only 1 item */
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1697
		if (!(tpf->hash_head[i] & 0x8000)) {
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1698
			/* Check if there is a vehicle on this tile */
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1699
			if (SignalVehicleCheck(tpf->hash_tile[i], tpf->hash_head[i])) {
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1700
				ssd->stop = true;
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1701
				return;
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1702
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1703
		} else {
1555
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1704
			/* There are multiple items, where hash_tile points to the first item in the list */
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1705
			offs = tpf->hash_tile[i];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1706
			do {
1555
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1707
				/* Find the next item */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1708
				link = PATHFIND_GET_LINK_PTR(tpf, offs);
1555
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1709
				/* Check if there is a vehicle on this tile */
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1710
				if (SignalVehicleCheck(link->tile, link->flags)) {
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1711
					ssd->stop = true;
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1712
					return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1713
				}
1555
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1714
				/* Goto the next item */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1715
			} while ((offs=link->next) != 0xFFFF);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1716
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1717
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1718
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1719
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1720
static const byte _dir_from_track[14] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1721
	0,1,0,1,2,1, 0,0,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1722
	2,3,3,2,3,0,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1723
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1724
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1725
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1726
static void ChangeSignalStates(SetSignalsData *ssd)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1727
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1728
	int i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1729
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1730
	// thinking about presignals...
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1731
	// the presignal is green if,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1732
	//   if no train is in the segment AND
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1733
	//   there is at least one green exit signal OR
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1734
	//   there are no exit signals in the segment
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1735
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1736
	// then mark the signals in the segment accordingly
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1737
	for (i = 0; i != ssd->cur; i++) {
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1963
diff changeset
  1738
		TileIndex tile = ssd->tile[i];
2821
ba75b5f98725 (svn r3369) - Codechange: Replace tables _signals_table, _signals_table_other and _signals_table_both by the equivalent calls to rail.h functions.
matthijs
parents: 2817
diff changeset
  1739
		byte bit = SignalAgainstTrackdir(ssd->bit[i]);
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2020
diff changeset
  1740
		uint16 m2 = _m[tile].m2;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1741
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1742
		// presignals don't turn green if there is at least one presignal exit and none are free
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2020
diff changeset
  1743
		if (_m[tile].m4 & 1) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1744
			int ex = ssd->presignal_exits, exfree = ssd->presignal_exits_free;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1745
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1746
			// subtract for dual combo signals so they don't count themselves
2821
ba75b5f98725 (svn r3369) - Codechange: Replace tables _signals_table, _signals_table_other and _signals_table_both by the equivalent calls to rail.h functions.
matthijs
parents: 2817
diff changeset
  1747
			if (_m[tile].m4&2 && HasSignalOnTrackdir(tile, ssd->bit[i])) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1748
				ex--;
2821
ba75b5f98725 (svn r3369) - Codechange: Replace tables _signals_table, _signals_table_other and _signals_table_both by the equivalent calls to rail.h functions.
matthijs
parents: 2817
diff changeset
  1749
				if (GetSignalState(tile, ssd->bit[i]) != SIGNAL_STATE_RED) exfree--;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1750
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1751
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1752
			// if we have exits and none are free, make red.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1753
			if (ex && !exfree) goto make_red;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1754
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1755
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1756
		// check if the signal is unaffected.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1757
		if (ssd->stop) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1758
make_red:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1759
			// turn red
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1760
			if ( (bit&m2) == 0 )
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1761
				continue;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1762
		} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1763
			// turn green
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1764
			if ( (bit&m2) != 0 )
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1765
				continue;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1766
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1767
1813
a4b17980b9e4 (svn r2317) - Fix: [ 1193048 ] Pre-signal stays red when there is only a single exit signal (dinno)
Darkvater
parents: 1796
diff changeset
  1768
		/* Update signals on the other side of this exit-combo signal; it changed. */
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2020
diff changeset
  1769
		if (_m[tile].m4 & 2 ) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1770
			if (ssd->cur_stack != NUM_SSD_STACK) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1771
				ssd->next_tile[ssd->cur_stack] = tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1772
				ssd->next_dir[ssd->cur_stack] = _dir_from_track[ssd->bit[i]];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1773
				ssd->cur_stack++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1774
			} else {
1813
a4b17980b9e4 (svn r2317) - Fix: [ 1193048 ] Pre-signal stays red when there is only a single exit signal (dinno)
Darkvater
parents: 1796
diff changeset
  1775
				printf("NUM_SSD_STACK too small\n"); /// @todo WTF is this???
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1776
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1777
		}
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1778
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1779
		// it changed, so toggle it
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2020
diff changeset
  1780
		_m[tile].m2 = m2 ^ bit;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1781
		MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1782
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1783
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1784
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1785
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1963
diff changeset
  1786
bool UpdateSignalsOnSegment(TileIndex tile, byte direction)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1787
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1788
	SetSignalsData ssd;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1789
	int result = -1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1790
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1791
	ssd.cur_stack = 0;
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1792
	direction >>= 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1793
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1794
	for(;;) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1795
		// go through one segment and update all signals pointing into that segment.
2916
8f1aa489701f (svn r3472) - [PBS] Remove from trunk. Anyone interested can still find it in branch/pbs. This reverts revisions r3158, r3140, r3075, r2977, r2674, r2625, r2621, r2529, r2528, r2525, r2524, r2519, r2517, r2516, r2507, r2499. (in conjunction with Tron)
Darkvater
parents: 2911
diff changeset
  1796
		ssd.cur = ssd.presignal_exits = ssd.presignal_exits_free = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1797
		ssd.has_presignal = false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1798
159
139cf78bfb28 (svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents: 149
diff changeset
  1799
		FollowTrack(tile, 0xC000 | TRANSPORT_RAIL, direction, (TPFEnumProc*)SetSignalsEnumProc, SetSignalsAfterProc, &ssd);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1800
		ChangeSignalStates(&ssd);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1801
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1802
		// remember the result only for the first iteration.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1803
		if (result < 0) result = ssd.stop;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1804
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1805
		// if any exit signals were changed, we need to keep going to modify the stuff behind those.
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1806
		if (ssd.cur_stack == 0) break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1807
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1808
		// one or more exit signals were changed, so we need to update another segment too.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1809
		tile = ssd.next_tile[--ssd.cur_stack];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1810
		direction = ssd.next_dir[ssd.cur_stack];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1811
	}
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1812
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1813
	return (bool)result;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1814
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1815
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1963
diff changeset
  1816
void SetSignalsOnBothDir(TileIndex tile, byte track)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1817
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1818
	static const byte _search_dir_1[6] = {1, 3, 1, 3, 5, 3};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1819
	static const byte _search_dir_2[6] = {5, 7, 7, 5, 7, 1};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1820
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1821
	UpdateSignalsOnSegment(tile, _search_dir_1[track]);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1822
	UpdateSignalsOnSegment(tile, _search_dir_2[track]);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1823
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1824
2537
d9c0df52a466 (svn r3066) Constify the parameter of GetSlopeZ_*()
tron
parents: 2520
diff changeset
  1825
static uint GetSlopeZ_Track(const TileInfo* ti)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1826
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1827
	uint z = ti->z;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1828
	int th = ti->tileh;
13
3e7c1f74a996 (svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents: 0
diff changeset
  1829
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1830
	// check if it's a foundation
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1831
	if (ti->tileh != 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1832
		if ((ti->map5 & 0x80) == 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1833
			uint f = GetRailFoundation(ti->tileh, ti->map5 & 0x3F);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1834
			if (f != 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1835
				if (f < 15) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1836
					// leveled foundation
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1837
					return z + 8;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1838
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1839
				// inclined foundation
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1840
				th = _inclined_tileh[f - 15];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1841
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1842
		} else if ((ti->map5 & 0xC0) == 0xC0) {
395
4c990f33dab7 (svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents: 393
diff changeset
  1843
			// depot or waypoint
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1844
			return z + 8;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1845
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1846
		return GetPartialZ(ti->x&0xF, ti->y&0xF, th) + z;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1847
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1848
	return z;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1849
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1850
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
  1851
static uint GetSlopeTileh_Track(const TileInfo *ti)
39
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 22
diff changeset
  1852
{
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 22
diff changeset
  1853
	// check if it's a foundation
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 22
diff changeset
  1854
	if (ti->tileh != 0) {
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 22
diff changeset
  1855
		if ((ti->map5 & 0x80) == 0) {
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 22
diff changeset
  1856
			uint f = GetRailFoundation(ti->tileh, ti->map5 & 0x3F);
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 22
diff changeset
  1857
			if (f != 0) {
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 22
diff changeset
  1858
				if (f < 15) {
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 22
diff changeset
  1859
					// leveled foundation
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 22
diff changeset
  1860
					return 0;
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 22
diff changeset
  1861
				}
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 22
diff changeset
  1862
				// inclined foundation
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 22
diff changeset
  1863
				return _inclined_tileh[f - 15];
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 22
diff changeset
  1864
			}
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 22
diff changeset
  1865
		} else if ((ti->map5 & 0xC0) == 0xC0) {
395
4c990f33dab7 (svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents: 393
diff changeset
  1866
			// depot or waypoint
39
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 22
diff changeset
  1867
			return 0;
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 22
diff changeset
  1868
		}
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 22
diff changeset
  1869
	}
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 22
diff changeset
  1870
	return ti->tileh;
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 22
diff changeset
  1871
}
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 22
diff changeset
  1872
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1963
diff changeset
  1873
static void GetAcceptedCargo_Track(TileIndex tile, AcceptedCargo ac)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1874
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1875
	/* not used */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1876
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1877
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1963
diff changeset
  1878
static void AnimateTile_Track(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1879
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1880
	/* not used */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1881
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1882
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1963
diff changeset
  1883
static void TileLoop_Track(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1884
{
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
  1885
	byte old_ground;
78b3c154afa4 (svn r3209) In TileLoop_Track(), use names based on function rather than their place in the map array.
peter1138
parents: 2645
diff changeset
  1886
	byte new_ground;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1887
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
  1888
	old_ground = _m[tile].m5 & RAIL_TYPE_SPECIAL ? GB(_m[tile].m4, 0, 4) : GB(_m[tile].m2, 0, 4);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1889
2631
13daba67f217 (svn r3173) Use the trinary operator and switch to improve readability
tron
parents: 2626
diff changeset
  1890
	switch (_opt.landscape) {
13daba67f217 (svn r3173) Use the trinary operator and switch to improve readability
tron
parents: 2626
diff changeset
  1891
		case LT_HILLY:
13daba67f217 (svn r3173) Use the trinary operator and switch to improve readability
tron
parents: 2626
diff changeset
  1892
			if (GetTileZ(tile) > _opt.snow_line) { /* convert into snow? */
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
  1893
				new_ground = RAIL_GROUND_ICE_DESERT;
2631
13daba67f217 (svn r3173) Use the trinary operator and switch to improve readability
tron
parents: 2626
diff changeset
  1894
				goto modify_me;
13daba67f217 (svn r3173) Use the trinary operator and switch to improve readability
tron
parents: 2626
diff changeset
  1895
			}
13daba67f217 (svn r3173) Use the trinary operator and switch to improve readability
tron
parents: 2626
diff changeset
  1896
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1897
2631
13daba67f217 (svn r3173) Use the trinary operator and switch to improve readability
tron
parents: 2626
diff changeset
  1898
		case LT_DESERT:
13daba67f217 (svn r3173) Use the trinary operator and switch to improve readability
tron
parents: 2626
diff changeset
  1899
			if (GetMapExtraBits(tile) == 1) { /* convert into desert? */
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
  1900
				new_ground = RAIL_GROUND_ICE_DESERT;
2631
13daba67f217 (svn r3173) Use the trinary operator and switch to improve readability
tron
parents: 2626
diff changeset
  1901
				goto modify_me;
13daba67f217 (svn r3173) Use the trinary operator and switch to improve readability
tron
parents: 2626
diff changeset
  1902
			}
13daba67f217 (svn r3173) Use the trinary operator and switch to improve readability
tron
parents: 2626
diff changeset
  1903
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1904
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1905
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1906
	// Don't continue tile loop for depots
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1907
	if (_m[tile].m5 & RAIL_TYPE_SPECIAL) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1908
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
  1909
	new_ground = RAIL_GROUND_GREEN;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1910
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
  1911
	if (old_ground != RAIL_GROUND_BROWN) { /* wait until bottom is green */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1912
		/* determine direction of fence */
2839
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  1913
		TrackBits rail = _m[tile].m5 & TRACK_BIT_MASK;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1914
2839
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  1915
		switch (rail) {
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  1916
			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
  1917
			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
  1918
			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
  1919
			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
  1920
2839
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  1921
			default: {
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  1922
				PlayerID owner = GetTileOwner(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1923
2839
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  1924
				if (rail == (TRACK_BIT_LOWER | TRACK_BIT_RIGHT) || (
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  1925
							!(rail & (TRACK_BIT_DIAG2 | TRACK_BIT_UPPER | TRACK_BIT_LEFT)) &&
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  1926
							(rail & TRACK_BIT_DIAG1)
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  1927
						)) {
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  1928
					TileIndex n = tile + TileDiffXY(0, -1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1929
2839
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  1930
					if (!IsTileType(n, MP_RAILWAY) ||
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  1931
							!IsTileOwner(n, owner) ||
2841
29df91f741d9 (svn r3389) -Fix: No fence was placed when placing fences and the neighbouring tile is a rail configuration which permits a fence but has a signal
tron
parents: 2839
diff changeset
  1932
							(_m[n].m5 & TRACK_BIT_MASK) == TRACK_BIT_UPPER ||
29df91f741d9 (svn r3389) -Fix: No fence was placed when placing fences and the neighbouring tile is a rail configuration which permits a fence but has a signal
tron
parents: 2839
diff changeset
  1933
							(_m[n].m5 & TRACK_BIT_MASK) == TRACK_BIT_LEFT) {
2839
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  1934
						new_ground = RAIL_GROUND_FENCE_NW;
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  1935
					}
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  1936
				}
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  1937
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  1938
				if (rail == (TRACK_BIT_UPPER | TRACK_BIT_LEFT) || (
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  1939
							!(rail & (TRACK_BIT_DIAG2 | TRACK_BIT_LOWER | TRACK_BIT_RIGHT)) &&
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  1940
							(rail & TRACK_BIT_DIAG1)
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  1941
						)) {
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  1942
					TileIndex n = tile + TileDiffXY(0, 1);
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  1943
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  1944
					if (!IsTileType(n, MP_RAILWAY) ||
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  1945
							!IsTileOwner(n, owner) ||
2841
29df91f741d9 (svn r3389) -Fix: No fence was placed when placing fences and the neighbouring tile is a rail configuration which permits a fence but has a signal
tron
parents: 2839
diff changeset
  1946
							(_m[n].m5 & TRACK_BIT_MASK) == TRACK_BIT_LOWER ||
29df91f741d9 (svn r3389) -Fix: No fence was placed when placing fences and the neighbouring tile is a rail configuration which permits a fence but has a signal
tron
parents: 2839
diff changeset
  1947
							(_m[n].m5 & TRACK_BIT_MASK) == TRACK_BIT_RIGHT) {
2839
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  1948
						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
  1949
							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
  1950
					}
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  1951
				}
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  1952
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  1953
				if (rail == (TRACK_BIT_LOWER | TRACK_BIT_LEFT) || (
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  1954
							!(rail & (TRACK_BIT_DIAG1 | TRACK_BIT_UPPER | TRACK_BIT_RIGHT)) &&
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  1955
							(rail & TRACK_BIT_DIAG2)
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  1956
						)) {
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  1957
					TileIndex n = tile + TileDiffXY(-1, 0);
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  1958
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  1959
					if (!IsTileType(n, MP_RAILWAY) ||
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  1960
							!IsTileOwner(n, owner) ||
2841
29df91f741d9 (svn r3389) -Fix: No fence was placed when placing fences and the neighbouring tile is a rail configuration which permits a fence but has a signal
tron
parents: 2839
diff changeset
  1961
							(_m[n].m5 & TRACK_BIT_MASK) == TRACK_BIT_UPPER ||
29df91f741d9 (svn r3389) -Fix: No fence was placed when placing fences and the neighbouring tile is a rail configuration which permits a fence but has a signal
tron
parents: 2839
diff changeset
  1962
							(_m[n].m5 & TRACK_BIT_MASK) == TRACK_BIT_RIGHT) {
2839
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  1963
						new_ground = RAIL_GROUND_FENCE_NE;
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  1964
					}
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  1965
				}
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  1966
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  1967
				if (rail == (TRACK_BIT_UPPER | TRACK_BIT_RIGHT) || (
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  1968
							!(rail & (TRACK_BIT_DIAG1 | TRACK_BIT_LOWER | TRACK_BIT_LEFT)) &&
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  1969
							(rail & TRACK_BIT_DIAG2)
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  1970
						)) {
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  1971
					TileIndex n = tile + TileDiffXY(1, 0);
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  1972
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  1973
					if (!IsTileType(n, MP_RAILWAY) ||
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  1974
							!IsTileOwner(n, owner) ||
2841
29df91f741d9 (svn r3389) -Fix: No fence was placed when placing fences and the neighbouring tile is a rail configuration which permits a fence but has a signal
tron
parents: 2839
diff changeset
  1975
							(_m[n].m5 & TRACK_BIT_MASK) == TRACK_BIT_LOWER ||
29df91f741d9 (svn r3389) -Fix: No fence was placed when placing fences and the neighbouring tile is a rail configuration which permits a fence but has a signal
tron
parents: 2839
diff changeset
  1976
							(_m[n].m5 & TRACK_BIT_MASK) == TRACK_BIT_LEFT) {
2839
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  1977
						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
  1978
							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
  1979
					}
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  1980
				}
665d7c92448b (svn r3387) Restructure the code, which places fences along railroad tracks.
tron
parents: 2821
diff changeset
  1981
				break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1982
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1983
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1984
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1985
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1986
modify_me:;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1987
	/* tile changed? */
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
  1988
	if (old_ground != new_ground) {
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
  1989
		if (_m[tile].m5 & RAIL_TYPE_SPECIAL) {
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
  1990
			SB(_m[tile].m4, 0, 4, new_ground);
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
  1991
		} else {
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
  1992
			SB(_m[tile].m2, 0, 4, new_ground);
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
  1993
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1994
		MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1995
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1996
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1997
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1998
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1963
diff changeset
  1999
static uint32 GetTileTrackStatus_Track(TileIndex tile, TransportType mode)
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1963
diff changeset
  2000
{
817
4f9377b7fd2b (svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents: 679
diff changeset
  2001
	byte m5, a;
4f9377b7fd2b (svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents: 679
diff changeset
  2002
	uint16 b;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2003
	uint32 ret;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2004
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  2005
	if (mode != TRANSPORT_RAIL) return 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2006
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2020
diff changeset
  2007
	m5 = _m[tile].m5;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2008
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2009
	if (!(m5 & RAIL_TYPE_SPECIAL)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2010
		ret = (m5 | (m5 << 8)) & 0x3F3F;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2011
		if (!(m5 & RAIL_TYPE_SIGNALS)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2012
			if ( (ret & 0xFF) == 3)
22
fe6f35cc987b (svn r23) -Some omments on the code (blathijs)
darkvater
parents: 13
diff changeset
  2013
			/* Diagonal crossing? */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2014
				ret |= 0x40;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2015
		} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2016
			/* has_signals */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2017
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2020
diff changeset
  2018
			a = _m[tile].m3;
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2020
diff changeset
  2019
			b = _m[tile].m2;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2020
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2021
			b &= a;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2022
22
fe6f35cc987b (svn r23) -Some omments on the code (blathijs)
darkvater
parents: 13
diff changeset
  2023
			/* When signals are not present (in neither
fe6f35cc987b (svn r23) -Some omments on the code (blathijs)
darkvater
parents: 13
diff changeset
  2024
			 * direction), we pretend them to be green. (So if
fe6f35cc987b (svn r23) -Some omments on the code (blathijs)
darkvater
parents: 13
diff changeset
  2025
			 * signals are only one way, the other way will
fe6f35cc987b (svn r23) -Some omments on the code (blathijs)
darkvater
parents: 13
diff changeset
  2026
			 * implicitely become `red' */
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  2027
			if ((a & 0xC0) == 0) b |= 0xC0;
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  2028
			if ((a & 0x30) == 0) b |= 0x30;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2029
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  2030
			if ((b & 0x80) == 0) ret |= 0x10070000;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  2031
			if ((b & 0x40) == 0) ret |= 0x07100000;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  2032
			if ((b & 0x20) == 0) ret |= 0x20080000;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  2033
			if ((b & 0x10) == 0) ret |= 0x08200000;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2034
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2035
	} else if (m5 & 0x40) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2036
		static const byte _train_spec_tracks[6] = {1,2,1,2,1,2};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2037
		m5 = _train_spec_tracks[m5 & 0x3F];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2038
		ret = (m5 << 8) + m5;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2039
	} else
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2040
		return 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2041
	return ret;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2042
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2043
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1963
diff changeset
  2044
static void ClickTile_Track(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2045
{
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
  2046
	if (IsTileDepotType(tile, TRANSPORT_RAIL)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2047
		ShowTrainDepotWindow(tile);
2668
54d9f9d4dca3 (svn r3210) -Codechange: use IsRailWaypoint where possible (instead of magicnumbers)
truelight
parents: 2667
diff changeset
  2048
	} else if (IsRailWaypoint(tile)) {
1542
2ca6d1624e6d (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1536
diff changeset
  2049
		ShowRenameWaypointWindow(GetWaypointByTile(tile));
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
  2050
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2051
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2052
1590
4e39d1da10c7 (svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron
parents: 1555
diff changeset
  2053
static void GetTileDesc_Track(TileIndex tile, TileDesc *td)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2054
{
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
  2055
	td->owner = GetTileOwner(tile);
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
  2056
	switch (GetRailTileType(tile)) {
1590
4e39d1da10c7 (svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron
parents: 1555
diff changeset
  2057
		case RAIL_TYPE_NORMAL:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2058
			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
  2059
			break;
4e39d1da10c7 (svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron
parents: 1555
diff changeset
  2060
4e39d1da10c7 (svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron
parents: 1555
diff changeset
  2061
		case RAIL_TYPE_SIGNALS: {
2916
8f1aa489701f (svn r3472) - [PBS] Remove from trunk. Anyone interested can still find it in branch/pbs. This reverts revisions r3158, r3140, r3075, r2977, r2674, r2625, r2621, r2529, r2528, r2525, r2524, r2519, r2517, r2516, r2507, r2499. (in conjunction with Tron)
Darkvater
parents: 2911
diff changeset
  2062
			const StringID signal_type[] = {
1590
4e39d1da10c7 (svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron
parents: 1555
diff changeset
  2063
				STR_RAILROAD_TRACK_WITH_NORMAL_SIGNALS,
4e39d1da10c7 (svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron
parents: 1555
diff changeset
  2064
				STR_RAILROAD_TRACK_WITH_PRESIGNALS,
4e39d1da10c7 (svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron
parents: 1555
diff changeset
  2065
				STR_RAILROAD_TRACK_WITH_EXITSIGNALS,
2916
8f1aa489701f (svn r3472) - [PBS] Remove from trunk. Anyone interested can still find it in branch/pbs. This reverts revisions r3158, r3140, r3075, r2977, r2674, r2625, r2621, r2529, r2528, r2525, r2524, r2519, r2517, r2516, r2507, r2499. (in conjunction with Tron)
Darkvater
parents: 2911
diff changeset
  2066
				STR_RAILROAD_TRACK_WITH_COMBOSIGNALS
1590
4e39d1da10c7 (svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron
parents: 1555
diff changeset
  2067
			};
4e39d1da10c7 (svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron
parents: 1555
diff changeset
  2068
2916
8f1aa489701f (svn r3472) - [PBS] Remove from trunk. Anyone interested can still find it in branch/pbs. This reverts revisions r3158, r3140, r3075, r2977, r2674, r2625, r2621, r2529, r2528, r2525, r2524, r2519, r2517, r2516, r2507, r2499. (in conjunction with Tron)
Darkvater
parents: 2911
diff changeset
  2069
			td->str = signal_type[GB(_m[tile].m4, 0, 2)];
1590
4e39d1da10c7 (svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron
parents: 1555
diff changeset
  2070
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2071
		}
1590
4e39d1da10c7 (svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron
parents: 1555
diff changeset
  2072
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
  2073
		case RAIL_TYPE_DEPOT_WAYPOINT:
1590
4e39d1da10c7 (svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron
parents: 1555
diff changeset
  2074
		default:
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2020
diff changeset
  2075
			td->str = ((_m[tile].m5 & RAIL_SUBTYPE_MASK) == RAIL_SUBTYPE_DEPOT) ?
1590
4e39d1da10c7 (svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron
parents: 1555
diff changeset
  2076
				STR_1023_RAILROAD_TRAIN_DEPOT : STR_LANDINFO_WAYPOINT;
4e39d1da10c7 (svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron
parents: 1555
diff changeset
  2077
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2078
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2079
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2080
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
  2081
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
  2082
{
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
  2083
	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
  2084
2502
35e279b13856 (svn r3028) s/255/OWNER_SPECTATOR/
tron
parents: 2499
diff changeset
  2085
	if (new_player != OWNER_SPECTATOR) {
1902
5d653da1abb7 (svn r2408) Introduce SetTileOwner() and use it
tron
parents: 1901
diff changeset
  2086
		SetTileOwner(tile, new_player);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2087
	}	else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2088
		DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
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
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2091
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2092
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
  2093
static const byte _fractcoords_enter[4] = { 0x8A, 0x48, 0x84, 0xA8 };
1922
797081e56d13 (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents: 1903
diff changeset
  2094
static const byte _deltacoord_leaveoffset[8] = {
797081e56d13 (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents: 1903
diff changeset
  2095
	-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
  2096
	 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
  2097
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2098
static const byte _enter_directions[4] = {5, 7, 1, 3};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2099
static const byte _leave_directions[4] = {1, 3, 5, 7};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2100
static const byte _depot_track_mask[4] = {1, 2, 1, 2};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2101
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1963
diff changeset
  2102
static uint32 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
  2103
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2104
	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
  2105
	byte fract_coord_leave;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2106
	int dir;
1922
797081e56d13 (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents: 1903
diff changeset
  2107
	int length;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  2108
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2109
	// this routine applies only to trains in depot tiles
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  2110
	if (v->type != VEH_Train || !IsTileDepotType(tile, TRANSPORT_RAIL)) return 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2111
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2112
	/* depot direction */
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1928
diff changeset
  2113
	dir = GetDepotDirection(tile, TRANSPORT_RAIL);
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  2114
1922
797081e56d13 (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents: 1903
diff changeset
  2115
	/* 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
  2116
	/* 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
  2117
	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
  2118
797081e56d13 (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents: 1903
diff changeset
  2119
	fract_coord_leave =
797081e56d13 (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents: 1903
diff changeset
  2120
		((_fractcoords_enter[dir] & 0x0F) +				// x
797081e56d13 (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents: 1903
diff changeset
  2121
			(length + 1) * _deltacoord_leaveoffset[dir]) +
797081e56d13 (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents: 1903
diff changeset
  2122
		(((_fractcoords_enter[dir] >> 4) +				// y
797081e56d13 (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents: 1903
diff changeset
  2123
			((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
  2124
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2125
	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
  2126
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2127
	if (_fractcoords_behind[dir] == fract_coord) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2128
		/* make sure a train is not entering the tile from behind */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2129
		return 8;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2130
	} else if (_fractcoords_enter[dir] == fract_coord) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2131
		if (_enter_directions[dir] == v->direction) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2132
			/* enter the depot */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2133
			v->u.rail.track = 0x80,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2134
			v->vehstatus |= VS_HIDDEN; /* hide it */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2135
			v->direction ^= 4;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2136
			if (v->next == NULL)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2137
				TrainEnterDepot(v, tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2138
			v->tile = tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2139
			InvalidateWindow(WC_VEHICLE_DEPOT, tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2140
			return 4;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2141
		}
1922
797081e56d13 (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents: 1903
diff changeset
  2142
	} else if (fract_coord_leave == fract_coord) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2143
		if (_leave_directions[dir] == v->direction) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2144
			/* leave the depot? */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2145
			if ((v=v->next) != NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2146
				v->vehstatus &= ~VS_HIDDEN;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2147
				v->u.rail.track = _depot_track_mask[dir];
1330
8a67d04016ce (svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents: 1328
diff changeset
  2148
				assert(v->u.rail.track);
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
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2151
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2152
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2153
	return 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2154
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2155
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1084
diff changeset
  2156
void InitializeRail(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2157
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2158
	_last_built_train_depot_tile = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2159
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2160
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2161
const TileTypeProcs _tile_type_rail_procs = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2162
	DrawTile_Track,						/* draw_tile_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2163
	GetSlopeZ_Track,					/* get_slope_z_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2164
	ClearTile_Track,					/* clear_tile_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2165
	GetAcceptedCargo_Track,		/* get_accepted_cargo_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2166
	GetTileDesc_Track,				/* get_tile_desc_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2167
	GetTileTrackStatus_Track,	/* get_tile_track_status_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2168
	ClickTile_Track,					/* click_tile_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2169
	AnimateTile_Track,				/* animate_tile_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2170
	TileLoop_Track,						/* tile_loop_clear */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2171
	ChangeTileOwner_Track,		/* change_tile_owner_clear */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2172
	NULL,											/* get_produced_cargo_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2173
	VehicleEnter_Track,				/* vehicle_enter_tile_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2174
	NULL,											/* vehicle_leave_tile_proc */
39
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 22
diff changeset
  2175
	GetSlopeTileh_Track,			/* get_slope_tileh_proc */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2176
};