mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-11 18:10:14 +00:00
(svn r11946) -Fix: slope detection of bridge ramps.
YAPF failed for steep slopes. Trolly failed for a lot.
This commit is contained in:
parent
7d1e3086b8
commit
b99c83246b
@ -359,10 +359,6 @@ static void AyStar_AiPathFinder_GetNeighbours(AyStar *aystar, OpenListNode *curr
|
|||||||
|
|
||||||
extern Foundation GetRailFoundation(Slope tileh, TrackBits bits); // XXX function declaration in .c
|
extern Foundation GetRailFoundation(Slope tileh, TrackBits bits); // XXX function declaration in .c
|
||||||
extern Foundation GetRoadFoundation(Slope tileh, RoadBits bits); // XXX function declaration in .c
|
extern Foundation GetRoadFoundation(Slope tileh, RoadBits bits); // XXX function declaration in .c
|
||||||
extern Foundation GetBridgeFoundation(Slope tileh, Axis); // XXX function declaration in .c
|
|
||||||
enum BridgeFoundation {
|
|
||||||
BRIDGE_NO_FOUNDATION = 1 << 0 | 1 << 3 | 1 << 6 | 1 << 9 | 1 << 12,
|
|
||||||
};
|
|
||||||
|
|
||||||
// The most important function: it calculates the g-value
|
// The most important function: it calculates the g-value
|
||||||
static int32 AyStar_AiPathFinder_CalculateG(AyStar *aystar, AyStarNode *current, OpenListNode *parent)
|
static int32 AyStar_AiPathFinder_CalculateG(AyStar *aystar, AyStarNode *current, OpenListNode *parent)
|
||||||
@ -403,10 +399,10 @@ static int32 AyStar_AiPathFinder_CalculateG(AyStar *aystar, AyStarNode *current,
|
|||||||
if (parent_tileh != SLOPE_FLAT && parent->path.parent != NULL) {
|
if (parent_tileh != SLOPE_FLAT && parent->path.parent != NULL) {
|
||||||
// Skip if the tile was from a bridge or tunnel
|
// Skip if the tile was from a bridge or tunnel
|
||||||
if (parent->path.node.user_data[0] == 0 && current->user_data[0] == 0) {
|
if (parent->path.node.user_data[0] == 0 && current->user_data[0] == 0) {
|
||||||
|
static const uint32 SLOPED_TILEHS = (1 << SLOPE_NW) | (1 << SLOPE_SW) | (1 << SLOPE_SE) | (1 << SLOPE_NE);
|
||||||
if (PathFinderInfo->rail_or_road) {
|
if (PathFinderInfo->rail_or_road) {
|
||||||
Foundation f = GetRailFoundation(parent_tileh, (TrackBits)(1 << AiNew_GetRailDirection(parent->path.parent->node.tile, parent->path.node.tile, current->tile)));
|
Foundation f = GetRailFoundation(parent_tileh, (TrackBits)(1 << AiNew_GetRailDirection(parent->path.parent->node.tile, parent->path.node.tile, current->tile)));
|
||||||
// Maybe is BRIDGE_NO_FOUNDATION a bit strange here, but it contains just the right information..
|
if (IsInclinedFoundation(f) || (!IsFoundation(f) && HasBit(SLOPED_TILEHS, parent_tileh))) {
|
||||||
if (IsInclinedFoundation(f) || (!IsFoundation(f) && HasBit(BRIDGE_NO_FOUNDATION, parent_tileh))) {
|
|
||||||
res += AI_PATHFINDER_TILE_GOES_UP_PENALTY;
|
res += AI_PATHFINDER_TILE_GOES_UP_PENALTY;
|
||||||
} else {
|
} else {
|
||||||
res += AI_PATHFINDER_FOUNDATION_PENALTY;
|
res += AI_PATHFINDER_FOUNDATION_PENALTY;
|
||||||
@ -414,7 +410,7 @@ static int32 AyStar_AiPathFinder_CalculateG(AyStar *aystar, AyStarNode *current,
|
|||||||
} else {
|
} else {
|
||||||
if (!IsRoad(parent->path.node.tile) || !IsTileType(parent->path.node.tile, MP_TUNNELBRIDGE)) {
|
if (!IsRoad(parent->path.node.tile) || !IsTileType(parent->path.node.tile, MP_TUNNELBRIDGE)) {
|
||||||
Foundation f = GetRoadFoundation(parent_tileh, (RoadBits)AiNew_GetRoadDirection(parent->path.parent->node.tile, parent->path.node.tile, current->tile));
|
Foundation f = GetRoadFoundation(parent_tileh, (RoadBits)AiNew_GetRoadDirection(parent->path.parent->node.tile, parent->path.node.tile, current->tile));
|
||||||
if (IsInclinedFoundation(f) || (!IsFoundation(f) && HasBit(BRIDGE_NO_FOUNDATION, parent_tileh))) {
|
if (IsInclinedFoundation(f) || (!IsFoundation(f) && HasBit(SLOPED_TILEHS, parent_tileh))) {
|
||||||
res += AI_PATHFINDER_TILE_GOES_UP_PENALTY;
|
res += AI_PATHFINDER_TILE_GOES_UP_PENALTY;
|
||||||
} else {
|
} else {
|
||||||
res += AI_PATHFINDER_FOUNDATION_PENALTY;
|
res += AI_PATHFINDER_FOUNDATION_PENALTY;
|
||||||
@ -439,19 +435,9 @@ static int32 AyStar_AiPathFinder_CalculateG(AyStar *aystar, AyStarNode *current,
|
|||||||
res += AI_PATHFINDER_BRIDGE_PENALTY * GetBridgeLength(current->tile, parent->path.node.tile);
|
res += AI_PATHFINDER_BRIDGE_PENALTY * GetBridgeLength(current->tile, parent->path.node.tile);
|
||||||
// Check if we are going up or down, first for the starting point
|
// Check if we are going up or down, first for the starting point
|
||||||
// In user_data[0] is at the 8th bit the direction
|
// In user_data[0] is at the 8th bit the direction
|
||||||
if (!HasBit(BRIDGE_NO_FOUNDATION, parent_tileh)) {
|
if (!HasBridgeFlatRamp(parent_tileh, (Axis)((current->user_data[0] >> 8) & 1))) res += AI_PATHFINDER_BRIDGE_GOES_UP_PENALTY;
|
||||||
if (IsLeveledFoundation(GetBridgeFoundation(parent_tileh, (Axis)((current->user_data[0] >> 8) & 1)))) {
|
|
||||||
res += AI_PATHFINDER_BRIDGE_GOES_UP_PENALTY;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Second for the end point
|
// Second for the end point
|
||||||
if (!HasBit(BRIDGE_NO_FOUNDATION, tileh)) {
|
if (!HasBridgeFlatRamp(tileh, (Axis)((current->user_data[0] >> 8) & 1))) res += AI_PATHFINDER_BRIDGE_GOES_UP_PENALTY;
|
||||||
if (IsLeveledFoundation(GetBridgeFoundation(tileh, (Axis)((current->user_data[0] >> 8) & 1)))) {
|
|
||||||
res += AI_PATHFINDER_BRIDGE_GOES_UP_PENALTY;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (parent_tileh == SLOPE_FLAT) res += AI_PATHFINDER_BRIDGE_GOES_UP_PENALTY;
|
|
||||||
if (tileh == SLOPE_FLAT) res += AI_PATHFINDER_BRIDGE_GOES_UP_PENALTY;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// To prevent the AI from taking the fastest way in tiles, but not the fastest way
|
// To prevent the AI from taking the fastest way in tiles, but not the fastest way
|
||||||
|
@ -32,6 +32,7 @@ extern const Bridge orig_bridge[MAX_BRIDGES];
|
|||||||
extern Bridge _bridge[MAX_BRIDGES];
|
extern Bridge _bridge[MAX_BRIDGES];
|
||||||
|
|
||||||
Foundation GetBridgeFoundation(Slope tileh, Axis axis);
|
Foundation GetBridgeFoundation(Slope tileh, Axis axis);
|
||||||
|
bool HasBridgeFlatRamp(Slope tileh, Axis axis);
|
||||||
|
|
||||||
static inline const Bridge *GetBridge(uint i)
|
static inline const Bridge *GetBridge(uint i)
|
||||||
{
|
{
|
||||||
|
@ -90,6 +90,20 @@ Foundation GetBridgeFoundation(Slope tileh, Axis axis)
|
|||||||
return (HasSlopeHighestCorner(tileh) ? InclinedFoundation(axis) : FlatteningFoundation(tileh));
|
return (HasSlopeHighestCorner(tileh) ? InclinedFoundation(axis) : FlatteningFoundation(tileh));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines if the track on a bridge ramp is flat or goes up/down.
|
||||||
|
*
|
||||||
|
* @param tileh Slope of the tile under the bridge head
|
||||||
|
* @param axis Orientation of bridge
|
||||||
|
* @return true iff the track is flat.
|
||||||
|
*/
|
||||||
|
bool HasBridgeFlatRamp(Slope tileh, Axis axis)
|
||||||
|
{
|
||||||
|
ApplyFoundationToSlope(GetBridgeFoundation(tileh, axis), &tileh);
|
||||||
|
/* If the foundation slope is flat the bridge has a non-flat ramp and vice versa. */
|
||||||
|
return (tileh != SLOPE_FLAT);
|
||||||
|
}
|
||||||
|
|
||||||
static inline const PalSpriteID *GetBridgeSpriteTable(int index, byte table)
|
static inline const PalSpriteID *GetBridgeSpriteTable(int index, byte table)
|
||||||
{
|
{
|
||||||
const Bridge *bridge = &_bridge[index];
|
const Bridge *bridge = &_bridge[index];
|
||||||
@ -1084,7 +1098,6 @@ void DrawBridgeMiddle(const TileInfo* ti)
|
|||||||
|
|
||||||
static uint GetSlopeZ_TunnelBridge(TileIndex tile, uint x, uint y)
|
static uint GetSlopeZ_TunnelBridge(TileIndex tile, uint x, uint y)
|
||||||
{
|
{
|
||||||
static const uint32 BRIDGE_HORZ_RAMP = (1 << SLOPE_SW) | (1 << SLOPE_SE) | (1 << SLOPE_NW) | (1 << SLOPE_NE);
|
|
||||||
uint z;
|
uint z;
|
||||||
Slope tileh = GetTileSlope(tile, &z);
|
Slope tileh = GetTileSlope(tile, &z);
|
||||||
|
|
||||||
@ -1106,7 +1119,7 @@ static uint GetSlopeZ_TunnelBridge(TileIndex tile, uint x, uint y)
|
|||||||
if (5 <= pos && pos <= 10) {
|
if (5 <= pos && pos <= 10) {
|
||||||
uint delta;
|
uint delta;
|
||||||
|
|
||||||
if (HasBit(BRIDGE_HORZ_RAMP, tileh)) return z + TILE_HEIGHT;
|
if (tileh != SLOPE_FLAT) return z + TILE_HEIGHT;
|
||||||
|
|
||||||
switch (dir) {
|
switch (dir) {
|
||||||
default: NOT_REACHED();
|
default: NOT_REACHED();
|
||||||
|
@ -13,11 +13,9 @@ struct CYapfCostBase {
|
|||||||
// it is bridge ramp, check if we are entering the bridge
|
// it is bridge ramp, check if we are entering the bridge
|
||||||
if (GetTunnelBridgeDirection(tile) != TrackdirToExitdir(td)) return false; // no, we are living it, no penalty
|
if (GetTunnelBridgeDirection(tile) != TrackdirToExitdir(td)) return false; // no, we are living it, no penalty
|
||||||
// we are entering the bridge
|
// we are entering the bridge
|
||||||
// if the tile slope is downwards, then bridge ramp has not upward slope
|
Slope tile_slope = GetTileSlope(tile, NULL);
|
||||||
uint tile_slope = GetTileSlope(tile, NULL) & 0x0F;
|
Axis axis = DiagDirToAxis(GetTunnelBridgeDirection(tile));
|
||||||
if ((c_upwards_slopes[tile_slope] & TrackdirToTrackdirBits(ReverseTrackdir(td))) != 0) return false; // tile under ramp goes down, no penalty
|
return !HasBridgeFlatRamp(tile_slope, axis);
|
||||||
// tile under ramp isn't going down, so ramp must go up
|
|
||||||
return true;
|
|
||||||
} else {
|
} else {
|
||||||
// not bridge ramp
|
// not bridge ramp
|
||||||
if (IsTunnelTile(tile)) return false; // tunnel entry/exit doesn't slope
|
if (IsTunnelTile(tile)) return false; // tunnel entry/exit doesn't slope
|
||||||
|
Loading…
Reference in New Issue
Block a user