elrail.c
author rubidium
Mon, 04 Sep 2006 20:40:33 +0000
changeset 4549 106ed18a7675
parent 4480 e7d8faa8ba93
child 4559 aa0c13e39840
permissions -rw-r--r--
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
-Cleanup: whitespace alignment of a few tables.
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
4549
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4480
diff changeset
     3
 * This file deals with displaying wires and pylons for electric railways.
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4480
diff changeset
     4
 * <h2>Basics</h2>
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4480
diff changeset
     5
 *
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4480
diff changeset
     6
 * <h3>Tile Types</h3>
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4480
diff changeset
     7
 *
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4480
diff changeset
     8
 * We have two different types of tiles in the drawing code:
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4480
diff changeset
     9
 * Normal Railway Tiles (NRTs) which can have more than one track on it, and
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4480
diff changeset
    10
 * Special Railways tiles (SRTs) which have only one track (like crossings, depots
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4480
diff changeset
    11
 * stations, etc).
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4480
diff changeset
    12
 *
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4480
diff changeset
    13
 * <h3>Location Categories</h3>
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4480
diff changeset
    14
 *
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4480
diff changeset
    15
 * All tiles are categorized into three location groups (TLG):
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4480
diff changeset
    16
 * Group 0: Tiles with both an even X coordinate and an even Y coordinate
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4480
diff changeset
    17
 * Group 1: Tiles with an even X and an odd Y coordinate
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4480
diff changeset
    18
 * Group 2: Tiles with an odd X and an even Y coordinate
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4480
diff changeset
    19
 * Group 3: Tiles with both an odd X and Y coordnate.
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4480
diff changeset
    20
 *
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4480
diff changeset
    21
 * <h3>Pylon Points</h3>
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4480
diff changeset
    22
 * <h4>Control Points</h4>
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4480
diff changeset
    23
 * A Pylon Control Point (PCP) is a position where a wire (or rather two)
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4480
diff changeset
    24
 * is mounted onto a pylon.
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4480
diff changeset
    25
 * Each NRT does contain 4 PCPs which are bitmapped to a byte
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4480
diff changeset
    26
 * variable and are represented by the DiagDirection enum
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4480
diff changeset
    27
 *
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4480
diff changeset
    28
 * Each track ends on two PCPs and thus requires one pylon on each end. However,
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4480
diff changeset
    29
 * there is one exception: Straight-and-level tracks only have one pylon every
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4480
diff changeset
    30
 * other tile.
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4480
diff changeset
    31
 *
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4480
diff changeset
    32
 * Now on each edge there are two PCPs: One from each adjacent tile. Both PCPs
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4480
diff changeset
    33
 * are merged using an OR operation (i. e. if one tile needs a PCP at the postion
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4480
diff changeset
    34
 * in question, both tiles get it).
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4480
diff changeset
    35
 *
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4480
diff changeset
    36
 * <h4>Position Points</h4>
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4480
diff changeset
    37
 * A Pylon Position Point (PPP) is a position where a pylon is located on the
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4480
diff changeset
    38
 * ground.  Each PCP owns 8 in (45 degree steps) PPPs that are located around
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4480
diff changeset
    39
 * it. PPPs are represented using the Direction enum. Each track bit has PPPs
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4480
diff changeset
    40
 * that are impossible (because the pylon would be situated on the track) and
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4480
diff changeset
    41
 * some that are preferred (because the pylon would be rectangular to the track).
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4480
diff changeset
    42
 *
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4480
diff changeset
    43
 * <img src="../../elrail_tile.png">
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4480
diff changeset
    44
 * <img src="../../elrail_track.png">
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4480
diff changeset
    45
 *
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4480
diff changeset
    46
 */
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
    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,
4549
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4480
diff changeset
    71
 * returns track bits under the bridge
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4480
diff changeset
    72
 */
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
    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)) {
3792
67c865c9315c (svn r4788) - Codechange: RAILTYPE_{NORMAL,ELECTRIC,...} and RAIL_TYPE_{NORMAL,SIGNAL,...} have nearly the same name, rename RAIL_TYPE_* to RAIL_TILE_* of extra clarity
rubidium
parents: 3789
diff changeset
    79
				case RAIL_TILE_NORMAL: case RAIL_TILE_SIGNALS:
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
    80
					return GetTrackBits(t);
3792
67c865c9315c (svn r4788) - Codechange: RAILTYPE_{NORMAL,ELECTRIC,...} and RAIL_TYPE_{NORMAL,SIGNAL,...} have nearly the same name, rename RAIL_TYPE_* to RAIL_TILE_* of extra clarity
rubidium
parents: 3789
diff changeset
    81
				case RAIL_TILE_DEPOT_WAYPOINT:
3376
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;
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4021
diff changeset
    87
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
    88
		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
    89
			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
    90
				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
    91
				if (override != NULL) *override = 1 << GetTunnelDirection(t);
4158
91ff9bb84ced (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4077
diff changeset
    92
				return AxisToTrackBits(DiagDirToAxis(GetTunnelDirection(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
    93
			} 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
    94
				if (GetRailType(t) != RAILTYPE_ELECTRIC) return 0;
3977
513433ebd092 (svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents: 3971
diff changeset
    95
				if (IsBridgeMiddle(t)) {
513433ebd092 (svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents: 3971
diff changeset
    96
					if (IsTransportUnderBridge(t) &&
513433ebd092 (svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents: 3971
diff changeset
    97
						GetTransportTypeUnderBridge(t) == TRANSPORT_RAIL) {
513433ebd092 (svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents: 3971
diff changeset
    98
						return GetRailBitsUnderBridge(t);
513433ebd092 (svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents: 3971
diff changeset
    99
					} else {
513433ebd092 (svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents: 3971
diff changeset
   100
						return 0;
513433ebd092 (svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents: 3971
diff changeset
   101
					}
513433ebd092 (svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents: 3971
diff changeset
   102
				} else {
513433ebd092 (svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents: 3971
diff changeset
   103
					if (override != NULL && DistanceMax(t, GetOtherBridgeEnd(t)) > 1) *override = 1 << GetBridgeRampDirection(t);
513433ebd092 (svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents: 3971
diff changeset
   104
4158
91ff9bb84ced (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4077
diff changeset
   105
					return AxisToTrackBits(DiagDirToAxis(GetBridgeRampDirection(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
   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
			}
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4021
diff changeset
   108
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
   109
		case MP_STREET:
3793
7fe24e10ea63 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3792
diff changeset
   110
			if (GetRoadTileType(t) != ROAD_TILE_CROSSING) return 0;
3367
a995838e8d85 (svn r4164) Use acessor functions
tron
parents: 3355
diff changeset
   111
			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
   112
			return GetCrossingRailBits(t);
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4021
diff changeset
   113
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
   114
		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
   115
			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
   116
			if (GetRailType(t) != RAILTYPE_ELECTRIC) return 0;
3789
c50647c927e4 (svn r4785) - Newstations: don't draw catenary on non-track tiles
glx
parents: 3645
diff changeset
   117
			if (!IsStationTileElectrifiable(t)) return 0;
3375
5f3ddc988795 (svn r4177) -Fix: GetRailTrackBitsUniversal needs Trackbits, not Track. While at it, remove an unused variable
celestar
parents: 3368
diff changeset
   118
			return TrackToTrackBits(GetRailStationTrack(t));
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4021
diff changeset
   119
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
   120
		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
   121
			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
   122
	}
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   123
}
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   124
3451
0e8ccac68fdf (svn r4283) -Cleanup: More elrail housekeeping, remove code dublication, more meaningful variable names, simplify control flow..
celestar
parents: 3449
diff changeset
   125
/** Corrects the tileh for certain tile types. Returns an effective tileh for the track on the tile.
4549
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4480
diff changeset
   126
 * @param tile The tile to analyse
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4480
diff changeset
   127
 * @param *tileh the tileh
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4480
diff changeset
   128
 */
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4159
diff changeset
   129
static void AdjustTileh(TileIndex tile, Slope *tileh)
3451
0e8ccac68fdf (svn r4283) -Cleanup: More elrail housekeeping, remove code dublication, more meaningful variable names, simplify control flow..
celestar
parents: 3449
diff changeset
   130
{
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4021
diff changeset
   131
	if (IsTileType(tile, MP_TUNNELBRIDGE)) {
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4021
diff changeset
   132
		if (IsTunnel(tile)) {
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3463
diff changeset
   133
			*tileh = SLOPE_FLAT;
3451
0e8ccac68fdf (svn r4283) -Cleanup: More elrail housekeeping, remove code dublication, more meaningful variable names, simplify control flow..
celestar
parents: 3449
diff changeset
   134
		} else {
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4021
diff changeset
   135
			if (IsBridgeRamp(tile)) {
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4021
diff changeset
   136
				if (*tileh != SLOPE_FLAT) {
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4021
diff changeset
   137
					*tileh = SLOPE_FLAT;
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4021
diff changeset
   138
				} else {
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4021
diff changeset
   139
					switch (GetBridgeRampDirection(tile)) {
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4021
diff changeset
   140
						case DIAGDIR_NE: *tileh = SLOPE_NE; break;
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4021
diff changeset
   141
						case DIAGDIR_SE: *tileh = SLOPE_SE; break;
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4021
diff changeset
   142
						case DIAGDIR_SW: *tileh = SLOPE_SW; break;
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4021
diff changeset
   143
						case DIAGDIR_NW: *tileh = SLOPE_NW; break;
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4021
diff changeset
   144
						default: break;
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4021
diff changeset
   145
					}
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4021
diff changeset
   146
				}
3451
0e8ccac68fdf (svn r4283) -Cleanup: More elrail housekeeping, remove code dublication, more meaningful variable names, simplify control flow..
celestar
parents: 3449
diff changeset
   147
			}
0e8ccac68fdf (svn r4283) -Cleanup: More elrail housekeeping, remove code dublication, more meaningful variable names, simplify control flow..
celestar
parents: 3449
diff changeset
   148
		}
0e8ccac68fdf (svn r4283) -Cleanup: More elrail housekeeping, remove code dublication, more meaningful variable names, simplify control flow..
celestar
parents: 3449
diff changeset
   149
	}
0e8ccac68fdf (svn r4283) -Cleanup: More elrail housekeeping, remove code dublication, more meaningful variable names, simplify control flow..
celestar
parents: 3449
diff changeset
   150
}
0e8ccac68fdf (svn r4283) -Cleanup: More elrail housekeeping, remove code dublication, more meaningful variable names, simplify control flow..
celestar
parents: 3449
diff changeset
   151
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
   152
/** Draws wires and, if required, pylons on a given tile
4549
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4480
diff changeset
   153
 * @param ti The Tileinfo to draw the tile for
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4480
diff changeset
   154
 */
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
   155
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
   156
{
e414a0b104a6 (svn r4150) -Feature: Merged elrails into 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
	/* Pylons are placed on a tile edge, so we need to take into account
4549
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4480
diff changeset
   158
	 * the track configuration of 2 adjacent tiles. trackconfig[0] stores the
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4480
diff changeset
   159
	 * current tile (home tile) while [1] holds the 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
   160
	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
   161
	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
   162
	/* Note that ti->tileh has already been adjusted for Foundations */
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3463
diff changeset
   163
	Slope tileh[TS_END] = { ti->tileh, SLOPE_FLAT };
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
   164
e414a0b104a6 (svn r4150) -Feature: Merged elrails into 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
	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
   166
	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
   167
	byte OverridePCP = 0;
3395
edfd22fd92c9 (svn r4204) - Get trunk compiling again on OS/2
orudge
parents: 3378
diff changeset
   168
	byte PPPpreferred[DIAGDIR_END];
edfd22fd92c9 (svn r4204) - Get trunk compiling again on OS/2
orudge
parents: 3378
diff changeset
   169
	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
   170
	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
   171
	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
   172
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   173
	/* Find which rail bits are present, and select the override points.
4549
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4480
diff changeset
   174
	 * We don't draw a pylon:
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4480
diff changeset
   175
	 * 1) INSIDE a tunnel (we wouldn't see it anyway)
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4480
diff changeset
   176
	 * 2) on the "far" end of a bridge head (the one that connects to bridge middle),
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4480
diff changeset
   177
	 *    because that one is drawn on the bridge. Exception is for length 0 bridges
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4480
diff changeset
   178
	 *    which have no middle 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
   179
	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
   180
	/* 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
   181
	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
   182
3451
0e8ccac68fdf (svn r4283) -Cleanup: More elrail housekeeping, remove code dublication, more meaningful variable names, simplify control flow..
celestar
parents: 3449
diff changeset
   183
	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
   184
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   185
	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
   186
		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
   187
		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
   188
		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
   189
e414a0b104a6 (svn r4150) -Feature: Merged elrails into 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
		/* Here's one of the main headaches. GetTileSlope does not correct for possibly
4549
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4480
diff changeset
   191
		 * existing foundataions, so we do have to do that manually later on.*/
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
   192
		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
   193
		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
   194
		if (IsTunnelTile(neighbour) && i != GetTunnelDirection(neighbour)) trackconfig[TS_NEIGHBOUR] = 0;
3461
098d2998fb0b (svn r4305) -Codechange: Minor elrail cleanup (Tron)
celestar
parents: 3452
diff changeset
   195
		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
   196
3451
0e8ccac68fdf (svn r4283) -Cleanup: More elrail housekeeping, remove code dublication, more meaningful variable names, simplify control flow..
celestar
parents: 3449
diff changeset
   197
		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
   198
		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
   199
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
   200
		/* We cycle through all the existing tracks at a PCP and see what
4549
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4480
diff changeset
   201
		 * 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
   202
		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
   203
			/* 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
   204
			if (TrackSourceTile[i][k] == TS_NEIGHBOUR &&
3977
513433ebd092 (svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents: 3971
diff changeset
   205
			    IsBridgeTile(neighbour) && IsBridgeRamp(neighbour) &&
4000
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3995
diff changeset
   206
			    GetBridgeRampDirection(neighbour) == ReverseDiagDir(i)) {
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3995
diff changeset
   207
				continue;
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3995
diff changeset
   208
			}
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
3451
0e8ccac68fdf (svn r4283) -Cleanup: More elrail housekeeping, remove code dublication, more meaningful variable names, simplify control flow..
celestar
parents: 3449
diff changeset
   210
			/* We check whether the track in question (k) is present in the tile
4549
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4480
diff changeset
   211
			 * (TrackSourceTile) */
3451
0e8ccac68fdf (svn r4283) -Cleanup: More elrail housekeeping, remove code dublication, more meaningful variable names, simplify control flow..
celestar
parents: 3449
diff changeset
   212
			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
   213
				/* track found, if track is in the neighbour tile, adjust the number
4549
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4480
diff changeset
   214
				 * of the PCP for preferred/allowed determination*/
3451
0e8ccac68fdf (svn r4283) -Cleanup: More elrail housekeeping, remove code dublication, more meaningful variable names, simplify control flow..
celestar
parents: 3449
diff changeset
   215
				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
   216
				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
   217
0e8ccac68fdf (svn r4283) -Cleanup: More elrail housekeeping, remove code dublication, more meaningful variable names, simplify control flow..
celestar
parents: 3449
diff changeset
   218
				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
   219
				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
   220
			}
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   221
		}
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   222
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   223
		/* 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
   224
		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
   225
		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
   226
3880
b493c5318c9b (svn r4934) -Fix: Correct a misleading comment, and remove an unneeded condition from the corresponding if (thans Tron for pointing it out)
celestar
parents: 3793
diff changeset
   227
		/* A station is always "flat", so adjust the tileh accordingly */
b493c5318c9b (svn r4934) -Fix: Correct a misleading comment, and remove an unneeded condition from the corresponding if (thans Tron for pointing it out)
celestar
parents: 3793
diff changeset
   228
		if (IsTileType(neighbour, MP_STATION)) tileh[TS_NEIGHBOUR] = SLOPE_FLAT;
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
   229
e414a0b104a6 (svn r4150) -Feature: Merged elrails into 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
		/* Read the foundataions if they are present, and adjust the tileh */
4448
f19eae76b448 (svn r6226) -Fix(r5864): an assertion was triggered when drawing catenary on steep slopes (TrueLight)
glx
parents: 4182
diff changeset
   231
		if (IsTileType(neighbour, MP_RAILWAY) && GetRailType(neighbour) == RAILTYPE_ELECTRIC) foundation = GetRailFoundation(tileh[TS_NEIGHBOUR], trackconfig[TS_NEIGHBOUR]);
3977
513433ebd092 (svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents: 3971
diff changeset
   232
		if (IsBridgeTile(neighbour) && IsBridgeRamp(neighbour)) {
3368
d57156668a59 (svn r4165) -Do not use GetBridgeAxis on bridge ramps (request by Tron)
celestar
parents: 3367
diff changeset
   233
			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
   234
		}
d57156668a59 (svn r4165) -Do not use GetBridgeAxis on bridge ramps (request by Tron)
celestar
parents: 3367
diff changeset
   235
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
   236
		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
   237
			if (foundation < 15) {
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3463
diff changeset
   238
				tileh[TS_NEIGHBOUR] = SLOPE_FLAT;
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
   239
			} 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
   240
				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
   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
		}
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   243
3451
0e8ccac68fdf (svn r4283) -Cleanup: More elrail housekeeping, remove code dublication, more meaningful variable names, simplify control flow..
celestar
parents: 3449
diff changeset
   244
		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
   245
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   246
		/* If we have a straight (and level) track, we want a pylon only every 2 tiles
4549
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4480
diff changeset
   247
		 * Delete the PCP if this is the case. */
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
		/* 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
   249
		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
   250
			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
   251
				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
   252
		}
e414a0b104a6 (svn r4150) -Feature: Merged elrails into 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
3451
0e8ccac68fdf (svn r4283) -Cleanup: More elrail housekeeping, remove code dublication, more meaningful variable names, simplify control flow..
celestar
parents: 3449
diff changeset
   254
		/* Now decide where we draw our pylons. First try the preferred PPPs, but they may not exist.
4549
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4480
diff changeset
   255
		 * In that case, we try the any of the allowed ones. if they don't exist either, don't draw
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4480
diff changeset
   256
		 * anything. Note that the preferred PPPs still contain the end-of-line markers.
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4480
diff changeset
   257
		 * Remove those (simply by ANDing with allowed, since these markers are never allowed) */
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4021
diff changeset
   258
		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
   259
3451
0e8ccac68fdf (svn r4283) -Cleanup: More elrail housekeeping, remove code dublication, more meaningful variable names, simplify control flow..
celestar
parents: 3449
diff changeset
   260
		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
   261
			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
   262
				byte temp = PPPorder[i][GetTLG(ti->tile)][k];
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4021
diff changeset
   263
3451
0e8ccac68fdf (svn r4283) -Cleanup: More elrail housekeeping, remove code dublication, more meaningful variable names, simplify control flow..
celestar
parents: 3449
diff changeset
   264
				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
   265
					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
   266
					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
   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
					/* 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
   269
					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
   270
						/* 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
   271
						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
   272
						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
   273
					}
e414a0b104a6 (svn r4150) -Feature: Merged elrails into 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
					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
   276
							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
   277
					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
   278
				}
e414a0b104a6 (svn r4150) -Feature: Merged elrails into 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
			}
e414a0b104a6 (svn r4150) -Feature: Merged elrails into 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
	}
e414a0b104a6 (svn r4150) -Feature: Merged elrails into 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
4480
e7d8faa8ba93 (svn r6265) Check whether to draw catenary at all once before the drawing loop instead of on every iteration
tron
parents: 4470
diff changeset
   283
	/* Don't draw a wire under a low bridge */
e7d8faa8ba93 (svn r6265) Check whether to draw catenary at all once before the drawing loop instead of on every iteration
tron
parents: 4470
diff changeset
   284
	if (IsBridgeTile(ti->tile) &&
e7d8faa8ba93 (svn r6265) Check whether to draw catenary at all once before the drawing loop instead of on every iteration
tron
parents: 4470
diff changeset
   285
			IsBridgeMiddle(ti->tile) &&
e7d8faa8ba93 (svn r6265) Check whether to draw catenary at all once before the drawing loop instead of on every iteration
tron
parents: 4470
diff changeset
   286
			!(_display_opt & DO_TRANS_BUILDINGS) &&
e7d8faa8ba93 (svn r6265) Check whether to draw catenary at all once before the drawing loop instead of on every iteration
tron
parents: 4470
diff changeset
   287
			GetBridgeHeight(ti->tile) <= TilePixelHeight(ti->tile) + TILE_HEIGHT) {
e7d8faa8ba93 (svn r6265) Check whether to draw catenary at all once before the drawing loop instead of on every iteration
tron
parents: 4470
diff changeset
   288
		return;
e7d8faa8ba93 (svn r6265) Check whether to draw catenary at all once before the drawing loop instead of on every iteration
tron
parents: 4470
diff changeset
   289
	}
e7d8faa8ba93 (svn r6265) Check whether to draw catenary at all once before the drawing loop instead of on every iteration
tron
parents: 4470
diff changeset
   290
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
   291
	/* 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
   292
	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
   293
		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
   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
			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
   296
				(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
   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
			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
   299
			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
   300
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   301
			assert(PCPconfig != 0); /* We have a pylon on neither end of the wire, that doesn't work (since we have no sprites for that) */
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3463
diff changeset
   302
			assert(!IsSteepSlope(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
   303
			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
   304
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   305
			AddSortableSpriteToDraw( sss->image, ti->x + sss->x_offset, ti->y + sss->y_offset,
3645
7f950533d510 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3636
diff changeset
   306
				sss->x_size, sss->y_size, sss->z_size, GetSlopeZ(ti->x + min(sss->x_offset, TILE_SIZE - 1), ti->y + min(sss->y_offset, TILE_SIZE - 1)) + sss->z_offset);
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
   307
		}
e414a0b104a6 (svn r4150) -Feature: Merged elrails into 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
	}
e414a0b104a6 (svn r4150) -Feature: Merged elrails into 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
e414a0b104a6 (svn r4150) -Feature: Merged elrails into 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
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
   312
{
3445
972e0aa84c51 (svn r4276) -Codechange: Cleaned DrawCatenaryOnBridge a bit (requested by Tron)
celestar
parents: 3405
diff changeset
   313
	TileIndex end = GetSouthernBridgeEnd(ti->tile);
972e0aa84c51 (svn r4276) -Codechange: Cleaned DrawCatenaryOnBridge a bit (requested by Tron)
celestar
parents: 3405
diff changeset
   314
	TileIndex start = GetOtherBridgeEnd(end);
972e0aa84c51 (svn r4276) -Codechange: Cleaned DrawCatenaryOnBridge a bit (requested by Tron)
celestar
parents: 3405
diff changeset
   315
972e0aa84c51 (svn r4276) -Codechange: Cleaned DrawCatenaryOnBridge a bit (requested by Tron)
celestar
parents: 3405
diff changeset
   316
	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
   317
	uint num = DistanceMax(ti->tile, start);
4159
fc1d8605596d (svn r5584) When drawing catenary on a bridge calculate its height only once
tron
parents: 4158
diff changeset
   318
	uint height;
3445
972e0aa84c51 (svn r4276) -Codechange: Cleaned DrawCatenaryOnBridge a bit (requested by Tron)
celestar
parents: 3405
diff changeset
   319
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
   320
	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
   321
	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
   322
	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
   323
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   324
	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
   325
e414a0b104a6 (svn r4150) -Feature: Merged elrails into 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 ((length % 2) && num == length) {
3445
972e0aa84c51 (svn r4276) -Codechange: Cleaned DrawCatenaryOnBridge a bit (requested by Tron)
celestar
parents: 3405
diff changeset
   327
		/* 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
   328
		 * 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
   329
		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
   330
	} else {
3445
972e0aa84c51 (svn r4276) -Codechange: Cleaned DrawCatenaryOnBridge a bit (requested by Tron)
celestar
parents: 3405
diff changeset
   331
		/* 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
   332
		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
   333
	}
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   334
4159
fc1d8605596d (svn r5584) When drawing catenary on a bridge calculate its height only once
tron
parents: 4158
diff changeset
   335
	height = GetBridgeHeight(ti->tile);
fc1d8605596d (svn r5584) When drawing catenary on a bridge calculate its height only once
tron
parents: 4158
diff changeset
   336
3445
972e0aa84c51 (svn r4276) -Codechange: Cleaned DrawCatenaryOnBridge a bit (requested by Tron)
celestar
parents: 3405
diff changeset
   337
	AddSortableSpriteToDraw( sss->image, ti->x + sss->x_offset, ti->y + sss->y_offset,
4159
fc1d8605596d (svn r5584) When drawing catenary on a bridge calculate its height only once
tron
parents: 4158
diff changeset
   338
		sss->x_size, sss->y_size, sss->z_size, height + sss->z_offset
fc1d8605596d (svn r5584) When drawing catenary on a bridge calculate its height only once
tron
parents: 4158
diff changeset
   339
	);
3445
972e0aa84c51 (svn r4276) -Codechange: Cleaned DrawCatenaryOnBridge a bit (requested by Tron)
celestar
parents: 3405
diff changeset
   340
972e0aa84c51 (svn r4276) -Codechange: Cleaned DrawCatenaryOnBridge a bit (requested by Tron)
celestar
parents: 3405
diff changeset
   341
	/* Finished with wires, draw pylons */
972e0aa84c51 (svn r4276) -Codechange: Cleaned DrawCatenaryOnBridge a bit (requested by Tron)
celestar
parents: 3405
diff changeset
   342
	/* 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
   343
	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
   344
		if (axis == AXIS_X) {
4159
fc1d8605596d (svn r5584) When drawing catenary on a bridge calculate its height only once
tron
parents: 4158
diff changeset
   345
			AddSortableSpriteToDraw(pylons_bridge[0 + HASBIT(tlg, 0)], ti->x, ti->y + 4 + 8 * HASBIT(tlg, 0), 1, 1, 10, height);
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
   346
		} else {
4159
fc1d8605596d (svn r5584) When drawing catenary on a bridge calculate its height only once
tron
parents: 4158
diff changeset
   347
			AddSortableSpriteToDraw(pylons_bridge[2 + HASBIT(tlg, 1)], ti->x + 4 + 8 * HASBIT(tlg, 1), ti->y, 1, 1, 10, height);
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
   348
		}
e414a0b104a6 (svn r4150) -Feature: Merged elrails into 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
	}
e414a0b104a6 (svn r4150) -Feature: Merged elrails into 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
3445
972e0aa84c51 (svn r4276) -Codechange: Cleaned DrawCatenaryOnBridge a bit (requested by Tron)
celestar
parents: 3405
diff changeset
   351
	/* 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
   352
	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
   353
		if (axis == AXIS_X) {
4159
fc1d8605596d (svn r5584) When drawing catenary on a bridge calculate its height only once
tron
parents: 4158
diff changeset
   354
			AddSortableSpriteToDraw(pylons_bridge[0 + HASBIT(tlg, 0)], ti->x + 16, ti->y + 4 + 8 * HASBIT(tlg, 0), 1, 1, 10, height);
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
   355
		} else {
4159
fc1d8605596d (svn r5584) When drawing catenary on a bridge calculate its height only once
tron
parents: 4158
diff changeset
   356
			AddSortableSpriteToDraw(pylons_bridge[2 + HASBIT(tlg, 1)], ti->x + 4 + 8 * HASBIT(tlg, 1), ti->y + 16, 1, 1, 10, height);
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
   357
		}
e414a0b104a6 (svn r4150) -Feature: Merged elrails into 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
	}
e414a0b104a6 (svn r4150) -Feature: Merged elrails into 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
}
e414a0b104a6 (svn r4150) -Feature: Merged elrails into 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
e414a0b104a6 (svn r4150) -Feature: Merged elrails into 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
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
   362
{
e414a0b104a6 (svn r4150) -Feature: Merged elrails into 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
	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
   364
		case MP_RAILWAY:
4182
48dba107ff43 (svn r5624) Use {IsPlainRailTile,IsRailDepot,IsRailWaypoint,HasSignals}() instead of GetRailTile{T,Subt}ype() - this is more concise and a bit more flexible if/when the rail tile encoding changes
tron
parents: 4171
diff changeset
   365
			if (IsRailDepot(ti->tile)) {
4470
4518cc0ec616 (svn r6255) Simplify drawing of catenary in depots
tron
parents: 4448
diff changeset
   366
				const SortableSpriteStruct* sss = &CatenarySpriteData_Depot[GetRailDepotDirection(ti->tile)];
4518cc0ec616 (svn r6255) Simplify drawing of catenary in depots
tron
parents: 4448
diff changeset
   367
4518cc0ec616 (svn r6255) Simplify drawing of catenary in depots
tron
parents: 4448
diff changeset
   368
				AddSortableSpriteToDraw(
4518cc0ec616 (svn r6255) Simplify drawing of catenary in depots
tron
parents: 4448
diff changeset
   369
					sss->image, ti->x + sss->x_offset, ti->y + sss->y_offset,
4518cc0ec616 (svn r6255) Simplify drawing of catenary in depots
tron
parents: 4448
diff changeset
   370
					sss->x_size, sss->y_size, sss->z_size,
4518cc0ec616 (svn r6255) Simplify drawing of catenary in depots
tron
parents: 4448
diff changeset
   371
					GetTileMaxZ(ti->tile) + sss->z_offset
4518cc0ec616 (svn r6255) Simplify drawing of catenary in depots
tron
parents: 4448
diff changeset
   372
				);
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
   373
				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
   374
			}
3995
2b86d5a99f0f (svn r5198) Fix some strange control flow: the case for MP_RAILWAY fell through the case for MP_TUNNELBRIDGE
tron
parents: 3977
diff changeset
   375
			break;
2b86d5a99f0f (svn r5198) Fix some strange control flow: the case for MP_RAILWAY fell through the case for MP_TUNNELBRIDGE
tron
parents: 3977
diff changeset
   376
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
   377
		case MP_TUNNELBRIDGE:
3995
2b86d5a99f0f (svn r5198) Fix some strange control flow: the case for MP_RAILWAY fell through the case for MP_TUNNELBRIDGE
tron
parents: 3977
diff changeset
   378
			if (IsBridge(ti->tile) && IsBridgeMiddle(ti->tile) && GetRailTypeOnBridge(ti->tile) == RAILTYPE_ELECTRIC) DrawCatenaryOnBridge(ti);
3355
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   379
			break;
3995
2b86d5a99f0f (svn r5198) Fix some strange control flow: the case for MP_RAILWAY fell through the case for MP_TUNNELBRIDGE
tron
parents: 3977
diff changeset
   380
2b86d5a99f0f (svn r5198) Fix some strange control flow: the case for MP_RAILWAY fell through the case for MP_TUNNELBRIDGE
tron
parents: 3977
diff changeset
   381
		case MP_STREET:  break;
2b86d5a99f0f (svn r5198) Fix some strange control flow: the case for MP_RAILWAY fell through the case for MP_TUNNELBRIDGE
tron
parents: 3977
diff changeset
   382
		case MP_STATION: break;
2b86d5a99f0f (svn r5198) Fix some strange control flow: the case for MP_RAILWAY fell through the case for MP_TUNNELBRIDGE
tron
parents: 3977
diff changeset
   383
2b86d5a99f0f (svn r5198) Fix some strange control flow: the case for MP_RAILWAY fell through the case for MP_TUNNELBRIDGE
tron
parents: 3977
diff changeset
   384
		default: return;
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
   385
	}
3995
2b86d5a99f0f (svn r5198) Fix some strange control flow: the case for MP_RAILWAY fell through the case for MP_TUNNELBRIDGE
tron
parents: 3977
diff changeset
   386
	DrawCatenaryRailway(ti);
3355
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   387
}