src/elrail.cpp
author peter1138
Tue, 22 Jan 2008 07:27:06 +0000
changeset 8374 7a1b6c89cb89
parent 8270 e7c342f6b14c
child 8398 1e181e2e4e15
permissions -rw-r--r--
(svn r11940) -Codechange: Store short filename once per open file instead of once per sprite cache entry. Not all file types need this, but most of the time no sprite cache entry needed it either.
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$ */
6117
6507b2a7e71d (svn r8853) -Cleanup: doxygen changes. Correct forgotten c files to cpp files with the @file tag as well as a few general comments style
belugas
parents: 5823
diff changeset
     2
/** @file elrail.cpp
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"
8224
c5a64d87cc54 (svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents: 8144
diff changeset
    51
#include "viewport_func.h"
8270
e7c342f6b14c (svn r11834) -Codechange: only include settings_type.h if needed.
rubidium
parents: 8264
diff changeset
    52
#include "settings_type.h"
6453
226bcddeba32 (svn r9609) -Codechange: Move some function prototypes out of functions.h and into landscape.h, and add a few where they didn't exist.
maedhros
parents: 6450
diff changeset
    53
#include "landscape.h"
8103
cf92483a0abf (svn r11664) -Codechange: use more specific ("rail_type.h" instead of "rail.h" that includes way more than only "rail_type.h") includes at some places.
rubidium
parents: 8088
diff changeset
    54
#include "rail_type.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
    55
#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
    56
#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
    57
#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
    58
#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
    59
#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
    60
#include "rail_map.h"
5116
3c0c3da214ca (svn r7195) -Feature: [FS#297, optional elrails] New patches/vehicles option 'disable electrified railways'.
KUDr
parents: 4559
diff changeset
    61
#include "train.h"
8111
02d19f43eea6 (svn r11672) -Codechange: refactor some stuff out of gui.h.
rubidium
parents: 8108
diff changeset
    62
#include "rail_gui.h"
7849
0a1c0af2c96c (svn r11399) -Feature(ette): transparency settings can now be saved and thus remembered.
belugas
parents: 7764
diff changeset
    63
#include "transparency.h"
8083
ad22eade501f (svn r11644) -Codechange: merge some functions from tunnel_map.h and bridge_map.h into tunnelbridge_map.h
smatz
parents: 7931
diff changeset
    64
#include "tunnelbridge_map.h"
8144
65cec0877b78 (svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium
parents: 8131
diff changeset
    65
#include "vehicle_func.h"
8254
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents: 8237
diff changeset
    66
#include "player_base.h"
8083
ad22eade501f (svn r11644) -Codechange: merge some functions from tunnel_map.h and bridge_map.h into tunnelbridge_map.h
smatz
parents: 7931
diff changeset
    67
8264
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8254
diff changeset
    68
#include "table/sprites.h"
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8254
diff changeset
    69
#include "table/elrail_data.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
    70
e414a0b104a6 (svn r4150) -Feature: Merged elrails into 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
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
    72
{
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7849
diff changeset
    73
	return (TLG)((HasBit(TileX(t), 0) << 1) + HasBit(TileY(t), 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
    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
e414a0b104a6 (svn r4150) -Feature: Merged elrails into 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
/** 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
    77
 * returns track bits under the bridge
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4480
diff changeset
    78
 */
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
    79
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
    80
{
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
    81
	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
    82
		case MP_RAILWAY:
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
    83
			if (GetRailType(t) != RAILTYPE_ELECTRIC) return TRACK_BIT_NONE;
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
    84
			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
    85
				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
    86
					return GetTrackBits(t);
6172
e6d7a5b3d63f (svn r8935) -Codechange: unification of track type between road and rail tiles, unification of ground type between normal rail tiles and depots/waypoints and removing the need for RailTileSubType.
rubidium
parents: 6117
diff changeset
    87
				case RAIL_TILE_WAYPOINT:
e6d7a5b3d63f (svn r8935) -Codechange: unification of track type between road and rail tiles, unification of ground type between normal rail tiles and depots/waypoints and removing the need for RailTileSubType.
rubidium
parents: 6117
diff changeset
    88
					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
    89
				default:
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
    90
					return TRACK_BIT_NONE;
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
    91
			}
e414a0b104a6 (svn r4150) -Feature: Merged elrails into 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
			break;
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4021
diff changeset
    93
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
    94
		case MP_TUNNELBRIDGE:
8088
92fca5b09665 (svn r11649) -Codechange: some code can be simplified thanks to changes in r11642
smatz
parents: 8083
diff changeset
    95
			if (GetRailType(t) != RAILTYPE_ELECTRIC) return TRACK_BIT_NONE;
92fca5b09665 (svn r11649) -Codechange: some code can be simplified thanks to changes in r11642
smatz
parents: 8083
diff changeset
    96
			if (override != NULL && (IsTunnel(t) || DistanceMax(t, GetOtherBridgeEnd(t)) > 1)) {
92fca5b09665 (svn r11649) -Codechange: some code can be simplified thanks to changes in r11642
smatz
parents: 8083
diff changeset
    97
				*override = 1 << GetTunnelBridgeDirection(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
    98
			}
8088
92fca5b09665 (svn r11649) -Codechange: some code can be simplified thanks to changes in r11642
smatz
parents: 8083
diff changeset
    99
			return AxisToTrackBits(DiagDirToAxis(GetTunnelBridgeDirection(t)));
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4021
diff changeset
   100
7370
41adc721b1fa (svn r10733) -Codechange: change MP_STREET into MP_ROAD as we use the word "road" everywhere except in the tile type.
rubidium
parents: 7335
diff changeset
   101
		case MP_ROAD:
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   102
			if (GetRoadTileType(t) != ROAD_TILE_CROSSING) return TRACK_BIT_NONE;
6172
e6d7a5b3d63f (svn r8935) -Codechange: unification of track type between road and rail tiles, unification of ground type between normal rail tiles and depots/waypoints and removing the need for RailTileSubType.
rubidium
parents: 6117
diff changeset
   103
			if (GetRailType(t) != RAILTYPE_ELECTRIC) return TRACK_BIT_NONE;
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
   104
			return GetCrossingRailBits(t);
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4021
diff changeset
   105
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
		case MP_STATION:
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   107
			if (!IsRailwayStation(t)) return TRACK_BIT_NONE;
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   108
			if (GetRailType(t) != RAILTYPE_ELECTRIC) return TRACK_BIT_NONE;
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   109
			if (!IsStationTileElectrifiable(t)) return TRACK_BIT_NONE;
3375
5f3ddc988795 (svn r4177) -Fix: GetRailTrackBitsUniversal needs Trackbits, not Track. While at it, remove an unused variable
celestar
parents: 3368
diff changeset
   110
			return TrackToTrackBits(GetRailStationTrack(t));
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4021
diff changeset
   111
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
		default:
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   113
			return TRACK_BIT_NONE;
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
	}
e414a0b104a6 (svn r4150) -Feature: Merged elrails into 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
}
e414a0b104a6 (svn r4150) -Feature: Merged elrails into 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
3451
0e8ccac68fdf (svn r4283) -Cleanup: More elrail housekeeping, remove code dublication, more meaningful variable names, simplify control flow..
celestar
parents: 3449
diff changeset
   117
/** 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
   118
 * @param tile The tile to analyse
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4480
diff changeset
   119
 * @param *tileh the tileh
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4480
diff changeset
   120
 */
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4159
diff changeset
   121
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
   122
{
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4021
diff changeset
   123
	if (IsTileType(tile, MP_TUNNELBRIDGE)) {
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4021
diff changeset
   124
		if (IsTunnel(tile)) {
6269
3e10e20eecff (svn r9078) -Codechange: coding style.
rubidium
parents: 6268
diff changeset
   125
			*tileh = SLOPE_STEEP; // XXX - Hack to make tunnel entrances to always have a pylon
3e10e20eecff (svn r9078) -Codechange: coding style.
rubidium
parents: 6268
diff changeset
   126
		} else if (*tileh != SLOPE_FLAT) {
3e10e20eecff (svn r9078) -Codechange: coding style.
rubidium
parents: 6268
diff changeset
   127
			*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
   128
		} else {
8083
ad22eade501f (svn r11644) -Codechange: merge some functions from tunnel_map.h and bridge_map.h into tunnelbridge_map.h
smatz
parents: 7931
diff changeset
   129
			switch (GetTunnelBridgeDirection(tile)) {
6269
3e10e20eecff (svn r9078) -Codechange: coding style.
rubidium
parents: 6268
diff changeset
   130
				case DIAGDIR_NE: *tileh = SLOPE_NE; break;
3e10e20eecff (svn r9078) -Codechange: coding style.
rubidium
parents: 6268
diff changeset
   131
				case DIAGDIR_SE: *tileh = SLOPE_SE; break;
3e10e20eecff (svn r9078) -Codechange: coding style.
rubidium
parents: 6268
diff changeset
   132
				case DIAGDIR_SW: *tileh = SLOPE_SW; break;
3e10e20eecff (svn r9078) -Codechange: coding style.
rubidium
parents: 6268
diff changeset
   133
				case DIAGDIR_NW: *tileh = SLOPE_NW; break;
3e10e20eecff (svn r9078) -Codechange: coding style.
rubidium
parents: 6268
diff changeset
   134
				default: NOT_REACHED();
3451
0e8ccac68fdf (svn r4283) -Cleanup: More elrail housekeeping, remove code dublication, more meaningful variable names, simplify control flow..
celestar
parents: 3449
diff changeset
   135
			}
0e8ccac68fdf (svn r4283) -Cleanup: More elrail housekeeping, remove code dublication, more meaningful variable names, simplify control flow..
celestar
parents: 3449
diff changeset
   136
		}
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
7534
2e4dcc2c3bc9 (svn r11054) -Fix [FS#944]: mismatch between TTDP's and OTTD's placement of catenary, creating graphical glitches when loading a catenary replacement. Patch by frosch.
rubidium
parents: 7472
diff changeset
   140
/**
2e4dcc2c3bc9 (svn r11054) -Fix [FS#944]: mismatch between TTDP's and OTTD's placement of catenary, creating graphical glitches when loading a catenary replacement. Patch by frosch.
rubidium
parents: 7472
diff changeset
   141
 * Returns the Z position of a Pylon Control Point.
2e4dcc2c3bc9 (svn r11054) -Fix [FS#944]: mismatch between TTDP's and OTTD's placement of catenary, creating graphical glitches when loading a catenary replacement. Patch by frosch.
rubidium
parents: 7472
diff changeset
   142
 *
2e4dcc2c3bc9 (svn r11054) -Fix [FS#944]: mismatch between TTDP's and OTTD's placement of catenary, creating graphical glitches when loading a catenary replacement. Patch by frosch.
rubidium
parents: 7472
diff changeset
   143
 * @param tile The tile the pylon should stand on.
2e4dcc2c3bc9 (svn r11054) -Fix [FS#944]: mismatch between TTDP's and OTTD's placement of catenary, creating graphical glitches when loading a catenary replacement. Patch by frosch.
rubidium
parents: 7472
diff changeset
   144
 * @param PCPpos The PCP of the tile.
2e4dcc2c3bc9 (svn r11054) -Fix [FS#944]: mismatch between TTDP's and OTTD's placement of catenary, creating graphical glitches when loading a catenary replacement. Patch by frosch.
rubidium
parents: 7472
diff changeset
   145
 * @return The Z position of the PCP.
2e4dcc2c3bc9 (svn r11054) -Fix [FS#944]: mismatch between TTDP's and OTTD's placement of catenary, creating graphical glitches when loading a catenary replacement. Patch by frosch.
rubidium
parents: 7472
diff changeset
   146
 */
2e4dcc2c3bc9 (svn r11054) -Fix [FS#944]: mismatch between TTDP's and OTTD's placement of catenary, creating graphical glitches when loading a catenary replacement. Patch by frosch.
rubidium
parents: 7472
diff changeset
   147
static byte GetPCPElevation(TileIndex tile, DiagDirection PCPpos)
2e4dcc2c3bc9 (svn r11054) -Fix [FS#944]: mismatch between TTDP's and OTTD's placement of catenary, creating graphical glitches when loading a catenary replacement. Patch by frosch.
rubidium
parents: 7472
diff changeset
   148
{
2e4dcc2c3bc9 (svn r11054) -Fix [FS#944]: mismatch between TTDP's and OTTD's placement of catenary, creating graphical glitches when loading a catenary replacement. Patch by frosch.
rubidium
parents: 7472
diff changeset
   149
	/* The elevation of the "pylon"-sprite should be the elevation at the PCP.
2e4dcc2c3bc9 (svn r11054) -Fix [FS#944]: mismatch between TTDP's and OTTD's placement of catenary, creating graphical glitches when loading a catenary replacement. Patch by frosch.
rubidium
parents: 7472
diff changeset
   150
	 * PCPs are always on a tile edge.
2e4dcc2c3bc9 (svn r11054) -Fix [FS#944]: mismatch between TTDP's and OTTD's placement of catenary, creating graphical glitches when loading a catenary replacement. Patch by frosch.
rubidium
parents: 7472
diff changeset
   151
	 *
2e4dcc2c3bc9 (svn r11054) -Fix [FS#944]: mismatch between TTDP's and OTTD's placement of catenary, creating graphical glitches when loading a catenary replacement. Patch by frosch.
rubidium
parents: 7472
diff changeset
   152
	 * This position can be outside of the tile, i.e. ?_pcp_offset == TILE_SIZE > TILE_SIZE - 1.
2e4dcc2c3bc9 (svn r11054) -Fix [FS#944]: mismatch between TTDP's and OTTD's placement of catenary, creating graphical glitches when loading a catenary replacement. Patch by frosch.
rubidium
parents: 7472
diff changeset
   153
	 * So we have to move it inside the tile, because if the neighboured tile has a foundation,
2e4dcc2c3bc9 (svn r11054) -Fix [FS#944]: mismatch between TTDP's and OTTD's placement of catenary, creating graphical glitches when loading a catenary replacement. Patch by frosch.
rubidium
parents: 7472
diff changeset
   154
	 * that does not smoothly connect to the current tile, we will get a wrong elevation from GetSlopeZ().
2e4dcc2c3bc9 (svn r11054) -Fix [FS#944]: mismatch between TTDP's and OTTD's placement of catenary, creating graphical glitches when loading a catenary replacement. Patch by frosch.
rubidium
parents: 7472
diff changeset
   155
	 *
2e4dcc2c3bc9 (svn r11054) -Fix [FS#944]: mismatch between TTDP's and OTTD's placement of catenary, creating graphical glitches when loading a catenary replacement. Patch by frosch.
rubidium
parents: 7472
diff changeset
   156
	 * When we move the position inside the tile, we will get a wrong elevation if we have a slope.
2e4dcc2c3bc9 (svn r11054) -Fix [FS#944]: mismatch between TTDP's and OTTD's placement of catenary, creating graphical glitches when loading a catenary replacement. Patch by frosch.
rubidium
parents: 7472
diff changeset
   157
	 * To catch all cases we round the Z position to the next (TILE_HEIGHT / 2).
2e4dcc2c3bc9 (svn r11054) -Fix [FS#944]: mismatch between TTDP's and OTTD's placement of catenary, creating graphical glitches when loading a catenary replacement. Patch by frosch.
rubidium
parents: 7472
diff changeset
   158
	 * This will return the correct elevation for slopes and will also detect non-continuous elevation on edges.
2e4dcc2c3bc9 (svn r11054) -Fix [FS#944]: mismatch between TTDP's and OTTD's placement of catenary, creating graphical glitches when loading a catenary replacement. Patch by frosch.
rubidium
parents: 7472
diff changeset
   159
	 *
2e4dcc2c3bc9 (svn r11054) -Fix [FS#944]: mismatch between TTDP's and OTTD's placement of catenary, creating graphical glitches when loading a catenary replacement. Patch by frosch.
rubidium
parents: 7472
diff changeset
   160
	 * Also note that the result of GetSlopeZ() is very special on bridge-ramps.
2e4dcc2c3bc9 (svn r11054) -Fix [FS#944]: mismatch between TTDP's and OTTD's placement of catenary, creating graphical glitches when loading a catenary replacement. Patch by frosch.
rubidium
parents: 7472
diff changeset
   161
	 */
2e4dcc2c3bc9 (svn r11054) -Fix [FS#944]: mismatch between TTDP's and OTTD's placement of catenary, creating graphical glitches when loading a catenary replacement. Patch by frosch.
rubidium
parents: 7472
diff changeset
   162
2e4dcc2c3bc9 (svn r11054) -Fix [FS#944]: mismatch between TTDP's and OTTD's placement of catenary, creating graphical glitches when loading a catenary replacement. Patch by frosch.
rubidium
parents: 7472
diff changeset
   163
	byte z = GetSlopeZ(TileX(tile) * TILE_SIZE + min(x_pcp_offsets[PCPpos], TILE_SIZE - 1), TileY(tile) * TILE_SIZE + min(y_pcp_offsets[PCPpos], TILE_SIZE - 1));
2e4dcc2c3bc9 (svn r11054) -Fix [FS#944]: mismatch between TTDP's and OTTD's placement of catenary, creating graphical glitches when loading a catenary replacement. Patch by frosch.
rubidium
parents: 7472
diff changeset
   164
	return (z + 2) & ~3; // this means z = (z + TILE_HEIGHT / 4) / (TILE_HEIGHT / 2) * (TILE_HEIGHT / 2);
2e4dcc2c3bc9 (svn r11054) -Fix [FS#944]: mismatch between TTDP's and OTTD's placement of catenary, creating graphical glitches when loading a catenary replacement. Patch by frosch.
rubidium
parents: 7472
diff changeset
   165
}
2e4dcc2c3bc9 (svn r11054) -Fix [FS#944]: mismatch between TTDP's and OTTD's placement of catenary, creating graphical glitches when loading a catenary replacement. Patch by frosch.
rubidium
parents: 7472
diff changeset
   166
7601
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7534
diff changeset
   167
/**
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7534
diff changeset
   168
 * Draws wires on a tunnel tile
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7534
diff changeset
   169
 *
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7534
diff changeset
   170
 * DrawTile_TunnelBridge() calls this function to draw the wires as SpriteCombine with the tunnel roof.
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7534
diff changeset
   171
 *
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7534
diff changeset
   172
 * @param ti The Tileinfo to draw the tile for
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7534
diff changeset
   173
 */
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7534
diff changeset
   174
void DrawCatenaryOnTunnel(const TileInfo *ti)
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7534
diff changeset
   175
{
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7534
diff changeset
   176
	/* xmin, ymin, xmax + 1, ymax + 1 of BB */
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7534
diff changeset
   177
	static const int _tunnel_wire_BB[4][4] = {
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7534
diff changeset
   178
		{ 0, 1, 16, 15 }, // NE
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7534
diff changeset
   179
		{ 1, 0, 15, 16 }, // SE
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7534
diff changeset
   180
		{ 0, 1, 16, 15 }, // SW
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7534
diff changeset
   181
		{ 1, 0, 15, 16 }, // NW
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7534
diff changeset
   182
	};
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7534
diff changeset
   183
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7534
diff changeset
   184
	if ((GetRailType(ti->tile) != RAILTYPE_ELECTRIC) || _patches.disable_elrails) return;
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7534
diff changeset
   185
8083
ad22eade501f (svn r11644) -Codechange: merge some functions from tunnel_map.h and bridge_map.h into tunnelbridge_map.h
smatz
parents: 7931
diff changeset
   186
	DiagDirection dir = GetTunnelBridgeDirection(ti->tile);
7601
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7534
diff changeset
   187
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7534
diff changeset
   188
	const SortableSpriteStruct *sss = &CatenarySpriteData_Tunnel[dir];
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7534
diff changeset
   189
	const int *BB_data = _tunnel_wire_BB[dir];
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7534
diff changeset
   190
	AddSortableSpriteToDraw(
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7534
diff changeset
   191
		sss->image, PAL_NONE, ti->x + sss->x_offset, ti->y + sss->y_offset,
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7534
diff changeset
   192
		BB_data[2] - sss->x_offset, BB_data[3] - sss->y_offset, BB_Z_SEPARATOR - sss->z_offset + 1,
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7534
diff changeset
   193
		GetTileZ(ti->tile) + sss->z_offset,
7849
0a1c0af2c96c (svn r11399) -Feature(ette): transparency settings can now be saved and thus remembered.
belugas
parents: 7764
diff changeset
   194
		IsTransparencySet(TO_BUILDINGS),
7601
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7534
diff changeset
   195
		BB_data[0] - sss->x_offset, BB_data[1] - sss->y_offset, BB_Z_SEPARATOR - sss->z_offset
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7534
diff changeset
   196
	);
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7534
diff changeset
   197
}
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7534
diff changeset
   198
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
   199
/** 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
   200
 * @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
   201
 */
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
   202
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
   203
{
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   204
	/* 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
   205
	 * 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
   206
	 * 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
   207
	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
   208
	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
   209
	/* 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
   210
	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
   211
7764
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7601
diff changeset
   212
	/* Half tile slopes coincide only with horizontal/vertical track.
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7601
diff changeset
   213
	 * Faking a flat slope results in the correct sprites on positions. */
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7601
diff changeset
   214
	if (IsHalftileSlope(tileh[TS_HOME])) tileh[TS_HOME] = SLOPE_FLAT;
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7601
diff changeset
   215
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
   216
	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
   217
	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
   218
	byte OverridePCP = 0;
3395
edfd22fd92c9 (svn r4204) - Get trunk compiling again on OS/2
orudge
parents: 3378
diff changeset
   219
	byte PPPpreferred[DIAGDIR_END];
edfd22fd92c9 (svn r4204) - Get trunk compiling again on OS/2
orudge
parents: 3378
diff changeset
   220
	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
   221
	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
   222
	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
   223
e414a0b104a6 (svn r4150) -Feature: Merged elrails into 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
	/* 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
   225
	 * We don't draw a pylon:
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4480
diff changeset
   226
	 * 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
   227
	 * 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
   228
	 *    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
   229
	 *    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
   230
	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
   231
	/* If a track bit is present that is not in the main direction, the track is level */
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   232
	isflat[TS_HOME] = ((trackconfig[TS_HOME] & (TRACK_BIT_HORZ | TRACK_BIT_VERT)) != 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
   233
3451
0e8ccac68fdf (svn r4283) -Cleanup: More elrail housekeeping, remove code dublication, more meaningful variable names, simplify control flow..
celestar
parents: 3449
diff changeset
   234
	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
   235
e414a0b104a6 (svn r4150) -Feature: Merged elrails into 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
	for (i = DIAGDIR_NE; i < DIAGDIR_END; i++) {
4559
aa0c13e39840 (svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents: 4549
diff changeset
   237
		TileIndex neighbour = ti->tile + TileOffsByDiagDir(i);
7335
141c6b86ec1f (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7333
diff changeset
   238
		Foundation foundation = FOUNDATION_NONE;
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
		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
   240
e414a0b104a6 (svn r4150) -Feature: Merged elrails into 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
		/* 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
   242
		 * 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
   243
		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
   244
		trackconfig[TS_NEIGHBOUR] = GetRailTrackBitsUniversal(neighbour, NULL);
8083
ad22eade501f (svn r11644) -Codechange: merge some functions from tunnel_map.h and bridge_map.h into tunnelbridge_map.h
smatz
parents: 7931
diff changeset
   245
		if (IsTunnelTile(neighbour) && i != GetTunnelBridgeDirection(neighbour)) trackconfig[TS_NEIGHBOUR] = TRACK_BIT_NONE;
7534
2e4dcc2c3bc9 (svn r11054) -Fix [FS#944]: mismatch between TTDP's and OTTD's placement of catenary, creating graphical glitches when loading a catenary replacement. Patch by frosch.
rubidium
parents: 7472
diff changeset
   246
2e4dcc2c3bc9 (svn r11054) -Fix [FS#944]: mismatch between TTDP's and OTTD's placement of catenary, creating graphical glitches when loading a catenary replacement. Patch by frosch.
rubidium
parents: 7472
diff changeset
   247
		/* If the neighboured tile does not smoothly connect to the current tile (because of a foundation),
2e4dcc2c3bc9 (svn r11054) -Fix [FS#944]: mismatch between TTDP's and OTTD's placement of catenary, creating graphical glitches when loading a catenary replacement. Patch by frosch.
rubidium
parents: 7472
diff changeset
   248
		 * we have to draw all pillars on the current tile. */
2e4dcc2c3bc9 (svn r11054) -Fix [FS#944]: mismatch between TTDP's and OTTD's placement of catenary, creating graphical glitches when loading a catenary replacement. Patch by frosch.
rubidium
parents: 7472
diff changeset
   249
		if (GetPCPElevation(ti->tile, i) != GetPCPElevation(neighbour, ReverseDiagDir(i))) trackconfig[TS_NEIGHBOUR] = TRACK_BIT_NONE;
2e4dcc2c3bc9 (svn r11054) -Fix [FS#944]: mismatch between TTDP's and OTTD's placement of catenary, creating graphical glitches when loading a catenary replacement. Patch by frosch.
rubidium
parents: 7472
diff changeset
   250
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   251
		isflat[TS_NEIGHBOUR] = ((trackconfig[TS_NEIGHBOUR] & (TRACK_BIT_HORZ | TRACK_BIT_VERT)) != 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
   252
6269
3e10e20eecff (svn r9078) -Codechange: coding style.
rubidium
parents: 6268
diff changeset
   253
		PPPpreferred[i] = 0xFF; // We start with preferring everything (end-of-line in any direction)
3451
0e8ccac68fdf (svn r4283) -Cleanup: More elrail housekeeping, remove code dublication, more meaningful variable names, simplify control flow..
celestar
parents: 3449
diff changeset
   254
		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
   255
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
   256
		/* 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
   257
		 * 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
   258
		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
   259
			/* 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
   260
			if (TrackSourceTile[i][k] == TS_NEIGHBOUR &&
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5314
diff changeset
   261
			    IsBridgeTile(neighbour) &&
8083
ad22eade501f (svn r11644) -Codechange: merge some functions from tunnel_map.h and bridge_map.h into tunnelbridge_map.h
smatz
parents: 7931
diff changeset
   262
			    GetTunnelBridgeDirection(neighbour) == ReverseDiagDir(i)) {
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
   263
				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
   264
			}
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
3451
0e8ccac68fdf (svn r4283) -Cleanup: More elrail housekeeping, remove code dublication, more meaningful variable names, simplify control flow..
celestar
parents: 3449
diff changeset
   266
			/* 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
   267
			 * (TrackSourceTile) */
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7849
diff changeset
   268
			if (HasBit(trackconfig[TrackSourceTile[i][k]], TracksAtPCP[i][k])) {
3451
0e8ccac68fdf (svn r4283) -Cleanup: More elrail housekeeping, remove code dublication, more meaningful variable names, simplify control flow..
celestar
parents: 3449
diff changeset
   269
				/* 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
   270
				 * 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
   271
				DiagDirection PCPpos = (TrackSourceTile[i][k] == TS_HOME) ? i : ReverseDiagDir(i);
7931
b0a46cd92225 (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents: 7929
diff changeset
   272
				SetBit(PCPstatus, i); // This PCP is in use
3451
0e8ccac68fdf (svn r4283) -Cleanup: More elrail housekeeping, remove code dublication, more meaningful variable names, simplify control flow..
celestar
parents: 3449
diff changeset
   273
0e8ccac68fdf (svn r4283) -Cleanup: More elrail housekeeping, remove code dublication, more meaningful variable names, simplify control flow..
celestar
parents: 3449
diff changeset
   274
				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
   275
				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
   276
			}
e414a0b104a6 (svn r4150) -Feature: Merged elrails into 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
e414a0b104a6 (svn r4150) -Feature: Merged elrails into 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
		/* Deactivate all PPPs if PCP is not used */
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7849
diff changeset
   280
		PPPpreferred[i] *= HasBit(PCPstatus, i);
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7849
diff changeset
   281
		PPPallowed[i] *= HasBit(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
   282
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
   283
		/* 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
   284
		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
   285
e414a0b104a6 (svn r4150) -Feature: Merged elrails into 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
		/* Read the foundataions if they are present, and adjust the tileh */
7534
2e4dcc2c3bc9 (svn r11054) -Fix [FS#944]: mismatch between TTDP's and OTTD's placement of catenary, creating graphical glitches when loading a catenary replacement. Patch by frosch.
rubidium
parents: 7472
diff changeset
   287
		if (trackconfig[TS_NEIGHBOUR] != TRACK_BIT_NONE && IsTileType(neighbour, MP_RAILWAY) && GetRailType(neighbour) == RAILTYPE_ELECTRIC) foundation = GetRailFoundation(tileh[TS_NEIGHBOUR], trackconfig[TS_NEIGHBOUR]);
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5314
diff changeset
   288
		if (IsBridgeTile(neighbour)) {
8083
ad22eade501f (svn r11644) -Codechange: merge some functions from tunnel_map.h and bridge_map.h into tunnelbridge_map.h
smatz
parents: 7931
diff changeset
   289
			foundation = GetBridgeFoundation(tileh[TS_NEIGHBOUR], DiagDirToAxis(GetTunnelBridgeDirection(neighbour)));
3368
d57156668a59 (svn r4165) -Do not use GetBridgeAxis on bridge ramps (request by Tron)
celestar
parents: 3367
diff changeset
   290
		}
d57156668a59 (svn r4165) -Do not use GetBridgeAxis on bridge ramps (request by Tron)
celestar
parents: 3367
diff changeset
   291
7335
141c6b86ec1f (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7333
diff changeset
   292
		ApplyFoundationToSlope(foundation, &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
   293
7764
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7601
diff changeset
   294
	/* Half tile slopes coincide only with horizontal/vertical track.
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7601
diff changeset
   295
	 * Faking a flat slope results in the correct sprites on positions. */
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7601
diff changeset
   296
		if (IsHalftileSlope(tileh[TS_NEIGHBOUR])) tileh[TS_NEIGHBOUR] = SLOPE_FLAT;
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7601
diff changeset
   297
3451
0e8ccac68fdf (svn r4283) -Cleanup: More elrail housekeeping, remove code dublication, more meaningful variable names, simplify control flow..
celestar
parents: 3449
diff changeset
   298
		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
   299
e414a0b104a6 (svn r4150) -Feature: Merged elrails into 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
		/* 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
   301
		 * 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
   302
		/* 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
   303
		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
   304
			for (k = 0; k < NUM_IGNORE_GROUPS; k++)
7929
6c9b25842b0f (svn r11482) -Codechange: Remove the doubled function ClrBitT and rename the remaining to fit with the naming style
skidd13
parents: 7928
diff changeset
   305
				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
   306
		}
e414a0b104a6 (svn r4150) -Feature: Merged elrails into 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
3451
0e8ccac68fdf (svn r4283) -Cleanup: More elrail housekeeping, remove code dublication, more meaningful variable names, simplify control flow..
celestar
parents: 3449
diff changeset
   308
		/* 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
   309
		 * 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
   310
		 * 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
   311
		 * 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
   312
		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
   313
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5314
diff changeset
   314
		if (MayHaveBridgeAbove(ti->tile) && IsBridgeAbove(ti->tile)) {
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5314
diff changeset
   315
			Track bridgetrack = GetBridgeAxis(ti->tile) == AXIS_X ? TRACK_X : TRACK_Y;
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5314
diff changeset
   316
			uint height = GetBridgeHeight(GetNorthernBridgeEnd(ti->tile));
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5314
diff changeset
   317
6699
d2f35126c1a6 (svn r9931) -Fix: some glitches with catenary and bridges.
rubidium
parents: 6453
diff changeset
   318
			if ((height <= GetTileMaxZ(ti->tile) + TILE_HEIGHT) &&
6269
3e10e20eecff (svn r9078) -Codechange: coding style.
rubidium
parents: 6268
diff changeset
   319
					(i == PCPpositions[bridgetrack][0] || i == PCPpositions[bridgetrack][1])) {
7931
b0a46cd92225 (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents: 7929
diff changeset
   320
				SetBit(OverridePCP, i);
6269
3e10e20eecff (svn r9078) -Codechange: coding style.
rubidium
parents: 6268
diff changeset
   321
			}
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5314
diff changeset
   322
		}
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5314
diff changeset
   323
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7849
diff changeset
   324
		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
   325
			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
   326
				byte temp = PPPorder[i][GetTLG(ti->tile)][k];
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4021
diff changeset
   327
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7849
diff changeset
   328
				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
   329
					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
   330
					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
   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
					/* Don't build the pylon if it would be outside the tile */
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7849
diff changeset
   333
					if (!HasBit(OwnedPPPonPCP[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
   334
						/* 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
   335
						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
   336
						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
   337
					}
e414a0b104a6 (svn r4150) -Feature: Merged elrails into 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
7601
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7534
diff changeset
   339
					AddSortableSpriteToDraw(pylon_sprites[temp], PAL_NONE, x, y, 1, 1, BB_HEIGHT_UNDER_BRIDGE,
7534
2e4dcc2c3bc9 (svn r11054) -Fix [FS#944]: mismatch between TTDP's and OTTD's placement of catenary, creating graphical glitches when loading a catenary replacement. Patch by frosch.
rubidium
parents: 7472
diff changeset
   340
							GetPCPElevation(ti->tile, i),
7849
0a1c0af2c96c (svn r11399) -Feature(ette): transparency settings can now be saved and thus remembered.
belugas
parents: 7764
diff changeset
   341
							IsTransparencySet(TO_BUILDINGS), -1, -1);
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
   342
					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
   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
			}
e414a0b104a6 (svn r4150) -Feature: Merged elrails into 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
	}
e414a0b104a6 (svn r4150) -Feature: Merged elrails into 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
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
   348
	/* Don't draw a wire under a low bridge */
7849
0a1c0af2c96c (svn r11399) -Feature(ette): transparency settings can now be saved and thus remembered.
belugas
parents: 7764
diff changeset
   349
	if (MayHaveBridgeAbove(ti->tile) && IsBridgeAbove(ti->tile) && !IsTransparencySet(TO_BUILDINGS)) {
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5314
diff changeset
   350
		uint height = GetBridgeHeight(GetNorthernBridgeEnd(ti->tile));
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5314
diff changeset
   351
6699
d2f35126c1a6 (svn r9931) -Fix: some glitches with catenary and bridges.
rubidium
parents: 6453
diff changeset
   352
		if (height <= GetTileMaxZ(ti->tile) + TILE_HEIGHT) return;
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
   353
	}
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
   354
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
	/* Drawing of pylons is finished, now draw the wires */
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   356
	for (t = TRACK_BEGIN; t < TRACK_END; t++) {
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7849
diff changeset
   357
		if (HasBit(trackconfig[TS_HOME], t)) {
7601
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7534
diff changeset
   358
			if (IsTunnelTile(ti->tile)) break; // drawn together with tunnel-roof (see DrawCatenaryOnTunnel())
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7849
diff changeset
   359
			byte PCPconfig = HasBit(PCPstatus, PCPpositions[t][0]) +
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7849
diff changeset
   360
				(HasBit(PCPstatus, PCPpositions[t][1]) << 1);
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
   361
e414a0b104a6 (svn r4150) -Feature: Merged elrails into 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
			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
   363
			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
   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
			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
   366
			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
   367
			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
   368
7534
2e4dcc2c3bc9 (svn r11054) -Fix [FS#944]: mismatch between TTDP's and OTTD's placement of catenary, creating graphical glitches when loading a catenary replacement. Patch by frosch.
rubidium
parents: 7472
diff changeset
   369
			/*
2e4dcc2c3bc9 (svn r11054) -Fix [FS#944]: mismatch between TTDP's and OTTD's placement of catenary, creating graphical glitches when loading a catenary replacement. Patch by frosch.
rubidium
parents: 7472
diff changeset
   370
			 * The "wire"-sprite position is inside the tile, i.e. 0 <= sss->?_offset < TILE_SIZE.
2e4dcc2c3bc9 (svn r11054) -Fix [FS#944]: mismatch between TTDP's and OTTD's placement of catenary, creating graphical glitches when loading a catenary replacement. Patch by frosch.
rubidium
parents: 7472
diff changeset
   371
			 * Therefore it is save to use GetSlopeZ() for the elevation.
2e4dcc2c3bc9 (svn r11054) -Fix [FS#944]: mismatch between TTDP's and OTTD's placement of catenary, creating graphical glitches when loading a catenary replacement. Patch by frosch.
rubidium
parents: 7472
diff changeset
   372
			 * Also note, that the result of GetSlopeZ() is very special for bridge-ramps.
2e4dcc2c3bc9 (svn r11054) -Fix [FS#944]: mismatch between TTDP's and OTTD's placement of catenary, creating graphical glitches when loading a catenary replacement. Patch by frosch.
rubidium
parents: 7472
diff changeset
   373
			 */
7333
e48228e44be8 (svn r10696) -Codechange: remove duplication of the "make sprite transparent" code.
rubidium
parents: 7020
diff changeset
   374
			AddSortableSpriteToDraw(sss->image, PAL_NONE, ti->x + sss->x_offset, ti->y + sss->y_offset,
7534
2e4dcc2c3bc9 (svn r11054) -Fix [FS#944]: mismatch between TTDP's and OTTD's placement of catenary, creating graphical glitches when loading a catenary replacement. Patch by frosch.
rubidium
parents: 7472
diff changeset
   375
				sss->x_size, sss->y_size, sss->z_size, GetSlopeZ(ti->x + sss->x_offset, ti->y + sss->y_offset) + sss->z_offset,
7849
0a1c0af2c96c (svn r11399) -Feature(ette): transparency settings can now be saved and thus remembered.
belugas
parents: 7764
diff changeset
   376
				IsTransparencySet(TO_BUILDINGS));
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
		}
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   378
	}
e414a0b104a6 (svn r4150) -Feature: Merged elrails into 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
}
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   380
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   381
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
   382
{
3445
972e0aa84c51 (svn r4276) -Codechange: Cleaned DrawCatenaryOnBridge a bit (requested by Tron)
celestar
parents: 3405
diff changeset
   383
	TileIndex end = GetSouthernBridgeEnd(ti->tile);
972e0aa84c51 (svn r4276) -Codechange: Cleaned DrawCatenaryOnBridge a bit (requested by Tron)
celestar
parents: 3405
diff changeset
   384
	TileIndex start = GetOtherBridgeEnd(end);
972e0aa84c51 (svn r4276) -Codechange: Cleaned DrawCatenaryOnBridge a bit (requested by Tron)
celestar
parents: 3405
diff changeset
   385
972e0aa84c51 (svn r4276) -Codechange: Cleaned DrawCatenaryOnBridge a bit (requested by Tron)
celestar
parents: 3405
diff changeset
   386
	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
   387
	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
   388
	uint height;
3445
972e0aa84c51 (svn r4276) -Codechange: Cleaned DrawCatenaryOnBridge a bit (requested by Tron)
celestar
parents: 3405
diff changeset
   389
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
   390
	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
   391
	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
   392
	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
   393
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   394
	CatenarySprite offset = (CatenarySprite)(axis == AXIS_X ? 0 : WIRE_Y_FLAT_BOTH - WIRE_X_FLAT_BOTH);
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
   395
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   396
	if ((length % 2) && num == length) {
3445
972e0aa84c51 (svn r4276) -Codechange: Cleaned DrawCatenaryOnBridge a bit (requested by Tron)
celestar
parents: 3405
diff changeset
   397
		/* 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
   398
		 * 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
   399
		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
   400
	} else {
3445
972e0aa84c51 (svn r4276) -Codechange: Cleaned DrawCatenaryOnBridge a bit (requested by Tron)
celestar
parents: 3405
diff changeset
   401
		/* 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
   402
		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
   403
	}
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   404
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5314
diff changeset
   405
	height = GetBridgeHeight(end);
4159
fc1d8605596d (svn r5584) When drawing catenary on a bridge calculate its height only once
tron
parents: 4158
diff changeset
   406
7333
e48228e44be8 (svn r10696) -Codechange: remove duplication of the "make sprite transparent" code.
rubidium
parents: 7020
diff changeset
   407
	AddSortableSpriteToDraw(sss->image, PAL_NONE, ti->x + sss->x_offset, ti->y + sss->y_offset,
e48228e44be8 (svn r10696) -Codechange: remove duplication of the "make sprite transparent" code.
rubidium
parents: 7020
diff changeset
   408
		sss->x_size, sss->y_size, sss->z_size, height + sss->z_offset,
7849
0a1c0af2c96c (svn r11399) -Feature(ette): transparency settings can now be saved and thus remembered.
belugas
parents: 7764
diff changeset
   409
		IsTransparencySet(TO_BUILDINGS)
4159
fc1d8605596d (svn r5584) When drawing catenary on a bridge calculate its height only once
tron
parents: 4158
diff changeset
   410
	);
3445
972e0aa84c51 (svn r4276) -Codechange: Cleaned DrawCatenaryOnBridge a bit (requested by Tron)
celestar
parents: 3405
diff changeset
   411
972e0aa84c51 (svn r4276) -Codechange: Cleaned DrawCatenaryOnBridge a bit (requested by Tron)
celestar
parents: 3405
diff changeset
   412
	/* Finished with wires, draw pylons */
972e0aa84c51 (svn r4276) -Codechange: Cleaned DrawCatenaryOnBridge a bit (requested by Tron)
celestar
parents: 3405
diff changeset
   413
	/* 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
   414
	if (num % 2) {
7534
2e4dcc2c3bc9 (svn r11054) -Fix [FS#944]: mismatch between TTDP's and OTTD's placement of catenary, creating graphical glitches when loading a catenary replacement. Patch by frosch.
rubidium
parents: 7472
diff changeset
   415
		DiagDirection PCPpos = (axis == AXIS_X ? DIAGDIR_NE : DIAGDIR_NW);
2e4dcc2c3bc9 (svn r11054) -Fix [FS#944]: mismatch between TTDP's and OTTD's placement of catenary, creating graphical glitches when loading a catenary replacement. Patch by frosch.
rubidium
parents: 7472
diff changeset
   416
		Direction PPPpos = (axis == AXIS_X ? DIR_NW : DIR_NE);
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7849
diff changeset
   417
		if (HasBit(tlg, (axis == AXIS_X ? 0 : 1))) PPPpos = ReverseDir(PPPpos);
7534
2e4dcc2c3bc9 (svn r11054) -Fix [FS#944]: mismatch between TTDP's and OTTD's placement of catenary, creating graphical glitches when loading a catenary replacement. Patch by frosch.
rubidium
parents: 7472
diff changeset
   418
		uint x = ti->x + x_pcp_offsets[PCPpos] + x_ppp_offsets[PPPpos];
2e4dcc2c3bc9 (svn r11054) -Fix [FS#944]: mismatch between TTDP's and OTTD's placement of catenary, creating graphical glitches when loading a catenary replacement. Patch by frosch.
rubidium
parents: 7472
diff changeset
   419
		uint y = ti->y + y_pcp_offsets[PCPpos] + y_ppp_offsets[PPPpos];
7849
0a1c0af2c96c (svn r11399) -Feature(ette): transparency settings can now be saved and thus remembered.
belugas
parents: 7764
diff changeset
   420
		AddSortableSpriteToDraw(pylon_sprites[PPPpos], PAL_NONE, x, y, 1, 1, BB_HEIGHT_UNDER_BRIDGE, height, IsTransparencySet(TO_BUILDINGS), -1, -1);
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
   421
	}
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   422
3445
972e0aa84c51 (svn r4276) -Codechange: Cleaned DrawCatenaryOnBridge a bit (requested by Tron)
celestar
parents: 3405
diff changeset
   423
	/* 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
   424
	if (DistanceMax(ti->tile, start) == length) {
7534
2e4dcc2c3bc9 (svn r11054) -Fix [FS#944]: mismatch between TTDP's and OTTD's placement of catenary, creating graphical glitches when loading a catenary replacement. Patch by frosch.
rubidium
parents: 7472
diff changeset
   425
		DiagDirection PCPpos = (axis == AXIS_X ? DIAGDIR_SW : DIAGDIR_SE);
2e4dcc2c3bc9 (svn r11054) -Fix [FS#944]: mismatch between TTDP's and OTTD's placement of catenary, creating graphical glitches when loading a catenary replacement. Patch by frosch.
rubidium
parents: 7472
diff changeset
   426
		Direction PPPpos = (axis == AXIS_X ? DIR_NW : DIR_NE);
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7849
diff changeset
   427
		if (HasBit(tlg, (axis == AXIS_X ? 0 : 1))) PPPpos = ReverseDir(PPPpos);
7534
2e4dcc2c3bc9 (svn r11054) -Fix [FS#944]: mismatch between TTDP's and OTTD's placement of catenary, creating graphical glitches when loading a catenary replacement. Patch by frosch.
rubidium
parents: 7472
diff changeset
   428
		uint x = ti->x + x_pcp_offsets[PCPpos] + x_ppp_offsets[PPPpos];
2e4dcc2c3bc9 (svn r11054) -Fix [FS#944]: mismatch between TTDP's and OTTD's placement of catenary, creating graphical glitches when loading a catenary replacement. Patch by frosch.
rubidium
parents: 7472
diff changeset
   429
		uint y = ti->y + y_pcp_offsets[PCPpos] + y_ppp_offsets[PPPpos];
7849
0a1c0af2c96c (svn r11399) -Feature(ette): transparency settings can now be saved and thus remembered.
belugas
parents: 7764
diff changeset
   430
		AddSortableSpriteToDraw(pylon_sprites[PPPpos], PAL_NONE, x, y, 1, 1, BB_HEIGHT_UNDER_BRIDGE, height, IsTransparencySet(TO_BUILDINGS), -1, -1);
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
   431
	}
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   432
}
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   433
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
diff changeset
   434
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
   435
{
7020
f59d32034735 (svn r10283) -Fix [FS#913]: catenary was drawn on bridges when elrail was disabled. Patch by B. N. SmatZ!.
rubidium
parents: 6699
diff changeset
   436
	if (_patches.disable_elrails) return;
f59d32034735 (svn r10283) -Fix [FS#913]: catenary was drawn on bridges when elrail was disabled. Patch by B. N. SmatZ!.
rubidium
parents: 6699
diff changeset
   437
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5314
diff changeset
   438
	if (MayHaveBridgeAbove(ti->tile) && IsBridgeAbove(ti->tile)) {
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5314
diff changeset
   439
		TileIndex head = GetNorthernBridgeEnd(ti->tile);
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5314
diff changeset
   440
8083
ad22eade501f (svn r11644) -Codechange: merge some functions from tunnel_map.h and bridge_map.h into tunnelbridge_map.h
smatz
parents: 7931
diff changeset
   441
		if (GetTunnelBridgeTransportType(head) == TRANSPORT_RAIL && GetRailType(head) == RAILTYPE_ELECTRIC) {
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5314
diff changeset
   442
			DrawCatenaryOnBridge(ti);
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5314
diff changeset
   443
		}
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5314
diff changeset
   444
	}
5116
3c0c3da214ca (svn r7195) -Feature: [FS#297, optional elrails] New patches/vehicles option 'disable electrified railways'.
KUDr
parents: 4559
diff changeset
   445
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
   446
	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
   447
		case MP_RAILWAY:
6269
3e10e20eecff (svn r9078) -Codechange: coding style.
rubidium
parents: 6268
diff changeset
   448
			if (IsRailDepot(ti->tile)) {
3e10e20eecff (svn r9078) -Codechange: coding style.
rubidium
parents: 6268
diff changeset
   449
				const SortableSpriteStruct *sss = &CatenarySpriteData_Depot[GetRailDepotDirection(ti->tile)];
4470
4518cc0ec616 (svn r6255) Simplify drawing of catenary in depots
tron
parents: 4448
diff changeset
   450
7534
2e4dcc2c3bc9 (svn r11054) -Fix [FS#944]: mismatch between TTDP's and OTTD's placement of catenary, creating graphical glitches when loading a catenary replacement. Patch by frosch.
rubidium
parents: 7472
diff changeset
   451
				/* This wire is not visible with the default depot sprites */
4470
4518cc0ec616 (svn r6255) Simplify drawing of catenary in depots
tron
parents: 4448
diff changeset
   452
				AddSortableSpriteToDraw(
7333
e48228e44be8 (svn r10696) -Codechange: remove duplication of the "make sprite transparent" code.
rubidium
parents: 7020
diff changeset
   453
					sss->image, PAL_NONE, ti->x + sss->x_offset, ti->y + sss->y_offset,
4470
4518cc0ec616 (svn r6255) Simplify drawing of catenary in depots
tron
parents: 4448
diff changeset
   454
					sss->x_size, sss->y_size, sss->z_size,
7333
e48228e44be8 (svn r10696) -Codechange: remove duplication of the "make sprite transparent" code.
rubidium
parents: 7020
diff changeset
   455
					GetTileMaxZ(ti->tile) + sss->z_offset,
7849
0a1c0af2c96c (svn r11399) -Feature(ette): transparency settings can now be saved and thus remembered.
belugas
parents: 7764
diff changeset
   456
					IsTransparencySet(TO_BUILDINGS)
4470
4518cc0ec616 (svn r6255) Simplify drawing of catenary in depots
tron
parents: 4448
diff changeset
   457
				);
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
   458
				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
   459
			}
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
   460
			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
   461
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
   462
		case MP_TUNNELBRIDGE:
7370
41adc721b1fa (svn r10733) -Codechange: change MP_STREET into MP_ROAD as we use the word "road" everywhere except in the tile type.
rubidium
parents: 7335
diff changeset
   463
		case MP_ROAD:
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5314
diff changeset
   464
		case MP_STATION:
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
   465
			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
   466
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
   467
		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
   468
	}
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
   469
	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
   470
}
5116
3c0c3da214ca (svn r7195) -Feature: [FS#297, optional elrails] New patches/vehicles option 'disable electrified railways'.
KUDr
parents: 4559
diff changeset
   471
3c0c3da214ca (svn r7195) -Feature: [FS#297, optional elrails] New patches/vehicles option 'disable electrified railways'.
KUDr
parents: 4559
diff changeset
   472
int32 SettingsDisableElrail(int32 p1)
3c0c3da214ca (svn r7195) -Feature: [FS#297, optional elrails] New patches/vehicles option 'disable electrified railways'.
KUDr
parents: 4559
diff changeset
   473
{
3c0c3da214ca (svn r7195) -Feature: [FS#297, optional elrails] New patches/vehicles option 'disable electrified railways'.
KUDr
parents: 4559
diff changeset
   474
	EngineID e_id;
6269
3e10e20eecff (svn r9078) -Codechange: coding style.
rubidium
parents: 6268
diff changeset
   475
	Vehicle *v;
5116
3c0c3da214ca (svn r7195) -Feature: [FS#297, optional elrails] New patches/vehicles option 'disable electrified railways'.
KUDr
parents: 4559
diff changeset
   476
	Player *p;
3c0c3da214ca (svn r7195) -Feature: [FS#297, optional elrails] New patches/vehicles option 'disable electrified railways'.
KUDr
parents: 4559
diff changeset
   477
	bool disable = (p1 != 0);
3c0c3da214ca (svn r7195) -Feature: [FS#297, optional elrails] New patches/vehicles option 'disable electrified railways'.
KUDr
parents: 4559
diff changeset
   478
3c0c3da214ca (svn r7195) -Feature: [FS#297, optional elrails] New patches/vehicles option 'disable electrified railways'.
KUDr
parents: 4559
diff changeset
   479
	/* we will now walk through all electric train engines and change their railtypes if it is the wrong one*/
3c0c3da214ca (svn r7195) -Feature: [FS#297, optional elrails] New patches/vehicles option 'disable electrified railways'.
KUDr
parents: 4559
diff changeset
   480
	const RailType old_railtype = disable ? RAILTYPE_ELECTRIC : RAILTYPE_RAIL;
3c0c3da214ca (svn r7195) -Feature: [FS#297, optional elrails] New patches/vehicles option 'disable electrified railways'.
KUDr
parents: 4559
diff changeset
   481
	const RailType new_railtype = disable ? RAILTYPE_RAIL : RAILTYPE_ELECTRIC;
3c0c3da214ca (svn r7195) -Feature: [FS#297, optional elrails] New patches/vehicles option 'disable electrified railways'.
KUDr
parents: 4559
diff changeset
   482
3c0c3da214ca (svn r7195) -Feature: [FS#297, optional elrails] New patches/vehicles option 'disable electrified railways'.
KUDr
parents: 4559
diff changeset
   483
	/* walk through all train engines */
5314
fda2b099eec5 (svn r7470) -Codechange: Leave elrails enabled after loading old (pre-optional) and very old (pre-elrails) games. Let the user manually disable if if undesired.
Darkvater
parents: 5116
diff changeset
   484
	for (e_id = 0; e_id < NUM_TRAIN_ENGINES; e_id++) {
5823
7aa8c2312103 (svn r8385) -Fix
tron
parents: 5668
diff changeset
   485
		RailVehicleInfo *rv_info = &_rail_vehicle_info[e_id];
5116
3c0c3da214ca (svn r7195) -Feature: [FS#297, optional elrails] New patches/vehicles option 'disable electrified railways'.
KUDr
parents: 4559
diff changeset
   486
		/* if it is an electric rail engine and its railtype is the wrong one */
5823
7aa8c2312103 (svn r8385) -Fix
tron
parents: 5668
diff changeset
   487
		if (rv_info->engclass == 2 && rv_info->railtype == old_railtype) {
5116
3c0c3da214ca (svn r7195) -Feature: [FS#297, optional elrails] New patches/vehicles option 'disable electrified railways'.
KUDr
parents: 4559
diff changeset
   488
			/* change it to the proper one */
5823
7aa8c2312103 (svn r8385) -Fix
tron
parents: 5668
diff changeset
   489
			rv_info->railtype = new_railtype;
5116
3c0c3da214ca (svn r7195) -Feature: [FS#297, optional elrails] New patches/vehicles option 'disable electrified railways'.
KUDr
parents: 4559
diff changeset
   490
		}
3c0c3da214ca (svn r7195) -Feature: [FS#297, optional elrails] New patches/vehicles option 'disable electrified railways'.
KUDr
parents: 4559
diff changeset
   491
	}
3c0c3da214ca (svn r7195) -Feature: [FS#297, optional elrails] New patches/vehicles option 'disable electrified railways'.
KUDr
parents: 4559
diff changeset
   492
3c0c3da214ca (svn r7195) -Feature: [FS#297, optional elrails] New patches/vehicles option 'disable electrified railways'.
KUDr
parents: 4559
diff changeset
   493
	/* when disabling elrails, make sure that all existing trains can run on
3c0c3da214ca (svn r7195) -Feature: [FS#297, optional elrails] New patches/vehicles option 'disable electrified railways'.
KUDr
parents: 4559
diff changeset
   494
	*  normal rail too */
3c0c3da214ca (svn r7195) -Feature: [FS#297, optional elrails] New patches/vehicles option 'disable electrified railways'.
KUDr
parents: 4559
diff changeset
   495
	if (disable) {
3c0c3da214ca (svn r7195) -Feature: [FS#297, optional elrails] New patches/vehicles option 'disable electrified railways'.
KUDr
parents: 4559
diff changeset
   496
		FOR_ALL_VEHICLES(v) {
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6172
diff changeset
   497
			if (v->type == VEH_TRAIN && v->u.rail.railtype == RAILTYPE_ELECTRIC) {
5116
3c0c3da214ca (svn r7195) -Feature: [FS#297, optional elrails] New patches/vehicles option 'disable electrified railways'.
KUDr
parents: 4559
diff changeset
   498
				/* this railroad vehicle is now compatible only with elrail,
3c0c3da214ca (svn r7195) -Feature: [FS#297, optional elrails] New patches/vehicles option 'disable electrified railways'.
KUDr
parents: 4559
diff changeset
   499
				*  so add there also normal rail compatibility */
8236
8a5dd0b42e47 (svn r11800) -Codechange: move some functions to a more logical location + some type safety.
rubidium
parents: 8224
diff changeset
   500
				v->u.rail.compatible_railtypes |= RAILTYPES_RAIL;
5116
3c0c3da214ca (svn r7195) -Feature: [FS#297, optional elrails] New patches/vehicles option 'disable electrified railways'.
KUDr
parents: 4559
diff changeset
   501
				v->u.rail.railtype = RAILTYPE_RAIL;
7931
b0a46cd92225 (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents: 7929
diff changeset
   502
				SetBit(v->u.rail.flags, VRF_EL_ENGINE_ALLOWED_NORMAL_RAIL);
5116
3c0c3da214ca (svn r7195) -Feature: [FS#297, optional elrails] New patches/vehicles option 'disable electrified railways'.
KUDr
parents: 4559
diff changeset
   503
			}
3c0c3da214ca (svn r7195) -Feature: [FS#297, optional elrails] New patches/vehicles option 'disable electrified railways'.
KUDr
parents: 4559
diff changeset
   504
		}
3c0c3da214ca (svn r7195) -Feature: [FS#297, optional elrails] New patches/vehicles option 'disable electrified railways'.
KUDr
parents: 4559
diff changeset
   505
	}
3c0c3da214ca (svn r7195) -Feature: [FS#297, optional elrails] New patches/vehicles option 'disable electrified railways'.
KUDr
parents: 4559
diff changeset
   506
3c0c3da214ca (svn r7195) -Feature: [FS#297, optional elrails] New patches/vehicles option 'disable electrified railways'.
KUDr
parents: 4559
diff changeset
   507
	/* setup total power for trains */
3c0c3da214ca (svn r7195) -Feature: [FS#297, optional elrails] New patches/vehicles option 'disable electrified railways'.
KUDr
parents: 4559
diff changeset
   508
	FOR_ALL_VEHICLES(v) {
3c0c3da214ca (svn r7195) -Feature: [FS#297, optional elrails] New patches/vehicles option 'disable electrified railways'.
KUDr
parents: 4559
diff changeset
   509
		/* power is cached only for front engines */
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6172
diff changeset
   510
		if (v->type == VEH_TRAIN && IsFrontEngine(v)) TrainPowerChanged(v);
5116
3c0c3da214ca (svn r7195) -Feature: [FS#297, optional elrails] New patches/vehicles option 'disable electrified railways'.
KUDr
parents: 4559
diff changeset
   511
	}
3c0c3da214ca (svn r7195) -Feature: [FS#297, optional elrails] New patches/vehicles option 'disable electrified railways'.
KUDr
parents: 4559
diff changeset
   512
3c0c3da214ca (svn r7195) -Feature: [FS#297, optional elrails] New patches/vehicles option 'disable electrified railways'.
KUDr
parents: 4559
diff changeset
   513
	FOR_ALL_PLAYERS(p) p->avail_railtypes = GetPlayerRailtypes(p->index);
3c0c3da214ca (svn r7195) -Feature: [FS#297, optional elrails] New patches/vehicles option 'disable electrified railways'.
KUDr
parents: 4559
diff changeset
   514
3c0c3da214ca (svn r7195) -Feature: [FS#297, optional elrails] New patches/vehicles option 'disable electrified railways'.
KUDr
parents: 4559
diff changeset
   515
	/* This resets the _last_built_railtype, which will be invalid for electric
3c0c3da214ca (svn r7195) -Feature: [FS#297, optional elrails] New patches/vehicles option 'disable electrified railways'.
KUDr
parents: 4559
diff changeset
   516
	* rails. It may have unintended consequences if that function is ever
3c0c3da214ca (svn r7195) -Feature: [FS#297, optional elrails] New patches/vehicles option 'disable electrified railways'.
KUDr
parents: 4559
diff changeset
   517
	* extended, though. */
3c0c3da214ca (svn r7195) -Feature: [FS#297, optional elrails] New patches/vehicles option 'disable electrified railways'.
KUDr
parents: 4559
diff changeset
   518
	ReinitGuiAfterToggleElrail(disable);
3c0c3da214ca (svn r7195) -Feature: [FS#297, optional elrails] New patches/vehicles option 'disable electrified railways'.
KUDr
parents: 4559
diff changeset
   519
	return 0;
3c0c3da214ca (svn r7195) -Feature: [FS#297, optional elrails] New patches/vehicles option 'disable electrified railways'.
KUDr
parents: 4559
diff changeset
   520
}