bridge_map.c
author KUDr
Sun, 31 Dec 2006 02:53:23 +0000
branchcustombridgeheads
changeset 5611 11da6bafbfb9
parent 5591 8cd83b10634f
permissions -rw-r--r--
(svn r7687) [cbh] - Fix: trains can now enter the bridge from side. They still can't leave it from side (pathfinder will need to be invoked when the other ramp is entered). Also the code is not very clear and needs review. It is more proof of concept than final solution. I hope that somebody smarter (Celestar) can do it better.
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;
5591
8cd83b10634f (svn r7598) [cbh] - Codechange: Remove the functions IsTunnel() and IsBridge() as they are no longer needed.
celestar
parents: 5590
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;
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 tileh = GetTileSlope(t, &h);
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
}