elrail.c
author tron
Mon, 10 Apr 2006 07:15:58 +0000
changeset 3491 35d747bb5e82
parent 3463 efc2db302555
child 3636 a36cc46e754d
permissions -rw-r--r--
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
Remove DoCommandByTile(), because now it does the same as DoCommand()
3355
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
     1
/* $Id$ */
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
     2
/** @file elrail.c
3449
d45c8d0bf848 (svn r4281) -Cleanup: Begun cleaning up elrail code a bit, mostly comments and enum/array alignment
celestar
parents: 3445
diff changeset
     3
  This file deals with displaying wires and pylons for electric railways.
3355
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
     4
<h2>Basics</h2>
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
     5
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
     6
<h3>Tile Types</h3>
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
     7
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
     8
We have two different types of tiles in the drawing code:
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
     9
Normal Railway Tiles (NRTs) which can have more than one track on it, and
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
    10
Special Railways tiles (SRTs) which have only one track (like crossings, depots
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
    11
stations, etc).
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
    12
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
    13
<h3>Location Categories</h3>
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
    14
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
    15
All tiles are categorized into three location groups (TLG):
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
    16
Group 0: Tiles with both an even X coordinate and an even Y coordinate
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
    17
Group 1: Tiles with an even X and an odd Y coordinate
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
    18
Group 2: Tiles with an odd X and an even Y coordinate
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
    19
Group 3: Tiles with both an odd X and Y coordnate.
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
    20
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
    21
<h3>Pylon Points</h3>
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
    22
<h4>Control Points</h4>
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
    23
A Pylon Control Point (PCP) is a position where a wire (or rather two)
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
    24
is mounted onto a pylon.
3449
d45c8d0bf848 (svn r4281) -Cleanup: Begun cleaning up elrail code a bit, mostly comments and enum/array alignment
celestar
parents: 3445
diff changeset
    25
Each NRT does contain 4 PCPs which are bitmapped to a byte
d45c8d0bf848 (svn r4281) -Cleanup: Begun cleaning up elrail code a bit, mostly comments and enum/array alignment
celestar
parents: 3445
diff changeset
    26
variable and are represented by the DiagDirection enum
3355
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
    27
3449
d45c8d0bf848 (svn r4281) -Cleanup: Begun cleaning up elrail code a bit, mostly comments and enum/array alignment
celestar
parents: 3445
diff changeset
    28
Each track ends on two PCPs and thus requires one pylon on each end. However,
d45c8d0bf848 (svn r4281) -Cleanup: Begun cleaning up elrail code a bit, mostly comments and enum/array alignment
celestar
parents: 3445
diff changeset
    29
there is one exception: Straight-and-level tracks only have one pylon every
d45c8d0bf848 (svn r4281) -Cleanup: Begun cleaning up elrail code a bit, mostly comments and enum/array alignment
celestar
parents: 3445
diff changeset
    30
other tile.
3355
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
    31
3449
d45c8d0bf848 (svn r4281) -Cleanup: Begun cleaning up elrail code a bit, mostly comments and enum/array alignment
celestar
parents: 3445
diff changeset
    32
Now on each edge there are two PCPs: One from each adjacent tile. Both PCPs
d45c8d0bf848 (svn r4281) -Cleanup: Begun cleaning up elrail code a bit, mostly comments and enum/array alignment
celestar
parents: 3445
diff changeset
    33
are merged using an OR operation (i. e. if one tile needs a PCP at the postion
d45c8d0bf848 (svn r4281) -Cleanup: Begun cleaning up elrail code a bit, mostly comments and enum/array alignment
celestar
parents: 3445
diff changeset
    34
in question, both tiles get it).
3355
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
    35
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
    36
<h4>Position Points</h4>
3449
d45c8d0bf848 (svn r4281) -Cleanup: Begun cleaning up elrail code a bit, mostly comments and enum/array alignment
celestar
parents: 3445
diff changeset
    37
A Pylon Position Point (PPP) is a position where a pylon is located on the
d45c8d0bf848 (svn r4281) -Cleanup: Begun cleaning up elrail code a bit, mostly comments and enum/array alignment
celestar
parents: 3445
diff changeset
    38
ground.  Each PCP owns 8 in (45 degree steps) PPPs that are located around
d45c8d0bf848 (svn r4281) -Cleanup: Begun cleaning up elrail code a bit, mostly comments and enum/array alignment
celestar
parents: 3445
diff changeset
    39
it. PPPs are represented using the Direction enum. Each track bit has PPPs
d45c8d0bf848 (svn r4281) -Cleanup: Begun cleaning up elrail code a bit, mostly comments and enum/array alignment
celestar
parents: 3445
diff changeset
    40
that are impossible (because the pylon would be situated on the track) and
d45c8d0bf848 (svn r4281) -Cleanup: Begun cleaning up elrail code a bit, mostly comments and enum/array alignment
celestar
parents: 3445
diff changeset
    41
some that are preferred (because the pylon would be rectangular to the track).
3355
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
    42
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
    43
<img src="../../elrail_tile.png">
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
    44
<img src="../../elrail_track.png">
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
    45
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
    46
  */
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
    47
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
    48
#include "stdafx.h"
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
    49
#include "openttd.h"
3367
a995838e8d85 (svn r4164) Use acessor functions
tron
parents: 3355
diff changeset
    50
#include "station_map.h"
3355
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
    51
#include "tile.h"
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
    52
#include "viewport.h"
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
    53
#include "functions.h" /* We should REALLY get rid of this goddamn file, as it is butt-ugly */
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
    54
#include "variables.h" /* ... same here */
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
    55
#include "rail.h"
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
    56
#include "debug.h"
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
    57
#include "tunnel_map.h"
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
    58
#include "road_map.h"
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
    59
#include "bridge_map.h"
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
    60
#include "bridge.h"
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
    61
#include "rail_map.h"
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
    62
#include "table/sprites.h"
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
    63
#include "table/elrail_data.h"
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
    64
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
    65
static inline TLG GetTLG(TileIndex t)
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
    66
{
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
    67
	return (HASBIT(TileX(t), 0) << 1) + HASBIT(TileY(t), 0);
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
    68
}
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
    69
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
    70
/** Finds which Rail Bits are present on a given tile. For bridge tiles,
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
    71
  * returns track bits under the bridge
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
    72
  */
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
    73
static TrackBits GetRailTrackBitsUniversal(TileIndex t, byte *override)
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
    74
{
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
    75
	switch (GetTileType(t)) {
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
    76
		case MP_RAILWAY:
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
    77
			if (GetRailType(t) != RAILTYPE_ELECTRIC) return 0;
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
    78
			switch (GetRailTileType(t)) {
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
    79
				case RAIL_TYPE_NORMAL: case RAIL_TYPE_SIGNALS:
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
    80
					return GetTrackBits(t);
3376
d094df422fa9 (svn r4178) -Fix: Draw catenary inside waypoints as well
celestar
parents: 3375
diff changeset
    81
				case RAIL_TYPE_DEPOT_WAYPOINT:
d094df422fa9 (svn r4178) -Fix: Draw catenary inside waypoints as well
celestar
parents: 3375
diff changeset
    82
					if (GetRailTileSubtype(t) == RAIL_SUBTYPE_WAYPOINT) return GetRailWaypointBits(t);
3355
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
    83
				default:
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
    84
					return 0;
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
    85
			}
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
    86
			break;
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
    87
		case MP_TUNNELBRIDGE:
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
    88
			if (IsTunnel(t)) {
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
    89
				if (GetRailType(t) != RAILTYPE_ELECTRIC) return 0;
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
    90
				if (override != NULL) *override = 1 << GetTunnelDirection(t);
3367
a995838e8d85 (svn r4164) Use acessor functions
tron
parents: 3355
diff changeset
    91
				return DiagDirToAxis(GetTunnelDirection(t)) == AXIS_X ? TRACK_BIT_X : TRACK_BIT_Y;
3355
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
    92
			} else {
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
    93
				if (GetRailType(t) != RAILTYPE_ELECTRIC) return 0;
3462
988f336179ba (svn r4306) -Fix (103). Assertion when removing elrails under bridges. Thanks to Rubidium for reporting and fixing
celestar
parents: 3461
diff changeset
    94
				if (IsBridgeMiddle(t)) {
988f336179ba (svn r4306) -Fix (103). Assertion when removing elrails under bridges. Thanks to Rubidium for reporting and fixing
celestar
parents: 3461
diff changeset
    95
					if (IsTransportUnderBridge(t) &&
988f336179ba (svn r4306) -Fix (103). Assertion when removing elrails under bridges. Thanks to Rubidium for reporting and fixing
celestar
parents: 3461
diff changeset
    96
						GetTransportTypeUnderBridge(t) == TRANSPORT_RAIL) {
988f336179ba (svn r4306) -Fix (103). Assertion when removing elrails under bridges. Thanks to Rubidium for reporting and fixing
celestar
parents: 3461
diff changeset
    97
						return GetRailBitsUnderBridge(t);
3463
efc2db302555 (svn r4307) -Fix: Coding style in previous commit. Thanks to Tron for instant notice
celestar
parents: 3462
diff changeset
    98
					} else {
3462
988f336179ba (svn r4306) -Fix (103). Assertion when removing elrails under bridges. Thanks to Rubidium for reporting and fixing
celestar
parents: 3461
diff changeset
    99
						return 0;
3463
efc2db302555 (svn r4307) -Fix: Coding style in previous commit. Thanks to Tron for instant notice
celestar
parents: 3462
diff changeset
   100
					}
3355
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   101
				} else {
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   102
					if (override != NULL && DistanceMax(t, GetOtherBridgeEnd(t)) > 1) *override = 1 << GetBridgeRampDirection(t);
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   103
3368
d57156668a59 (svn r4165) -Do not use GetBridgeAxis on bridge ramps (request by Tron)
celestar
parents: 3367
diff changeset
   104
					return DiagDirToAxis(GetBridgeRampDirection(t)) == AXIS_X ? TRACK_BIT_X : TRACK_BIT_Y;
3355
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   105
				}
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   106
			}
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   107
		case MP_STREET:
3405
618519c19cf6 (svn r4216) -Fix: Fixed revision 4214, did a bad error there. Thanks MiHaMiX for pointing it out
celestar
parents: 3403
diff changeset
   108
			if (GetRoadType(t) != ROAD_CROSSING) return 0;
3367
a995838e8d85 (svn r4164) Use acessor functions
tron
parents: 3355
diff changeset
   109
			if (GetRailTypeCrossing(t) != RAILTYPE_ELECTRIC) return 0;
3355
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   110
			return GetCrossingRailBits(t);
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   111
		case MP_STATION:
3403
66cfd06c7c6f (svn r4214) -Fix: Do not try to obtain Trackbits for normal rails, bus stops, airports and other non-rail tiles
celestar
parents: 3395
diff changeset
   112
			if (!IsRailwayStation(t)) return 0;
3355
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   113
			if (GetRailType(t) != RAILTYPE_ELECTRIC) return 0;
3375
5f3ddc988795 (svn r4177) -Fix: GetRailTrackBitsUniversal needs Trackbits, not Track. While at it, remove an unused variable
celestar
parents: 3368
diff changeset
   114
			return TrackToTrackBits(GetRailStationTrack(t));
3355
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   115
		default:
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   116
			return 0;
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   117
	}
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   118
}
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   119
3451
0e8ccac68fdf (svn r4283) -Cleanup: More elrail housekeeping, remove code dublication, more meaningful variable names, simplify control flow..
celestar
parents: 3449
diff changeset
   120
/** Corrects the tileh for certain tile types. Returns an effective tileh for the track on the tile.
0e8ccac68fdf (svn r4283) -Cleanup: More elrail housekeeping, remove code dublication, more meaningful variable names, simplify control flow..
celestar
parents: 3449
diff changeset
   121
  * @param tile The tile to analyse
0e8ccac68fdf (svn r4283) -Cleanup: More elrail housekeeping, remove code dublication, more meaningful variable names, simplify control flow..
celestar
parents: 3449
diff changeset
   122
  * @param *tileh the tileh
0e8ccac68fdf (svn r4283) -Cleanup: More elrail housekeeping, remove code dublication, more meaningful variable names, simplify control flow..
celestar
parents: 3449
diff changeset
   123
  */
0e8ccac68fdf (svn r4283) -Cleanup: More elrail housekeeping, remove code dublication, more meaningful variable names, simplify control flow..
celestar
parents: 3449
diff changeset
   124
static void AdjustTileh(TileIndex tile, uint *tileh)
0e8ccac68fdf (svn r4283) -Cleanup: More elrail housekeeping, remove code dublication, more meaningful variable names, simplify control flow..
celestar
parents: 3449
diff changeset
   125
{
0e8ccac68fdf (svn r4283) -Cleanup: More elrail housekeeping, remove code dublication, more meaningful variable names, simplify control flow..
celestar
parents: 3449
diff changeset
   126
	if (IsTunnelTile(tile)) *tileh = 0;
0e8ccac68fdf (svn r4283) -Cleanup: More elrail housekeeping, remove code dublication, more meaningful variable names, simplify control flow..
celestar
parents: 3449
diff changeset
   127
	if (IsBridgeTile(tile) && IsBridgeRamp(tile)) {
0e8ccac68fdf (svn r4283) -Cleanup: More elrail housekeeping, remove code dublication, more meaningful variable names, simplify control flow..
celestar
parents: 3449
diff changeset
   128
		if (*tileh != 0) {
0e8ccac68fdf (svn r4283) -Cleanup: More elrail housekeeping, remove code dublication, more meaningful variable names, simplify control flow..
celestar
parents: 3449
diff changeset
   129
			*tileh = 0;
0e8ccac68fdf (svn r4283) -Cleanup: More elrail housekeeping, remove code dublication, more meaningful variable names, simplify control flow..
celestar
parents: 3449
diff changeset
   130
		} else {
0e8ccac68fdf (svn r4283) -Cleanup: More elrail housekeeping, remove code dublication, more meaningful variable names, simplify control flow..
celestar
parents: 3449
diff changeset
   131
			switch (GetBridgeRampDirection(tile)) {
0e8ccac68fdf (svn r4283) -Cleanup: More elrail housekeeping, remove code dublication, more meaningful variable names, simplify control flow..
celestar
parents: 3449
diff changeset
   132
				case DIAGDIR_NE: *tileh = 12; break;
0e8ccac68fdf (svn r4283) -Cleanup: More elrail housekeeping, remove code dublication, more meaningful variable names, simplify control flow..
celestar
parents: 3449
diff changeset
   133
				case DIAGDIR_SE: *tileh =  6; break;
0e8ccac68fdf (svn r4283) -Cleanup: More elrail housekeeping, remove code dublication, more meaningful variable names, simplify control flow..
celestar
parents: 3449
diff changeset
   134
				case DIAGDIR_SW: *tileh =  3; break;
0e8ccac68fdf (svn r4283) -Cleanup: More elrail housekeeping, remove code dublication, more meaningful variable names, simplify control flow..
celestar
parents: 3449
diff changeset
   135
				case DIAGDIR_NW: *tileh =  9; break;
0e8ccac68fdf (svn r4283) -Cleanup: More elrail housekeeping, remove code dublication, more meaningful variable names, simplify control flow..
celestar
parents: 3449
diff changeset
   136
				default: break;
0e8ccac68fdf (svn r4283) -Cleanup: More elrail housekeeping, remove code dublication, more meaningful variable names, simplify control flow..
celestar
parents: 3449
diff changeset
   137
			}
0e8ccac68fdf (svn r4283) -Cleanup: More elrail housekeeping, remove code dublication, more meaningful variable names, simplify control flow..
celestar
parents: 3449
diff changeset
   138
		}
0e8ccac68fdf (svn r4283) -Cleanup: More elrail housekeeping, remove code dublication, more meaningful variable names, simplify control flow..
celestar
parents: 3449
diff changeset
   139
	}
0e8ccac68fdf (svn r4283) -Cleanup: More elrail housekeeping, remove code dublication, more meaningful variable names, simplify control flow..
celestar
parents: 3449
diff changeset
   140
}
0e8ccac68fdf (svn r4283) -Cleanup: More elrail housekeeping, remove code dublication, more meaningful variable names, simplify control flow..
celestar
parents: 3449
diff changeset
   141
3355
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   142
/** Draws wires and, if required, pylons on a given tile
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   143
  * @param ti The Tileinfo to draw the tile for
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   144
  */
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   145
static void DrawCatenaryRailway(const TileInfo *ti)
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   146
{
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   147
	/* Pylons are placed on a tile edge, so we need to take into account
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   148
	   the track configuration of 2 adjacent tiles. trackconfig[0] stores the
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   149
	   current tile (home tile) while [1] holds the neighbour */
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   150
	TrackBits trackconfig[TS_END];
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   151
	bool isflat[TS_END];
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   152
	/* Note that ti->tileh has already been adjusted for Foundations */
3451
0e8ccac68fdf (svn r4283) -Cleanup: More elrail housekeeping, remove code dublication, more meaningful variable names, simplify control flow..
celestar
parents: 3449
diff changeset
   153
	uint tileh[TS_END] = {ti->tileh, 0};
3355
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   154
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   155
	TLG tlg = GetTLG(ti->tile);
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   156
	byte PCPstatus = 0;
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   157
	byte OverridePCP = 0;
3395
edfd22fd92c9 (svn r4204) - Get trunk compiling again on OS/2
orudge
parents: 3378
diff changeset
   158
	byte PPPpreferred[DIAGDIR_END];
edfd22fd92c9 (svn r4204) - Get trunk compiling again on OS/2
orudge
parents: 3378
diff changeset
   159
	byte PPPallowed[DIAGDIR_END];
3355
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   160
	DiagDirection i;
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   161
	Track t;
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   162
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   163
	/* Find which rail bits are present, and select the override points.
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   164
	   We don't draw a pylon:
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   165
	   1) INSIDE a tunnel (we wouldn't see it anyway)
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   166
	   2) on the "far" end of a bridge head (the one that connects to bridge middle),
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   167
	      because that one is drawn on the bridge. Exception is for length 0 bridges
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   168
	      which have no middle tiles */
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   169
	trackconfig[TS_HOME] = GetRailTrackBitsUniversal(ti->tile, &OverridePCP);
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   170
	/* If a track bit is present that is not in the main direction, the track is level */
3461
098d2998fb0b (svn r4305) -Codechange: Minor elrail cleanup (Tron)
celestar
parents: 3452
diff changeset
   171
	isflat[TS_HOME] = trackconfig[TS_HOME] & (TRACK_BIT_HORZ | TRACK_BIT_VERT);
3355
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   172
3451
0e8ccac68fdf (svn r4283) -Cleanup: More elrail housekeeping, remove code dublication, more meaningful variable names, simplify control flow..
celestar
parents: 3449
diff changeset
   173
	AdjustTileh(ti->tile, &tileh[TS_HOME]);
3355
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   174
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   175
	for (i = DIAGDIR_NE; i < DIAGDIR_END; i++) {
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   176
		TileIndex neighbour = ti->tile + TileOffsByDir(i);
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   177
		uint foundation = 0;
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   178
		int k;
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   179
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   180
		/* Here's one of the main headaches. GetTileSlope does not correct for possibly
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   181
		   existing foundataions, so we do have to do that manually later on.*/
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   182
		tileh[TS_NEIGHBOUR] = GetTileSlope(neighbour, NULL);
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   183
		trackconfig[TS_NEIGHBOUR] = GetRailTrackBitsUniversal(neighbour, NULL);
3452
39f2a612f855 (svn r4284) -Fix: Tunnel portals no longer have a pylon ON them if there is a track right above the portal
celestar
parents: 3451
diff changeset
   184
		if (IsTunnelTile(neighbour) && i != GetTunnelDirection(neighbour)) trackconfig[TS_NEIGHBOUR] = 0;
3461
098d2998fb0b (svn r4305) -Codechange: Minor elrail cleanup (Tron)
celestar
parents: 3452
diff changeset
   185
		isflat[TS_NEIGHBOUR] = trackconfig[TS_NEIGHBOUR] & (TRACK_BIT_HORZ | TRACK_BIT_VERT);
3355
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   186
3451
0e8ccac68fdf (svn r4283) -Cleanup: More elrail housekeeping, remove code dublication, more meaningful variable names, simplify control flow..
celestar
parents: 3449
diff changeset
   187
		PPPpreferred[i] = 0xFF; /* We start with preferring everything (end-of-line in any direction) */
0e8ccac68fdf (svn r4283) -Cleanup: More elrail housekeeping, remove code dublication, more meaningful variable names, simplify control flow..
celestar
parents: 3449
diff changeset
   188
		PPPallowed[i] = AllowedPPPonPCP[i];
0e8ccac68fdf (svn r4283) -Cleanup: More elrail housekeeping, remove code dublication, more meaningful variable names, simplify control flow..
celestar
parents: 3449
diff changeset
   189
3355
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   190
		/* We cycle through all the existing tracks at a PCP and see what
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   191
		   PPPs we want to have, or may not have at all */
3451
0e8ccac68fdf (svn r4283) -Cleanup: More elrail housekeeping, remove code dublication, more meaningful variable names, simplify control flow..
celestar
parents: 3449
diff changeset
   192
		for (k = 0; k < NUM_TRACKS_AT_PCP; k++) {
3355
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   193
			/* Next to us, we have a bridge head, don't worry about that one, if it shows away from us */
3451
0e8ccac68fdf (svn r4283) -Cleanup: More elrail housekeeping, remove code dublication, more meaningful variable names, simplify control flow..
celestar
parents: 3449
diff changeset
   194
			if (TrackSourceTile[i][k] == TS_NEIGHBOUR &&
0e8ccac68fdf (svn r4283) -Cleanup: More elrail housekeeping, remove code dublication, more meaningful variable names, simplify control flow..
celestar
parents: 3449
diff changeset
   195
			    IsBridgeTile(neighbour) && IsBridgeRamp(neighbour) &&
0e8ccac68fdf (svn r4283) -Cleanup: More elrail housekeeping, remove code dublication, more meaningful variable names, simplify control flow..
celestar
parents: 3449
diff changeset
   196
			    GetBridgeRampDirection(neighbour) == ReverseDiagDir(i)
3355
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   197
			   ) continue;
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   198
3451
0e8ccac68fdf (svn r4283) -Cleanup: More elrail housekeeping, remove code dublication, more meaningful variable names, simplify control flow..
celestar
parents: 3449
diff changeset
   199
			/* We check whether the track in question (k) is present in the tile
0e8ccac68fdf (svn r4283) -Cleanup: More elrail housekeeping, remove code dublication, more meaningful variable names, simplify control flow..
celestar
parents: 3449
diff changeset
   200
			   (TrackSourceTile) */
0e8ccac68fdf (svn r4283) -Cleanup: More elrail housekeeping, remove code dublication, more meaningful variable names, simplify control flow..
celestar
parents: 3449
diff changeset
   201
			if (HASBIT(trackconfig[TrackSourceTile[i][k]], TracksAtPCP[i][k])) {
0e8ccac68fdf (svn r4283) -Cleanup: More elrail housekeeping, remove code dublication, more meaningful variable names, simplify control flow..
celestar
parents: 3449
diff changeset
   202
				/* track found, if track is in the neighbour tile, adjust the number
0e8ccac68fdf (svn r4283) -Cleanup: More elrail housekeeping, remove code dublication, more meaningful variable names, simplify control flow..
celestar
parents: 3449
diff changeset
   203
				   of the PCP for preferred/allowed determination*/
0e8ccac68fdf (svn r4283) -Cleanup: More elrail housekeeping, remove code dublication, more meaningful variable names, simplify control flow..
celestar
parents: 3449
diff changeset
   204
				DiagDirection PCPpos = (TrackSourceTile[i][k] == TS_HOME) ? i : ReverseDiagDir(i);
0e8ccac68fdf (svn r4283) -Cleanup: More elrail housekeeping, remove code dublication, more meaningful variable names, simplify control flow..
celestar
parents: 3449
diff changeset
   205
				SETBIT(PCPstatus, i); /* This PCP is in use */
0e8ccac68fdf (svn r4283) -Cleanup: More elrail housekeeping, remove code dublication, more meaningful variable names, simplify control flow..
celestar
parents: 3449
diff changeset
   206
0e8ccac68fdf (svn r4283) -Cleanup: More elrail housekeeping, remove code dublication, more meaningful variable names, simplify control flow..
celestar
parents: 3449
diff changeset
   207
				PPPpreferred[i] &= PreferredPPPofTrackAtPCP[TracksAtPCP[i][k]][PCPpos];
0e8ccac68fdf (svn r4283) -Cleanup: More elrail housekeeping, remove code dublication, more meaningful variable names, simplify control flow..
celestar
parents: 3449
diff changeset
   208
				PPPallowed[i] &= ~DisallowedPPPofTrackAtPCP[TracksAtPCP[i][k]][PCPpos];
3355
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   209
			}
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   210
		}
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   211
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   212
		/* Deactivate all PPPs if PCP is not used */
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   213
		PPPpreferred[i] *= HASBIT(PCPstatus, i);
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   214
		PPPallowed[i] *= HASBIT(PCPstatus, i);
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   215
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   216
		/* Station on a non-flat tile means foundation. add one height level and adjust tileh */
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   217
		if (IsTileType(neighbour, MP_STATION) && tileh[TS_NEIGHBOUR] != 0) tileh[TS_NEIGHBOUR] = 0;
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   218
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   219
		/* Read the foundataions if they are present, and adjust the tileh */
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   220
		if (IsTileType(neighbour, MP_RAILWAY)) foundation = GetRailFoundation(tileh[TS_NEIGHBOUR], trackconfig[TS_NEIGHBOUR]);
3368
d57156668a59 (svn r4165) -Do not use GetBridgeAxis on bridge ramps (request by Tron)
celestar
parents: 3367
diff changeset
   221
		if (IsBridgeTile(neighbour) && IsBridgeRamp(neighbour)) {
d57156668a59 (svn r4165) -Do not use GetBridgeAxis on bridge ramps (request by Tron)
celestar
parents: 3367
diff changeset
   222
			foundation = GetBridgeFoundation(tileh[TS_NEIGHBOUR], DiagDirToAxis(GetBridgeRampDirection(neighbour)));
d57156668a59 (svn r4165) -Do not use GetBridgeAxis on bridge ramps (request by Tron)
celestar
parents: 3367
diff changeset
   223
		}
d57156668a59 (svn r4165) -Do not use GetBridgeAxis on bridge ramps (request by Tron)
celestar
parents: 3367
diff changeset
   224
3355
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   225
		if (foundation != 0) {
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   226
			if (foundation < 15) {
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   227
				tileh[TS_NEIGHBOUR] = 0;
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   228
			} else {
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   229
				tileh[TS_NEIGHBOUR] = _inclined_tileh[foundation - 15];
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   230
			}
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   231
		}
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   232
3451
0e8ccac68fdf (svn r4283) -Cleanup: More elrail housekeeping, remove code dublication, more meaningful variable names, simplify control flow..
celestar
parents: 3449
diff changeset
   233
		AdjustTileh(neighbour, &tileh[TS_NEIGHBOUR]);
3355
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   234
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   235
		/* If we have a straight (and level) track, we want a pylon only every 2 tiles
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   236
		   Delete the PCP if this is the case. */
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   237
		/* Level means that the slope is the same, or the track is flat */
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   238
		if (tileh[TS_HOME] == tileh[TS_NEIGHBOUR] || (isflat[TS_HOME] && isflat[TS_NEIGHBOUR])) {
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   239
			for (k = 0; k < NUM_IGNORE_GROUPS; k++)
3451
0e8ccac68fdf (svn r4283) -Cleanup: More elrail housekeeping, remove code dublication, more meaningful variable names, simplify control flow..
celestar
parents: 3449
diff changeset
   240
				if (PPPpreferred[i] == IgnoredPCP[k][tlg][i]) CLRBIT(PCPstatus, i);
3355
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   241
		}
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   242
3451
0e8ccac68fdf (svn r4283) -Cleanup: More elrail housekeeping, remove code dublication, more meaningful variable names, simplify control flow..
celestar
parents: 3449
diff changeset
   243
		/* Now decide where we draw our pylons. First try the preferred PPPs, but they may not exist.
3355
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   244
		   In that case, we try the any of the allowed ones. if they don't exist either, don't draw
3451
0e8ccac68fdf (svn r4283) -Cleanup: More elrail housekeeping, remove code dublication, more meaningful variable names, simplify control flow..
celestar
parents: 3449
diff changeset
   245
		   anything. Note that the preferred PPPs still contain the end-of-line markers.
0e8ccac68fdf (svn r4283) -Cleanup: More elrail housekeeping, remove code dublication, more meaningful variable names, simplify control flow..
celestar
parents: 3449
diff changeset
   246
		   Remove those (simply by ANDing with allowed, since these markers are never allowed) */
0e8ccac68fdf (svn r4283) -Cleanup: More elrail housekeeping, remove code dublication, more meaningful variable names, simplify control flow..
celestar
parents: 3449
diff changeset
   247
		if ( (PPPallowed[i] & PPPpreferred[i]) != 0) PPPallowed[i] &= PPPpreferred[i];
3355
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   248
3451
0e8ccac68fdf (svn r4283) -Cleanup: More elrail housekeeping, remove code dublication, more meaningful variable names, simplify control flow..
celestar
parents: 3449
diff changeset
   249
		if (PPPallowed[i] != 0 && HASBIT(PCPstatus, i) && !HASBIT(OverridePCP, i)) {
3355
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   250
			for (k = 0; k < DIR_END; k++) {
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   251
				byte temp = PPPorder[i][GetTLG(ti->tile)][k];
3451
0e8ccac68fdf (svn r4283) -Cleanup: More elrail housekeeping, remove code dublication, more meaningful variable names, simplify control flow..
celestar
parents: 3449
diff changeset
   252
				if (HASBIT(PPPallowed[i], temp)) {
3355
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   253
					uint x  = ti->x + x_pcp_offsets[i] + x_ppp_offsets[temp];
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   254
					uint y  = ti->y + y_pcp_offsets[i] + y_ppp_offsets[temp];
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   255
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   256
					/* Don't build the pylon if it would be outside the tile */
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   257
					if (!HASBIT(OwnedPPPonPCP[i], temp)) {
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   258
						/* We have a neighour that will draw it, bail out */
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   259
						if (trackconfig[TS_NEIGHBOUR] != 0) break;
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   260
						continue; /* No neighbour, go looking for a better position */
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   261
					}
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   262
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   263
					AddSortableSpriteToDraw(pylons_normal[temp], x, y, 1, 1, 10,
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   264
							GetSlopeZ(ti->x + x_pcp_offsets[i], ti->y + y_pcp_offsets[i]));
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   265
					break; /* We already have drawn a pylon, bail out */
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   266
				}
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   267
			}
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   268
		}
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   269
	}
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   270
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   271
	/* Drawing of pylons is finished, now draw the wires */
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   272
	for (t = 0; t < TRACK_END; t++) {
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   273
		if (HASBIT(trackconfig[TS_HOME], t)) {
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   274
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   275
			byte PCPconfig = HASBIT(PCPstatus, PCPpositions[t][0]) +
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   276
				(HASBIT(PCPstatus, PCPpositions[t][1]) << 1);
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   277
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   278
			const SortableSpriteStruct *sss;
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   279
			int tileh_selector = !(tileh[TS_HOME] % 3) * tileh[TS_HOME] / 3; /* tileh for the slopes, 0 otherwise */
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   280
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   281
			if ( /* We are not drawing a wire under a low bridge */
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   282
					IsBridgeTile(ti->tile) &&
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   283
					IsBridgeMiddle(ti->tile) &&
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   284
					!(_display_opt & DO_TRANS_BUILDINGS) &&
3378
4057cbcc6b86 (svn r4180) -Fix: Fixed an assert in the elrail drawing code due to passing of a wrong variable. I wish the compiler would warn about different enum types used...
celestar
parents: 3376
diff changeset
   285
					GetBridgeHeight(ti->tile) <= TilePixelHeight(ti->tile)
3355
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   286
			   ) return;
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   287
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   288
			assert(PCPconfig != 0); /* We have a pylon on neither end of the wire, that doesn't work (since we have no sprites for that) */
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   289
			assert(!IsSteepTileh(tileh[TS_HOME]));
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   290
			sss = &CatenarySpriteData[Wires[tileh_selector][t][PCPconfig]];
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   291
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   292
			AddSortableSpriteToDraw( sss->image, ti->x + sss->x_offset, ti->y + sss->y_offset,
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   293
				sss->x_size, sss->y_size, sss->z_size, GetSlopeZ(ti->x + min(sss->x_offset, 15), ti->y + min(sss->y_offset, 15)) + sss->z_offset);
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   294
		}
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   295
	}
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   296
}
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   297
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   298
static void DrawCatenaryOnBridge(const TileInfo *ti)
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   299
{
3445
972e0aa84c51 (svn r4276) -Codechange: Cleaned DrawCatenaryOnBridge a bit (requested by Tron)
celestar
parents: 3405
diff changeset
   300
	TileIndex end = GetSouthernBridgeEnd(ti->tile);
972e0aa84c51 (svn r4276) -Codechange: Cleaned DrawCatenaryOnBridge a bit (requested by Tron)
celestar
parents: 3405
diff changeset
   301
	TileIndex start = GetOtherBridgeEnd(end);
972e0aa84c51 (svn r4276) -Codechange: Cleaned DrawCatenaryOnBridge a bit (requested by Tron)
celestar
parents: 3405
diff changeset
   302
972e0aa84c51 (svn r4276) -Codechange: Cleaned DrawCatenaryOnBridge a bit (requested by Tron)
celestar
parents: 3405
diff changeset
   303
	uint length = GetBridgeLength(start, end);
3355
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   304
	uint num = DistanceMax(ti->tile, start);
3445
972e0aa84c51 (svn r4276) -Codechange: Cleaned DrawCatenaryOnBridge a bit (requested by Tron)
celestar
parents: 3405
diff changeset
   305
3355
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   306
	const SortableSpriteStruct *sss;
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   307
	Axis axis = GetBridgeAxis(ti->tile);
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   308
	TLG tlg = GetTLG(ti->tile);
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   309
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   310
	CatenarySprite offset = axis == AXIS_X ? 0 : WIRE_Y_FLAT_BOTH - WIRE_X_FLAT_BOTH;
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   311
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   312
	if ((length % 2) && num == length) {
3445
972e0aa84c51 (svn r4276) -Codechange: Cleaned DrawCatenaryOnBridge a bit (requested by Tron)
celestar
parents: 3405
diff changeset
   313
		/* Draw the "short" wire on the southern end of the bridge
972e0aa84c51 (svn r4276) -Codechange: Cleaned DrawCatenaryOnBridge a bit (requested by Tron)
celestar
parents: 3405
diff changeset
   314
		 * only needed if the length of the bridge is odd */
3355
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   315
		sss = &CatenarySpriteData[WIRE_X_FLAT_BOTH + offset];
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   316
	} else {
3445
972e0aa84c51 (svn r4276) -Codechange: Cleaned DrawCatenaryOnBridge a bit (requested by Tron)
celestar
parents: 3405
diff changeset
   317
		/* Draw "long" wires on all other tiles of the bridge (one pylon every two tiles) */
3355
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   318
		sss = &CatenarySpriteData[WIRE_X_FLAT_SW + (num % 2) + offset];
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   319
	}
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   320
3445
972e0aa84c51 (svn r4276) -Codechange: Cleaned DrawCatenaryOnBridge a bit (requested by Tron)
celestar
parents: 3405
diff changeset
   321
	AddSortableSpriteToDraw( sss->image, ti->x + sss->x_offset, ti->y + sss->y_offset,
972e0aa84c51 (svn r4276) -Codechange: Cleaned DrawCatenaryOnBridge a bit (requested by Tron)
celestar
parents: 3405
diff changeset
   322
			sss->x_size, sss->y_size, sss->z_size, GetBridgeHeight(ti->tile) + sss->z_offset + 8);
972e0aa84c51 (svn r4276) -Codechange: Cleaned DrawCatenaryOnBridge a bit (requested by Tron)
celestar
parents: 3405
diff changeset
   323
972e0aa84c51 (svn r4276) -Codechange: Cleaned DrawCatenaryOnBridge a bit (requested by Tron)
celestar
parents: 3405
diff changeset
   324
	/* Finished with wires, draw pylons */
972e0aa84c51 (svn r4276) -Codechange: Cleaned DrawCatenaryOnBridge a bit (requested by Tron)
celestar
parents: 3405
diff changeset
   325
	/* every other tile needs a pylon on the northern end */
3355
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   326
	if (num % 2) {
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   327
		if (axis == AXIS_X) {
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   328
			AddSortableSpriteToDraw( pylons_bridge[0 + HASBIT(tlg, 0)], ti->x, ti->y + 4 + 8 * HASBIT(tlg, 0), 1, 1, 10, GetBridgeHeight(ti->tile) + 8);
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   329
		} else {
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   330
			AddSortableSpriteToDraw( pylons_bridge[2 + HASBIT(tlg, 1)], ti->x + 4 + 8 * HASBIT(tlg, 1), ti->y, 1, 1, 10, GetBridgeHeight(ti->tile) + 8);
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   331
		}
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   332
	}
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   333
3445
972e0aa84c51 (svn r4276) -Codechange: Cleaned DrawCatenaryOnBridge a bit (requested by Tron)
celestar
parents: 3405
diff changeset
   334
	/* need a pylon on the southern end of the bridge */
972e0aa84c51 (svn r4276) -Codechange: Cleaned DrawCatenaryOnBridge a bit (requested by Tron)
celestar
parents: 3405
diff changeset
   335
	if (DistanceMax(ti->tile, start) == length) {
3355
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   336
		if (axis == AXIS_X) {
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   337
			AddSortableSpriteToDraw( pylons_bridge[0 + HASBIT(tlg, 0)], ti->x + 16, ti->y + 4 + 8 * HASBIT(tlg, 0), 1, 1, 10, GetBridgeHeight(ti->tile) + 8);
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   338
		} else {
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   339
			AddSortableSpriteToDraw( pylons_bridge[2 + HASBIT(tlg, 1)], ti->x + 4 + 8 * HASBIT(tlg, 1), ti->y + 16, 1, 1, 10, GetBridgeHeight(ti->tile) + 8);
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   340
		}
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   341
	}
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   342
}
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   343
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   344
void DrawCatenary(const TileInfo *ti)
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   345
{
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   346
	switch (GetTileType(ti->tile)) {
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   347
		case MP_RAILWAY:
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   348
			if (GetRailTileType(ti->tile) == RAIL_TYPE_DEPOT_WAYPOINT && GetRailTileSubtype(ti->tile) == RAIL_SUBTYPE_DEPOT) {
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   349
				const SortableSpriteStruct *sss = &CatenarySpriteData[WIRE_DEPOT_SW + ReverseDiagDir(GetRailDepotDirection(ti->tile))];
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   350
				AddSortableSpriteToDraw( sss->image, ti->x + sss->x_offset, ti->y + sss->y_offset,
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   351
					sss->x_size, sss->y_size, sss->z_size, GetSlopeZ(ti->x, ti->y) + sss->z_offset);
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   352
				return;
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   353
			}
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   354
			/* Fall through */
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   355
		case MP_TUNNELBRIDGE:
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   356
			if (IsBridgeTile(ti->tile) && IsBridgeMiddle(ti->tile) && GetRailTypeOnBridge(ti->tile) == RAILTYPE_ELECTRIC) DrawCatenaryOnBridge(ti);
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   357
			/* Fall further */
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   358
		case MP_STREET: case MP_STATION:
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   359
			DrawCatenaryRailway(ti);
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   360
			break;
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   361
		default:
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   362
			break;
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   363
	}
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   364
}
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   365