mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r11968) -Codechange: remove redundant FindLengthOfTunnel(), use GetTunnelBridgeLength() and/or GetOtherTunnelEnd() instead
This commit is contained in:
parent
b5641ae0f2
commit
5a7c903770
|
@ -708,6 +708,9 @@
|
||||||
<File
|
<File
|
||||||
RelativePath=".\..\src\transparency_gui.h">
|
RelativePath=".\..\src\transparency_gui.h">
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\..\src\tunnelbridge.h">
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath=".\..\src\variables.h">
|
RelativePath=".\..\src\variables.h">
|
||||||
</File>
|
</File>
|
||||||
|
|
|
@ -1175,6 +1175,10 @@
|
||||||
RelativePath=".\..\src\transparency_gui.h"
|
RelativePath=".\..\src\transparency_gui.h"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\..\src\tunnelbridge.h"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath=".\..\src\variables.h"
|
RelativePath=".\..\src\variables.h"
|
||||||
>
|
>
|
||||||
|
|
|
@ -1172,6 +1172,10 @@
|
||||||
RelativePath=".\..\src\transparency_gui.h"
|
RelativePath=".\..\src\transparency_gui.h"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\..\src\tunnelbridge.h"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath=".\..\src\variables.h"
|
RelativePath=".\..\src\variables.h"
|
||||||
>
|
>
|
||||||
|
|
|
@ -202,6 +202,7 @@ town.h
|
||||||
train.h
|
train.h
|
||||||
transparency.h
|
transparency.h
|
||||||
transparency_gui.h
|
transparency_gui.h
|
||||||
|
tunnelbridge.h
|
||||||
variables.h
|
variables.h
|
||||||
vehicle.h
|
vehicle.h
|
||||||
vehicle_gui.h
|
vehicle_gui.h
|
||||||
|
|
|
@ -31,6 +31,7 @@
|
||||||
#include "../../player_base.h"
|
#include "../../player_base.h"
|
||||||
#include "../../settings_type.h"
|
#include "../../settings_type.h"
|
||||||
#include "default.h"
|
#include "default.h"
|
||||||
|
#include "../../tunnelbridge.h"
|
||||||
|
|
||||||
#include "../../table/ai_rail.h"
|
#include "../../table/ai_rail.h"
|
||||||
|
|
||||||
|
@ -2173,7 +2174,7 @@ static void AiBuildRailConstruct(Player *p)
|
||||||
|
|
||||||
if (arf.best_ptr[0] & 0x80) {
|
if (arf.best_ptr[0] & 0x80) {
|
||||||
int i;
|
int i;
|
||||||
int32 bridge_len = GetBridgeLength(arf.bridge_end_tile, _players_ai[p->index].cur_tile_a);
|
int32 bridge_len = GetTunnelBridgeLength(arf.bridge_end_tile, _players_ai[p->index].cur_tile_a);
|
||||||
|
|
||||||
/* Figure out which (rail)bridge type to build
|
/* Figure out which (rail)bridge type to build
|
||||||
* start with best bridge, then go down to worse and worse bridges
|
* start with best bridge, then go down to worse and worse bridges
|
||||||
|
@ -3065,7 +3066,7 @@ do_some_terraform:
|
||||||
int i;
|
int i;
|
||||||
int32 bridge_len;
|
int32 bridge_len;
|
||||||
_players_ai[p->index].cur_tile_a = arf.bridge_end_tile;
|
_players_ai[p->index].cur_tile_a = arf.bridge_end_tile;
|
||||||
bridge_len = GetBridgeLength(tile, _players_ai[p->index].cur_tile_a); // tile
|
bridge_len = GetTunnelBridgeLength(tile, _players_ai[p->index].cur_tile_a); // tile
|
||||||
|
|
||||||
/* Figure out what (road)bridge type to build
|
/* Figure out what (road)bridge type to build
|
||||||
* start with best bridge, then go down to worse and worse bridges
|
* start with best bridge, then go down to worse and worse bridges
|
||||||
|
|
|
@ -15,6 +15,8 @@
|
||||||
#include "../../player_base.h"
|
#include "../../player_base.h"
|
||||||
#include "../../player_func.h"
|
#include "../../player_func.h"
|
||||||
#include "../ai.h"
|
#include "../ai.h"
|
||||||
|
#include "../../tunnelbridge.h"
|
||||||
|
|
||||||
|
|
||||||
// Build HQ
|
// Build HQ
|
||||||
// Params:
|
// Params:
|
||||||
|
@ -58,7 +60,7 @@ CommandCost AiNew_Build_Bridge(Player *p, TileIndex tile_a, TileIndex tile_b, by
|
||||||
int bridge_type, bridge_len, type, type2;
|
int bridge_type, bridge_len, type, type2;
|
||||||
|
|
||||||
// Find a good bridgetype (the best money can buy)
|
// Find a good bridgetype (the best money can buy)
|
||||||
bridge_len = GetBridgeLength(tile_a, tile_b);
|
bridge_len = GetTunnelBridgeLength(tile_a, tile_b);
|
||||||
type = type2 = 0;
|
type = type2 = 0;
|
||||||
for (bridge_type = MAX_BRIDGES-1; bridge_type >= 0; bridge_type--) {
|
for (bridge_type = MAX_BRIDGES-1; bridge_type >= 0; bridge_type--) {
|
||||||
if (CheckBridge_Stuff(bridge_type, bridge_len)) {
|
if (CheckBridge_Stuff(bridge_type, bridge_len)) {
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
#include "../../variables.h"
|
#include "../../variables.h"
|
||||||
#include "../../player_base.h"
|
#include "../../player_base.h"
|
||||||
#include "../../player_func.h"
|
#include "../../player_func.h"
|
||||||
|
#include "../../tunnelbridge.h"
|
||||||
|
|
||||||
|
|
||||||
#define TEST_STATION_NO_DIR 0xFF
|
#define TEST_STATION_NO_DIR 0xFF
|
||||||
|
@ -320,7 +321,7 @@ static void AyStar_AiPathFinder_GetNeighbours(AyStar *aystar, OpenListNode *curr
|
||||||
new_tile += TileOffsByDiagDir(dir);
|
new_tile += TileOffsByDiagDir(dir);
|
||||||
|
|
||||||
// Precheck, is the length allowed?
|
// Precheck, is the length allowed?
|
||||||
if (!CheckBridge_Stuff(0, GetBridgeLength(tile, new_tile))) break;
|
if (!CheckBridge_Stuff(0, GetTunnelBridgeLength(tile, new_tile))) break;
|
||||||
|
|
||||||
// Check if we hit the station-tile.. we don't like that!
|
// Check if we hit the station-tile.. we don't like that!
|
||||||
if (TILES_BETWEEN(new_tile, PathFinderInfo->end_tile_tl, PathFinderInfo->end_tile_br)) break;
|
if (TILES_BETWEEN(new_tile, PathFinderInfo->end_tile_tl, PathFinderInfo->end_tile_br)) break;
|
||||||
|
@ -425,14 +426,14 @@ static int32 AyStar_AiPathFinder_CalculateG(AyStar *aystar, AyStarNode *current,
|
||||||
int r;
|
int r;
|
||||||
// Tunnels are very expensive when build on long routes..
|
// Tunnels are very expensive when build on long routes..
|
||||||
// Ironicly, we are using BridgeCode here ;)
|
// Ironicly, we are using BridgeCode here ;)
|
||||||
r = AI_PATHFINDER_TUNNEL_PENALTY * GetBridgeLength(current->tile, parent->path.node.tile);
|
r = AI_PATHFINDER_TUNNEL_PENALTY * GetTunnelBridgeLength(current->tile, parent->path.node.tile);
|
||||||
res += r + (r >> 8);
|
res += r + (r >> 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Are we part of a bridge?
|
// Are we part of a bridge?
|
||||||
if ((AI_PATHFINDER_FLAG_BRIDGE & current->user_data[0]) != 0) {
|
if ((AI_PATHFINDER_FLAG_BRIDGE & current->user_data[0]) != 0) {
|
||||||
// That means for every length a penalty
|
// That means for every length a penalty
|
||||||
res += AI_PATHFINDER_BRIDGE_PENALTY * GetBridgeLength(current->tile, parent->path.node.tile);
|
res += AI_PATHFINDER_BRIDGE_PENALTY * GetTunnelBridgeLength(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 (!HasBridgeFlatRamp(parent_tileh, (Axis)((current->user_data[0] >> 8) & 1))) res += AI_PATHFINDER_BRIDGE_GOES_UP_PENALTY;
|
if (!HasBridgeFlatRamp(parent_tileh, (Axis)((current->user_data[0] >> 8) & 1))) res += AI_PATHFINDER_BRIDGE_GOES_UP_PENALTY;
|
||||||
|
|
|
@ -43,7 +43,6 @@ static inline const Bridge *GetBridge(uint i)
|
||||||
void DrawBridgeMiddle(const TileInfo *ti);
|
void DrawBridgeMiddle(const TileInfo *ti);
|
||||||
|
|
||||||
bool CheckBridge_Stuff(byte bridge_type, uint bridge_len);
|
bool CheckBridge_Stuff(byte bridge_type, uint bridge_len);
|
||||||
uint32 GetBridgeLength(TileIndex begin, TileIndex end);
|
|
||||||
int CalcBridgeLenCostFactor(int x);
|
int CalcBridgeLenCostFactor(int x);
|
||||||
|
|
||||||
#endif /* BRIDGE_H */
|
#endif /* BRIDGE_H */
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
#include "map_func.h"
|
#include "map_func.h"
|
||||||
#include "viewport_func.h"
|
#include "viewport_func.h"
|
||||||
#include "gfx_func.h"
|
#include "gfx_func.h"
|
||||||
|
#include "tunnelbridge.h"
|
||||||
|
|
||||||
#include "table/strings.h"
|
#include "table/strings.h"
|
||||||
|
|
||||||
|
@ -182,7 +183,7 @@ void ShowBuildBridgeWindow(TileIndex start, TileIndex end, byte bridge_type)
|
||||||
/* check which bridges can be built
|
/* check which bridges can be built
|
||||||
* get absolute bridge length
|
* get absolute bridge length
|
||||||
* length of the middle parts of the bridge */
|
* length of the middle parts of the bridge */
|
||||||
const uint bridge_len = GetBridgeLength(start, end);
|
const uint bridge_len = GetTunnelBridgeLength(start, end);
|
||||||
/* total length of bridge */
|
/* total length of bridge */
|
||||||
const uint tot_bridgedata_len = CalcBridgeLenCostFactor(bridge_len + 2);
|
const uint tot_bridgedata_len = CalcBridgeLenCostFactor(bridge_len + 2);
|
||||||
|
|
||||||
|
|
|
@ -64,6 +64,7 @@
|
||||||
#include "tunnelbridge_map.h"
|
#include "tunnelbridge_map.h"
|
||||||
#include "vehicle_func.h"
|
#include "vehicle_func.h"
|
||||||
#include "player_base.h"
|
#include "player_base.h"
|
||||||
|
#include "tunnelbridge.h"
|
||||||
|
|
||||||
#include "table/sprites.h"
|
#include "table/sprites.h"
|
||||||
#include "table/elrail_data.h"
|
#include "table/elrail_data.h"
|
||||||
|
@ -383,8 +384,8 @@ static void DrawCatenaryOnBridge(const TileInfo *ti)
|
||||||
TileIndex end = GetSouthernBridgeEnd(ti->tile);
|
TileIndex end = GetSouthernBridgeEnd(ti->tile);
|
||||||
TileIndex start = GetOtherBridgeEnd(end);
|
TileIndex start = GetOtherBridgeEnd(end);
|
||||||
|
|
||||||
uint length = GetBridgeLength(start, end);
|
uint length = GetTunnelBridgeLength(start, end);
|
||||||
uint num = DistanceMax(ti->tile, start);
|
uint num = GetTunnelBridgeLength(ti->tile, start) + 1;
|
||||||
uint height;
|
uint height;
|
||||||
|
|
||||||
const SortableSpriteStruct *sss;
|
const SortableSpriteStruct *sss;
|
||||||
|
@ -421,7 +422,7 @@ static void DrawCatenaryOnBridge(const TileInfo *ti)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* need a pylon on the southern end of the bridge */
|
/* need a pylon on the southern end of the bridge */
|
||||||
if (DistanceMax(ti->tile, start) == length) {
|
if (GetTunnelBridgeLength(ti->tile, start) + 1 == length) {
|
||||||
DiagDirection PCPpos = (axis == AXIS_X ? DIAGDIR_SW : DIAGDIR_SE);
|
DiagDirection PCPpos = (axis == AXIS_X ? DIAGDIR_SW : DIAGDIR_SE);
|
||||||
Direction PPPpos = (axis == AXIS_X ? DIR_NW : DIR_NE);
|
Direction PPPpos = (axis == AXIS_X ? DIR_NW : DIR_NE);
|
||||||
if (HasBit(tlg, (axis == AXIS_X ? 0 : 1))) PPPpos = ReverseDir(PPPpos);
|
if (HasBit(tlg, (axis == AXIS_X ? 0 : 1))) PPPpos = ReverseDir(PPPpos);
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#include "functions.h"
|
#include "functions.h"
|
||||||
#include "vehicle_base.h"
|
#include "vehicle_base.h"
|
||||||
#include "settings_type.h"
|
#include "settings_type.h"
|
||||||
|
#include "tunnelbridge.h"
|
||||||
|
|
||||||
static AyStar _npf_aystar;
|
static AyStar _npf_aystar;
|
||||||
|
|
||||||
|
@ -176,9 +177,7 @@ static uint NPFTunnelCost(AyStarNode* current)
|
||||||
if (GetTunnelBridgeDirection(tile) == ReverseDiagDir(exitdir)) {
|
if (GetTunnelBridgeDirection(tile) == ReverseDiagDir(exitdir)) {
|
||||||
/* We just popped out if this tunnel, since were
|
/* We just popped out if this tunnel, since were
|
||||||
* facing the tunnel exit */
|
* facing the tunnel exit */
|
||||||
FindLengthOfTunnelResult flotr;
|
return NPF_TILE_LENGTH * (GetTunnelBridgeLength(current->tile, GetOtherTunnelEnd(current->tile)) + 1);
|
||||||
flotr = FindLengthOfTunnel(tile, ReverseDiagDir(exitdir));
|
|
||||||
return flotr.length * NPF_TILE_LENGTH;
|
|
||||||
/* @todo: Penalty for tunnels? */
|
/* @todo: Penalty for tunnels? */
|
||||||
} else {
|
} else {
|
||||||
/* We are entering the tunnel, the enter tile is just a
|
/* We are entering the tunnel, the enter tile is just a
|
||||||
|
@ -189,7 +188,7 @@ static uint NPFTunnelCost(AyStarNode* current)
|
||||||
|
|
||||||
static inline uint NPFBridgeCost(AyStarNode *current)
|
static inline uint NPFBridgeCost(AyStarNode *current)
|
||||||
{
|
{
|
||||||
return NPF_TILE_LENGTH * GetBridgeLength(current->tile, GetOtherBridgeEnd(current->tile));
|
return NPF_TILE_LENGTH * GetTunnelBridgeLength(current->tile, GetOtherBridgeEnd(current->tile));
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint NPFSlopeCost(AyStarNode* current)
|
static uint NPFSlopeCost(AyStarNode* current)
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
#include "depot.h"
|
#include "depot.h"
|
||||||
#include "tunnelbridge_map.h"
|
#include "tunnelbridge_map.h"
|
||||||
#include "core/random_func.hpp"
|
#include "core/random_func.hpp"
|
||||||
|
#include "tunnelbridge.h"
|
||||||
|
|
||||||
/* remember which tiles we have already visited so we don't visit them again. */
|
/* remember which tiles we have already visited so we don't visit them again. */
|
||||||
static bool TPFSetTileBit(TrackPathFinder *tpf, TileIndex tile, int dir)
|
static bool TPFSetTileBit(TrackPathFinder *tpf, TileIndex tile, int dir)
|
||||||
|
@ -192,32 +193,6 @@ continue_here:
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Returns the end tile and the length of a tunnel. The length does not
|
|
||||||
* include the starting tile (entry), it does include the end tile (exit).
|
|
||||||
*/
|
|
||||||
FindLengthOfTunnelResult FindLengthOfTunnel(TileIndex tile, DiagDirection dir)
|
|
||||||
{
|
|
||||||
TileIndexDiff delta = TileOffsByDiagDir(dir);
|
|
||||||
uint z = GetTileZ(tile);
|
|
||||||
FindLengthOfTunnelResult flotr;
|
|
||||||
|
|
||||||
flotr.length = 0;
|
|
||||||
|
|
||||||
dir = ReverseDiagDir(dir);
|
|
||||||
do {
|
|
||||||
flotr.length++;
|
|
||||||
tile += delta;
|
|
||||||
} while(
|
|
||||||
!IsTunnelTile(tile) ||
|
|
||||||
GetTunnelBridgeDirection(tile) != dir ||
|
|
||||||
GetTileZ(tile) != z
|
|
||||||
);
|
|
||||||
|
|
||||||
flotr.tile = tile;
|
|
||||||
return flotr;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if any vehicle can enter/leave tile in given diagdir
|
* Checks if any vehicle can enter/leave tile in given diagdir
|
||||||
* Checks only for rail/road depots and road non-drivethrough stations
|
* Checks only for rail/road depots and road non-drivethrough stations
|
||||||
|
@ -257,7 +232,7 @@ static void TPFMode1(TrackPathFinder* tpf, TileIndex tile, DiagDirection directi
|
||||||
if (dir == direction) {
|
if (dir == direction) {
|
||||||
TileIndex endtile = GetOtherTunnelBridgeEnd(tile);
|
TileIndex endtile = GetOtherTunnelBridgeEnd(tile);
|
||||||
|
|
||||||
tpf->rd.cur_length += DistanceManhattan(tile, endtile);
|
tpf->rd.cur_length += GetTunnelBridgeLength(tile, endtile) + 1;
|
||||||
|
|
||||||
TPFSetTileBit(tpf, tile, 14);
|
TPFSetTileBit(tpf, tile, 14);
|
||||||
TPFSetTileBit(tpf, endtile, 14);
|
TPFSetTileBit(tpf, endtile, 14);
|
||||||
|
@ -665,8 +640,6 @@ start_at:
|
||||||
if (IsTileType(tile, MP_TUNNELBRIDGE)) {
|
if (IsTileType(tile, MP_TUNNELBRIDGE)) {
|
||||||
if (IsTunnel(tile)) {
|
if (IsTunnel(tile)) {
|
||||||
if (GetTunnelBridgeDirection(tile) != ReverseDiagDir(direction)) {
|
if (GetTunnelBridgeDirection(tile) != ReverseDiagDir(direction)) {
|
||||||
FindLengthOfTunnelResult flotr;
|
|
||||||
|
|
||||||
/* We are not just driving out of the tunnel */
|
/* We are not just driving out of the tunnel */
|
||||||
if (GetTunnelBridgeDirection(tile) != direction ||
|
if (GetTunnelBridgeDirection(tile) != direction ||
|
||||||
GetTunnelBridgeTransportType(tile) != tpf->tracktype) {
|
GetTunnelBridgeTransportType(tile) != tpf->tracktype) {
|
||||||
|
@ -677,9 +650,10 @@ start_at:
|
||||||
bits = TRACK_BIT_NONE;
|
bits = TRACK_BIT_NONE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
flotr = FindLengthOfTunnel(tile, direction);
|
|
||||||
si.cur_length += flotr.length * DIAG_FACTOR;
|
TileIndex endtile = GetOtherTunnelEnd(tile);
|
||||||
tile = flotr.tile;
|
si.cur_length += DIAG_FACTOR * (GetTunnelBridgeLength(tile, endtile) + 1);
|
||||||
|
tile = endtile;
|
||||||
/* tile now points to the exit tile of the tunnel */
|
/* tile now points to the exit tile of the tunnel */
|
||||||
}
|
}
|
||||||
} else { // IsBridge(tile)
|
} else { // IsBridge(tile)
|
||||||
|
@ -693,7 +667,7 @@ start_at:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tile_end = GetOtherBridgeEnd(tile);
|
tile_end = GetOtherBridgeEnd(tile);
|
||||||
si.cur_length += DistanceManhattan(tile, tile_end) * DIAG_FACTOR;
|
si.cur_length += DIAG_FACTOR * (GetTunnelBridgeLength(tile, tile_end) + 1);
|
||||||
tile = tile_end;
|
tile = tile_end;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,13 +68,6 @@ struct TrackPathFinder {
|
||||||
};
|
};
|
||||||
|
|
||||||
void FollowTrack(TileIndex tile, uint16 flags, uint sub_type, DiagDirection direction, TPFEnumProc* enum_proc, TPFAfterProc* after_proc, void* data);
|
void FollowTrack(TileIndex tile, uint16 flags, uint sub_type, DiagDirection direction, TPFEnumProc* enum_proc, TPFAfterProc* after_proc, void* data);
|
||||||
|
|
||||||
struct FindLengthOfTunnelResult {
|
|
||||||
TileIndex tile;
|
|
||||||
int length;
|
|
||||||
};
|
|
||||||
FindLengthOfTunnelResult FindLengthOfTunnel(TileIndex tile, DiagDirection direction);
|
|
||||||
|
|
||||||
void NewTrainPathfind(TileIndex tile, TileIndex dest, RailTypes railtypes, DiagDirection direction, NTPEnumProc* enum_proc, void* data);
|
void NewTrainPathfind(TileIndex tile, TileIndex dest, RailTypes railtypes, DiagDirection direction, NTPEnumProc* enum_proc, void* data);
|
||||||
|
|
||||||
#endif /* PATHFIND_H */
|
#endif /* PATHFIND_H */
|
||||||
|
|
|
@ -40,6 +40,7 @@
|
||||||
#include "vehicle_func.h"
|
#include "vehicle_func.h"
|
||||||
#include "sound_func.h"
|
#include "sound_func.h"
|
||||||
#include "signal_func.h"
|
#include "signal_func.h"
|
||||||
|
#include "tunnelbridge.h"
|
||||||
|
|
||||||
#include "table/sprites.h"
|
#include "table/sprites.h"
|
||||||
#include "table/strings.h"
|
#include "table/strings.h"
|
||||||
|
@ -939,7 +940,7 @@ static bool CheckSignalAutoFill(TileIndex &tile, Trackdir &trackdir, int &signal
|
||||||
* note that tile is a parameter by reference, so it must be updated */
|
* note that tile is a parameter by reference, so it must be updated */
|
||||||
tile = GetOtherTunnelBridgeEnd(tile);
|
tile = GetOtherTunnelBridgeEnd(tile);
|
||||||
|
|
||||||
signal_ctr += 2 + DistanceMax(orig_tile, tile) * 2;
|
signal_ctr += (GetTunnelBridgeLength(orig_tile, tile) + 2) * 2;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1294,7 +1295,7 @@ CommandCost CmdConvertRail(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cost.AddCost((DistanceManhattan(tile, endtile) + 1) * RailConvertCost(type, totype));
|
cost.AddCost((GetTunnelBridgeLength(tile, endtile) + 2) * RailConvertCost(type, totype));
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
default: // MP_STATION, MP_ROAD
|
default: // MP_STATION, MP_ROAD
|
||||||
|
|
|
@ -33,6 +33,7 @@
|
||||||
#include "vehicle_base.h"
|
#include "vehicle_base.h"
|
||||||
#include "sound_func.h"
|
#include "sound_func.h"
|
||||||
#include "road_func.h"
|
#include "road_func.h"
|
||||||
|
#include "tunnelbridge.h"
|
||||||
|
|
||||||
#include "table/sprites.h"
|
#include "table/sprites.h"
|
||||||
#include "table/strings.h"
|
#include "table/strings.h"
|
||||||
|
@ -159,7 +160,7 @@ CommandCost CmdRemoveRoad(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
||||||
if (IsTileType(tile, MP_TUNNELBRIDGE)) {
|
if (IsTileType(tile, MP_TUNNELBRIDGE)) {
|
||||||
TileIndex other_end = GetOtherTunnelBridgeEnd(tile);
|
TileIndex other_end = GetOtherTunnelBridgeEnd(tile);
|
||||||
/* Pay for *every* tile of the bridge or tunnel */
|
/* Pay for *every* tile of the bridge or tunnel */
|
||||||
cost.AddCost((DistanceManhattan(other_end, tile) + 1) * _price.remove_road);
|
cost.AddCost((GetTunnelBridgeLength(other_end, tile) + 2) * _price.remove_road);
|
||||||
if (flags & DC_EXEC) {
|
if (flags & DC_EXEC) {
|
||||||
SetRoadTypes(other_end, GetRoadTypes(other_end) & ~RoadTypeToRoadTypes(rt));
|
SetRoadTypes(other_end, GetRoadTypes(other_end) & ~RoadTypeToRoadTypes(rt));
|
||||||
SetRoadTypes(tile, GetRoadTypes(tile) & ~RoadTypeToRoadTypes(rt));
|
SetRoadTypes(tile, GetRoadTypes(tile) & ~RoadTypeToRoadTypes(rt));
|
||||||
|
@ -551,7 +552,7 @@ do_clear:;
|
||||||
cost.AddCost(CountBits(pieces) * _price.build_road);
|
cost.AddCost(CountBits(pieces) * _price.build_road);
|
||||||
if (IsTileType(tile, MP_TUNNELBRIDGE)) {
|
if (IsTileType(tile, MP_TUNNELBRIDGE)) {
|
||||||
/* Pay for *every* tile of the bridge or tunnel */
|
/* Pay for *every* tile of the bridge or tunnel */
|
||||||
cost.MultiplyCost(DistanceManhattan(GetOtherTunnelBridgeEnd(tile), tile) + 1);
|
cost.MultiplyCost(GetTunnelBridgeLength(GetOtherTunnelBridgeEnd(tile), tile) + 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flags & DC_EXEC) {
|
if (flags & DC_EXEC) {
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
/* $Id$ */
|
||||||
|
|
||||||
|
/** @file tunnelbridge.h Header file for things common for tunnels and bridges */
|
||||||
|
|
||||||
|
#ifndef TUNNELBRIDGE_H
|
||||||
|
#define TUNNELBRIDGE_H
|
||||||
|
|
||||||
|
#include "tile_type.h"
|
||||||
|
#include "map_func.h"
|
||||||
|
#include "tunnelbridge_map.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculates the length of a tunnel or a bridge (without end tiles)
|
||||||
|
* @return length of bridge/tunnel middle
|
||||||
|
*/
|
||||||
|
static inline uint GetTunnelBridgeLength(TileIndex begin, TileIndex end)
|
||||||
|
{
|
||||||
|
int x1 = TileX(begin);
|
||||||
|
int y1 = TileY(begin);
|
||||||
|
int x2 = TileX(end);
|
||||||
|
int y2 = TileY(end);
|
||||||
|
|
||||||
|
return abs(x2 + y2 - x1 - y1) - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* TUNNELBRIDGE_H */
|
|
@ -32,6 +32,7 @@
|
||||||
#include "vehicle_func.h"
|
#include "vehicle_func.h"
|
||||||
#include "sound_func.h"
|
#include "sound_func.h"
|
||||||
#include "signal_func.h"
|
#include "signal_func.h"
|
||||||
|
#include "tunnelbridge.h"
|
||||||
|
|
||||||
#include "table/sprites.h"
|
#include "table/sprites.h"
|
||||||
#include "table/strings.h"
|
#include "table/strings.h"
|
||||||
|
@ -160,17 +161,6 @@ static CommandCost CheckBridgeSlopeSouth(Axis axis, Slope *tileh, uint *z)
|
||||||
return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform);
|
return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
uint32 GetBridgeLength(TileIndex begin, TileIndex end)
|
|
||||||
{
|
|
||||||
int x1 = TileX(begin);
|
|
||||||
int y1 = TileY(begin);
|
|
||||||
int x2 = TileX(end);
|
|
||||||
int y2 = TileY(end);
|
|
||||||
|
|
||||||
return abs(x2 + y2 - x1 - y1) - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CheckBridge_Stuff(byte bridge_type, uint bridge_len)
|
bool CheckBridge_Stuff(byte bridge_type, uint bridge_len)
|
||||||
{
|
{
|
||||||
const Bridge *b = &_bridge[bridge_type];
|
const Bridge *b = &_bridge[bridge_type];
|
||||||
|
@ -633,7 +623,7 @@ static CommandCost DoClearTunnel(TileIndex tile, uint32 flags)
|
||||||
DoClearSquare(endtile);
|
DoClearSquare(endtile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return CommandCost(EXPENSES_CONSTRUCTION, _price.clear_tunnel * (DistanceManhattan(tile, endtile) + 1));
|
return CommandCost(EXPENSES_CONSTRUCTION, _price.clear_tunnel * (GetTunnelBridgeLength(tile, endtile) + 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -693,7 +683,7 @@ static CommandCost DoClearBridge(TileIndex tile, uint32 flags)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return CommandCost(EXPENSES_CONSTRUCTION, (DistanceManhattan(tile, endtile) + 1) * _price.clear_bridge);
|
return CommandCost(EXPENSES_CONSTRUCTION, (GetTunnelBridgeLength(tile, endtile) + 2) * _price.clear_bridge);
|
||||||
}
|
}
|
||||||
|
|
||||||
static CommandCost ClearTile_TunnelBridge(TileIndex tile, byte flags)
|
static CommandCost ClearTile_TunnelBridge(TileIndex tile, byte flags)
|
||||||
|
@ -1018,8 +1008,8 @@ void DrawBridgeMiddle(const TileInfo* ti)
|
||||||
|
|
||||||
axis = GetBridgeAxis(ti->tile);
|
axis = GetBridgeAxis(ti->tile);
|
||||||
piece = CalcBridgePiece(
|
piece = CalcBridgePiece(
|
||||||
DistanceManhattan(ti->tile, rampnorth),
|
GetTunnelBridgeLength(ti->tile, rampnorth) + 1,
|
||||||
DistanceManhattan(ti->tile, rampsouth)
|
GetTunnelBridgeLength(ti->tile, rampsouth) + 1
|
||||||
);
|
);
|
||||||
type = GetBridgeType(rampsouth);
|
type = GetBridgeType(rampsouth);
|
||||||
|
|
||||||
|
|
|
@ -76,32 +76,22 @@ protected:
|
||||||
m_is_station = m_is_bridge = m_is_tunnel = false;
|
m_is_station = m_is_bridge = m_is_tunnel = false;
|
||||||
m_tiles_skipped = 0;
|
m_tiles_skipped = 0;
|
||||||
|
|
||||||
// extra handling for tunnels in our direction
|
// extra handling for tunnels and bridges in our direction
|
||||||
if (IsTunnelTile(m_old_tile)) {
|
if (IsTileType(m_old_tile, MP_TUNNELBRIDGE)) {
|
||||||
DiagDirection tunnel_enterdir = GetTunnelBridgeDirection(m_old_tile);
|
DiagDirection enterdir = GetTunnelBridgeDirection(m_old_tile);
|
||||||
if (tunnel_enterdir == m_exitdir) {
|
if (enterdir == m_exitdir) {
|
||||||
// we are entering the tunnel
|
// we are entering the tunnel / bridge
|
||||||
FindLengthOfTunnelResult flotr = FindLengthOfTunnel(m_old_tile, m_exitdir);
|
if (IsTunnel(m_old_tile)) {
|
||||||
m_new_tile = flotr.tile;
|
m_is_tunnel = true;
|
||||||
m_is_tunnel = true;
|
m_new_tile = GetOtherTunnelEnd(m_old_tile);
|
||||||
m_tiles_skipped = flotr.length - 1;
|
} else { // IsBridge(m_old_tile)
|
||||||
|
m_is_bridge = true;
|
||||||
|
m_new_tile = GetOtherBridgeEnd(m_old_tile);
|
||||||
|
}
|
||||||
|
m_tiles_skipped = GetTunnelBridgeLength(m_new_tile, m_old_tile);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
assert(ReverseDiagDir(tunnel_enterdir) == m_exitdir);
|
assert(ReverseDiagDir(enterdir) == m_exitdir);
|
||||||
}
|
|
||||||
|
|
||||||
// extra handling for bridge ramp in our direction
|
|
||||||
if (IsBridgeTile(m_old_tile)) {
|
|
||||||
DiagDirection bridge_enterdir = GetTunnelBridgeDirection(m_old_tile);
|
|
||||||
if (bridge_enterdir == m_exitdir) {
|
|
||||||
// we are entering the bridge ramp
|
|
||||||
m_new_tile = GetOtherBridgeEnd(m_old_tile);
|
|
||||||
uint32 bridge_length = GetBridgeLength(m_old_tile, m_new_tile);
|
|
||||||
m_tiles_skipped = bridge_length;
|
|
||||||
m_is_bridge = true;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
assert(ReverseDiagDir(bridge_enterdir) == m_exitdir);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// normal or station tile, do one step
|
// normal or station tile, do one step
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#include "../waypoint.h"
|
#include "../waypoint.h"
|
||||||
#include "../debug.h"
|
#include "../debug.h"
|
||||||
#include "../settings_type.h"
|
#include "../settings_type.h"
|
||||||
|
#include "../tunnelbridge.h"
|
||||||
|
|
||||||
extern uint64 _rdtsc();
|
extern uint64 _rdtsc();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue