src/bridge_map.cpp
author celestar
Wed, 13 Jun 2007 11:00:24 +0000
branchgamebalance
changeset 9909 dce9a6923bb7
parent 9908 0fa543611bbe
child 6743 cabfaa4a0295
permissions -rw-r--r--
(svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
3214
172b409bf612 (svn r3887) Add a function to get the other bridge end when you're at a bridge ramp
tron
parents:
diff changeset
     1
/* $Id$ */
172b409bf612 (svn r3887) Add a function to get the other bridge end when you're at a bridge ramp
tron
parents:
diff changeset
     2
9908
0fa543611bbe (svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents: 6449
diff changeset
     3
/** @file bridge_map.cpp Map accessor functions for bridges. */
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 5838
diff changeset
     4
3214
172b409bf612 (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"
172b409bf612 (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"
172b409bf612 (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"
9908
0fa543611bbe (svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents: 6449
diff changeset
     8
#include "bridge.h"
5573
afa6f92a71fd (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"
3214
172b409bf612 (svn r3887) Add a function to get the other bridge end when you're at a bridge ramp
tron
parents:
diff changeset
    10
172b409bf612 (svn r3887) Add a function to get the other bridge end when you're at a bridge ramp
tron
parents:
diff changeset
    11
3225
655763f3861c (svn r3898) Add functions to find a bridge end starting at a middle tile
tron
parents: 3214
diff changeset
    12
TileIndex GetBridgeEnd(TileIndex tile, DiagDirection dir)
655763f3861c (svn r3898) Add functions to find a bridge end starting at a middle tile
tron
parents: 3214
diff changeset
    13
{
4559
c853d2440065 (svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents: 3977
diff changeset
    14
	TileIndexDiff delta = TileOffsByDiagDir(dir);
3225
655763f3861c (svn r3898) Add functions to find a bridge end starting at a middle tile
tron
parents: 3214
diff changeset
    15
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
    16
	dir = ReverseDiagDir(dir);
3977
edb5b94e2094 (svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents: 3933
diff changeset
    17
	do {
edb5b94e2094 (svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents: 3933
diff changeset
    18
		tile += delta;
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
    19
	} while (!IsBridgeTile(tile) || GetBridgeRampDirection(tile) != dir);
3225
655763f3861c (svn r3898) Add functions to find a bridge end starting at a middle tile
tron
parents: 3214
diff changeset
    20
655763f3861c (svn r3898) Add functions to find a bridge end starting at a middle tile
tron
parents: 3214
diff changeset
    21
	return tile;
655763f3861c (svn r3898) Add functions to find a bridge end starting at a middle tile
tron
parents: 3214
diff changeset
    22
}
655763f3861c (svn r3898) Add functions to find a bridge end starting at a middle tile
tron
parents: 3214
diff changeset
    23
655763f3861c (svn r3898) Add functions to find a bridge end starting at a middle tile
tron
parents: 3214
diff changeset
    24
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
    25
TileIndex GetNorthernBridgeEnd(TileIndex t)
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
    26
{
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
    27
	return GetBridgeEnd(t, ReverseDiagDir(AxisToDiagDir(GetBridgeAxis(t))));
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
    28
}
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
    29
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
    30
3225
655763f3861c (svn r3898) Add functions to find a bridge end starting at a middle tile
tron
parents: 3214
diff changeset
    31
TileIndex GetSouthernBridgeEnd(TileIndex t)
655763f3861c (svn r3898) Add functions to find a bridge end starting at a middle tile
tron
parents: 3214
diff changeset
    32
{
655763f3861c (svn r3898) Add functions to find a bridge end starting at a middle tile
tron
parents: 3214
diff changeset
    33
	return GetBridgeEnd(t, AxisToDiagDir(GetBridgeAxis(t)));
655763f3861c (svn r3898) Add functions to find a bridge end starting at a middle tile
tron
parents: 3214
diff changeset
    34
}
655763f3861c (svn r3898) Add functions to find a bridge end starting at a middle tile
tron
parents: 3214
diff changeset
    35
655763f3861c (svn r3898) Add functions to find a bridge end starting at a middle tile
tron
parents: 3214
diff changeset
    36
3214
172b409bf612 (svn r3887) Add a function to get the other bridge end when you're at a bridge ramp
tron
parents:
diff changeset
    37
TileIndex GetOtherBridgeEnd(TileIndex tile)
172b409bf612 (svn r3887) Add a function to get the other bridge end when you're at a bridge ramp
tron
parents:
diff changeset
    38
{
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
    39
	assert(IsBridgeTile(tile));
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
    40
	return GetBridgeEnd(tile, GetBridgeRampDirection(tile));
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
    41
}
3933
a5f08e17f4a0 (svn r5070) Merged the bridge branch
celestar
parents: 3225
diff changeset
    42
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
    43
uint GetBridgeHeight(TileIndex t)
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
    44
{
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
    45
	uint h;
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
    46
	Slope tileh = GetTileSlope(t, &h);
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
    47
	uint f = GetBridgeFoundation(tileh, DiagDirToAxis(GetBridgeRampDirection(t)));
3933
a5f08e17f4a0 (svn r5070) Merged the bridge branch
celestar
parents: 3225
diff changeset
    48
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 5838
diff changeset
    49
	/* one height level extra if the ramp is on a flat foundation */
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
    50
	return
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
    51
		h + TILE_HEIGHT +
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
    52
		(IS_INT_INSIDE(f, 1, 15) ? TILE_HEIGHT : 0) +
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
    53
		(IsSteepSlope(tileh) ? TILE_HEIGHT : 0);
3214
172b409bf612 (svn r3887) Add a function to get the other bridge end when you're at a bridge ramp
tron
parents:
diff changeset
    54
}