src/bridge_map.cpp
author rubidium
Sat, 17 Nov 2007 12:42:15 +0000
changeset 7898 7c6a9c9030b5
parent 7764 e594296e90f6
child 8083 ad22eade501f
permissions -rw-r--r--
(svn r11449) -Fix [FS#1160]: trams could deadlock themselves. As of now trams will turn as roadvehicles do when the player cannot build a tram track piece on the next tile without destroying anything. It will not turn when the player can build the before mentioned track piece on the 'next' tile.
3214
dd744119dfac (svn r3887) Add a function to get the other bridge end when you're at a bridge ramp
tron
parents:
diff changeset
     1
/* $Id$ */
dd744119dfac (svn r3887) Add a function to get the other bridge end when you're at a bridge ramp
tron
parents:
diff changeset
     2
6418
e04693bbe82a (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6123
diff changeset
     3
/** @file bridge_map.cpp Map accessor functions for bridges. */
6123
04eb770ec17e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 5587
diff changeset
     4
3214
dd744119dfac (svn r3887) Add a function to get the other bridge end when you're at a bridge ramp
tron
parents:
diff changeset
     5
#include "stdafx.h"
dd744119dfac (svn r3887) Add a function to get the other bridge end when you're at a bridge ramp
tron
parents:
diff changeset
     6
#include "openttd.h"
dd744119dfac (svn r3887) Add a function to get the other bridge end when you're at a bridge ramp
tron
parents:
diff changeset
     7
#include "bridge_map.h"
6418
e04693bbe82a (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6123
diff changeset
     8
#include "bridge.h"
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
     9
#include "variables.h"
7764
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7336
diff changeset
    10
#include "landscape.h"
3214
dd744119dfac (svn r3887) Add a function to get the other bridge end when you're at a bridge ramp
tron
parents:
diff changeset
    11
dd744119dfac (svn r3887) Add a function to get the other bridge end when you're at a bridge ramp
tron
parents:
diff changeset
    12
3225
3a3e35bd39a6 (svn r3898) Add functions to find a bridge end starting at a middle tile
tron
parents: 3214
diff changeset
    13
TileIndex GetBridgeEnd(TileIndex tile, DiagDirection dir)
3a3e35bd39a6 (svn r3898) Add functions to find a bridge end starting at a middle tile
tron
parents: 3214
diff changeset
    14
{
4559
aa0c13e39840 (svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents: 3977
diff changeset
    15
	TileIndexDiff delta = TileOffsByDiagDir(dir);
3225
3a3e35bd39a6 (svn r3898) Add functions to find a bridge end starting at a middle tile
tron
parents: 3214
diff changeset
    16
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
    17
	dir = ReverseDiagDir(dir);
3977
513433ebd092 (svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents: 3933
diff changeset
    18
	do {
513433ebd092 (svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents: 3933
diff changeset
    19
		tile += delta;
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
    20
	} while (!IsBridgeTile(tile) || GetBridgeRampDirection(tile) != dir);
3225
3a3e35bd39a6 (svn r3898) Add functions to find a bridge end starting at a middle tile
tron
parents: 3214
diff changeset
    21
3a3e35bd39a6 (svn r3898) Add functions to find a bridge end starting at a middle tile
tron
parents: 3214
diff changeset
    22
	return tile;
3a3e35bd39a6 (svn r3898) Add functions to find a bridge end starting at a middle tile
tron
parents: 3214
diff changeset
    23
}
3a3e35bd39a6 (svn r3898) Add functions to find a bridge end starting at a middle tile
tron
parents: 3214
diff changeset
    24
3a3e35bd39a6 (svn r3898) Add functions to find a bridge end starting at a middle tile
tron
parents: 3214
diff changeset
    25
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
    26
TileIndex GetNorthernBridgeEnd(TileIndex t)
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
    27
{
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
    28
	return GetBridgeEnd(t, ReverseDiagDir(AxisToDiagDir(GetBridgeAxis(t))));
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
    29
}
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
    30
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
    31
3225
3a3e35bd39a6 (svn r3898) Add functions to find a bridge end starting at a middle tile
tron
parents: 3214
diff changeset
    32
TileIndex GetSouthernBridgeEnd(TileIndex t)
3a3e35bd39a6 (svn r3898) Add functions to find a bridge end starting at a middle tile
tron
parents: 3214
diff changeset
    33
{
3a3e35bd39a6 (svn r3898) Add functions to find a bridge end starting at a middle tile
tron
parents: 3214
diff changeset
    34
	return GetBridgeEnd(t, AxisToDiagDir(GetBridgeAxis(t)));
3a3e35bd39a6 (svn r3898) Add functions to find a bridge end starting at a middle tile
tron
parents: 3214
diff changeset
    35
}
3a3e35bd39a6 (svn r3898) Add functions to find a bridge end starting at a middle tile
tron
parents: 3214
diff changeset
    36
3a3e35bd39a6 (svn r3898) Add functions to find a bridge end starting at a middle tile
tron
parents: 3214
diff changeset
    37
3214
dd744119dfac (svn r3887) Add a function to get the other bridge end when you're at a bridge ramp
tron
parents:
diff changeset
    38
TileIndex GetOtherBridgeEnd(TileIndex tile)
dd744119dfac (svn r3887) Add a function to get the other bridge end when you're at a bridge ramp
tron
parents:
diff changeset
    39
{
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
    40
	assert(IsBridgeTile(tile));
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
    41
	return GetBridgeEnd(tile, GetBridgeRampDirection(tile));
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
    42
}
3933
231ae3c419f4 (svn r5070) Merged the bridge branch
celestar
parents: 3225
diff changeset
    43
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
    44
uint GetBridgeHeight(TileIndex t)
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
    45
{
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
    46
	uint h;
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
    47
	Slope tileh = GetTileSlope(t, &h);
7336
180fe387acfc (svn r10699) -Fix (r10698): bridge middle parts were drawn too high if the southern bridge head has a foundation.
rubidium
parents: 6418
diff changeset
    48
	Foundation f = GetBridgeFoundation(tileh, DiagDirToAxis(GetBridgeRampDirection(t)));
3933
231ae3c419f4 (svn r5070) Merged the bridge branch
celestar
parents: 3225
diff changeset
    49
7764
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7336
diff changeset
    50
	/* one height level extra for the ramp */
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7336
diff changeset
    51
	return h + TILE_HEIGHT + ApplyFoundationToSlope(f, &tileh);
3214
dd744119dfac (svn r3887) Add a function to get the other bridge end when you're at a bridge ramp
tron
parents:
diff changeset
    52
}