rail_cmd.c
author tron
Mon, 28 Mar 2005 18:59:33 +0000
changeset 1598 4425f756c19b
parent 1591 bf840aede1b1
child 1609 b4d11170cbb5
permissions -rw-r--r--
(svn r2102) Fix bug introduced in r2038, which gave you money for clearing occupied railway tiles ([1171926])
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     1
#include "stdafx.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     2
#include "ttd.h"
1363
01d3de5d8039 (svn r1867) Include tables/sprites.h only in files which need it
tron
parents: 1330
diff changeset
     3
#include "table/sprites.h"
507
8aa8100b0b22 (svn r815) Include strings.h only in the files which need it.
tron
parents: 497
diff changeset
     4
#include "table/strings.h"
1009
a7ccb8e39cbc (svn r1508) Remove duplicate declarations and include proper headers where necessary
tron
parents: 926
diff changeset
     5
#include "gfx.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
     6
#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
     7
#include "tile.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     8
#include "vehicle.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     9
#include "viewport.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    10
#include "command.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    11
#include "pathfind.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    12
#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
    13
#include "sound.h"
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 337
diff changeset
    14
#include "station.h"
405
6830ae7a0d5d (svn r602) -newgrf: Move DrawTileSeqStruct & co and struct SpriteGroup to sprite.h (pasky)
darkvater
parents: 403
diff changeset
    15
#include "sprite.h"
1313
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents: 1247
diff changeset
    16
#include "depot.h"
1542
2ca6d1624e6d (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1536
diff changeset
    17
#include "waypoint.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    18
415
423de36034b8 (svn r612) [newgrf] Fix: custom waypoints on monorail/maglev are displayed correctly
dominik
parents: 413
diff changeset
    19
extern uint16 _custom_sprites_base;
423de36034b8 (svn r612) [newgrf] Fix: custom waypoints on monorail/maglev are displayed correctly
dominik
parents: 413
diff changeset
    20
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    21
void ShowTrainDepotWindow(uint tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    22
22
fe6f35cc987b (svn r23) -Some omments on the code (blathijs)
darkvater
parents: 13
diff changeset
    23
enum { /* These values are bitmasks for the map5 byte */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    24
	RAIL_TYPE_NORMAL = 0,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    25
	RAIL_TYPE_SIGNALS = 0x40,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    26
	RAIL_TYPE_SPECIAL = 0x80, // If this bit is set, then it's not a regular track.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    27
	RAIL_TYPE_DEPOT = 0xC0,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    28
	RAIL_TYPE_MASK = 0xC0,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    29
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    30
	RAIL_BIT_DIAG1 = 1,  // 0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    31
	RAIL_BIT_DIAG2 = 2,  // 1
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    32
	RAIL_BIT_UPPER = 4,  // 2
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    33
	RAIL_BIT_LOWER = 8,  // 3
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    34
	RAIL_BIT_LEFT  = 16, // 4
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    35
	RAIL_BIT_RIGHT = 32, // 5
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    36
	RAIL_BIT_MASK = 0x3F,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    37
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    38
	RAIL_DEPOT_TRACK_MASK = 1,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    39
	RAIL_DEPOT_DIR = 3,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    40
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
    41
	RAIL_SUBTYPE_MASK     = 0x3C,
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
    42
	RAIL_SUBTYPE_DEPOT    = 0x00,
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
    43
	RAIL_SUBTYPE_WAYPOINT = 0x04
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
1535
a5f686a20d2c (svn r2039) IS_RAIL_DEPOT -> IsRailDepot, IS_RAIL_WAYPOINT -> IsRailWaypoint
tron
parents: 1534
diff changeset
    46
static inline bool IsRailDepot(byte m5)
a5f686a20d2c (svn r2039) IS_RAIL_DEPOT -> IsRailDepot, IS_RAIL_WAYPOINT -> IsRailWaypoint
tron
parents: 1534
diff changeset
    47
{
a5f686a20d2c (svn r2039) IS_RAIL_DEPOT -> IsRailDepot, IS_RAIL_WAYPOINT -> IsRailWaypoint
tron
parents: 1534
diff changeset
    48
	return
a5f686a20d2c (svn r2039) IS_RAIL_DEPOT -> IsRailDepot, IS_RAIL_WAYPOINT -> IsRailWaypoint
tron
parents: 1534
diff changeset
    49
		(m5 & RAIL_TYPE_MASK) == RAIL_TYPE_DEPOT &&
a5f686a20d2c (svn r2039) IS_RAIL_DEPOT -> IsRailDepot, IS_RAIL_WAYPOINT -> IsRailWaypoint
tron
parents: 1534
diff changeset
    50
		(m5 & RAIL_SUBTYPE_MASK) == RAIL_SUBTYPE_DEPOT;
a5f686a20d2c (svn r2039) IS_RAIL_DEPOT -> IsRailDepot, IS_RAIL_WAYPOINT -> IsRailWaypoint
tron
parents: 1534
diff changeset
    51
}
a5f686a20d2c (svn r2039) IS_RAIL_DEPOT -> IsRailDepot, IS_RAIL_WAYPOINT -> IsRailWaypoint
tron
parents: 1534
diff changeset
    52
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    53
/* Format of rail map5 byte.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    54
 * 00 abcdef  => Normal rail
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    55
 * 01 abcdef  => Rail with signals
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    56
 * 10 ??????  => Unused
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    57
 * 11 ????dd  => Depot
22
fe6f35cc987b (svn r23) -Some omments on the code (blathijs)
darkvater
parents: 13
diff changeset
    58
 *
fe6f35cc987b (svn r23) -Some omments on the code (blathijs)
darkvater
parents: 13
diff changeset
    59
 * 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
    60
 * value for each track is given.
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    61
 */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    62
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    63
/*         4
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    64
 *     ---------
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    65
 *    |\       /|
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    66
 *    | \    1/ |
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    67
 *    |  \   /  |
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    68
 *    |   \ /   |
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    69
 *  16|    \    |32
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
    70
 *    |   / \2  |
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    71
 *    |  /   \  |
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    72
 *    | /     \ |
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    73
 *    |/       \|
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    74
 *     ---------
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    75
 *         8
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    76
 */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    77
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
// 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
    80
enum RailMap2Lower4 {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    81
	RAIL_MAP2LO_GROUND_MASK = 0xF,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    82
	RAIL_GROUND_BROWN = 0,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    83
	RAIL_GROUND_GREEN = 1,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    84
	RAIL_GROUND_FENCE_NW = 2,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    85
	RAIL_GROUND_FENCE_SE = 3,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    86
	RAIL_GROUND_FENCE_SENW = 4,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    87
	RAIL_GROUND_FENCE_NE = 5,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    88
	RAIL_GROUND_FENCE_SW = 6,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    89
	RAIL_GROUND_FENCE_NESW = 7,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    90
	RAIL_GROUND_FENCE_VERT1 = 8,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    91
	RAIL_GROUND_FENCE_VERT2 = 9,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    92
	RAIL_GROUND_FENCE_HORIZ1 = 10,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    93
	RAIL_GROUND_FENCE_HORIZ2 = 11,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    94
	RAIL_GROUND_ICE_DESERT = 12,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    95
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    96
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    97
22
fe6f35cc987b (svn r23) -Some omments on the code (blathijs)
darkvater
parents: 13
diff changeset
    98
/* 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
    99
 * MAP3LO byte:  abcd???? => Signal Exists?
22
fe6f35cc987b (svn r23) -Some omments on the code (blathijs)
darkvater
parents: 13
diff changeset
   100
 *				 a and b are for diagonals, upper and left,
fe6f35cc987b (svn r23) -Some omments on the code (blathijs)
darkvater
parents: 13
diff changeset
   101
 *				 one for each direction. (ie a == NE->SW, b ==
fe6f35cc987b (svn r23) -Some omments on the code (blathijs)
darkvater
parents: 13
diff changeset
   102
 *				 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
   103
 *				 similar for lower and right.
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   104
 * MAP2 byte:    ????abcd => Type of ground.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   105
 * MAP3LO byte:  ????abcd => Type of rail.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   106
 * MAP5:         00abcdef => rail
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   107
 *               01abcdef => rail w/ signals
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   108
 *               10uuuuuu => unused
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   109
 *               11uuuudd => rail depot
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   110
 */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   111
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   112
static bool CheckTrackCombination(byte map5, byte trackbits, byte flags)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   113
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   114
	_error_message = STR_1001_IMPOSSIBLE_TRACK_COMBINATION;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   115
1591
bf840aede1b1 (svn r2095) In CheckTrackCombination(): if () cascade -> switch, improve readability
tron
parents: 1590
diff changeset
   116
	switch (map5 & RAIL_TYPE_MASK) {
bf840aede1b1 (svn r2095) In CheckTrackCombination(): if () cascade -> switch, improve readability
tron
parents: 1590
diff changeset
   117
		case RAIL_TYPE_NORMAL:
bf840aede1b1 (svn r2095) In CheckTrackCombination(): if () cascade -> switch, improve readability
tron
parents: 1590
diff changeset
   118
			if (map5 & trackbits) {
bf840aede1b1 (svn r2095) In CheckTrackCombination(): if () cascade -> switch, improve readability
tron
parents: 1590
diff changeset
   119
				_error_message = STR_1007_ALREADY_BUILT;
bf840aede1b1 (svn r2095) In CheckTrackCombination(): if () cascade -> switch, improve readability
tron
parents: 1590
diff changeset
   120
				return false;
bf840aede1b1 (svn r2095) In CheckTrackCombination(): if () cascade -> switch, improve readability
tron
parents: 1590
diff changeset
   121
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   122
1591
bf840aede1b1 (svn r2095) In CheckTrackCombination(): if () cascade -> switch, improve readability
tron
parents: 1590
diff changeset
   123
			if (flags & DC_NO_RAIL_OVERLAP) {
bf840aede1b1 (svn r2095) In CheckTrackCombination(): if () cascade -> switch, improve readability
tron
parents: 1590
diff changeset
   124
				// Computer players are not allowed to intersect pieces of rail.
bf840aede1b1 (svn r2095) In CheckTrackCombination(): if () cascade -> switch, improve readability
tron
parents: 1590
diff changeset
   125
				map5 |= trackbits;
bf840aede1b1 (svn r2095) In CheckTrackCombination(): if () cascade -> switch, improve readability
tron
parents: 1590
diff changeset
   126
				return
bf840aede1b1 (svn r2095) In CheckTrackCombination(): if () cascade -> switch, improve readability
tron
parents: 1590
diff changeset
   127
					map5 == (RAIL_BIT_UPPER | RAIL_BIT_LOWER) ||
bf840aede1b1 (svn r2095) In CheckTrackCombination(): if () cascade -> switch, improve readability
tron
parents: 1590
diff changeset
   128
					map5 == (RAIL_BIT_LEFT  | RAIL_BIT_RIGHT);
bf840aede1b1 (svn r2095) In CheckTrackCombination(): if () cascade -> switch, improve readability
tron
parents: 1590
diff changeset
   129
			} else {
bf840aede1b1 (svn r2095) In CheckTrackCombination(): if () cascade -> switch, improve readability
tron
parents: 1590
diff changeset
   130
				return true;
bf840aede1b1 (svn r2095) In CheckTrackCombination(): if () cascade -> switch, improve readability
tron
parents: 1590
diff changeset
   131
			}
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   132
1591
bf840aede1b1 (svn r2095) In CheckTrackCombination(): if () cascade -> switch, improve readability
tron
parents: 1590
diff changeset
   133
		case RAIL_TYPE_SIGNALS:
bf840aede1b1 (svn r2095) In CheckTrackCombination(): if () cascade -> switch, improve readability
tron
parents: 1590
diff changeset
   134
			if (map5 & trackbits) {
bf840aede1b1 (svn r2095) In CheckTrackCombination(): if () cascade -> switch, improve readability
tron
parents: 1590
diff changeset
   135
				_error_message = STR_1007_ALREADY_BUILT;
bf840aede1b1 (svn r2095) In CheckTrackCombination(): if () cascade -> switch, improve readability
tron
parents: 1590
diff changeset
   136
				return false;
bf840aede1b1 (svn r2095) In CheckTrackCombination(): if () cascade -> switch, improve readability
tron
parents: 1590
diff changeset
   137
			}
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   138
1591
bf840aede1b1 (svn r2095) In CheckTrackCombination(): if () cascade -> switch, improve readability
tron
parents: 1590
diff changeset
   139
			map5 |= trackbits;
bf840aede1b1 (svn r2095) In CheckTrackCombination(): if () cascade -> switch, improve readability
tron
parents: 1590
diff changeset
   140
			return
bf840aede1b1 (svn r2095) In CheckTrackCombination(): if () cascade -> switch, improve readability
tron
parents: 1590
diff changeset
   141
				map5 == (RAIL_TYPE_SIGNALS | RAIL_BIT_UPPER | RAIL_BIT_LOWER) ||
bf840aede1b1 (svn r2095) In CheckTrackCombination(): if () cascade -> switch, improve readability
tron
parents: 1590
diff changeset
   142
				map5 == (RAIL_TYPE_SIGNALS | RAIL_BIT_LEFT  | RAIL_BIT_RIGHT);
bf840aede1b1 (svn r2095) In CheckTrackCombination(): if () cascade -> switch, improve readability
tron
parents: 1590
diff changeset
   143
bf840aede1b1 (svn r2095) In CheckTrackCombination(): if () cascade -> switch, improve readability
tron
parents: 1590
diff changeset
   144
		default:
bf840aede1b1 (svn r2095) In CheckTrackCombination(): if () cascade -> switch, improve readability
tron
parents: 1590
diff changeset
   145
			return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   146
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   147
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   148
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   149
13
3e7c1f74a996 (svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents: 0
diff changeset
   150
static const byte _valid_tileh_slopes[4][15] = {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   151
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   152
// set of normal ones
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
	RAIL_BIT_DIAG1|RAIL_BIT_DIAG2|RAIL_BIT_UPPER|RAIL_BIT_LOWER|RAIL_BIT_LEFT|RAIL_BIT_RIGHT,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   155
	RAIL_BIT_RIGHT,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   156
	RAIL_BIT_UPPER,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   157
	RAIL_BIT_DIAG1,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   158
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   159
	RAIL_BIT_LEFT,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   160
	0,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   161
	RAIL_BIT_DIAG2,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   162
	RAIL_BIT_LOWER,
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   163
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   164
	RAIL_BIT_LOWER,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   165
	RAIL_BIT_DIAG2,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   166
	0,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   167
	RAIL_BIT_LEFT,
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   168
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   169
	RAIL_BIT_DIAG1,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   170
	RAIL_BIT_UPPER,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   171
	RAIL_BIT_RIGHT,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   172
},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   173
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   174
// allowed rail for an evenly raised platform
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
	0,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   177
	RAIL_BIT_LEFT,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   178
	RAIL_BIT_LOWER,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   179
	RAIL_BIT_DIAG2 | RAIL_BIT_LOWER | RAIL_BIT_LEFT,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   180
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   181
	RAIL_BIT_RIGHT,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   182
	RAIL_BIT_DIAG1|RAIL_BIT_DIAG2|RAIL_BIT_UPPER|RAIL_BIT_LOWER|RAIL_BIT_LEFT|RAIL_BIT_RIGHT,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   183
	RAIL_BIT_DIAG1 | RAIL_BIT_LOWER | RAIL_BIT_RIGHT,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   184
	RAIL_BIT_DIAG1|RAIL_BIT_DIAG2|RAIL_BIT_UPPER|RAIL_BIT_LOWER|RAIL_BIT_LEFT|RAIL_BIT_RIGHT,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   185
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   186
	RAIL_BIT_UPPER,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   187
	RAIL_BIT_DIAG1 | RAIL_BIT_UPPER | RAIL_BIT_LEFT,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   188
	RAIL_BIT_DIAG1|RAIL_BIT_DIAG2|RAIL_BIT_UPPER|RAIL_BIT_LOWER|RAIL_BIT_LEFT|RAIL_BIT_RIGHT,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   189
	RAIL_BIT_DIAG1|RAIL_BIT_DIAG2|RAIL_BIT_UPPER|RAIL_BIT_LOWER|RAIL_BIT_LEFT|RAIL_BIT_RIGHT,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   190
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   191
	RAIL_BIT_DIAG2 | RAIL_BIT_UPPER | RAIL_BIT_RIGHT,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   192
	RAIL_BIT_DIAG1|RAIL_BIT_DIAG2|RAIL_BIT_UPPER|RAIL_BIT_LOWER|RAIL_BIT_LEFT|RAIL_BIT_RIGHT,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   193
	RAIL_BIT_DIAG1|RAIL_BIT_DIAG2|RAIL_BIT_UPPER|RAIL_BIT_LOWER|RAIL_BIT_LEFT|RAIL_BIT_RIGHT,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   194
},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   195
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   196
// allowed rail on coast tile
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   197
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   198
	0,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   199
	RAIL_BIT_LEFT,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   200
	RAIL_BIT_LOWER,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   201
	RAIL_BIT_DIAG2|RAIL_BIT_LEFT|RAIL_BIT_LOWER,
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   202
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   203
	RAIL_BIT_RIGHT,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   204
	RAIL_BIT_DIAG1|RAIL_BIT_DIAG2|RAIL_BIT_UPPER|RAIL_BIT_LOWER|RAIL_BIT_LEFT|RAIL_BIT_RIGHT,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   205
	RAIL_BIT_DIAG1|RAIL_BIT_RIGHT|RAIL_BIT_LOWER,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   206
	RAIL_BIT_DIAG1|RAIL_BIT_DIAG2|RAIL_BIT_UPPER|RAIL_BIT_LOWER|RAIL_BIT_LEFT|RAIL_BIT_RIGHT,
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
	RAIL_BIT_UPPER,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   209
	RAIL_BIT_DIAG1|RAIL_BIT_LEFT|RAIL_BIT_UPPER,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   210
	RAIL_BIT_DIAG1|RAIL_BIT_DIAG2|RAIL_BIT_UPPER|RAIL_BIT_LOWER|RAIL_BIT_LEFT|RAIL_BIT_RIGHT,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   211
	RAIL_BIT_DIAG1|RAIL_BIT_DIAG2|RAIL_BIT_UPPER|RAIL_BIT_LOWER|RAIL_BIT_LEFT|RAIL_BIT_RIGHT,
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
	RAIL_BIT_DIAG2|RAIL_BIT_RIGHT|RAIL_BIT_UPPER,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   214
	RAIL_BIT_DIAG1|RAIL_BIT_DIAG2|RAIL_BIT_UPPER|RAIL_BIT_LOWER|RAIL_BIT_LEFT|RAIL_BIT_RIGHT,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   215
	RAIL_BIT_DIAG1|RAIL_BIT_DIAG2|RAIL_BIT_UPPER|RAIL_BIT_LOWER|RAIL_BIT_LEFT|RAIL_BIT_RIGHT,
13
3e7c1f74a996 (svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents: 0
diff changeset
   216
	},
3e7c1f74a996 (svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents: 0
diff changeset
   217
3e7c1f74a996 (svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents: 0
diff changeset
   218
	// valid railway crossings on slopes
3e7c1f74a996 (svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents: 0
diff changeset
   219
	{
3e7c1f74a996 (svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents: 0
diff changeset
   220
		1, 0, 0, // 0, 1, 2
3e7c1f74a996 (svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents: 0
diff changeset
   221
		0, 0, 1, // 3, 4, 5
3e7c1f74a996 (svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents: 0
diff changeset
   222
		0, 1, 0, // 6, 7, 8
3e7c1f74a996 (svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents: 0
diff changeset
   223
		0, 1, 1, // 9, 10, 11
3e7c1f74a996 (svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents: 0
diff changeset
   224
		0, 1, 1, // 12, 13, 14
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   225
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   226
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   227
84
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents: 59
diff changeset
   228
uint GetRailFoundation(uint tileh, uint bits)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   229
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   230
	int i;
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
	if ((~_valid_tileh_slopes[0][tileh] & bits) == 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   233
		return 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   234
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   235
	if ((~_valid_tileh_slopes[1][tileh] & bits) == 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   236
		return tileh;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   237
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   238
	if ( ((i=0, tileh == 1) || (i+=2, tileh == 2) || (i+=2, tileh == 4) || (i+=2, tileh == 8)) && (bits == RAIL_BIT_DIAG1 || (i++, bits == RAIL_BIT_DIAG2)))
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   239
		return i + 15;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   240
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   241
	return 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   242
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   243
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   244
//
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   245
static uint32 CheckRailSlope(int tileh, uint rail_bits, uint existing, uint tile)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   246
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   247
	// never allow building on top of steep tiles
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   248
	if (!(tileh & 0x10)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   249
		rail_bits |= existing;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   250
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   251
		// don't allow building on the lower side of a coast
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
   252
		if (IsTileType(tile, MP_WATER) && ~_valid_tileh_slopes[2][tileh] & rail_bits) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   253
			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
   254
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   255
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   256
		// no special foundation
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   257
		if ((~_valid_tileh_slopes[0][tileh] & rail_bits) == 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   258
			return 0;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   259
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   260
		if (((~_valid_tileh_slopes[1][tileh] & rail_bits) == 0) || // whole tile is leveled up
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   261
			((rail_bits == RAIL_BIT_DIAG1 || rail_bits == RAIL_BIT_DIAG2) && (tileh == 1 || tileh == 2 || tileh == 4 || tileh == 8))) { // partly up
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   262
			return existing ? 0 : _price.terraform;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   263
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   264
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   265
	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
   266
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   267
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   268
/* Build a single track.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   269
 * p1 - railroad type normal/maglev
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   270
 * p2 - tile direction
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   271
 */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   272
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   273
int32 CmdBuildSingleRail(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
   274
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   275
	TileInfo ti;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   276
	int32 ret, cost = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   277
	byte rail_bit = 1 << p2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   278
	byte rail_type = (byte)(p1 & 0xF);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   279
	uint tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   280
	byte existing = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   281
	bool need_clear = false;
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   285
	_error_message = STR_1007_ALREADY_BUILT;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   286
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   287
	FindLandscapeHeight(&ti, x, y);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   288
	tile = ti.tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   289
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   290
	// allow building rail under bridge
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   291
	if (ti.type != MP_TUNNELBRIDGE && !EnsureNoVehicle(tile))
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   292
		return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   293
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   294
	if (ti.type == MP_TUNNELBRIDGE) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   295
/* BUILD ON BRIDGE CODE */
1041
be151b7bc909 (svn r1542) Rename TileHeight to TilePixelHeight, because this is what it actually returns
tron
parents: 1035
diff changeset
   296
		if (!EnsureNoVehicleZ(tile, TilePixelHeight(tile)))
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   297
			return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   298
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   299
		if ((ti.map5 & 0xF8) == 0xC0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   300
			if (ti.tileh & 0x10 || rail_bit != (byte)((ti.map5 & 1) ? 1 : 2)) goto need_clear;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   301
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   302
			if (!(flags & DC_EXEC))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   303
				return _price.build_rail;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   304
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   305
			_map5[tile] = (ti.map5 & 0xC7) | 0x20;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   306
			goto set_ownership;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   307
		} else if ((ti.map5 & 0xF8) == 0xE0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   308
			if ((_map3_lo[tile] & 0xF) != (int)p1) goto need_clear;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   309
			if (rail_bit != (byte)((ti.map5 & 1) ? 1 : 2)) goto need_clear;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   310
			return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   311
		} else
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   312
			goto need_clear;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   313
	} else if (ti.type == MP_STREET) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   314
		byte m5;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   315
/* BUILD ON STREET CODE */
13
3e7c1f74a996 (svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents: 0
diff changeset
   316
		if (ti.tileh & 0x10) // very steep tile
3e7c1f74a996 (svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents: 0
diff changeset
   317
				return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
3e7c1f74a996 (svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents: 0
diff changeset
   318
3e7c1f74a996 (svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents: 0
diff changeset
   319
		if (!_valid_tileh_slopes[3][ti.tileh]) // prevent certain slopes
3e7c1f74a996 (svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents: 0
diff changeset
   320
				return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
3e7c1f74a996 (svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents: 0
diff changeset
   321
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   322
		if (!(ti.map5 & 0xF0)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   323
			if ((ti.map5 & 0x0F) == 0xA) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   324
				if (rail_bit != 2) goto need_clear;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   325
				m5 = 0x10;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   326
			} else if ((ti.map5 & 0x0F) == 0x5) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   327
				if (rail_bit != 1) goto need_clear;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   328
				m5 = 0x18;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   329
			} else
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   330
				goto need_clear;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   331
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   332
			if (!(flags & DC_EXEC))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   333
				return _price.build_rail;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   334
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   335
			ModifyTile(tile,
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   336
				MP_SETTYPE(MP_STREET) |
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   337
				MP_MAP3LO | MP_MAP3HI | MP_MAPOWNER_CURRENT | MP_MAP5,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   338
				_map_owner[tile], /* map3_lo */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   339
				p1, /* map3_hi */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   340
				m5  /* map5 */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   341
			);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   342
			goto fix_signals;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   343
		} else if (!(ti.map5 & 0xE0)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   344
			if (rail_bit != (byte)((ti.map5 & 8) ? 1 : 2)) goto need_clear;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   345
			return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   346
		} else
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   347
			goto need_clear;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   348
	} else if (ti.type == MP_RAILWAY) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   349
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   350
/* BUILD ON RAILWAY CODE */
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   351
		if (_map_owner[tile] != _current_player || (byte)(_map3_lo[tile]&0xF) != rail_type)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   352
			goto need_clear;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   353
		if (!CheckTrackCombination(ti.map5, rail_bit, (byte)flags))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   354
			return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   355
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   356
		existing = ti.map5 & 0x3F;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   357
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   358
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   359
/* DEFAULT BUILD ON CODE */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   360
need_clear:;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   361
		/* isnot_railway */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   362
		if (!(flags & DC_EXEC)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   363
			ret = DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   364
			if (ret == CMD_ERROR) return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   365
			cost += ret;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   366
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   367
		need_clear = true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   368
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   369
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   370
	ret = CheckRailSlope(ti.tileh, rail_bit, existing, tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   371
	if (ret & 0x80000000)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   372
		return ret;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   373
	cost += ret;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   374
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   375
	// the AI is not allowed to used foundationed tiles.
84
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents: 59
diff changeset
   376
	if (ret && (!_patches.build_on_slopes || (!_patches.ainew_active && _is_ai_player)))
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   377
		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
   378
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   379
	if (flags & DC_EXEC && need_clear) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   380
		ret = DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   381
		if (ret == CMD_ERROR) return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   382
		cost += ret;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   383
	}
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
	if (flags & DC_EXEC) {
1059
c28c6be74291 (svn r1560) Introduce SetTileType() and SetTileHeight()
tron
parents: 1041
diff changeset
   386
		SetTileType(tile, MP_RAILWAY);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   387
		_map5[tile] |= rail_bit;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   388
		_map2[tile] &= ~RAIL_MAP2LO_GROUND_MASK;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   389
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   390
		// In case it's a tile without signals, clear the signal bits. Why?
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   391
		if ((_map5[tile] & RAIL_TYPE_MASK) != RAIL_TYPE_SIGNALS)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   392
			_map2[tile] &= ~0xF0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   393
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   394
set_ownership:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   395
		_map_owner[tile] = _current_player;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   396
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   397
		_map3_lo[tile] &= ~0xF;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   398
		_map3_lo[tile] |= rail_type;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   399
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   400
		MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   401
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   402
fix_signals:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   403
		SetSignalsOnBothDir(tile, (byte)p2);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   404
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   405
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   406
	return cost + _price.build_rail;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   407
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   408
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   409
static const byte _signals_table[] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   410
	0x40, 0x40, 0x40, 0x10, 0x80, 0x20, 0, 0, // direction 1
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   411
	0x80, 0x80, 0x80, 0x20, 0x40, 0x10, 0, 0  // direction 2
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   414
static const byte _signals_table_other[] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   415
	0x80, 0x80, 0x80, 0x20, 0x40, 0x10, 0, 0, // direction 1
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   416
	0x40, 0x40, 0x40, 0x10, 0x80, 0x20, 0, 0  // direction 2
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   417
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   418
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   419
static const byte _signals_table_both[] = {
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   420
	0xC0, 0xC0, 0xC0, 0x30, 0xC0, 0x30, 0, 0,	// both directions combined
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   421
	0xC0, 0xC0, 0xC0, 0x30, 0xC0, 0x30, 0, 0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   422
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   423
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   424
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   425
/* Remove a single track.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   426
 * p1 - unused
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   427
 * p2 - tile direction
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   428
 */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   429
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   430
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
   431
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   432
	TileInfo ti;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   433
	byte rail_bit = 1 << p2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   434
	byte m5;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   435
	uint tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   436
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   437
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   438
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   439
	FindLandscapeHeight(&ti, x, y);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   440
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   441
	tile = ti.tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   442
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   443
	if (!((1<<ti.type) & ((1<<MP_TUNNELBRIDGE)|(1<<MP_STREET)|(1<<MP_RAILWAY))))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   444
		return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   445
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   446
	if (_current_player != OWNER_WATER && !CheckTileOwnership(tile))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   447
		return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   448
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   449
	// allow building rail under bridge
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   450
	if (ti.type != MP_TUNNELBRIDGE && !EnsureNoVehicle(tile))
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   451
		return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   452
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   453
	if (ti.type == MP_TUNNELBRIDGE) {
1041
be151b7bc909 (svn r1542) Rename TileHeight to TilePixelHeight, because this is what it actually returns
tron
parents: 1035
diff changeset
   454
		if (!EnsureNoVehicleZ(tile, TilePixelHeight(tile)))
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   455
			return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   456
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   457
		if ((ti.map5 & 0xF8) != 0xE0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   458
			return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   459
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   460
		if ( ((ti.map5 & 1) ? 1 : 2) != rail_bit )
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   461
			return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   462
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   463
		if (!(flags & DC_EXEC))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   464
			return _price.remove_rail;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   465
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   466
		_map_owner[tile] = OWNER_NONE;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   467
		_map5[tile] = ti.map5 & 0xC7;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   468
	} else if (ti.type == MP_STREET) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   469
		if (!(ti.map5 & 0xF0))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   470
			return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   471
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   472
		if (ti.map5 & 0xE0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   473
			return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   474
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   475
		if (ti.map5 & 8) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   476
			m5 = 5;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   477
			if (rail_bit != 1)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   478
				return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   479
		} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   480
			m5 = 10;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   481
			if (rail_bit != 2)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   482
				return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   483
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   484
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   485
		if (!(flags & DC_EXEC))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   486
			return _price.remove_rail;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   487
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   488
		_map5[tile] = m5;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   489
		_map_owner[tile] = _map3_lo[tile];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   490
		_map2[tile] = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   491
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   492
		assert(ti.type == MP_RAILWAY);
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
		if (ti.map5 & RAIL_TYPE_SPECIAL)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   495
			return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   496
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   497
		if (!(ti.map5 & rail_bit))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   498
			return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   499
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   500
		// don't allow remove if there are signals on the track
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   501
		if (ti.map5 & RAIL_TYPE_SIGNALS) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   502
			if (_map3_lo[tile] & _signals_table_both[p2])
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   503
				return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   504
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   505
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   506
		if (!(flags & DC_EXEC))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   507
			return _price.remove_rail;
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
		if ( (_map5[tile] ^= rail_bit) == 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   510
			DoClearSquare(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   511
			goto skip_mark_dirty;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   512
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   513
	}
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
	/* mark_dirty */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   516
	MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   517
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   518
skip_mark_dirty:;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   519
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   520
	SetSignalsOnBothDir(tile, (byte)p2);
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   521
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   522
	return _price.remove_rail;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   523
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   524
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   525
static const struct {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   526
	int8 xinc[16];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   527
	int8 yinc[16];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   528
} _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
   529
//  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
   530
	-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
   531
	 16,  0,  0, 16,  0,-16,    0,  0,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   532
},{
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
	  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
   534
	  0,-16,-16,  0,-16,  0,    0,  0,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   535
}};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   536
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
   537
static int32 ValidateAutoDrag(int *railbit, int x, int y, int ex, int 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
   538
{
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
   539
	int dx, dy, trdx, trdy;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   540
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
	if (*railbit > 5) return CMD_ERROR; // only 6 possible track-combinations
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
   542
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
   543
	// 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
   544
	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
   545
	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
   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
	// calculate delta x,y for the first 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
	trdx = _railbit.xinc[*railbit];
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 = _railbit.yinc[*railbit];
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
   550
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
   551
	if (*railbit & 0x6) {
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 += _railbit.xinc[*railbit ^ 1];
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 += _railbit.yinc[*railbit ^ 1];
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
	}
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
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
	// 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
   557
	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
   558
	       ((trdy <= 0) && (dy > 0)) || ((trdy >= 0) && (dy < 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
   559
		if (*railbit < 8) { // first direction is invalid, try the other
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
   560
			SETBIT(*railbit, 3);
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
   561
			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
   562
			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
   563
		} 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
   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
	// (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
   568
	// for non-diagonal tracks, check if the start and end tile are on 1 line
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
	if (*railbit & 0x6) {
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
   570
		trdx = _railbit.xinc[*railbit];
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
   571
		trdy = _railbit.yinc[*railbit];
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
   572
		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
   573
			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
   574
	}
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
   575
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
   576
	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
   577
}
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
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
/* Build a stretch of railroad tracks.
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
 * x,y= start 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
   581
 * p1 = 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
   582
 * p2 = (bit 0-3)		- railroad type normal/maglev
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
   583
 * p2 = (bit 4-6)		- track-orientation, valid values: 0-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
   584
 * p2 = (bit 7)			- 0 = build, 1 = remove tracks
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   585
 */
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
   586
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
   587
{
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
   588
	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
   589
	int32 ret, total_cost = 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
   590
	int railbit = (p2 >> 4) & 7;
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
	byte mode = HASBIT(p2, 7);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   592
1227
3552f20fcfcb (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater
parents: 1209
diff changeset
   593
	/* unpack end point */
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
   594
	ex = TileX(p1) * 16;
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
   595
	ey = TileY(p1) * 16;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   596
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
   597
	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
   598
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   599
	if (flags & DC_EXEC)
541
e1cd34389f79 (svn r925) Use sound enums
tron
parents: 507
diff changeset
   600
		SndPlayTileFx(SND_20_SPLAT_2, TILE_FROM_XY(x,y));
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   601
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
   602
	if (ValidateAutoDrag(&railbit, x, y, ex, ey) == 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
   603
		return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   604
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   605
	for(;;) {
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
   606
		ret = DoCommand(x, y, p2&0x3, railbit&7, 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
   607
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   608
		if (ret == 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
   609
			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
   610
				break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   611
		} else
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   612
			total_cost += ret;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   613
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
   614
		if (x == ex && y == ey)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   615
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   616
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   617
		x += _railbit.xinc[railbit];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   618
		y += _railbit.yinc[railbit];
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   619
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
   620
		// toggle railbit for the non-diagonal tracks
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   621
		if (railbit & 0x6) railbit ^= 1;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   622
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   623
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   624
	if (total_cost == 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   625
		return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   626
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   627
	return total_cost;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   628
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   629
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
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
   631
{
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
   632
	return CmdRailTrackHelper(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
   633
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   634
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   635
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
   636
{
1227
3552f20fcfcb (svn r1731) - Fix: [ 1106930 ] BugFix: placing signals with 2x1 drags workaround is completely rewritten. Also features checks for hacked/modified clients. Thanks a lot Hackykid!
darkvater
parents: 1209
diff changeset
   637
	return CmdRailTrackHelper(x, y, flags, p1, SETBIT(p2, 7));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   638
}
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
/* Build a train depot
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   641
 * p1 = rail type
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   642
 * p2 = depot direction
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   643
 */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   644
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
   645
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   646
	uint tile = TILE_FROM_XY(x,y);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   647
	int32 cost, ret;
1313
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents: 1247
diff changeset
   648
	Depot *depot;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   649
	uint tileh;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   650
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   651
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   652
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   653
	if (!EnsureNoVehicle(tile)) return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   654
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   655
	tileh = GetTileSlope(tile, NULL);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   656
	if (tileh != 0) {
84
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents: 59
diff changeset
   657
		if ((!_patches.ainew_active && _is_ai_player) || !_patches.build_on_slopes || (tileh & 0x10 || !((0x4C >> p2) & tileh) ))
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   658
			return_cmd_error(STR_0007_FLAT_LAND_REQUIRED);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   659
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   660
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   661
	ret = DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   662
	if (ret == CMD_ERROR) return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   663
	cost = ret;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   664
1313
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents: 1247
diff changeset
   665
	depot = AllocateDepot();
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents: 1247
diff changeset
   666
	if (depot == NULL)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   667
		return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   668
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   669
	if (flags & DC_EXEC) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   670
		if (_current_player == _local_player)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   671
			_last_built_train_depot_tile = (TileIndex)tile;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   672
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   673
		ModifyTile(tile,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   674
			MP_SETTYPE(MP_RAILWAY) |
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   675
			MP_MAP3LO | MP_MAPOWNER_CURRENT | MP_MAP5,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   676
			p1, /* map3_lo */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   677
			p2 | RAIL_TYPE_DEPOT /* map5 */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   678
		);
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   679
1313
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents: 1247
diff changeset
   680
		depot->xy = tile;
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents: 1247
diff changeset
   681
		depot->town_index = ClosestTownFromTile(tile, (uint)-1)->index;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   682
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   683
		SetSignalsOnBothDir(tile, (p2&1) ? 2 : 1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   684
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   685
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   686
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   687
	return cost + _price.build_train_depot;
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
1084
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   690
/* build signals, alternate between double/single, signal/semaphore,
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   691
 * pre/exit/combo-signals
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   692
 * p1 bits 0-2 - track-orientation, valid values: 0-5
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   693
 * p1 bit  3   - choose semaphores/signals or cycle normal/pre/exit/combo
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   694
 *               depending on context
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   695
 * p2 = used for CmdBuildManySignals() to copy style of first signal
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
   696
 */
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
   697
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
   698
{
1084
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   699
	TileIndex tile = TILE_FROM_XY(x, y);
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   700
	bool semaphore;
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   701
	bool pre_signal;
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   702
	uint track = p1 & 0x7;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   703
	byte m5;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   704
	int32 cost;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   705
1084
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   706
	if (!(track < 6) || // only 6 possible track-combinations
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   707
			!IsTileType(tile, MP_RAILWAY) ||
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   708
			!EnsureNoVehicle(tile))
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   709
		return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   710
1084
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   711
	// Protect against invalid signal copying
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   712
	if (p2 != 0 && (p2 & _signals_table_both[track]) == 0)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   713
		return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   714
1084
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   715
	m5 = _map5[tile];
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   716
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   717
	if (m5 & 0x80 || // mustn't be a depot
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   718
			!HASBIT(m5, track)) // track must exist
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   719
		return CMD_ERROR;
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   720
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   721
	if (!CheckTileOwnership(tile)) return CMD_ERROR;
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   722
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
   723
	_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
   724
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   725
	{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   726
		byte m = m5 & RAIL_BIT_MASK;
1084
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   727
		if (m != RAIL_BIT_DIAG1 &&
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   728
				m != RAIL_BIT_DIAG2 &&
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   729
				m != RAIL_BIT_UPPER &&
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   730
				m != RAIL_BIT_LOWER &&
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   731
				m != RAIL_BIT_LEFT &&
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   732
				m != RAIL_BIT_RIGHT &&
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   733
				m != (RAIL_BIT_UPPER | RAIL_BIT_LOWER) &&
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   734
				m != (RAIL_BIT_LEFT | RAIL_BIT_RIGHT))
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   735
			return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   736
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   737
1084
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   738
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   739
1084
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   740
	// Same bit, used in different contexts
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   741
	semaphore = pre_signal = HASBIT(p1, 3);
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
   742
1084
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   743
	if ((_map3_lo[tile] & _signals_table_both[track]) == 0) {
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   744
		// build new signals
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   745
		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
   746
	} else {
1084
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   747
		if (p2 != 0 &&
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   748
				((semaphore && !HASBIT(_map3_hi[tile], 2)) ||
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   749
				(!semaphore && HASBIT(_map3_hi[tile], 2)))) {
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   750
			// convert signals <-> semaphores
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   751
			cost = _price.build_signals + _price.remove_signals;
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   752
		} else {
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   753
			// it is free to change orientation/pre-exit-combo signals
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   754
			cost = 0;
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   755
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   756
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   757
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   758
	if (flags & DC_EXEC) {
1084
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   759
		if (!(m5 & RAIL_TYPE_SIGNALS)) {
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   760
			// there are no signals at all on this tile yet
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   761
			_map5[tile] |= RAIL_TYPE_SIGNALS; // change into signals
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   762
			_map2[tile] |= 0xF0;              // all signals are on
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   763
			_map3_lo[tile] &= ~0xF0;          // no signals built by default
1084
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   764
			_map3_hi[tile] = semaphore ? 4 : 0;
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
1084
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   767
		if (p2 == 0) {
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   768
			if ((_map3_lo[tile] & _signals_table_both[track]) == 0) {
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   769
				// build new signals
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   770
				_map3_lo[tile] |= _signals_table_both[track];
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   771
			} else {
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   772
				if (pre_signal) {
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   773
					// cycle between normal -> pre -> exit -> combo -> ...
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   774
					byte type = (_map3_hi[tile] + 1) & 0x03;
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   775
					_map3_hi[tile] &= ~0x03;
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   776
					_map3_hi[tile] |= type;
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   777
				} else {
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   778
					// cycle between two-way -> one-way -> one-way -> ...
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   779
					switch (track) {
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   780
						case 3:
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   781
						case 5: {
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   782
							byte signal = (_map3_lo[tile] - 0x10) & 0x30;
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   783
							if (signal == 0) signal = 0x30;
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   784
							_map3_lo[tile] &= ~0x30;
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   785
							_map3_lo[tile] |= signal;
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   786
							break;
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   787
						}
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
   788
1084
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   789
						default: {
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   790
							byte signal = (_map3_lo[tile] - 0x40) & 0xC0;
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   791
							if (signal == 0) signal = 0xC0;
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   792
							_map3_lo[tile] &= ~0xC0;
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   793
							_map3_lo[tile] |= signal;
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   794
							break;
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   795
						}
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   796
					}
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   797
				}
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   798
			}
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
   799
		} else {
1084
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   800
			/* If CmdBuildManySignals is called with copying signals, just copy the
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   801
			 * style of the first signal given as parameter by CmdBuildManySignals */
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   802
			_map3_lo[tile] &= ~_signals_table_both[track];
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   803
			_map3_lo[tile] |= p2 & _signals_table_both[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
   804
			// convert between signal<->semaphores when dragging
1084
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   805
			if (semaphore)
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   806
				SETBIT(_map3_hi[tile], 2);
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   807
			else
16db2b52597e (svn r1585) Rewrite CmdBuildSignals()
tron
parents: 1066
diff changeset
   808
				CLRBIT(_map3_hi[tile], 2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   809
		}
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   810
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   811
		MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   812
		SetSignalsOnBothDir(tile, track);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   813
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   814
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   815
	return cost;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   816
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   817
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
   818
/*	Build many signals by dragging: AutoSignals
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
   819
 * x,y = start 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
   820
 * p1  = 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
   821
 * p2  = (bit 0)			- 0 = build, 1 = remove signals
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
   822
 * p2  = (bit 3)			- 0 = signals, 1 = semaphores
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
   823
 * p2  = (bit 4-6)		- track-orientation, valid values: 0-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
   824
 * 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
   825
 */
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
   826
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
   827
{
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
   828
	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
   829
	int railbit = (p2 >> 4) & 7;
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
   830
	bool error = true;
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
   831
	TileIndex tile = TILE_FROM_XY(x, y);
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
   832
	int32 ret, total_cost, signal_ctr;
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
   833
	byte m5, semaphores = (HASBIT(p2, 3)) ? 8 : 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
   834
	int mode = p2 & 0x1;
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
   835
	// for vertical/horizontal tracks, double the given signals density
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
	// since the original amount will be too dense (shorter tracks)
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
	byte signal_density = (railbit & 0x6) ? (p2 >> 24) * 2: (p2 >> 24);
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
   838
	byte 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
   839
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
   840
	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
   841
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
   842
	// unpack end tile
926
bd4312619522 (svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents: 919
diff changeset
   843
	ex = TileX(p1) * 16;
bd4312619522 (svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents: 919
diff changeset
   844
	ey = TileY(p1) * 16;
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
   845
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
   846
	if (ValidateAutoDrag(&railbit, x, y, ex, ey) == 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
   847
		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
   848
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
   849
	// copy the signal-style of the first rail-piece if existing
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
   850
	m5 = _map5[tile];
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
   851
	if (!(m5 & RAIL_TYPE_SPECIAL) && (m5 & RAIL_BIT_MASK) && (m5 & RAIL_TYPE_SIGNALS)) {
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
   852
		signals = _map3_lo[tile] & _signals_table_both[railbit];
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
   853
		if (signals == 0) signals = _signals_table_both[railbit];
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
   854
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
   855
		semaphores = (_map3_hi[tile] & ~3) ? 8 : 0; // copy signal/semaphores style (independent of CTRL)
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
   856
	} else { // no signals exist, drag a two-way signal stretch
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
   857
		signals = _signals_table_both[railbit];
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
   858
	}
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
   859
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
   860
	/* signal_density_ctr	- amount of tiles already processed
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
   861
	 * signals_density		- patch setting to put signal on every Nth tile (double space on |, -- tracks)
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
   862
	 **********
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
   863
	 * railbit		- direction of autorail
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
   864
	 * semaphores	- semaphores or signals
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   865
	 * signals		- is there a signal/semaphore on the first tile, copy its style (two-way/single-way)
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
									and convert all others to semaphore/signal
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
   867
	 * mode				- 1 remove signals, 0 build signals */
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
   868
	signal_ctr = total_cost = 0;
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
   869
	for(;;) {
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
		// only build/remove signals with the specified density
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
		if ((signal_ctr %	signal_density) == 0 ) {
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
   872
			ret = DoCommand(x, y, (railbit & 7) | semaphores, signals, flags, (mode == 1) ? CMD_REMOVE_SIGNALS : CMD_BUILD_SIGNALS);
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
   873
826
0e2b569b737b (svn r1297) Language fixes in the source.. (ln-)
miham
parents: 817
diff changeset
   874
			/* 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
   875
			 * This includes vehicles on track, competitor's tracks, etc. */
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
   876
			if (ret == CMD_ERROR) {
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
   877
				if (_error_message != STR_1005_NO_SUITABLE_RAILROAD_TRACK && mode != 1) {
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
   878
					return CMD_ERROR;
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
				}
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
   880
			} 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
   881
				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
   882
				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
   883
			}
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
   884
		}
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
   885
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
   886
		if (ex == x && ey == y) // reached end of drag
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
   887
			break;
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
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
   889
		x += _railbit.xinc[railbit];
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   890
		y += _railbit.yinc[railbit];
58
b9fdcc9b5c90 (svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents: 39
diff changeset
   891
		signal_ctr++;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   892
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
   893
		// toggle railbit for the non-diagonal tracks (|, -- 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
   894
		if (railbit & 0x6) railbit ^= 1;
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
	}
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
   896
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
   897
	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
   898
}
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
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
   900
/* Stub for the unified Signal builder/remover */
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
   901
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
   902
{
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
   903
	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
   904
}
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
   905
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   906
/* Remove signals
1518
ade7a74ac31a (svn r2022) Revise CmdRemoveSingleSignal: Check parameters for validity and simplify the function
tron
parents: 1477
diff changeset
   907
 * p1 bits 0-2 = track, valid values: 0-5
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   908
 * p2 = unused
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
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
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
   911
{
1518
ade7a74ac31a (svn r2022) Revise CmdRemoveSingleSignal: Check parameters for validity and simplify the function
tron
parents: 1477
diff changeset
   912
	TileIndex tile = TILE_FROM_XY(x, y);
ade7a74ac31a (svn r2022) Revise CmdRemoveSingleSignal: Check parameters for validity and simplify the function
tron
parents: 1477
diff changeset
   913
	uint track = p1 & 0x7;
ade7a74ac31a (svn r2022) Revise CmdRemoveSingleSignal: Check parameters for validity and simplify the function
tron
parents: 1477
diff changeset
   914
ade7a74ac31a (svn r2022) Revise CmdRemoveSingleSignal: Check parameters for validity and simplify the function
tron
parents: 1477
diff changeset
   915
	if (!(track < 6) || // only 6 possible track-combinations
ade7a74ac31a (svn r2022) Revise CmdRemoveSingleSignal: Check parameters for validity and simplify the function
tron
parents: 1477
diff changeset
   916
			!IsTileType(tile, MP_RAILWAY) ||
ade7a74ac31a (svn r2022) Revise CmdRemoveSingleSignal: Check parameters for validity and simplify the function
tron
parents: 1477
diff changeset
   917
			!EnsureNoVehicle(tile))
ade7a74ac31a (svn r2022) Revise CmdRemoveSingleSignal: Check parameters for validity and simplify the function
tron
parents: 1477
diff changeset
   918
		return CMD_ERROR;
ade7a74ac31a (svn r2022) Revise CmdRemoveSingleSignal: Check parameters for validity and simplify the function
tron
parents: 1477
diff changeset
   919
ade7a74ac31a (svn r2022) Revise CmdRemoveSingleSignal: Check parameters for validity and simplify the function
tron
parents: 1477
diff changeset
   920
	if ((_map5[tile] & RAIL_TYPE_MASK) != RAIL_TYPE_SIGNALS ||
ade7a74ac31a (svn r2022) Revise CmdRemoveSingleSignal: Check parameters for validity and simplify the function
tron
parents: 1477
diff changeset
   921
			(_map3_lo[tile] & _signals_table_both[track]) == 0) // signals on track?
ade7a74ac31a (svn r2022) Revise CmdRemoveSingleSignal: Check parameters for validity and simplify the function
tron
parents: 1477
diff changeset
   922
		return CMD_ERROR;
ade7a74ac31a (svn r2022) Revise CmdRemoveSingleSignal: Check parameters for validity and simplify the function
tron
parents: 1477
diff changeset
   923
1536
69c91cec07c5 (svn r2040) Readd check that got accidently removed in r2022
tron
parents: 1535
diff changeset
   924
	if (_current_player != OWNER_WATER && !CheckTileOwnership(tile))
69c91cec07c5 (svn r2040) Readd check that got accidently removed in r2022
tron
parents: 1535
diff changeset
   925
		return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   926
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   927
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   928
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   929
	/* Do it? */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   930
	if (flags & DC_EXEC) {
1518
ade7a74ac31a (svn r2022) Revise CmdRemoveSingleSignal: Check parameters for validity and simplify the function
tron
parents: 1477
diff changeset
   931
		_map3_lo[tile] &= ~_signals_table_both[track];
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   932
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
   933
		/* removed last signal from tile? */
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
   934
		if ((_map3_lo[tile] & 0xF0) == 0) {
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
   935
			_map5[tile] &= ~RAIL_TYPE_SIGNALS;
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
   936
			_map2[tile] &= ~0xF0;
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
   937
			CLRBIT(_map3_hi[tile], 2); // remove any possible semaphores
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
   938
		}
1109
1bab892228cd (svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents: 1095
diff changeset
   939
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
   940
		SetSignalsOnBothDir(tile, track);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   941
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   942
		MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   943
	}
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   944
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   945
	return _price.remove_signals;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   946
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   947
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
   948
/* Stub for the unified Signal builder/remover */
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
   949
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
   950
{
1229
4c965ad79a0b (svn r1733) - Fix: oops "| 1" is SETBIT(x, 0), not 1 :(. Now you can remove signals again
darkvater
parents: 1227
diff changeset
   951
	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
   952
}
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
   953
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   954
typedef int32 DoConvertRailProc(uint tile, uint totype, bool exec);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   955
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   956
static int32 DoConvertRail(uint tile, uint totype, bool exec)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   957
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   958
	if (!CheckTileOwnership(tile) || !EnsureNoVehicle(tile))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   959
		return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   960
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   961
	// tile is already of requested type?
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   962
	if ( (uint)(_map3_lo[tile] & 0xF) == totype)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   963
		return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   964
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   965
	// change type.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   966
	if (exec) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   967
		_map3_lo[tile] = (_map3_lo[tile] & 0xF0) + totype;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   968
		MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   969
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   970
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   971
	return _price.build_rail >> 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   972
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   973
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   974
extern int32 DoConvertStationRail(uint tile, uint totype, bool exec);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   975
extern int32 DoConvertStreetRail(uint tile, uint totype, bool exec);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   976
extern int32 DoConvertTunnelBridgeRail(uint tile, uint totype, bool exec);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   977
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   978
// p1 = start tile
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   979
// p2 = new railtype
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   980
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
   981
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   982
	int32 ret, cost, money;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   983
	int sx,sy,x,y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   984
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
   985
	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
   986
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   987
	// make sure sx,sy are smaller than ex,ey
926
bd4312619522 (svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents: 919
diff changeset
   988
	sx = TileX(p1) * 16;
bd4312619522 (svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents: 919
diff changeset
   989
	sy = TileY(p1) * 16;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   990
	if (ex < sx) intswap(ex, sx);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   991
	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
   992
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   993
	money = GetAvailableMoneyForCommand();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   994
	ret = false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   995
	cost = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   996
	for(x=sx; x<=ex; x+=16) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   997
		for(y=sy; y<=ey; y+=16) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   998
			uint tile = TILE_FROM_XY(x,y);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   999
			DoConvertRailProc *p;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1000
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
  1001
			if (IsTileType(tile, MP_RAILWAY)) p = DoConvertRail;
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
  1002
			else if (IsTileType(tile, MP_STATION)) p = DoConvertStationRail;
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
  1003
			else if (IsTileType(tile, MP_STREET)) p = DoConvertStreetRail;
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
  1004
			else if (IsTileType(tile, MP_TUNNELBRIDGE)) p = DoConvertTunnelBridgeRail;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1005
			else continue;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1006
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1007
			ret = p(tile, p2, false);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1008
			if (ret == CMD_ERROR) continue;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1009
			cost += ret;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1010
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1011
			if (flags & DC_EXEC) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1012
				if ( (money -= ret) < 0) { _additional_cash_required = ret; return cost - ret; }
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1013
				p(tile, p2, true);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1014
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1015
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1016
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1017
	if (cost == 0) cost = CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1018
	return cost;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1019
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1020
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1021
static int32 RemoveTrainDepot(uint tile, uint32 flags)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1022
{
149
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 84
diff changeset
  1023
	if (!CheckTileOwnership(tile) && _current_player != OWNER_WATER)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1024
		return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1025
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1026
	if (!EnsureNoVehicle(tile))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1027
		return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1028
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1029
	if (flags & DC_EXEC) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1030
		int track = _map5[tile] & RAIL_DEPOT_TRACK_MASK;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1031
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1032
		DoDeleteDepot(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1033
		SetSignalsOnBothDir(tile, track);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1034
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1035
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1036
	return _price.remove_train_depot;
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
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
  1039
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
  1040
{
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
  1041
	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
  1042
	int32 ret;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1043
	byte m5;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1044
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1045
	m5 = _map5[tile];
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
	if (flags & DC_AUTO) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1048
		if (m5 & RAIL_TYPE_SPECIAL)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1049
			return_cmd_error(STR_2004_BUILDING_MUST_BE_DEMOLISHED);
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
		if (_map_owner[tile] != _current_player)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1052
			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
  1053
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1054
		return_cmd_error(STR_1008_MUST_REMOVE_RAILROAD_TRACK);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1055
	}
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
	cost = 0;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1058
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
  1059
	switch (m5 & RAIL_TYPE_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
  1060
		case RAIL_TYPE_SIGNALS:
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
  1061
			if (_map3_lo[tile] & _signals_table_both[0]) {
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
  1062
				ret = DoCommandByTile(tile, 0, 0, flags, CMD_REMOVE_SIGNALS);
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
  1063
				if (ret == CMD_ERROR) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1064
				cost += ret;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1065
			}
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
  1066
			if (_map3_lo[tile] & _signals_table_both[3]) {
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
  1067
				ret = DoCommandByTile(tile, 3, 0, flags, CMD_REMOVE_SIGNALS);
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
  1068
				if (ret == CMD_ERROR) 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
  1069
				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
  1070
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1071
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
  1072
			m5 &= RAIL_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
  1073
			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
  1074
				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
  1075
				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
  1076
			}
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
  1077
			/* FALLTHROUGH */
1109
1bab892228cd (svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents: 1095
diff changeset
  1078
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
  1079
		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
  1080
			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
  1081
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
  1082
			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
  1083
				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
  1084
					ret = DoCommandByTile(tile, 0, i, flags, CMD_REMOVE_SINGLE_RAIL);
4425f756c19b (svn r2102) Fix bug introduced in r2038, which gave you money for clearing occupied railway tiles ([1171926])
tron
parents: 1591
diff changeset
  1085
					if (ret == CMD_ERROR) 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
  1086
					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
  1087
				}
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
  1088
			}
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
  1089
			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
  1090
		}
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
  1091
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_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
  1093
			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
  1094
				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
  1095
					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
  1096
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
  1097
				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
  1098
					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
  1099
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
  1100
				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
  1101
					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
  1102
			}
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
  1103
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
  1104
		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
  1105
			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
  1106
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1107
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1108
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1109
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1110
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1111
#include "table/track_land.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1112
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1113
// used for presignals
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1114
static const SpriteID _signal_base_sprites[16] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1115
	0x4FB,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1116
	0x1323,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1117
	0x1333,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1118
	0x1343,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1119
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1120
	// use semaphores instead of signals?
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1121
	0x1353,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1122
	0x1363,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1123
	0x1373,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1124
	0x1383,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1125
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1126
	// mirrored versions
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1127
	0x4FB,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1128
	0x1323,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1129
	0x1333,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1130
	0x1343,
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1131
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1132
	0x13C6,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1133
	0x13D6,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1134
	0x13E6,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1135
	0x13F6,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1136
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1137
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1138
// 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
  1139
static const byte _signal_position[24] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1140
	/* original: left side position */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1141
	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
  1142
	/* patch: ride side position */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1143
	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
  1144
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1145
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1146
static void DrawSignalHelper(TileInfo *ti, byte condition, uint32 image_and_pos)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1147
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1148
	bool otherside = _opt.road_side & _patches.signal_side;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1149
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1150
	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
  1151
	uint x = ti->x | (v&0xF);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1152
	uint y = ti->y | (v>>4);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1153
	uint sprite = _signal_base_sprites[(_map3_hi[ti->tile] & 7) + (otherside ? 8 : 0)] + (image_and_pos>>4) + ((condition != 0) ? 1 : 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1154
	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
  1155
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1156
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1157
static uint32 _drawtile_track_palette;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1158
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1159
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1160
static void DrawTrackFence_NW(TileInfo *ti)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1161
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1162
	uint32 image = 0x515;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1163
	if (ti->tileh != 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1164
		image = 0x519;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1165
		if (!(ti->tileh & 2)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1166
			image = 0x51B;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1167
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1168
	}
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1169
	AddSortableSpriteToDraw(image | _drawtile_track_palette,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1170
		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
  1171
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1172
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1173
static void DrawTrackFence_SE(TileInfo *ti)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1174
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1175
	uint32 image = 0x515;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1176
	if (ti->tileh != 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1177
		image = 0x519;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1178
		if (!(ti->tileh & 2)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1179
			image = 0x51B;
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
	}
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1182
	AddSortableSpriteToDraw(image | _drawtile_track_palette,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1183
		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
  1184
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1185
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1186
static void DrawTrackFence_NW_SE(TileInfo *ti)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1187
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1188
	DrawTrackFence_NW(ti);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1189
	DrawTrackFence_SE(ti);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1190
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1191
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1192
static void DrawTrackFence_NE(TileInfo *ti)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1193
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1194
	uint32 image = 0x516;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1195
	if (ti->tileh != 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1196
		image = 0x51A;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1197
		if (!(ti->tileh & 2)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1198
			image = 0x51C;
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
	}
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1201
	AddSortableSpriteToDraw(image | _drawtile_track_palette,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1202
		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
  1203
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1204
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1205
static void DrawTrackFence_SW(TileInfo *ti)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1206
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1207
	uint32 image = 0x516;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1208
	if (ti->tileh != 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1209
		image = 0x51A;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1210
		if (!(ti->tileh & 2)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1211
			image = 0x51C;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1212
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1213
	}
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1214
	AddSortableSpriteToDraw(image | _drawtile_track_palette,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1215
		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
  1216
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1217
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1218
static void DrawTrackFence_NE_SW(TileInfo *ti)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1219
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1220
	DrawTrackFence_NE(ti);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1221
	DrawTrackFence_SW(ti);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1222
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1223
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1224
static void DrawTrackFence_NS_1(TileInfo *ti)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1225
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1226
	int z = ti->z;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1227
	if (ti->tileh & 1)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1228
		z += 8;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1229
	AddSortableSpriteToDraw(0x517 | _drawtile_track_palette,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1230
		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
  1231
}
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
static void DrawTrackFence_NS_2(TileInfo *ti)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1234
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1235
	int z = ti->z;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1236
	if (ti->tileh & 4)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1237
		z += 8;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1238
	AddSortableSpriteToDraw(0x517 | _drawtile_track_palette,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1239
		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
  1240
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1241
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1242
static void DrawTrackFence_WE_1(TileInfo *ti)
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
	int z = ti->z;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1245
	if (ti->tileh & 8)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1246
		z += 8;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1247
	AddSortableSpriteToDraw(0x518 | _drawtile_track_palette,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1248
		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
  1249
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1250
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1251
static void DrawTrackFence_WE_2(TileInfo *ti)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1252
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1253
	int z = ti->z;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1254
	if (ti->tileh & 2)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1255
		z += 8;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1256
	AddSortableSpriteToDraw(0x518 | _drawtile_track_palette,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1257
		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
  1258
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1259
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1260
static void DetTrackDrawProc_Null(TileInfo *ti)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1261
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1262
	/* nothing should be here */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1263
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1264
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1265
typedef void DetailedTrackProc(TileInfo *ti);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1266
DetailedTrackProc * const _detailed_track_proc[16] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1267
	DetTrackDrawProc_Null,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1268
	DetTrackDrawProc_Null,
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1269
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1270
	DrawTrackFence_NW,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1271
	DrawTrackFence_SE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1272
	DrawTrackFence_NW_SE,
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1273
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1274
	DrawTrackFence_NE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1275
	DrawTrackFence_SW,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1276
	DrawTrackFence_NE_SW,
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1277
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1278
	DrawTrackFence_NS_1,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1279
	DrawTrackFence_NS_2,
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1280
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1281
	DrawTrackFence_WE_1,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1282
	DrawTrackFence_WE_2,
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1283
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1284
	DetTrackDrawProc_Null,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1285
	DetTrackDrawProc_Null,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1286
	DetTrackDrawProc_Null,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1287
	DetTrackDrawProc_Null,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1288
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1289
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 337
diff changeset
  1290
static void DrawSpecialBuilding(uint32 image, uint32 tracktype_offs,
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 337
diff changeset
  1291
                                TileInfo *ti,
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 337
diff changeset
  1292
                                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
  1293
                                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
  1294
{
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 337
diff changeset
  1295
	if (image & 0x8000)
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 337
diff changeset
  1296
		image |= _drawtile_track_palette;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 337
diff changeset
  1297
	image += tracktype_offs;
497
2d6d31173813 (svn r787) Invert the sense of the DO_TRANS_BUILDINGS flag to be consistent with its own name and all other DO_* flags.
tron
parents: 473
diff changeset
  1298
	if (_display_opt & DO_TRANS_BUILDINGS) // show transparent depots
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 337
diff changeset
  1299
		image = (image & 0x3FFF) | 0x3224000;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 337
diff changeset
  1300
	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
  1301
}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 337
diff changeset
  1302
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1303
static void DrawTile_Track(TileInfo *ti)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1304
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1305
	uint32 tracktype_offs, image;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1306
	byte m5;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1307
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1308
	_drawtile_track_palette = SPRITE_PALETTE(PLAYER_SPRITE_COLOR(_map_owner[ti->tile]));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1309
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1310
	tracktype_offs = (_map3_lo[ti->tile] & 0xF) * TRACKTYPE_SPRITE_PITCH;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1311
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1312
	m5 = (byte)ti->map5;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1313
	if (!(m5 & RAIL_TYPE_SPECIAL)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1314
		bool special;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1315
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1316
		m5 &= RAIL_BIT_MASK;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1317
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1318
		special = false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1319
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1320
		// select the sprite to use based on the map5 byte.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1321
		(image = 0x3F3, m5 == RAIL_BIT_DIAG2) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1322
		(image++,				m5 == RAIL_BIT_DIAG1) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1323
		(image++,				m5 == RAIL_BIT_UPPER) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1324
		(image++,				m5 == RAIL_BIT_LOWER) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1325
		(image++,				m5 == RAIL_BIT_RIGHT) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1326
		(image++,				m5 == RAIL_BIT_LEFT) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1327
		(image++,				m5 == (RAIL_BIT_DIAG1|RAIL_BIT_DIAG2)) ||
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1328
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1329
		(image = 0x40B, m5 == (RAIL_BIT_UPPER|RAIL_BIT_LOWER)) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1330
		(image++,				m5 == (RAIL_BIT_LEFT|RAIL_BIT_RIGHT)) ||
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1331
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1332
		(special=true, false) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1333
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1334
		(image = 0x3FA, !(m5 & (RAIL_BIT_RIGHT|RAIL_BIT_UPPER|RAIL_BIT_DIAG1))) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1335
		(image++,				!(m5 & (RAIL_BIT_LEFT|RAIL_BIT_LOWER|RAIL_BIT_DIAG1))) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1336
		(image++,				!(m5 & (RAIL_BIT_LEFT|RAIL_BIT_UPPER|RAIL_BIT_DIAG2))) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1337
		(image++,				!(m5 & (RAIL_BIT_RIGHT|RAIL_BIT_LOWER|RAIL_BIT_DIAG2))) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1338
		(image++, true);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1339
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1340
		if (ti->tileh != 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1341
			int f = GetRailFoundation(ti->tileh, ti->map5 & 0x3F);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1342
			if (f) DrawFoundation(ti, f);
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1343
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1344
			// default sloped sprites..
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1345
			if (ti->tileh != 0) image = _track_sloped_sprites[ti->tileh - 1] + 0x3F3;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1346
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1347
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1348
		if ((_map2[ti->tile] & RAIL_MAP2LO_GROUND_MASK)==RAIL_GROUND_BROWN)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1349
			image = (image & 0xFFFF) | 0x3178000; // use a brown palette
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1350
		else if ((_map2[ti->tile] & RAIL_MAP2LO_GROUND_MASK)==RAIL_GROUND_ICE_DESERT)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1351
			image += 26;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1352
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1353
		DrawGroundSprite(image + tracktype_offs);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1354
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1355
		if (special) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1356
			if (m5 & RAIL_BIT_DIAG1) DrawGroundSprite(0x3ED + tracktype_offs);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1357
			if (m5 & RAIL_BIT_DIAG2) DrawGroundSprite(0x3EE + tracktype_offs);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1358
			if (m5 & RAIL_BIT_UPPER) DrawGroundSprite(0x3EF + tracktype_offs);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1359
			if (m5 & RAIL_BIT_LOWER) DrawGroundSprite(0x3F0 + tracktype_offs);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1360
			if (m5 & RAIL_BIT_LEFT)  DrawGroundSprite(0x3F2 + tracktype_offs);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1361
			if (m5 & RAIL_BIT_RIGHT) DrawGroundSprite(0x3F1 + tracktype_offs);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1362
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1363
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1364
		if (_display_opt & DO_FULL_DETAIL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1365
			_detailed_track_proc[_map2[ti->tile] & RAIL_MAP2LO_GROUND_MASK](ti);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1366
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1367
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1368
		/* draw signals also? */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1369
		if (!(ti->map5 & RAIL_TYPE_SIGNALS))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1370
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1371
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1372
		{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1373
			byte m23;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1374
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1375
			m23 = (_map3_lo[ti->tile] >> 4) | (_map2[ti->tile] & 0xF0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1376
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1377
#define HAS_SIGNAL(x) (m23 & (byte)(0x1 << (x)))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1378
#define ISON_SIGNAL(x) (m23 & (byte)(0x10 << (x)))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1379
#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
  1380
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1381
		if (!(m5 & RAIL_BIT_DIAG2)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1382
			if (!(m5 & RAIL_BIT_DIAG1)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1383
				if (m5 & RAIL_BIT_LEFT) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1384
					MAYBE_DRAW_SIGNAL(2, 0x509, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1385
					MAYBE_DRAW_SIGNAL(3, 0x507, 1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1386
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1387
				if (m5 & RAIL_BIT_RIGHT) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1388
					MAYBE_DRAW_SIGNAL(0, 0x509, 2);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1389
					MAYBE_DRAW_SIGNAL(1, 0x507, 3);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1390
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1391
				if (m5 & RAIL_BIT_UPPER) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1392
					MAYBE_DRAW_SIGNAL(3, 0x505, 4);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1393
					MAYBE_DRAW_SIGNAL(2, 0x503, 5);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1394
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1395
				if (m5 & RAIL_BIT_LOWER) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1396
					MAYBE_DRAW_SIGNAL(1, 0x505, 6);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1397
					MAYBE_DRAW_SIGNAL(0, 0x503, 7);
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
			} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1400
				MAYBE_DRAW_SIGNAL(3, 0x4FB, 8);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1401
				MAYBE_DRAW_SIGNAL(2, 0x4FD, 9);
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
		} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1404
			MAYBE_DRAW_SIGNAL(3, 0x4FF, 10);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1405
			MAYBE_DRAW_SIGNAL(2, 0x501, 11);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1406
		}
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
	} 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
  1409
		/* draw depots / waypoints */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1410
		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
  1411
		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
  1412
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1413
		if (!(m5 & (RAIL_TYPE_MASK&~RAIL_TYPE_SPECIAL)))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1414
			return;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1415
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1416
		if (ti->tileh != 0) { DrawFoundation(ti, ti->tileh); }
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1417
1535
a5f686a20d2c (svn r2039) IS_RAIL_DEPOT -> IsRailDepot, IS_RAIL_WAYPOINT -> IsRailWaypoint
tron
parents: 1534
diff changeset
  1418
		if (IsRailWaypoint(m5) && _map3_lo[ti->tile] & 16) {
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 337
diff changeset
  1419
			// look for customization
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1399
diff changeset
  1420
			StationSpec *stat = GetCustomStation(STAT_CLASS_WAYP, _map3_hi[ti->tile]);
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 337
diff changeset
  1421
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
  1422
			if (stat) {
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 337
diff changeset
  1423
				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
  1424
				// emulate station tile - open with building
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
  1425
				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
  1426
				uint32 relocation = GetCustomStationRelocation(stat, ComposeWaypointStation(ti->tile), 0);
415
423de36034b8 (svn r612) [newgrf] Fix: custom waypoints on monorail/maglev are displayed correctly
dominik
parents: 413
diff changeset
  1427
				int railtype=(_map3_lo[ti->tile] & 0xF);
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 337
diff changeset
  1428
447
aaf1f59a8957 (svn r657) Do not touch 0x8000 bit in sprite index for custom waypoints. (pasky)
celestar
parents: 438
diff changeset
  1429
				/* 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
  1430
				 * 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
  1431
				 * 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
  1432
				 * 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
  1433
				 * 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
  1434
				 * 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
  1435
				 * 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
  1436
				 * 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
  1437
417
0c63a94557a5 (svn r614) [newgrf] Some minor code fixes
dominik
parents: 415
diff changeset
  1438
				image = cust->ground_sprite;
0c63a94557a5 (svn r614) [newgrf] Some minor code fixes
dominik
parents: 415
diff changeset
  1439
				image += railtype*((image<_custom_sprites_base)?TRACKTYPE_SPRITE_PITCH:1);
415
423de36034b8 (svn r612) [newgrf] Fix: custom waypoints on monorail/maglev are displayed correctly
dominik
parents: 413
diff changeset
  1440
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 337
diff changeset
  1441
				DrawGroundSprite(image);
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 337
diff changeset
  1442
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 337
diff changeset
  1443
				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
  1444
					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
  1445
					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
  1446
					                    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
  1447
					                    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
  1448
				}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 337
diff changeset
  1449
				return;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 337
diff changeset
  1450
			}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 337
diff changeset
  1451
		}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 337
diff changeset
  1452
1399
4503bd2bfb82 (svn r1903) Replace some casts and macro magic with proper typing, similar to r1902
tron
parents: 1363
diff changeset
  1453
		drss = _track_depot_layout_table[type];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1454
1399
4503bd2bfb82 (svn r1903) Replace some casts and macro magic with proper typing, similar to r1902
tron
parents: 1363
diff changeset
  1455
		image = drss++->image;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1456
		if (image & 0x8000) image = (image & 0x7FFF) + tracktype_offs;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1457
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1458
		// adjust ground tile for desert
283
c1a99d78e5a3 (svn r289) Fix: Checkpoints on snow have correct ground now
dominik
parents: 282
diff changeset
  1459
		// (don't adjust for arctic depots, because snow in depots looks weird)
c1a99d78e5a3 (svn r289) Fix: Checkpoints on snow have correct ground now
dominik
parents: 282
diff changeset
  1460
		if ((_map2[ti->tile] & RAIL_MAP2LO_GROUND_MASK)==RAIL_GROUND_ICE_DESERT && (_opt.landscape == LT_DESERT || type>=4))
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1461
		{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1462
			if(image!=3981)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1463
				image += 26; // tile with tracks
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1464
			else
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1465
				image = 4550; // flat ground
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1466
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1467
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1468
		DrawGroundSprite(image);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1469
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1470
		while ((image=drss->image) != 0) {
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 337
diff changeset
  1471
			DrawSpecialBuilding(image, type < 4 ? tracktype_offs : 0, ti,
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 337
diff changeset
  1472
			                    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
  1473
			                    drss->width, drss->height, 0x17);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1474
			drss++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1475
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1476
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1477
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1478
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1479
void DrawTrainDepotSprite(int x, int y, int image, int railtype)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1480
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1481
	uint32 ormod, img;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1482
	const DrawTrackSeqStruct *dtss;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1483
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1484
	/* baseimage */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1485
	railtype *= TRACKTYPE_SPRITE_PITCH;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1486
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1487
	ormod = PLAYER_SPRITE_COLOR(_local_player);
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
	dtss = _track_depot_layout_table[image];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1490
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1491
	x+=33;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1492
	y+=17;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1493
1399
4503bd2bfb82 (svn r1903) Replace some casts and macro magic with proper typing, similar to r1902
tron
parents: 1363
diff changeset
  1494
	img = dtss++->image;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1495
	if (img & 0x8000) img = (img & 0x7FFF) + railtype;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1496
	DrawSprite(img, x, y);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1497
1399
4503bd2bfb82 (svn r1903) Replace some casts and macro magic with proper typing, similar to r1902
tron
parents: 1363
diff changeset
  1498
	for (; dtss->image != 0; dtss++) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1499
		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
  1500
		image = dtss->image;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1501
		if (image & 0x8000) image |= ormod;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1502
		DrawSprite(image + railtype, x + pt.x, y + pt.y);
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1506
#define NUM_SSD_ENTRY 256
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1507
#define NUM_SSD_STACK 32
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1508
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1509
typedef struct SetSignalsData {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1510
	int cur;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1511
	int cur_stack;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1512
	bool stop;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1513
	bool has_presignal;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1514
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1515
	// presignal info
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1516
	int presignal_exits;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1517
	int presignal_exits_free;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1518
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1519
	// 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
  1520
	byte bit[NUM_SSD_ENTRY];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1521
	TileIndex tile[NUM_SSD_ENTRY];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1522
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1523
	// 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
  1524
	TileIndex next_tile[NUM_SSD_STACK];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1525
	byte next_dir[NUM_SSD_STACK];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1526
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1527
} SetSignalsData;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1528
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1529
static bool SetSignalsEnumProc(uint tile, SetSignalsData *ssd, int track, uint length, byte *state)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1530
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1531
	// 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
  1532
	if (IsTileType(tile, MP_RAILWAY)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1533
		if ((_map5[tile]&RAIL_TYPE_MASK) == RAIL_TYPE_SIGNALS) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1534
			if ((_map3_lo[tile] & _signals_table_both[track]) != 0) {
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1535
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1536
				// is the signal pointing in to the segment existing?
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1537
				if ((_map3_lo[tile] & _signals_table[track]) != 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1538
					// yes, add the signal to the list of signals
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1539
					if (ssd->cur != NUM_SSD_ENTRY) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1540
						ssd->tile[ssd->cur] = tile; // remember the tile index
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1541
						ssd->bit[ssd->cur] = track; // and the controlling bit number
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1542
						ssd->cur++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1543
					}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1544
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1545
					// remember if this block has a presignal.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1546
					ssd->has_presignal |= (_map3_hi[tile]&1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1547
				}
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1548
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1549
				// is this an exit signal that points out from the segment?
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1550
				if ((_map3_hi[tile]&2) && _map3_lo[tile]&_signals_table_other[track]) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1551
					ssd->presignal_exits++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1552
					if ((_map2[tile]&_signals_table_other[track]) != 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1553
						ssd->presignal_exits_free++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1554
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1555
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1556
				return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1557
			}
1535
a5f686a20d2c (svn r2039) IS_RAIL_DEPOT -> IsRailDepot, IS_RAIL_WAYPOINT -> IsRailWaypoint
tron
parents: 1534
diff changeset
  1558
		} else if (IsRailDepot(_map5[tile]))
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1559
			return true; // don't look further if the tile is a depot
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1560
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1561
	return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1562
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1563
1555
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1564
/* 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
  1565
typedef struct SignalVehicleCheckStruct {
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1566
	TileIndex tile;
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1567
	uint track;
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1568
} SignalVehicleCheckStruct;
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1569
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1570
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
  1571
{
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1572
	SignalVehicleCheckStruct *dest = data;
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1573
	TileIndex tile;
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1574
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1575
	/* Find the tile outside the tunnel, for signalling */
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1576
	if (v->u.rail.track == 0x40) {
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1577
		tile = GetVehicleOutOfTunnelTile(v);
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1578
	} else {
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1579
		tile = v->tile;
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1580
	}
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1581
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1582
	/* Wrong tile, or no train? Not a match */
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1583
	if (tile != dest->tile || v->type != VEH_Train)
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1584
		return NULL;
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1585
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1586
	/* Are we on the same piece of track? */
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1587
	if (dest->track & (v->u.rail.track + (v->u.rail.track<<8)))
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1588
		return v;
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1589
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1590
	return NULL;
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1591
}
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1592
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1593
/* Special check for SetSignalsAfterProc, to see 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
  1594
bool SignalVehicleCheck(TileIndex tile, uint track)
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1595
{
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1596
	SignalVehicleCheckStruct dest;
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1597
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1598
	dest.tile = tile;
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1599
	dest.track = track;
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1600
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1601
	return VehicleFromPos(tile, &dest, SignalVehicleCheckProc) != NULL;
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1602
}
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1603
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1604
static void SetSignalsAfterProc(TrackPathFinder *tpf)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1605
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1606
	SetSignalsData *ssd = tpf->userdata;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1607
	TrackPathFinderLink *link;
1555
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1608
	uint offs;
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1609
	uint i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1610
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1611
	ssd->stop = false;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1612
1555
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1613
	/* Go through all the PF tiles */
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1614
	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
  1615
		/* Empty hash item */
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1616
		if (tpf->hash_head[i] == 0)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1617
			continue;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1618
1555
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1619
		/* 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
  1620
		if (!(tpf->hash_head[i] & 0x8000)) {
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1621
			/* 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
  1622
			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
  1623
				ssd->stop = true;
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1624
				return;
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1625
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1626
		} else {
1555
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1627
			/* 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
  1628
			offs = tpf->hash_tile[i];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1629
			do {
1555
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1630
				/* Find the next item */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1631
				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
  1632
				/* 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
  1633
				if (SignalVehicleCheck(link->tile, link->flags)) {
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1634
					ssd->stop = true;
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1635
					return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1636
				}
1555
c7e5bb32f536 (svn r2059) -Codechange: rewrote SetSignalsAfterProc so now the tiles from the PF
truelight
parents: 1542
diff changeset
  1637
				/* Goto the next item */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1638
			} while ((offs=link->next) != 0xFFFF);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1639
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1640
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1641
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1642
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1643
static const byte _dir_from_track[14] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1644
	0,1,0,1,2,1, 0,0,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1645
	2,3,3,2,3,0,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1646
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1647
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1648
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1649
static void ChangeSignalStates(SetSignalsData *ssd)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1650
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1651
	int i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1652
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1653
	// thinking about presignals...
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1654
	// the presignal is green if,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1655
	//   if no train is in the segment AND
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1656
	//   there is at least one green exit signal OR
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1657
	//   there are no exit signals in the segment
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1658
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1659
	// then mark the signals in the segment accordingly
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1660
	for(i=0; i!=ssd->cur; i++) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1661
		uint tile = ssd->tile[i];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1662
		byte bit = _signals_table[ssd->bit[i]];
817
4f9377b7fd2b (svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents: 679
diff changeset
  1663
		uint16 m2 = _map2[tile];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1664
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1665
		// presignals don't turn green if there is at least one presignal exit and none are free
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1666
		if (_map3_hi[tile] & 1) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1667
			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
  1668
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1669
			// subtract for dual combo signals so they don't count themselves
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1670
			if (_map3_hi[tile]&2 && _map3_lo[tile]&_signals_table_other[ssd->bit[i]]) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1671
				ex--;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1672
				if ((_map2[tile]&_signals_table_other[ssd->bit[i]]) != 0) exfree--;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1673
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1674
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1675
			// 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
  1676
			if (ex && !exfree) goto make_red;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1677
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1678
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1679
		// check if the signal is unaffected.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1680
		if (ssd->stop) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1681
make_red:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1682
			// turn red
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1683
			if ( (bit&m2) == 0 )
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1684
				continue;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1685
		} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1686
			// turn green
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1687
			if ( (bit&m2) != 0 )
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1688
				continue;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1689
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1690
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1691
		// Update signals on the other side of this exit signal, it changed.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1692
		// If this segment has presignals, then we treat exit signals going into the segment as normal signals.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1693
		if (_map3_hi[tile]&2 && (_map3_hi[tile]&1 || !ssd->has_presignal)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1694
			if (ssd->cur_stack != NUM_SSD_STACK) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1695
				ssd->next_tile[ssd->cur_stack] = tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1696
				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
  1697
				ssd->cur_stack++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1698
			} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1699
				printf("NUM_SSD_STACK too small\n");
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1700
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1701
		}
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1702
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1703
		// it changed, so toggle it
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1704
		_map2[tile] = m2 ^ bit;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1705
		MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1706
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1707
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1708
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1709
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1710
bool UpdateSignalsOnSegment(uint tile, byte direction)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1711
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1712
	SetSignalsData ssd;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1713
	int result = -1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1714
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1715
	ssd.cur_stack = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1716
	direction>>=1;
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
	for(;;) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1719
		// go through one segment and update all signals pointing into that segment.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1720
		ssd.cur = ssd.presignal_exits = ssd.presignal_exits_free = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1721
		ssd.has_presignal = false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1722
159
139cf78bfb28 (svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents: 149
diff changeset
  1723
		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
  1724
		ChangeSignalStates(&ssd);
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
		// remember the result only for the first iteration.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1727
		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
  1728
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1729
		// if any exit signals were changed, we need to keep going to modify the stuff behind those.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1730
		if(!ssd.cur_stack)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1731
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1732
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1733
		// 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
  1734
		tile = ssd.next_tile[--ssd.cur_stack];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1735
		direction = ssd.next_dir[ssd.cur_stack];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1736
	}
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1737
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1738
	return (bool)result;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1739
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1740
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1741
void SetSignalsOnBothDir(uint tile, byte track)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1742
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1743
	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
  1744
	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
  1745
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1746
	UpdateSignalsOnSegment(tile, _search_dir_1[track]);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1747
	UpdateSignalsOnSegment(tile, _search_dir_2[track]);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1748
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1749
410
8de2aaf20800 (svn r607) -Patch: [ 985102 ] static cleanup
tron
parents: 408
diff changeset
  1750
static uint GetSlopeZ_Track(TileInfo *ti)
0
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
	uint z = ti->z;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1753
	int th = ti->tileh;
13
3e7c1f74a996 (svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents: 0
diff changeset
  1754
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1755
	// check if it's a foundation
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1756
	if (ti->tileh != 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1757
		if ((ti->map5 & 0x80) == 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1758
			uint f = GetRailFoundation(ti->tileh, ti->map5 & 0x3F);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1759
			if (f != 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1760
				if (f < 15) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1761
					// leveled foundation
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1762
					return z + 8;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1763
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1764
				// inclined foundation
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1765
				th = _inclined_tileh[f - 15];
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
		} 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
  1768
			// depot or waypoint
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1769
			return z + 8;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1770
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1771
		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
  1772
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1773
	return z;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1774
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1775
1095
90220990fd7c (svn r1596) Add some more statics
tron
parents: 1093
diff changeset
  1776
static uint GetSlopeTileh_Track(TileInfo *ti)
39
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 22
diff changeset
  1777
{
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 22
diff changeset
  1778
	// check if it's a foundation
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 22
diff changeset
  1779
	if (ti->tileh != 0) {
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 22
diff changeset
  1780
		if ((ti->map5 & 0x80) == 0) {
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 22
diff changeset
  1781
			uint f = GetRailFoundation(ti->tileh, ti->map5 & 0x3F);
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 22
diff changeset
  1782
			if (f != 0) {
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 22
diff changeset
  1783
				if (f < 15) {
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 22
diff changeset
  1784
					// leveled foundation
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 22
diff changeset
  1785
					return 0;
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 22
diff changeset
  1786
				}
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 22
diff changeset
  1787
				// inclined foundation
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 22
diff changeset
  1788
				return _inclined_tileh[f - 15];
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 22
diff changeset
  1789
			}
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 22
diff changeset
  1790
		} 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
  1791
			// depot or waypoint
39
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 22
diff changeset
  1792
			return 0;
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 22
diff changeset
  1793
		}
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 22
diff changeset
  1794
	}
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 22
diff changeset
  1795
	return ti->tileh;
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 22
diff changeset
  1796
}
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 22
diff changeset
  1797
473
0da86c59e3ae (svn r724) Remove restriction that a tile can only accept 3 cargo types.
tron
parents: 447
diff changeset
  1798
static void GetAcceptedCargo_Track(uint tile, AcceptedCargo ac)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1799
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1800
	/* not used */
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1803
static void AnimateTile_Track(uint tile)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1804
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1805
	/* not used */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1806
}
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
static void TileLoop_Track(uint tile)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1809
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1810
	byte a2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1811
	byte rail;
817
4f9377b7fd2b (svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents: 679
diff changeset
  1812
	uint16 m2;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1813
	byte owner;
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
	m2 = _map2[tile] & 0xF;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1816
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1817
	/* special code for alps landscape */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1818
	if (_opt.landscape == LT_HILLY) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1819
		/* convert into snow? */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1820
		if (GetTileZ(tile) > _opt.snow_line) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1821
			a2 = RAIL_GROUND_ICE_DESERT;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1822
			goto modify_me;
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1825
	/* special code for desert landscape */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1826
	} else if (_opt.landscape == LT_DESERT) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1827
		/* convert into desert? */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1828
		if (GetMapExtraBits(tile) == 1) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1829
			a2 = RAIL_GROUND_ICE_DESERT;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1830
			goto modify_me;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1831
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1832
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1833
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1834
	// Don't continue tile loop for depots
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1835
	if (_map5[tile] & RAIL_TYPE_SPECIAL)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1836
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1837
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1838
	a2 = RAIL_GROUND_GREEN;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1839
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1840
	if (m2 != RAIL_GROUND_BROWN) { /* wait until bottom is green */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1841
		/* determine direction of fence */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1842
		rail = _map5[tile] & RAIL_BIT_MASK;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1843
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1844
		if (rail == RAIL_BIT_UPPER) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1845
			a2 = RAIL_GROUND_FENCE_HORIZ1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1846
		} else if (rail == RAIL_BIT_LOWER) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1847
			a2 = RAIL_GROUND_FENCE_HORIZ2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1848
		} else if (rail == RAIL_BIT_LEFT) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1849
			a2 = RAIL_GROUND_FENCE_VERT1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1850
		} else if (rail == RAIL_BIT_RIGHT) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1851
			a2 = RAIL_GROUND_FENCE_VERT2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1852
		} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1853
			owner = _map_owner[tile];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1854
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1855
			if ( (!(rail&(RAIL_BIT_DIAG2|RAIL_BIT_UPPER|RAIL_BIT_LEFT)) && (rail&RAIL_BIT_DIAG1)) || rail==(RAIL_BIT_LOWER|RAIL_BIT_RIGHT)) {
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
  1856
				if (!IsTileType(tile + TILE_XY(0,-1), MP_RAILWAY) ||
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1857
						owner != _map_owner[tile + TILE_XY(0,-1)] ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1858
						(_map5[tile + TILE_XY(0,-1)]==RAIL_BIT_UPPER || _map5[tile + TILE_XY(0,-1)]==RAIL_BIT_LEFT))
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1859
							a2 = RAIL_GROUND_FENCE_NW;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1860
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1861
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1862
			if ( (!(rail&(RAIL_BIT_DIAG2|RAIL_BIT_LOWER|RAIL_BIT_RIGHT)) && (rail&RAIL_BIT_DIAG1)) || rail==(RAIL_BIT_UPPER|RAIL_BIT_LEFT)) {
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
  1863
				if (!IsTileType(tile + TILE_XY(0,1), MP_RAILWAY) ||
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1864
						owner != _map_owner[tile + TILE_XY(0,1)] ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1865
						(_map5[tile + TILE_XY(0,1)]==RAIL_BIT_LOWER || _map5[tile + TILE_XY(0,1)]==RAIL_BIT_RIGHT))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1866
							a2 = (a2 == RAIL_GROUND_FENCE_NW) ? RAIL_GROUND_FENCE_SENW : RAIL_GROUND_FENCE_SE;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1867
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1868
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1869
			if ( (!(rail&(RAIL_BIT_DIAG1|RAIL_BIT_UPPER|RAIL_BIT_RIGHT)) && (rail&RAIL_BIT_DIAG2)) || rail==(RAIL_BIT_LOWER|RAIL_BIT_LEFT)) {
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
  1870
				if (!IsTileType(tile + TILE_XY(-1,0), MP_RAILWAY) ||
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1871
						owner != _map_owner[tile + TILE_XY(-1,0)] ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1872
						(_map5[tile + TILE_XY(-1,0)]==RAIL_BIT_UPPER || _map5[tile + TILE_XY(-1,0)]==RAIL_BIT_RIGHT))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1873
							a2 = RAIL_GROUND_FENCE_NE;
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1876
			if ( (!(rail&(RAIL_BIT_DIAG1|RAIL_BIT_LOWER|RAIL_BIT_LEFT)) && (rail&RAIL_BIT_DIAG2)) || rail==(RAIL_BIT_UPPER|RAIL_BIT_RIGHT)) {
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
  1877
				if (!IsTileType(tile + TILE_XY(1,0), MP_RAILWAY) ||
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1878
						owner != _map_owner[tile + TILE_XY(1,0)] ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1879
						(_map5[tile + TILE_XY(1,0)]==RAIL_BIT_LOWER || _map5[tile + TILE_XY(1,0)]==RAIL_BIT_LEFT))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1880
							a2 = (a2 == RAIL_GROUND_FENCE_NE) ? RAIL_GROUND_FENCE_NESW : RAIL_GROUND_FENCE_SW;
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
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1883
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1884
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1885
modify_me:;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1886
	/* tile changed? */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1887
	if ( m2 != a2) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1888
		_map2[tile] = (_map2[tile] & ~RAIL_MAP2LO_GROUND_MASK) | a2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1889
		MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1890
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1891
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1892
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1893
159
139cf78bfb28 (svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents: 149
diff changeset
  1894
static uint32 GetTileTrackStatus_Track(uint tile, TransportType mode) {
817
4f9377b7fd2b (svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents: 679
diff changeset
  1895
	byte m5, a;
4f9377b7fd2b (svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents: 679
diff changeset
  1896
	uint16 b;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1897
	uint32 ret;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1898
159
139cf78bfb28 (svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents: 149
diff changeset
  1899
	if (mode != TRANSPORT_RAIL)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1900
		return 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1901
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1902
	m5 = _map5[tile];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1903
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1904
	if (!(m5 & RAIL_TYPE_SPECIAL)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1905
		ret = (m5 | (m5 << 8)) & 0x3F3F;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1906
		if (!(m5 & RAIL_TYPE_SIGNALS)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1907
			if ( (ret & 0xFF) == 3)
22
fe6f35cc987b (svn r23) -Some omments on the code (blathijs)
darkvater
parents: 13
diff changeset
  1908
			/* Diagonal crossing? */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1909
				ret |= 0x40;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1910
		} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1911
			/* has_signals */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1912
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1913
			a = _map3_lo[tile];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1914
			b = _map2[tile];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1915
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1916
			b &= a;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1917
22
fe6f35cc987b (svn r23) -Some omments on the code (blathijs)
darkvater
parents: 13
diff changeset
  1918
			/* When signals are not present (in neither
fe6f35cc987b (svn r23) -Some omments on the code (blathijs)
darkvater
parents: 13
diff changeset
  1919
			 * direction), we pretend them to be green. (So if
fe6f35cc987b (svn r23) -Some omments on the code (blathijs)
darkvater
parents: 13
diff changeset
  1920
			 * signals are only one way, the other way will
fe6f35cc987b (svn r23) -Some omments on the code (blathijs)
darkvater
parents: 13
diff changeset
  1921
			 * implicitely become `red' */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1922
			if ((a & 0xC0) == 0) { b |= 0xC0; }
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1923
			if ((a & 0x30) == 0) { b |= 0x30; }
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1924
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1925
			if ( (b & 0x80) == 0)	ret |= 0x10070000;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1926
			if ( (b & 0x40) == 0)	ret |= 0x7100000;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1927
			if ( (b & 0x20) == 0)	ret |= 0x20080000;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1928
			if ( (b & 0x10) == 0)	ret |= 0x8200000;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1929
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1930
	} else if (m5 & 0x40) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1931
		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
  1932
		m5 = _train_spec_tracks[m5 & 0x3F];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1933
		ret = (m5 << 8) + m5;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1934
	} else
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1935
		return 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1936
	return ret;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1937
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1938
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1939
static void ClickTile_Track(uint tile)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1940
{
1535
a5f686a20d2c (svn r2039) IS_RAIL_DEPOT -> IsRailDepot, IS_RAIL_WAYPOINT -> IsRailWaypoint
tron
parents: 1534
diff changeset
  1941
	if (IsRailDepot(_map5[tile]))
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1942
		ShowTrainDepotWindow(tile);
1535
a5f686a20d2c (svn r2039) IS_RAIL_DEPOT -> IsRailDepot, IS_RAIL_WAYPOINT -> IsRailWaypoint
tron
parents: 1534
diff changeset
  1943
	else if (IsRailWaypoint(_map5[tile]))
1542
2ca6d1624e6d (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1536
diff changeset
  1944
		ShowRenameWaypointWindow(GetWaypointByTile(tile));
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1945
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1946
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1947
1590
4e39d1da10c7 (svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron
parents: 1555
diff changeset
  1948
static void GetTileDesc_Track(TileIndex tile, TileDesc *td)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1949
{
1590
4e39d1da10c7 (svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron
parents: 1555
diff changeset
  1950
	td->owner = _map_owner[tile];
4e39d1da10c7 (svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron
parents: 1555
diff changeset
  1951
	switch (_map5[tile] & RAIL_TYPE_MASK) {
4e39d1da10c7 (svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron
parents: 1555
diff changeset
  1952
		case RAIL_TYPE_NORMAL:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1953
			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
  1954
			break;
4e39d1da10c7 (svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron
parents: 1555
diff changeset
  1955
4e39d1da10c7 (svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron
parents: 1555
diff changeset
  1956
		case RAIL_TYPE_SIGNALS: {
4e39d1da10c7 (svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron
parents: 1555
diff changeset
  1957
			const StringID signal_type[] = {
4e39d1da10c7 (svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron
parents: 1555
diff changeset
  1958
				STR_RAILROAD_TRACK_WITH_NORMAL_SIGNALS,
4e39d1da10c7 (svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron
parents: 1555
diff changeset
  1959
				STR_RAILROAD_TRACK_WITH_PRESIGNALS,
4e39d1da10c7 (svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron
parents: 1555
diff changeset
  1960
				STR_RAILROAD_TRACK_WITH_EXITSIGNALS,
4e39d1da10c7 (svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron
parents: 1555
diff changeset
  1961
				STR_RAILROAD_TRACK_WITH_COMBOSIGNALS
4e39d1da10c7 (svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron
parents: 1555
diff changeset
  1962
			};
4e39d1da10c7 (svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron
parents: 1555
diff changeset
  1963
4e39d1da10c7 (svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron
parents: 1555
diff changeset
  1964
			td->str = signal_type[_map3_hi[tile] & 0x03];
4e39d1da10c7 (svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron
parents: 1555
diff changeset
  1965
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1966
		}
1590
4e39d1da10c7 (svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron
parents: 1555
diff changeset
  1967
4e39d1da10c7 (svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron
parents: 1555
diff changeset
  1968
		case RAIL_TYPE_DEPOT:
4e39d1da10c7 (svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron
parents: 1555
diff changeset
  1969
		default:
4e39d1da10c7 (svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron
parents: 1555
diff changeset
  1970
			td->str = ((_map5[tile] & RAIL_SUBTYPE_MASK) == RAIL_SUBTYPE_DEPOT) ?
4e39d1da10c7 (svn r2094) In GetTileDesc_Track(): uint -> TileIndex, use enums, if () cascade -> switch
tron
parents: 1555
diff changeset
  1971
				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
  1972
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1973
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1974
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1975
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1976
static void ChangeTileOwner_Track(uint tile, byte old_player, byte new_player)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1977
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1978
	if (_map_owner[tile] != old_player)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1979
		return;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1980
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1981
	if (new_player != 255) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1982
		_map_owner[tile] = new_player;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1983
	}	else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1984
		DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
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
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1987
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1988
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
  1989
static const byte _fractcoords_enter[4] = { 0x8A, 0x48, 0x84, 0xA8 };
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1990
static const byte _fractcoords_leave[4] = { 0x81, 0xD8, 0x8D, 0x18 };
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1991
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
  1992
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
  1993
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
  1994
410
8de2aaf20800 (svn r607) -Patch: [ 985102 ] static cleanup
tron
parents: 408
diff changeset
  1995
static uint32 VehicleEnter_Track(Vehicle *v, uint tile, int x, int y)
0
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
	byte fract_coord;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1998
	int dir;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1999
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2000
	// this routine applies only to trains in depot tiles
1535
a5f686a20d2c (svn r2039) IS_RAIL_DEPOT -> IsRailDepot, IS_RAIL_WAYPOINT -> IsRailWaypoint
tron
parents: 1534
diff changeset
  2001
	if (v->type != VEH_Train || !IsRailDepot(_map5[tile]))
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2002
		return 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2003
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2004
	/* depot direction */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2005
	dir = _map5[tile] & RAIL_DEPOT_DIR;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  2006
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2007
	fract_coord = (x & 0xF) + ((y & 0xF) << 4);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2008
	if (_fractcoords_behind[dir] == fract_coord) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2009
		/* 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
  2010
		return 8;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2011
	} else if (_fractcoords_enter[dir] == fract_coord) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2012
		if (_enter_directions[dir] == v->direction) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2013
			/* enter the depot */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2014
			v->u.rail.track = 0x80,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2015
			v->vehstatus |= VS_HIDDEN; /* hide it */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2016
			v->direction ^= 4;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2017
			if (v->next == NULL)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2018
				TrainEnterDepot(v, tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2019
			v->tile = tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2020
			InvalidateWindow(WC_VEHICLE_DEPOT, tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2021
			return 4;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2022
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2023
	} else if (_fractcoords_leave[dir] == fract_coord) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2024
		if (_leave_directions[dir] == v->direction) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2025
			/* leave the depot? */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2026
			if ((v=v->next) != NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2027
				v->vehstatus &= ~VS_HIDDEN;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2028
				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
  2029
				assert(v->u.rail.track);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2030
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2031
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2032
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2033
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2034
	return 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2035
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2036
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
  2037
void InitializeRail(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2038
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2039
	_last_built_train_depot_tile = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2040
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2041
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2042
const TileTypeProcs _tile_type_rail_procs = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2043
	DrawTile_Track,						/* draw_tile_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2044
	GetSlopeZ_Track,					/* get_slope_z_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2045
	ClearTile_Track,					/* clear_tile_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2046
	GetAcceptedCargo_Track,		/* get_accepted_cargo_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2047
	GetTileDesc_Track,				/* get_tile_desc_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2048
	GetTileTrackStatus_Track,	/* get_tile_track_status_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2049
	ClickTile_Track,					/* click_tile_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2050
	AnimateTile_Track,				/* animate_tile_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2051
	TileLoop_Track,						/* tile_loop_clear */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2052
	ChangeTileOwner_Track,		/* change_tile_owner_clear */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2053
	NULL,											/* get_produced_cargo_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2054
	VehicleEnter_Track,				/* vehicle_enter_tile_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2055
	NULL,											/* vehicle_leave_tile_proc */
39
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 22
diff changeset
  2056
	GetSlopeTileh_Track,			/* get_slope_tileh_proc */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2057
};