mirror of https://github.com/OpenTTD/OpenTTD
(svn r14707) -Cleanup: Replace an 'int' by 'Trackdir'.
parent
400626d882
commit
ebf51ffb6b
|
@ -121,7 +121,7 @@ AyStar *new_AyStar_AiPathFinder(int max_tiles_around, Ai_PathFinderInfo *PathFin
|
||||||
|
|
||||||
// Set the start node
|
// Set the start node
|
||||||
start_node.parent = NULL;
|
start_node.parent = NULL;
|
||||||
start_node.node.direction = 0;
|
start_node.node.direction = INVALID_TRACKDIR;
|
||||||
start_node.node.user_data[0] = 0;
|
start_node.node.user_data[0] = 0;
|
||||||
|
|
||||||
// Now we add all the starting tiles
|
// Now we add all the starting tiles
|
||||||
|
@ -150,7 +150,7 @@ void clean_AyStar_AiPathFinder(AyStar *aystar, Ai_PathFinderInfo *PathFinderInfo
|
||||||
|
|
||||||
// Set the start node
|
// Set the start node
|
||||||
start_node.parent = NULL;
|
start_node.parent = NULL;
|
||||||
start_node.node.direction = 0;
|
start_node.node.direction = INVALID_TRACKDIR;
|
||||||
start_node.node.user_data[0] = 0;
|
start_node.node.user_data[0] = 0;
|
||||||
start_node.node.tile = PathFinderInfo->start_tile_tl;
|
start_node.node.tile = PathFinderInfo->start_tile_tl;
|
||||||
|
|
||||||
|
@ -300,7 +300,7 @@ static void AyStar_AiPathFinder_GetNeighbours(AyStar *aystar, OpenListNode *curr
|
||||||
// The tile can be connected
|
// The tile can be connected
|
||||||
aystar->neighbours[aystar->num_neighbours].tile = atile;
|
aystar->neighbours[aystar->num_neighbours].tile = atile;
|
||||||
aystar->neighbours[aystar->num_neighbours].user_data[0] = 0;
|
aystar->neighbours[aystar->num_neighbours].user_data[0] = 0;
|
||||||
aystar->neighbours[aystar->num_neighbours++].direction = 0;
|
aystar->neighbours[aystar->num_neighbours++].direction = INVALID_TRACKDIR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -333,7 +333,7 @@ static void AyStar_AiPathFinder_GetNeighbours(AyStar *aystar, OpenListNode *curr
|
||||||
// We can build a bridge here.. add him to the neighbours
|
// We can build a bridge here.. add him to the neighbours
|
||||||
aystar->neighbours[aystar->num_neighbours].tile = new_tile;
|
aystar->neighbours[aystar->num_neighbours].tile = new_tile;
|
||||||
aystar->neighbours[aystar->num_neighbours].user_data[0] = AI_PATHFINDER_FLAG_BRIDGE + (dir << 8);
|
aystar->neighbours[aystar->num_neighbours].user_data[0] = AI_PATHFINDER_FLAG_BRIDGE + (dir << 8);
|
||||||
aystar->neighbours[aystar->num_neighbours++].direction = 0;
|
aystar->neighbours[aystar->num_neighbours++].direction = INVALID_TRACKDIR;
|
||||||
// We can only have 12 neighbours, and we need 1 left for tunnels
|
// We can only have 12 neighbours, and we need 1 left for tunnels
|
||||||
if (aystar->num_neighbours == 11) break;
|
if (aystar->num_neighbours == 11) break;
|
||||||
}
|
}
|
||||||
|
@ -349,7 +349,7 @@ static void AyStar_AiPathFinder_GetNeighbours(AyStar *aystar, OpenListNode *curr
|
||||||
if (CmdSucceeded(ret) && IsInclinedSlope(tileh)) {
|
if (CmdSucceeded(ret) && IsInclinedSlope(tileh)) {
|
||||||
aystar->neighbours[aystar->num_neighbours].tile = _build_tunnel_endtile;
|
aystar->neighbours[aystar->num_neighbours].tile = _build_tunnel_endtile;
|
||||||
aystar->neighbours[aystar->num_neighbours].user_data[0] = AI_PATHFINDER_FLAG_TUNNEL + (dir << 8);
|
aystar->neighbours[aystar->num_neighbours].user_data[0] = AI_PATHFINDER_FLAG_TUNNEL + (dir << 8);
|
||||||
aystar->neighbours[aystar->num_neighbours++].direction = 0;
|
aystar->neighbours[aystar->num_neighbours++].direction = INVALID_TRACKDIR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
|
|
||||||
#include "queue.h"
|
#include "queue.h"
|
||||||
#include "tile_type.h"
|
#include "tile_type.h"
|
||||||
|
#include "track_type.h"
|
||||||
|
|
||||||
//#define AYSTAR_DEBUG
|
//#define AYSTAR_DEBUG
|
||||||
enum {
|
enum {
|
||||||
|
@ -30,7 +31,7 @@ enum{
|
||||||
|
|
||||||
struct AyStarNode {
|
struct AyStarNode {
|
||||||
TileIndex tile;
|
TileIndex tile;
|
||||||
int direction;
|
Trackdir direction;
|
||||||
uint user_data[2];
|
uint user_data[2];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
38
src/npf.cpp
38
src/npf.cpp
|
@ -158,7 +158,7 @@ static int32 NPFCalcStationOrTileHeuristic(AyStar* as, AyStarNode* current, Open
|
||||||
static void NPFFillTrackdirChoice(AyStarNode* current, OpenListNode* parent)
|
static void NPFFillTrackdirChoice(AyStarNode* current, OpenListNode* parent)
|
||||||
{
|
{
|
||||||
if (parent->path.parent == NULL) {
|
if (parent->path.parent == NULL) {
|
||||||
Trackdir trackdir = (Trackdir)current->direction;
|
Trackdir trackdir = current->direction;
|
||||||
/* This is a first order decision, so we'd better save the
|
/* This is a first order decision, so we'd better save the
|
||||||
* direction we chose */
|
* direction we chose */
|
||||||
current->user_data[NPF_TRACKDIR_CHOICE] = trackdir;
|
current->user_data[NPF_TRACKDIR_CHOICE] = trackdir;
|
||||||
|
@ -174,7 +174,7 @@ static void NPFFillTrackdirChoice(AyStarNode* current, OpenListNode* parent)
|
||||||
* including the exit tile. Requires that this is a Tunnel tile */
|
* including the exit tile. Requires that this is a Tunnel tile */
|
||||||
static uint NPFTunnelCost(AyStarNode* current)
|
static uint NPFTunnelCost(AyStarNode* current)
|
||||||
{
|
{
|
||||||
DiagDirection exitdir = TrackdirToExitdir((Trackdir)current->direction);
|
DiagDirection exitdir = TrackdirToExitdir(current->direction);
|
||||||
TileIndex tile = current->tile;
|
TileIndex tile = current->tile;
|
||||||
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
|
||||||
|
@ -195,7 +195,7 @@ static inline uint NPFBridgeCost(AyStarNode *current)
|
||||||
|
|
||||||
static uint NPFSlopeCost(AyStarNode* current)
|
static uint NPFSlopeCost(AyStarNode* current)
|
||||||
{
|
{
|
||||||
TileIndex next = current->tile + TileOffsByDiagDir(TrackdirToExitdir((Trackdir)current->direction));
|
TileIndex next = current->tile + TileOffsByDiagDir(TrackdirToExitdir(current->direction));
|
||||||
|
|
||||||
/* Get center of tiles */
|
/* Get center of tiles */
|
||||||
int x1 = TileX(current->tile) * TILE_SIZE + TILE_SIZE / 2;
|
int x1 = TileX(current->tile) * TILE_SIZE + TILE_SIZE / 2;
|
||||||
|
@ -225,13 +225,13 @@ static uint NPFSlopeCost(AyStarNode* current)
|
||||||
static uint NPFReservedTrackCost(AyStarNode *current)
|
static uint NPFReservedTrackCost(AyStarNode *current)
|
||||||
{
|
{
|
||||||
TileIndex tile = current->tile;
|
TileIndex tile = current->tile;
|
||||||
TrackBits track = TrackToTrackBits(TrackdirToTrack((Trackdir)current->direction));
|
TrackBits track = TrackToTrackBits(TrackdirToTrack(current->direction));
|
||||||
TrackBits res = GetReservedTrackbits(tile);
|
TrackBits res = GetReservedTrackbits(tile);
|
||||||
|
|
||||||
if (NPFGetFlag(current, NPF_FLAG_3RD_SIGNAL) || ((res & track) == TRACK_BIT_NONE && !TracksOverlap(res | track))) return 0;
|
if (NPFGetFlag(current, NPF_FLAG_3RD_SIGNAL) || ((res & track) == TRACK_BIT_NONE && !TracksOverlap(res | track))) return 0;
|
||||||
|
|
||||||
if (IsTileType(tile, MP_TUNNELBRIDGE)) {
|
if (IsTileType(tile, MP_TUNNELBRIDGE)) {
|
||||||
DiagDirection exitdir = TrackdirToExitdir((Trackdir)current->direction);
|
DiagDirection exitdir = TrackdirToExitdir(current->direction);
|
||||||
if (GetTunnelBridgeDirection(tile) == ReverseDiagDir(exitdir)) {
|
if (GetTunnelBridgeDirection(tile) == ReverseDiagDir(exitdir)) {
|
||||||
return _settings_game.pf.npf.npf_rail_pbs_cross_penalty * (GetTunnelBridgeLength(tile, GetOtherTunnelBridgeEnd(tile)) + 1);
|
return _settings_game.pf.npf.npf_rail_pbs_cross_penalty * (GetTunnelBridgeLength(tile, GetOtherTunnelBridgeEnd(tile)) + 1);
|
||||||
}
|
}
|
||||||
|
@ -273,7 +273,7 @@ static int32 NPFWaterPathCost(AyStar* as, AyStarNode* current, OpenListNode* par
|
||||||
{
|
{
|
||||||
/* TileIndex tile = current->tile; */
|
/* TileIndex tile = current->tile; */
|
||||||
int32 cost = 0;
|
int32 cost = 0;
|
||||||
Trackdir trackdir = (Trackdir)current->direction;
|
Trackdir trackdir = current->direction;
|
||||||
|
|
||||||
cost = _trackdir_length[trackdir]; // Should be different for diagonal tracks
|
cost = _trackdir_length[trackdir]; // Should be different for diagonal tracks
|
||||||
|
|
||||||
|
@ -323,7 +323,7 @@ static int32 NPFRoadPathCost(AyStar* as, AyStarNode* current, OpenListNode* pare
|
||||||
|
|
||||||
/* Check for turns. Road vehicles only really drive diagonal, turns are
|
/* Check for turns. Road vehicles only really drive diagonal, turns are
|
||||||
* represented by non-diagonal tracks */
|
* represented by non-diagonal tracks */
|
||||||
if (!IsDiagonalTrackdir((Trackdir)current->direction))
|
if (!IsDiagonalTrackdir(current->direction))
|
||||||
cost += _settings_game.pf.npf.npf_road_curve_penalty;
|
cost += _settings_game.pf.npf.npf_road_curve_penalty;
|
||||||
|
|
||||||
NPFMarkTile(tile);
|
NPFMarkTile(tile);
|
||||||
|
@ -336,7 +336,7 @@ static int32 NPFRoadPathCost(AyStar* as, AyStarNode* current, OpenListNode* pare
|
||||||
static int32 NPFRailPathCost(AyStar* as, AyStarNode* current, OpenListNode* parent)
|
static int32 NPFRailPathCost(AyStar* as, AyStarNode* current, OpenListNode* parent)
|
||||||
{
|
{
|
||||||
TileIndex tile = current->tile;
|
TileIndex tile = current->tile;
|
||||||
Trackdir trackdir = (Trackdir)current->direction;
|
Trackdir trackdir = current->direction;
|
||||||
int32 cost = 0;
|
int32 cost = 0;
|
||||||
/* HACK: We create a OpenListNode manually, so we can call EndNodeCheck */
|
/* HACK: We create a OpenListNode manually, so we can call EndNodeCheck */
|
||||||
OpenListNode new_node;
|
OpenListNode new_node;
|
||||||
|
@ -462,8 +462,8 @@ static int32 NPFFindSafeTile(AyStar *as, OpenListNode *current)
|
||||||
const Vehicle *v = ((NPFFindStationOrTileData*)as->user_target)->v;
|
const Vehicle *v = ((NPFFindStationOrTileData*)as->user_target)->v;
|
||||||
|
|
||||||
return
|
return
|
||||||
IsSafeWaitingPosition(v, current->path.node.tile, (Trackdir)current->path.node.direction, true, _settings_game.pf.forbid_90_deg) &&
|
IsSafeWaitingPosition(v, current->path.node.tile, current->path.node.direction, true, _settings_game.pf.forbid_90_deg) &&
|
||||||
IsWaitingPositionFree(v, current->path.node.tile, (Trackdir)current->path.node.direction, _settings_game.pf.forbid_90_deg) ?
|
IsWaitingPositionFree(v, current->path.node.tile, current->path.node.direction, _settings_game.pf.forbid_90_deg) ?
|
||||||
AYSTAR_FOUND_END_NODE : AYSTAR_DONE;
|
AYSTAR_FOUND_END_NODE : AYSTAR_DONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -499,7 +499,7 @@ static const PathNode* FindSafePosition(PathNode *path, const Vehicle *v)
|
||||||
PathNode *sig = path;
|
PathNode *sig = path;
|
||||||
|
|
||||||
for(; path->parent != NULL; path = path->parent) {
|
for(; path->parent != NULL; path = path->parent) {
|
||||||
if (IsSafeWaitingPosition(v, path->node.tile, (Trackdir)path->node.direction, true, _settings_game.pf.forbid_90_deg)) {
|
if (IsSafeWaitingPosition(v, path->node.tile, path->node.direction, true, _settings_game.pf.forbid_90_deg)) {
|
||||||
sig = path;
|
sig = path;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -515,9 +515,9 @@ static void ClearPathReservation(const PathNode *start, const PathNode *end)
|
||||||
bool first_run = true;
|
bool first_run = true;
|
||||||
for (; start != end; start = start->parent) {
|
for (; start != end; start = start->parent) {
|
||||||
if (IsRailwayStationTile(start->node.tile) && first_run) {
|
if (IsRailwayStationTile(start->node.tile) && first_run) {
|
||||||
SetRailwayStationPlatformReservation(start->node.tile, TrackdirToExitdir((Trackdir)start->node.direction), false);
|
SetRailwayStationPlatformReservation(start->node.tile, TrackdirToExitdir(start->node.direction), false);
|
||||||
} else {
|
} else {
|
||||||
UnreserveRailTrack(start->node.tile, TrackdirToTrack((Trackdir)start->node.direction));
|
UnreserveRailTrack(start->node.tile, TrackdirToTrack(start->node.direction));
|
||||||
}
|
}
|
||||||
first_run = false;
|
first_run = false;
|
||||||
}
|
}
|
||||||
|
@ -547,21 +547,21 @@ static void NPFSaveTargetData(AyStar* as, OpenListNode* current)
|
||||||
|
|
||||||
/* If the target is a station skip to platform end. */
|
/* If the target is a station skip to platform end. */
|
||||||
if (IsRailwayStationTile(target->node.tile)) {
|
if (IsRailwayStationTile(target->node.tile)) {
|
||||||
DiagDirection dir = TrackdirToExitdir((Trackdir)target->node.direction);
|
DiagDirection dir = TrackdirToExitdir(target->node.direction);
|
||||||
uint len = GetStationByTile(target->node.tile)->GetPlatformLength(target->node.tile, dir);
|
uint len = GetStationByTile(target->node.tile)->GetPlatformLength(target->node.tile, dir);
|
||||||
TileIndex end_tile = TILE_ADD(target->node.tile, (len - 1) * TileOffsByDiagDir(dir));
|
TileIndex end_tile = TILE_ADD(target->node.tile, (len - 1) * TileOffsByDiagDir(dir));
|
||||||
|
|
||||||
/* Update only end tile, trackdir of a station stays the same. */
|
/* Update only end tile, trackdir of a station stays the same. */
|
||||||
ftd->node.tile = end_tile;
|
ftd->node.tile = end_tile;
|
||||||
if (!IsWaitingPositionFree(v, end_tile, (Trackdir)target->node.direction, _settings_game.pf.forbid_90_deg)) return;
|
if (!IsWaitingPositionFree(v, end_tile, target->node.direction, _settings_game.pf.forbid_90_deg)) return;
|
||||||
SetRailwayStationPlatformReservation(target->node.tile, dir, true);
|
SetRailwayStationPlatformReservation(target->node.tile, dir, true);
|
||||||
SetRailwayStationReservation(target->node.tile, false);
|
SetRailwayStationReservation(target->node.tile, false);
|
||||||
} else {
|
} else {
|
||||||
if (!IsWaitingPositionFree(v, target->node.tile, (Trackdir)target->node.direction, _settings_game.pf.forbid_90_deg)) return;
|
if (!IsWaitingPositionFree(v, target->node.tile, target->node.direction, _settings_game.pf.forbid_90_deg)) return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const PathNode *cur = target; cur->parent != NULL; cur = cur->parent) {
|
for (const PathNode *cur = target; cur->parent != NULL; cur = cur->parent) {
|
||||||
if (!TryReserveRailTrack(cur->node.tile, TrackdirToTrack((Trackdir)cur->node.direction))) {
|
if (!TryReserveRailTrack(cur->node.tile, TrackdirToTrack(cur->node.direction))) {
|
||||||
/* Reservation failed, undo. */
|
/* Reservation failed, undo. */
|
||||||
ClearPathReservation(target, cur);
|
ClearPathReservation(target, cur);
|
||||||
return;
|
return;
|
||||||
|
@ -769,7 +769,7 @@ static TrackdirBits GetDriveableTrackdirBits(TileIndex dst_tile, Trackdir src_tr
|
||||||
static void NPFFollowTrack(AyStar* aystar, OpenListNode* current)
|
static void NPFFollowTrack(AyStar* aystar, OpenListNode* current)
|
||||||
{
|
{
|
||||||
/* We leave src_tile on track src_trackdir in direction src_exitdir */
|
/* We leave src_tile on track src_trackdir in direction src_exitdir */
|
||||||
Trackdir src_trackdir = (Trackdir)current->path.node.direction;
|
Trackdir src_trackdir = current->path.node.direction;
|
||||||
TileIndex src_tile = current->path.node.tile;
|
TileIndex src_tile = current->path.node.tile;
|
||||||
DiagDirection src_exitdir = TrackdirToExitdir(src_trackdir);
|
DiagDirection src_exitdir = TrackdirToExitdir(src_trackdir);
|
||||||
|
|
||||||
|
@ -1000,7 +1000,7 @@ NPFFoundTargetData NPFRouteToDepotTrialError(TileIndex tile, Trackdir trackdir,
|
||||||
*/
|
*/
|
||||||
Queue depots;
|
Queue depots;
|
||||||
int r;
|
int r;
|
||||||
NPFFoundTargetData best_result = {UINT_MAX, UINT_MAX, INVALID_TRACKDIR, {INVALID_TILE, 0, {0, 0}}, false};
|
NPFFoundTargetData best_result = {UINT_MAX, UINT_MAX, INVALID_TRACKDIR, {INVALID_TILE, INVALID_TRACKDIR, {0, 0}}, false};
|
||||||
NPFFoundTargetData result;
|
NPFFoundTargetData result;
|
||||||
NPFFindStationOrTileData target;
|
NPFFindStationOrTileData target;
|
||||||
AyStarNode start;
|
AyStarNode start;
|
||||||
|
|
Loading…
Reference in New Issue