src/bridge_map.cpp
author bjarni
Mon, 05 Feb 2007 21:16:56 +0000
changeset 6192 c6adfc929c6b
parent 5838 9c3129cb019b
child 6268 4b5241e5dd10
permissions -rw-r--r--
(svn r8605) -Codechange: [OSX] changed all objective C to objective C++
This will permanently solve the issue where compilation on OSX broke because C++ code was added to some header files

-Note: (important if you develop mac specific code)
taken from http://developer.apple.com/releasenotes/Cocoa/Objective-C++.html
gdb lacks an integrated C++ with Objective-C parser. This means that gdb won't be able to evaluate expressions that contain both C++ and Objective-C constructs.
gdb assumes that the language for ".mm" files is C++.
you can change it to objective C by typing: (gdb) set language objc
Mixing C++ and objective C has some limitation (see link for all of them)
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
172b409bf612 (svn r3887) Add a function to get the other bridge end when you're at a bridge ramp
tron
parents:
diff changeset
     3
#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
     4
#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
     5
#include "bridge_map.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
     6
#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
     7
172b409bf612 (svn r3887) Add a function to get the other bridge end when you're at a bridge ramp
tron
parents:
diff changeset
     8
3225
655763f3861c (svn r3898) Add functions to find a bridge end starting at a middle tile
tron
parents: 3214
diff changeset
     9
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
    10
{
4559
c853d2440065 (svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents: 3977
diff changeset
    11
	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
    12
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
    13
	dir = ReverseDiagDir(dir);
3977
edb5b94e2094 (svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents: 3933
diff changeset
    14
	do {
edb5b94e2094 (svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents: 3933
diff changeset
    15
		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
    16
	} 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
    17
655763f3861c (svn r3898) Add functions to find a bridge end starting at a middle tile
tron
parents: 3214
diff changeset
    18
	return tile;
655763f3861c (svn r3898) Add functions to find a bridge end starting at a middle tile
tron
parents: 3214
diff changeset
    19
}
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
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
    22
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
    23
{
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
    24
	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
    25
}
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
3225
655763f3861c (svn r3898) Add functions to find a bridge end starting at a middle tile
tron
parents: 3214
diff changeset
    28
TileIndex GetSouthernBridgeEnd(TileIndex t)
655763f3861c (svn r3898) Add functions to find a bridge end starting at a middle tile
tron
parents: 3214
diff changeset
    29
{
655763f3861c (svn r3898) Add functions to find a bridge end starting at a middle tile
tron
parents: 3214
diff changeset
    30
	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
    31
}
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
3214
172b409bf612 (svn r3887) Add a function to get the other bridge end when you're at a bridge ramp
tron
parents:
diff changeset
    34
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
    35
{
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
    36
	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
    37
	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
    38
}
3933
a5f08e17f4a0 (svn r5070) Merged the bridge branch
celestar
parents: 3225
diff changeset
    39
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
    40
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
    41
{
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
    42
	uint h;
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
    43
	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
    44
	uint f = GetBridgeFoundation(tileh, DiagDirToAxis(GetBridgeRampDirection(t)));
3933
a5f08e17f4a0 (svn r5070) Merged the bridge branch
celestar
parents: 3225
diff changeset
    45
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
    46
	// one height level extra if the ramp is on a flat foundation
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
    47
	return
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
    48
		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
    49
		(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
    50
		(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
    51
}