(svn r15718) -Cleanup: apply some comment coding style on the rest of the sources too
This commit is contained in:
@@ -61,7 +61,7 @@ struct CFollowTrackT
|
||||
assert((!IsRoadTT() || m_veh != NULL) && (!IsRailTT() || railtype_override != INVALID_RAILTYPES));
|
||||
m_veh_owner = o;
|
||||
m_pPerf = pPerf;
|
||||
// don't worry, all is inlined so compiler should remove unnecessary initializations
|
||||
/* don't worry, all is inlined so compiler should remove unnecessary initializations */
|
||||
m_new_tile = INVALID_TILE;
|
||||
m_new_td_bits = TRACKDIR_BIT_NONE;
|
||||
m_exitdir = INVALID_DIAGDIR;
|
||||
@@ -166,11 +166,11 @@ protected:
|
||||
m_is_station = m_is_bridge = m_is_tunnel = false;
|
||||
m_tiles_skipped = 0;
|
||||
|
||||
// extra handling for tunnels and bridges in our direction
|
||||
/* extra handling for tunnels and bridges in our direction */
|
||||
if (IsTileType(m_old_tile, MP_TUNNELBRIDGE)) {
|
||||
DiagDirection enterdir = GetTunnelBridgeDirection(m_old_tile);
|
||||
if (enterdir == m_exitdir) {
|
||||
// we are entering the tunnel / bridge
|
||||
/* we are entering the tunnel / bridge */
|
||||
if (IsTunnel(m_old_tile)) {
|
||||
m_is_tunnel = true;
|
||||
m_new_tile = GetOtherTunnelEnd(m_old_tile);
|
||||
@@ -184,11 +184,11 @@ protected:
|
||||
assert(ReverseDiagDir(enterdir) == m_exitdir);
|
||||
}
|
||||
|
||||
// normal or station tile, do one step
|
||||
/* normal or station tile, do one step */
|
||||
TileIndexDiff diff = TileOffsByDiagDir(m_exitdir);
|
||||
m_new_tile = TILE_ADD(m_old_tile, diff);
|
||||
|
||||
// special handling for stations
|
||||
/* special handling for stations */
|
||||
if (IsRailTT() && IsRailwayStationTile(m_new_tile)) {
|
||||
m_is_station = true;
|
||||
} else if (IsRoadTT() && IsRoadStopTile(m_new_tile)) {
|
||||
@@ -231,7 +231,7 @@ protected:
|
||||
/** return true if we can leave m_old_tile in m_exitdir */
|
||||
FORCEINLINE bool CanExitOldTile()
|
||||
{
|
||||
// road stop can be left at one direction only unless it's a drive-through stop
|
||||
/* road stop can be left at one direction only unless it's a drive-through stop */
|
||||
if (IsRoadTT() && IsStandardRoadStopTile(m_old_tile)) {
|
||||
DiagDirection exitdir = GetRoadStopDir(m_old_tile);
|
||||
if (exitdir != m_exitdir) {
|
||||
@@ -249,7 +249,7 @@ protected:
|
||||
}
|
||||
}
|
||||
|
||||
// road depots can be also left in one direction only
|
||||
/* road depots can be also left in one direction only */
|
||||
if (IsRoadTT() && IsDepotTypeTile(m_old_tile, TT())) {
|
||||
DiagDirection exitdir = GetRoadDepotDirection(m_old_tile);
|
||||
if (exitdir != m_exitdir) {
|
||||
@@ -264,7 +264,7 @@ protected:
|
||||
FORCEINLINE bool CanEnterNewTile()
|
||||
{
|
||||
if (IsRoadTT() && IsStandardRoadStopTile(m_new_tile)) {
|
||||
// road stop can be entered from one direction only unless it's a drive-through stop
|
||||
/* road stop can be entered from one direction only unless it's a drive-through stop */
|
||||
DiagDirection exitdir = GetRoadStopDir(m_new_tile);
|
||||
if (ReverseDiagDir(exitdir) != m_exitdir) {
|
||||
m_err = EC_NO_WAY;
|
||||
@@ -281,14 +281,14 @@ protected:
|
||||
}
|
||||
}
|
||||
|
||||
// road and rail depots can also be entered from one direction only
|
||||
/* road and rail depots can also be entered from one direction only */
|
||||
if (IsRoadTT() && IsDepotTypeTile(m_new_tile, TT())) {
|
||||
DiagDirection exitdir = GetRoadDepotDirection(m_new_tile);
|
||||
if (ReverseDiagDir(exitdir) != m_exitdir) {
|
||||
m_err = EC_NO_WAY;
|
||||
return false;
|
||||
}
|
||||
// don't try to enter other company's depots
|
||||
/* don't try to enter other company's depots */
|
||||
if (GetTileOwner(m_new_tile) != m_veh_owner) {
|
||||
m_err = EC_OWNER;
|
||||
return false;
|
||||
@@ -302,24 +302,24 @@ protected:
|
||||
}
|
||||
}
|
||||
|
||||
// rail transport is possible only on tiles with the same owner as vehicle
|
||||
/* rail transport is possible only on tiles with the same owner as vehicle */
|
||||
if (IsRailTT() && GetTileOwner(m_new_tile) != m_veh_owner) {
|
||||
// different owner
|
||||
/* different owner */
|
||||
m_err = EC_NO_WAY;
|
||||
return false;
|
||||
}
|
||||
|
||||
// rail transport is possible only on compatible rail types
|
||||
/* rail transport is possible only on compatible rail types */
|
||||
if (IsRailTT()) {
|
||||
RailType rail_type = GetTileRailType(m_new_tile);
|
||||
if (!HasBit(m_railtypes, rail_type)) {
|
||||
// incompatible rail type
|
||||
/* incompatible rail type */
|
||||
m_err = EC_RAIL_TYPE;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// tunnel holes and bridge ramps can be entered only from proper direction
|
||||
/* tunnel holes and bridge ramps can be entered only from proper direction */
|
||||
if (IsTileType(m_new_tile, MP_TUNNELBRIDGE)) {
|
||||
if (IsTunnel(m_new_tile)) {
|
||||
if (!m_is_tunnel) {
|
||||
@@ -340,14 +340,14 @@ protected:
|
||||
}
|
||||
}
|
||||
|
||||
// special handling for rail stations - get to the end of platform
|
||||
/* special handling for rail stations - get to the end of platform */
|
||||
if (IsRailTT() && m_is_station) {
|
||||
// entered railway station
|
||||
// get platform length
|
||||
/* entered railway station
|
||||
* get platform length */
|
||||
uint length = GetStationByTile(m_new_tile)->GetPlatformLength(m_new_tile, TrackdirToExitdir(m_old_td));
|
||||
// how big step we must do to get to the last platform tile;
|
||||
/* how big step we must do to get to the last platform tile; */
|
||||
m_tiles_skipped = length - 1;
|
||||
// move to the platform end
|
||||
/* move to the platform end */
|
||||
TileIndexDiff diff = TileOffsByDiagDir(m_exitdir);
|
||||
diff *= m_tiles_skipped;
|
||||
m_new_tile = TILE_ADD(m_new_tile, diff);
|
||||
@@ -360,11 +360,11 @@ protected:
|
||||
/** return true if we must reverse (in depots and single tram bits) */
|
||||
FORCEINLINE bool ForcedReverse()
|
||||
{
|
||||
// rail and road depots cause reversing
|
||||
/* rail and road depots cause reversing */
|
||||
if (!IsWaterTT() && IsDepotTypeTile(m_old_tile, TT())) {
|
||||
DiagDirection exitdir = IsRailTT() ? GetRailDepotDirection(m_old_tile) : GetRoadDepotDirection(m_old_tile);
|
||||
if (exitdir != m_exitdir) {
|
||||
// reverse
|
||||
/* reverse */
|
||||
m_new_tile = m_old_tile;
|
||||
m_new_td_bits = TrackdirToTrackdirBits(ReverseTrackdir(m_old_td));
|
||||
m_exitdir = exitdir;
|
||||
@@ -374,9 +374,9 @@ protected:
|
||||
}
|
||||
}
|
||||
|
||||
// single tram bits cause reversing
|
||||
/* single tram bits cause reversing */
|
||||
if (IsTram() && GetSingleTramBit(m_old_tile) == ReverseDiagDir(m_exitdir)) {
|
||||
// reverse
|
||||
/* reverse */
|
||||
m_new_tile = m_old_tile;
|
||||
m_new_td_bits = TrackdirToTrackdirBits(ReverseTrackdir(m_old_td));
|
||||
m_exitdir = ReverseDiagDir(m_exitdir);
|
||||
@@ -392,15 +392,15 @@ protected:
|
||||
FORCEINLINE bool TryReverse()
|
||||
{
|
||||
if (IsRoadTT() && !IsTram()) {
|
||||
// if we reached the end of road, we can reverse the RV and continue moving
|
||||
/* if we reached the end of road, we can reverse the RV and continue moving */
|
||||
m_exitdir = ReverseDiagDir(m_exitdir);
|
||||
// new tile will be the same as old one
|
||||
/* new tile will be the same as old one */
|
||||
m_new_tile = m_old_tile;
|
||||
// set new trackdir bits to all reachable trackdirs
|
||||
/* set new trackdir bits to all reachable trackdirs */
|
||||
QueryNewTileTrackStatus();
|
||||
m_new_td_bits &= DiagdirReachesTrackdirs(m_exitdir);
|
||||
if (m_new_td_bits != TRACKDIR_BIT_NONE) {
|
||||
// we have some trackdirs reachable after reversal
|
||||
/* we have some trackdirs reachable after reversal */
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -415,14 +415,14 @@ public:
|
||||
int min_speed = 0;
|
||||
int max_speed = INT_MAX; // no limit
|
||||
|
||||
// for now we handle only on-bridge speed limit
|
||||
/* for now we handle only on-bridge speed limit */
|
||||
if (!IsWaterTT() && IsBridgeTile(m_old_tile)) {
|
||||
int spd = GetBridgeSpec(GetBridgeType(m_old_tile))->speed;
|
||||
if (IsRoadTT()) spd *= 2;
|
||||
if (max_speed > spd) max_speed = spd;
|
||||
}
|
||||
|
||||
// if min speed was requested, return it
|
||||
/* if min speed was requested, return it */
|
||||
if (pmin_speed) *pmin_speed = min_speed;
|
||||
return max_speed;
|
||||
}
|
||||
|
@@ -74,11 +74,11 @@ public:
|
||||
/** notify the nodelist, that we don't want to discard the given node */
|
||||
FORCEINLINE void FoundBestNode(Titem_& item)
|
||||
{
|
||||
// for now it is enough to invalidate m_new_node if it is our given node
|
||||
/* for now it is enough to invalidate m_new_node if it is our given node */
|
||||
if (&item == m_new_node) {
|
||||
m_new_node = NULL;
|
||||
}
|
||||
// TODO: do we need to store best nodes found in some extra list/array? Probably not now.
|
||||
/* TODO: do we need to store best nodes found in some extra list/array? Probably not now. */
|
||||
}
|
||||
|
||||
/** insert given item as open node (into m_open and m_open_queue) */
|
||||
@@ -86,7 +86,7 @@ public:
|
||||
{
|
||||
assert(m_closed.Find(item.GetKey()) == NULL);
|
||||
m_open.Push(item);
|
||||
// TODO: check if m_open_queue is not full
|
||||
/* TODO: check if m_open_queue is not full */
|
||||
assert(!m_open_queue.IsFull());
|
||||
m_open_queue.Push(item);
|
||||
if (&item == m_new_node) {
|
||||
|
@@ -70,7 +70,7 @@ public:
|
||||
int m_num_steps; ///< this is there for debugging purposes (hope it doesn't hurt)
|
||||
|
||||
public:
|
||||
/// default constructor
|
||||
/** default constructor */
|
||||
FORCEINLINE CYapfBaseT()
|
||||
: m_pBestDestNode(NULL)
|
||||
, m_pBestIntermediateNode(NULL)
|
||||
@@ -83,18 +83,18 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
/// default destructor
|
||||
/** default destructor */
|
||||
~CYapfBaseT() {}
|
||||
|
||||
protected:
|
||||
/// to access inherited path finder
|
||||
/** to access inherited path finder */
|
||||
FORCEINLINE Tpf& Yapf()
|
||||
{
|
||||
return *static_cast<Tpf*>(this);
|
||||
}
|
||||
|
||||
public:
|
||||
/// return current settings (can be custom - company based - but later)
|
||||
/** return current settings (can be custom - company based - but later) */
|
||||
FORCEINLINE const YAPFSettings& PfGetSettings() const
|
||||
{
|
||||
return *m_settings;
|
||||
@@ -125,7 +125,7 @@ public:
|
||||
break;
|
||||
}
|
||||
|
||||
// if the best open node was worse than the best path found, we can finish
|
||||
/* if the best open node was worse than the best path found, we can finish */
|
||||
if (m_pBestDestNode != NULL && m_pBestDestNode->GetCost() < n->GetCostEstimate()) {
|
||||
break;
|
||||
}
|
||||
@@ -187,13 +187,13 @@ public:
|
||||
FORCEINLINE void AddStartupNode(Node& n)
|
||||
{
|
||||
Yapf().PfNodeCacheFetch(n);
|
||||
// insert the new node only if it is not there
|
||||
/* insert the new node only if it is not there */
|
||||
if (m_nodes.FindOpenNode(n.m_key) == NULL) {
|
||||
m_nodes.InsertOpenNode(n);
|
||||
} else {
|
||||
// if we are here, it means that node is already there - how it is possible?
|
||||
// probably the train is in the position that both its ends point to the same tile/exit-dir
|
||||
// very unlikely, but it happened
|
||||
/* if we are here, it means that node is already there - how it is possible?
|
||||
* probably the train is in the position that both its ends point to the same tile/exit-dir
|
||||
* very unlikely, but it happened */
|
||||
}
|
||||
}
|
||||
|
||||
@@ -213,7 +213,7 @@ public:
|
||||
* Nodes are evaluated here and added into open list */
|
||||
void AddNewNode(Node &n, const TrackFollower &tf)
|
||||
{
|
||||
// evaluate the node
|
||||
/* evaluate the node */
|
||||
bool bCached = Yapf().PfNodeCacheFetch(n);
|
||||
if (!bCached) {
|
||||
m_stats_cost_calcs++;
|
||||
@@ -229,10 +229,10 @@ public:
|
||||
|
||||
if (bValid) bValid = Yapf().PfCalcEstimate(n);
|
||||
|
||||
// have the cost or estimate callbacks marked this node as invalid?
|
||||
/* have the cost or estimate callbacks marked this node as invalid? */
|
||||
if (!bValid) return;
|
||||
|
||||
// detect the destination
|
||||
/* detect the destination */
|
||||
bool bDestination = Yapf().PfDetectDestination(n);
|
||||
if (bDestination) {
|
||||
if (m_pBestDestNode == NULL || n < *m_pBestDestNode) {
|
||||
@@ -246,43 +246,43 @@ public:
|
||||
m_pBestIntermediateNode = &n;
|
||||
}
|
||||
|
||||
// check new node against open list
|
||||
/* check new node against open list */
|
||||
Node *openNode = m_nodes.FindOpenNode(n.GetKey());
|
||||
if (openNode != NULL) {
|
||||
// another node exists with the same key in the open list
|
||||
// is it better than new one?
|
||||
/* another node exists with the same key in the open list
|
||||
* is it better than new one? */
|
||||
if (n.GetCostEstimate() < openNode->GetCostEstimate()) {
|
||||
// update the old node by value from new one
|
||||
/* update the old node by value from new one */
|
||||
m_nodes.PopOpenNode(n.GetKey());
|
||||
*openNode = n;
|
||||
// add the updated old node back to open list
|
||||
/* add the updated old node back to open list */
|
||||
m_nodes.InsertOpenNode(*openNode);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// check new node against closed list
|
||||
/* check new node against closed list */
|
||||
Node *closedNode = m_nodes.FindClosedNode(n.GetKey());
|
||||
if (closedNode != NULL) {
|
||||
// another node exists with the same key in the closed list
|
||||
// is it better than new one?
|
||||
/* another node exists with the same key in the closed list
|
||||
* is it better than new one? */
|
||||
int node_est = n.GetCostEstimate();
|
||||
int closed_est = closedNode->GetCostEstimate();
|
||||
if (node_est < closed_est) {
|
||||
// If this assert occurs, you have probably problem in
|
||||
// your Tderived::PfCalcCost() or Tderived::PfCalcEstimate().
|
||||
// The problem could be:
|
||||
// - PfCalcEstimate() gives too large numbers
|
||||
// - PfCalcCost() gives too small numbers
|
||||
// - You have used negative cost penalty in some cases (cost bonus)
|
||||
/* If this assert occurs, you have probably problem in
|
||||
* your Tderived::PfCalcCost() or Tderived::PfCalcEstimate().
|
||||
* The problem could be:
|
||||
* - PfCalcEstimate() gives too large numbers
|
||||
* - PfCalcCost() gives too small numbers
|
||||
* - You have used negative cost penalty in some cases (cost bonus) */
|
||||
assert(0);
|
||||
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
// the new node is really new
|
||||
// add it to the open list
|
||||
/* the new node is really new
|
||||
* add it to the open list */
|
||||
m_nodes.InsertOpenNode(n);
|
||||
}
|
||||
|
||||
@@ -297,13 +297,13 @@ public:
|
||||
dmp.WriteLine("m_num_steps = %d", m_num_steps);
|
||||
}
|
||||
|
||||
// methods that should be implemented at derived class Types::Tpf (derived from CYapfBaseT)
|
||||
/* methods that should be implemented at derived class Types::Tpf (derived from CYapfBaseT) */
|
||||
|
||||
#if 0
|
||||
/** Example: PfSetStartupNodes() - set source (origin) nodes */
|
||||
FORCEINLINE void PfSetStartupNodes()
|
||||
{
|
||||
// example:
|
||||
/* example: */
|
||||
Node& n1 = *base::m_nodes.CreateNewNode();
|
||||
.
|
||||
. // setup node members here
|
||||
@@ -327,9 +327,9 @@ public:
|
||||
/** Example: PfCalcCost() - set path cost from origin to the given node */
|
||||
FORCEINLINE bool PfCalcCost(Node& n)
|
||||
{
|
||||
// evaluate last step cost
|
||||
/* evaluate last step cost */
|
||||
int cost = ...;
|
||||
// set the node cost as sum of parent's cost and last step cost
|
||||
/* set the node cost as sum of parent's cost and last step cost */
|
||||
n.m_cost = n.m_parent->m_cost + cost;
|
||||
return true; // true if node is valid follower (i.e. no obstacle was found)
|
||||
}
|
||||
@@ -337,9 +337,9 @@ public:
|
||||
/** Example: PfCalcEstimate() - set path cost estimate from origin to the target through given node */
|
||||
FORCEINLINE bool PfCalcEstimate(Node& n)
|
||||
{
|
||||
// evaluate the distance to our destination
|
||||
/* evaluate the distance to our destination */
|
||||
int distance = ...;
|
||||
// set estimate as sum of cost from origin + distance to the target
|
||||
/* set estimate as sum of cost from origin + distance to the target */
|
||||
n.m_estimate = n.m_cost + distance;
|
||||
return true; // true if node is valid (i.e. not too far away :)
|
||||
}
|
||||
|
@@ -18,21 +18,21 @@ protected:
|
||||
TileIndex m_orgTile; ///< origin tile
|
||||
TrackdirBits m_orgTrackdirs; ///< origin trackdir mask
|
||||
|
||||
/// to access inherited path finder
|
||||
/** to access inherited path finder */
|
||||
FORCEINLINE Tpf& Yapf()
|
||||
{
|
||||
return *static_cast<Tpf*>(this);
|
||||
}
|
||||
|
||||
public:
|
||||
/// Set origin tile / trackdir mask
|
||||
/** Set origin tile / trackdir mask */
|
||||
void SetOrigin(TileIndex tile, TrackdirBits trackdirs)
|
||||
{
|
||||
m_orgTile = tile;
|
||||
m_orgTrackdirs = trackdirs;
|
||||
}
|
||||
|
||||
/// Called when YAPF needs to place origin nodes into open list
|
||||
/** Called when YAPF needs to place origin nodes into open list */
|
||||
void PfSetStartupNodes()
|
||||
{
|
||||
bool is_choice = (KillFirstBit(m_orgTrackdirs) != TRACKDIR_BIT_NONE);
|
||||
@@ -62,14 +62,14 @@ protected:
|
||||
int m_reverse_penalty; ///< penalty to be added for using the reversed origin
|
||||
bool m_treat_first_red_two_way_signal_as_eol; ///< in some cases (leaving station) we need to handle first two-way signal differently
|
||||
|
||||
/// to access inherited path finder
|
||||
/** to access inherited path finder */
|
||||
FORCEINLINE Tpf& Yapf()
|
||||
{
|
||||
return *static_cast<Tpf*>(this);
|
||||
}
|
||||
|
||||
public:
|
||||
/// set origin (tiles, trackdirs, etc.)
|
||||
/** set origin (tiles, trackdirs, etc.) */
|
||||
void SetOrigin(TileIndex tile, Trackdir td, TileIndex tiler = INVALID_TILE, Trackdir tdr = INVALID_TRACKDIR, int reverse_penalty = 0, bool treat_first_red_two_way_signal_as_eol = true)
|
||||
{
|
||||
m_orgTile = tile;
|
||||
@@ -80,7 +80,7 @@ public:
|
||||
m_treat_first_red_two_way_signal_as_eol = treat_first_red_two_way_signal_as_eol;
|
||||
}
|
||||
|
||||
/// Called when YAPF needs to place origin nodes into open list
|
||||
/** Called when YAPF needs to place origin nodes into open list */
|
||||
void PfSetStartupNodes()
|
||||
{
|
||||
if (m_orgTile != INVALID_TILE && m_orgTd != INVALID_TRACKDIR) {
|
||||
@@ -96,7 +96,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
/// return true if first two-way signal should be treated as dead end
|
||||
/** return true if first two-way signal should be treated as dead end */
|
||||
FORCEINLINE bool TreatFirstRedTwoWaySignalAsEOL()
|
||||
{
|
||||
return Yapf().PfGetSettings().rail_firstred_twoway_eol && m_treat_first_red_two_way_signal_as_eol;
|
||||
@@ -117,7 +117,7 @@ protected:
|
||||
TrackdirBits m_destTrackdirs; ///< destination trackdir mask
|
||||
|
||||
public:
|
||||
/// set the destination tile / more trackdirs
|
||||
/** set the destination tile / more trackdirs */
|
||||
void SetDestination(TileIndex tile, TrackdirBits trackdirs)
|
||||
{
|
||||
m_destTile = tile;
|
||||
@@ -125,14 +125,14 @@ public:
|
||||
}
|
||||
|
||||
protected:
|
||||
/// to access inherited path finder
|
||||
/** to access inherited path finder */
|
||||
Tpf& Yapf()
|
||||
{
|
||||
return *static_cast<Tpf*>(this);
|
||||
}
|
||||
|
||||
public:
|
||||
/// Called by YAPF to detect if node ends in the desired destination
|
||||
/** Called by YAPF to detect if node ends in the desired destination */
|
||||
FORCEINLINE bool PfDetectDestination(Node& n)
|
||||
{
|
||||
bool bDest = (n.m_key.m_tile == m_destTile) && ((m_destTrackdirs & TrackdirToTrackdirBits(n.GetTrackdir())) != TRACKDIR_BIT_NONE);
|
||||
|
@@ -10,14 +10,14 @@ struct CYapfCostBase {
|
||||
{
|
||||
if (IsDiagonalTrackdir(td)) {
|
||||
if (IsBridgeTile(tile)) {
|
||||
// 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 leaving it, no penalty
|
||||
// we are entering the bridge
|
||||
/* we are entering the bridge */
|
||||
Slope tile_slope = GetTileSlope(tile, NULL);
|
||||
Axis axis = DiagDirToAxis(GetTunnelBridgeDirection(tile));
|
||||
return !HasBridgeFlatRamp(tile_slope, axis);
|
||||
} else {
|
||||
// not bridge ramp
|
||||
/* not bridge ramp */
|
||||
if (IsTunnelTile(tile)) return false; // tunnel entry/exit doesn't slope
|
||||
Slope tile_slope = GetTileSlope(tile, NULL);
|
||||
return IsUphillTrackdir(tile_slope, td); // slopes uphill => apply penalty
|
||||
@@ -28,7 +28,7 @@ struct CYapfCostBase {
|
||||
};
|
||||
|
||||
struct CostRailSettings {
|
||||
// look-ahead signal penalty
|
||||
/* look-ahead signal penalty */
|
||||
};
|
||||
|
||||
|
||||
|
@@ -51,7 +51,7 @@ public:
|
||||
protected:
|
||||
LocalCache m_local_cache;
|
||||
|
||||
/// to access inherited path finder
|
||||
/** to access inherited path finder */
|
||||
FORCEINLINE Tpf& Yapf()
|
||||
{
|
||||
return *static_cast<Tpf*>(this);
|
||||
@@ -157,7 +157,7 @@ protected:
|
||||
|
||||
FORCEINLINE CYapfSegmentCostCacheGlobalT() : m_global_cache(stGetGlobalCache()) {};
|
||||
|
||||
/// to access inherited path finder
|
||||
/** to access inherited path finder */
|
||||
FORCEINLINE Tpf& Yapf()
|
||||
{
|
||||
return *static_cast<Tpf*>(this);
|
||||
@@ -169,14 +169,14 @@ protected:
|
||||
static Date last_date = 0;
|
||||
static Cache C;
|
||||
|
||||
// some statistics
|
||||
/* some statistics */
|
||||
if (last_date != _date) {
|
||||
last_date = _date;
|
||||
DEBUG(yapf, 2, "Pf time today: %5d ms", _total_pf_time_us / 1000);
|
||||
_total_pf_time_us = 0;
|
||||
}
|
||||
|
||||
// delete the cache sometimes...
|
||||
/* delete the cache sometimes... */
|
||||
if (last_rail_change_counter != Cache::s_rail_change_counter) {
|
||||
last_rail_change_counter = Cache::s_rail_change_counter;
|
||||
C.Flush();
|
||||
|
@@ -69,7 +69,7 @@ protected:
|
||||
, m_disable_cache(false)
|
||||
, m_stopped_on_first_two_way_signal(false)
|
||||
{
|
||||
// pre-compute look-ahead penalties into array
|
||||
/* pre-compute look-ahead penalties into array */
|
||||
int p0 = Yapf().PfGetSettings().rail_look_ahead_signal_p0;
|
||||
int p1 = Yapf().PfGetSettings().rail_look_ahead_signal_p1;
|
||||
int p2 = Yapf().PfGetSettings().rail_look_ahead_signal_p2;
|
||||
@@ -79,7 +79,7 @@ protected:
|
||||
}
|
||||
}
|
||||
|
||||
/// to access inherited path finder
|
||||
/** to access inherited path finder */
|
||||
Tpf& Yapf()
|
||||
{
|
||||
return *static_cast<Tpf*>(this);
|
||||
@@ -100,10 +100,10 @@ public:
|
||||
int cost = 0;
|
||||
if (TrackFollower::Allow90degTurns()
|
||||
&& ((TrackdirToTrackdirBits(td2) & (TrackdirBits)TrackdirCrossesTrackdirs(td1)) != 0)) {
|
||||
// 90-deg curve penalty
|
||||
/* 90-deg curve penalty */
|
||||
cost += Yapf().PfGetSettings().rail_curve90_penalty;
|
||||
} else if (td2 != NextTrackdir(td1)) {
|
||||
// 45-deg curve penalty
|
||||
/* 45-deg curve penalty */
|
||||
cost += Yapf().PfGetSettings().rail_curve45_penalty;
|
||||
}
|
||||
return cost;
|
||||
@@ -123,7 +123,7 @@ public:
|
||||
FORCEINLINE int OneTileCost(TileIndex& tile, Trackdir trackdir)
|
||||
{
|
||||
int cost = 0;
|
||||
// set base cost
|
||||
/* set base cost */
|
||||
if (IsDiagonalTrackdir(trackdir)) {
|
||||
cost += YAPF_TILE_LENGTH;
|
||||
switch (GetTileType(tile)) {
|
||||
@@ -138,7 +138,7 @@ public:
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
// non-diagonal trackdir
|
||||
/* non-diagonal trackdir */
|
||||
cost = YAPF_TILE_CORNER_LENGTH;
|
||||
}
|
||||
return cost;
|
||||
@@ -172,33 +172,33 @@ public:
|
||||
int SignalCost(Node& n, TileIndex tile, Trackdir trackdir)
|
||||
{
|
||||
int cost = 0;
|
||||
// if there is one-way signal in the opposite direction, then it is not our way
|
||||
/* if there is one-way signal in the opposite direction, then it is not our way */
|
||||
CPerfStart perf_cost(Yapf().m_perf_other_cost);
|
||||
if (IsTileType(tile, MP_RAILWAY)) {
|
||||
bool has_signal_against = HasSignalOnTrackdir(tile, ReverseTrackdir(trackdir));
|
||||
bool has_signal_along = HasSignalOnTrackdir(tile, trackdir);
|
||||
if (has_signal_against && !has_signal_along && IsOnewaySignal(tile, TrackdirToTrack(trackdir))) {
|
||||
// one-way signal in opposite direction
|
||||
/* one-way signal in opposite direction */
|
||||
n.m_segment->m_end_segment_reason |= ESRB_DEAD_END;
|
||||
} else {
|
||||
if (has_signal_along) {
|
||||
SignalState sig_state = GetSignalStateByTrackdir(tile, trackdir);
|
||||
// cache the look-ahead polynomial constant only if we didn't pass more signals than the look-ahead limit is
|
||||
/* cache the look-ahead polynomial constant only if we didn't pass more signals than the look-ahead limit is */
|
||||
int look_ahead_cost = (n.m_num_signals_passed < m_sig_look_ahead_costs.Size()) ? m_sig_look_ahead_costs.Data()[n.m_num_signals_passed] : 0;
|
||||
if (sig_state != SIGNAL_STATE_RED) {
|
||||
// green signal
|
||||
/* green signal */
|
||||
n.flags_u.flags_s.m_last_signal_was_red = false;
|
||||
// negative look-ahead red-signal penalties would cause problems later, so use them as positive penalties for green signal
|
||||
/* negative look-ahead red-signal penalties would cause problems later, so use them as positive penalties for green signal */
|
||||
if (look_ahead_cost < 0) {
|
||||
// add its negation to the cost
|
||||
/* add its negation to the cost */
|
||||
cost -= look_ahead_cost;
|
||||
}
|
||||
} else {
|
||||
SignalType sig_type = GetSignalType(tile, TrackdirToTrack(trackdir));
|
||||
// we have a red signal in our direction
|
||||
// was it first signal which is two-way?
|
||||
/* we have a red signal in our direction
|
||||
* was it first signal which is two-way? */
|
||||
if (!IsPbsSignal(sig_type) && Yapf().TreatFirstRedTwoWaySignalAsEOL() && n.flags_u.flags_s.m_choice_seen && has_signal_against && n.m_num_signals_passed == 0) {
|
||||
// yes, the first signal is two-way red signal => DEAD END
|
||||
/* yes, the first signal is two-way red signal => DEAD END */
|
||||
n.m_segment->m_end_segment_reason |= ESRB_DEAD_END;
|
||||
Yapf().m_stopped_on_first_two_way_signal = true;
|
||||
return -1;
|
||||
@@ -206,13 +206,13 @@ public:
|
||||
n.m_last_red_signal_type = sig_type;
|
||||
n.flags_u.flags_s.m_last_signal_was_red = true;
|
||||
|
||||
// look-ahead signal penalty
|
||||
/* look-ahead signal penalty */
|
||||
if (!IsPbsSignal(sig_type) && look_ahead_cost > 0) {
|
||||
// add the look ahead penalty only if it is positive
|
||||
/* add the look ahead penalty only if it is positive */
|
||||
cost += look_ahead_cost;
|
||||
}
|
||||
|
||||
// special signal penalties
|
||||
/* special signal penalties */
|
||||
if (n.m_num_signals_passed == 0) {
|
||||
switch (sig_type) {
|
||||
case SIGTYPE_COMBO:
|
||||
@@ -246,10 +246,10 @@ public:
|
||||
assert(v->u.rail.cached_total_length != 0);
|
||||
int needed_platform_length = (v->u.rail.cached_total_length + TILE_SIZE - 1) / TILE_SIZE;
|
||||
if (platform_length > needed_platform_length) {
|
||||
// apply penalty for longer platform than needed
|
||||
/* apply penalty for longer platform than needed */
|
||||
cost += Yapf().PfGetSettings().rail_longer_platform_penalty;
|
||||
} else if (needed_platform_length > platform_length) {
|
||||
// apply penalty for shorter platform than needed
|
||||
/* apply penalty for shorter platform than needed */
|
||||
cost += Yapf().PfGetSettings().rail_shorter_platform_penalty;
|
||||
}
|
||||
return cost;
|
||||
@@ -313,10 +313,10 @@ public:
|
||||
|
||||
const Vehicle *v = Yapf().GetVehicle();
|
||||
|
||||
// start at n.m_key.m_tile / n.m_key.m_td and walk to the end of segment
|
||||
/* start at n.m_key.m_tile / n.m_key.m_td and walk to the end of segment */
|
||||
TILE cur(n.m_key.m_tile, n.m_key.m_td);
|
||||
|
||||
// the previous tile will be needed for transition cost calculations
|
||||
/* the previous tile will be needed for transition cost calculations */
|
||||
TILE prev = !has_parent ? TILE() : TILE(n.m_parent->GetLastTile(), n.m_parent->GetLastTrackdir());
|
||||
|
||||
EndSegmentReasonBits end_segment_reason = ESRB_NONE;
|
||||
@@ -529,10 +529,10 @@ no_entry_cost: // jump here at the beginning if the node has no parent (it is th
|
||||
/* Last-red and last-red-exit penalties. */
|
||||
if (n.flags_u.flags_s.m_last_signal_was_red) {
|
||||
if (n.m_last_red_signal_type == SIGTYPE_EXIT) {
|
||||
// last signal was red pre-signal-exit
|
||||
/* last signal was red pre-signal-exit */
|
||||
extra_cost += Yapf().PfGetSettings().rail_lastred_exit_penalty;
|
||||
} else {
|
||||
// last signal was red, but not exit
|
||||
/* last signal was red, but not exit */
|
||||
extra_cost += Yapf().PfGetSettings().rail_lastred_penalty;
|
||||
}
|
||||
}
|
||||
@@ -549,7 +549,7 @@ no_entry_cost: // jump here at the beginning if the node has no parent (it is th
|
||||
}
|
||||
}
|
||||
|
||||
// total node cost
|
||||
/* total node cost */
|
||||
n.m_cost = parent_cost + segment_entry_cost + segment_cost + extra_cost;
|
||||
|
||||
return true;
|
||||
|
@@ -37,19 +37,19 @@ public:
|
||||
typedef typename Types::NodeList::Titem Node; ///< this will be our node type
|
||||
typedef typename Node::Key Key; ///< key to hash tables
|
||||
|
||||
/// to access inherited path finder
|
||||
/** to access inherited path finder */
|
||||
Tpf& Yapf()
|
||||
{
|
||||
return *static_cast<Tpf*>(this);
|
||||
}
|
||||
|
||||
/// Called by YAPF to detect if node ends in the desired destination
|
||||
/** Called by YAPF to detect if node ends in the desired destination */
|
||||
FORCEINLINE bool PfDetectDestination(Node& n)
|
||||
{
|
||||
return PfDetectDestination(n.GetLastTile(), n.GetLastTrackdir());
|
||||
}
|
||||
|
||||
/// Called by YAPF to detect if node ends in the desired destination
|
||||
/** Called by YAPF to detect if node ends in the desired destination */
|
||||
FORCEINLINE bool PfDetectDestination(TileIndex tile, Trackdir td)
|
||||
{
|
||||
bool bDest = IsRailDepotTile(tile);
|
||||
@@ -75,19 +75,19 @@ public:
|
||||
typedef typename Node::Key Key; ///< key to hash tables
|
||||
typedef typename Types::TrackFollower TrackFollower; ///< TrackFollower. Need to typedef for gcc 2.95
|
||||
|
||||
/// to access inherited path finder
|
||||
/** to access inherited path finder */
|
||||
Tpf& Yapf()
|
||||
{
|
||||
return *static_cast<Tpf*>(this);
|
||||
}
|
||||
|
||||
/// Called by YAPF to detect if node ends in the desired destination
|
||||
/** Called by YAPF to detect if node ends in the desired destination */
|
||||
FORCEINLINE bool PfDetectDestination(Node& n)
|
||||
{
|
||||
return PfDetectDestination(n.GetLastTile(), n.GetLastTrackdir());
|
||||
}
|
||||
|
||||
/// Called by YAPF to detect if node ends in the desired destination
|
||||
/** Called by YAPF to detect if node ends in the desired destination */
|
||||
FORCEINLINE bool PfDetectDestination(TileIndex tile, Trackdir td)
|
||||
{
|
||||
return
|
||||
@@ -118,7 +118,7 @@ protected:
|
||||
TrackdirBits m_destTrackdirs;
|
||||
StationID m_dest_station_id;
|
||||
|
||||
/// to access inherited path finder
|
||||
/** to access inherited path finder */
|
||||
Tpf& Yapf()
|
||||
{
|
||||
return *static_cast<Tpf*>(this);
|
||||
@@ -160,13 +160,13 @@ public:
|
||||
CYapfDestinationRailBase::SetDestination(v);
|
||||
}
|
||||
|
||||
/// Called by YAPF to detect if node ends in the desired destination
|
||||
/** Called by YAPF to detect if node ends in the desired destination */
|
||||
FORCEINLINE bool PfDetectDestination(Node& n)
|
||||
{
|
||||
return PfDetectDestination(n.GetLastTile(), n.GetLastTrackdir());
|
||||
}
|
||||
|
||||
/// Called by YAPF to detect if node ends in the desired destination
|
||||
/** Called by YAPF to detect if node ends in the desired destination */
|
||||
FORCEINLINE bool PfDetectDestination(TileIndex tile, Trackdir td)
|
||||
{
|
||||
bool bDest;
|
||||
|
@@ -82,11 +82,11 @@ struct CYapfShipNodeT
|
||||
|
||||
};
|
||||
|
||||
// now define two major node types (that differ by key type)
|
||||
/* now define two major node types (that differ by key type) */
|
||||
typedef CYapfShipNodeT<CYapfNodeKeyExitDir> CYapfShipNodeExitDir;
|
||||
typedef CYapfShipNodeT<CYapfNodeKeyTrackDir> CYapfShipNodeTrackDir;
|
||||
|
||||
// Default NodeList types
|
||||
/* Default NodeList types */
|
||||
typedef CNodeList_HashTableT<CYapfShipNodeExitDir , 14, 16> CShipNodeListExitDir;
|
||||
typedef CNodeList_HashTableT<CYapfShipNodeTrackDir, 16, 20> CShipNodeListTrackDir;
|
||||
|
||||
|
@@ -266,11 +266,11 @@ struct CYapfRailNodeT
|
||||
}
|
||||
};
|
||||
|
||||
// now define two major node types (that differ by key type)
|
||||
/* now define two major node types (that differ by key type) */
|
||||
typedef CYapfRailNodeT<CYapfNodeKeyExitDir> CYapfRailNodeExitDir;
|
||||
typedef CYapfRailNodeT<CYapfNodeKeyTrackDir> CYapfRailNodeTrackDir;
|
||||
|
||||
// Default NodeList types
|
||||
/* Default NodeList types */
|
||||
typedef CNodeList_HashTableT<CYapfRailNodeExitDir , 10, 12> CRailNodeListExitDir;
|
||||
typedef CNodeList_HashTableT<CYapfRailNodeTrackDir, 12, 16> CRailNodeListTrackDir;
|
||||
|
||||
|
@@ -23,11 +23,11 @@ struct CYapfRoadNodeT
|
||||
}
|
||||
};
|
||||
|
||||
// now define two major node types (that differ by key type)
|
||||
/* now define two major node types (that differ by key type) */
|
||||
typedef CYapfRoadNodeT<CYapfNodeKeyExitDir> CYapfRoadNodeExitDir;
|
||||
typedef CYapfRoadNodeT<CYapfNodeKeyTrackDir> CYapfRoadNodeTrackDir;
|
||||
|
||||
// Default NodeList types
|
||||
/* Default NodeList types */
|
||||
typedef CNodeList_HashTableT<CYapfRoadNodeExitDir , 8, 12> CRoadNodeListExitDir;
|
||||
typedef CNodeList_HashTableT<CYapfRoadNodeTrackDir, 10, 14> CRoadNodeListTrackDir;
|
||||
|
||||
|
@@ -24,7 +24,7 @@ public:
|
||||
typedef typename Types::NodeList::Titem Node; ///< this will be our node type
|
||||
|
||||
protected:
|
||||
/// to access inherited pathfinder
|
||||
/** to access inherited pathfinder */
|
||||
FORCEINLINE Tpf& Yapf()
|
||||
{
|
||||
return *static_cast<Tpf*>(this);
|
||||
@@ -171,7 +171,7 @@ public:
|
||||
typedef typename Node::Key Key; ///< key to hash tables
|
||||
|
||||
protected:
|
||||
/// to access inherited path finder
|
||||
/** to access inherited path finder */
|
||||
FORCEINLINE Tpf& Yapf()
|
||||
{
|
||||
return *static_cast<Tpf*>(this);
|
||||
@@ -189,7 +189,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
/// return debug report character to identify the transportation type
|
||||
/** return debug report character to identify the transportation type */
|
||||
FORCEINLINE char TransportTypeChar() const
|
||||
{
|
||||
return 't';
|
||||
@@ -216,28 +216,28 @@ public:
|
||||
|
||||
FORCEINLINE bool FindNearestDepotTwoWay(const Vehicle *v, TileIndex t1, Trackdir td1, TileIndex t2, Trackdir td2, int max_distance, int reverse_penalty, TileIndex *depot_tile, bool *reversed)
|
||||
{
|
||||
// set origin and destination nodes
|
||||
/* set origin and destination nodes */
|
||||
Yapf().SetOrigin(t1, td1, t2, td2, reverse_penalty, true);
|
||||
Yapf().SetDestination(v);
|
||||
Yapf().SetMaxCost(YAPF_TILE_LENGTH * max_distance);
|
||||
|
||||
// find the best path
|
||||
/* find the best path */
|
||||
bool bFound = Yapf().FindPath(v);
|
||||
if (!bFound) return false;
|
||||
|
||||
// some path found
|
||||
// get found depot tile
|
||||
/* some path found
|
||||
* get found depot tile */
|
||||
Node *n = Yapf().GetBestNode();
|
||||
*depot_tile = n->GetLastTile();
|
||||
|
||||
// walk through the path back to the origin
|
||||
/* walk through the path back to the origin */
|
||||
Node *pNode = n;
|
||||
while (pNode->m_parent != NULL) {
|
||||
pNode = pNode->m_parent;
|
||||
}
|
||||
|
||||
// if the origin node is our front vehicle tile/Trackdir then we didn't reverse
|
||||
// but we can also look at the cost (== 0 -> not reversed, == reverse_penalty -> reversed)
|
||||
/* if the origin node is our front vehicle tile/Trackdir then we didn't reverse
|
||||
* but we can also look at the cost (== 0 -> not reversed, == reverse_penalty -> reversed) */
|
||||
*reversed = (pNode->m_cost != 0);
|
||||
|
||||
return true;
|
||||
@@ -254,7 +254,7 @@ public:
|
||||
typedef typename Node::Key Key; ///< key to hash tables
|
||||
|
||||
protected:
|
||||
/// to access inherited path finder
|
||||
/** to access inherited path finder */
|
||||
FORCEINLINE Tpf& Yapf()
|
||||
{
|
||||
return *static_cast<Tpf*>(this);
|
||||
@@ -343,7 +343,7 @@ public:
|
||||
typedef typename Node::Key Key; ///< key to hash tables
|
||||
|
||||
protected:
|
||||
/// to access inherited path finder
|
||||
/** to access inherited path finder */
|
||||
FORCEINLINE Tpf& Yapf()
|
||||
{
|
||||
return *static_cast<Tpf*>(this);
|
||||
@@ -361,7 +361,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
/// return debug report character to identify the transportation type
|
||||
/** return debug report character to identify the transportation type */
|
||||
FORCEINLINE char TransportTypeChar() const
|
||||
{
|
||||
return 't';
|
||||
@@ -369,7 +369,7 @@ public:
|
||||
|
||||
static Trackdir stChooseRailTrack(const Vehicle *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool *path_not_found, bool reserve_track, PBSTileInfo *target)
|
||||
{
|
||||
// create pathfinder instance
|
||||
/* create pathfinder instance */
|
||||
Tpf pf1;
|
||||
#if !DEBUG_YAPF_CACHE
|
||||
Trackdir result1 = pf1.ChooseRailTrack(v, tile, enterdir, tracks, path_not_found, reserve_track, target);
|
||||
@@ -400,28 +400,28 @@ public:
|
||||
{
|
||||
if (target != NULL) target->tile = INVALID_TILE;
|
||||
|
||||
// set origin and destination nodes
|
||||
/* set origin and destination nodes */
|
||||
PBSTileInfo origin = FollowTrainReservation(v);
|
||||
Yapf().SetOrigin(origin.tile, origin.trackdir, INVALID_TILE, INVALID_TRACKDIR, 1, true);
|
||||
Yapf().SetDestination(v);
|
||||
|
||||
// find the best path
|
||||
/* find the best path */
|
||||
bool path_found = Yapf().FindPath(v);
|
||||
if (path_not_found != NULL) {
|
||||
// tell controller that the path was only 'guessed'
|
||||
// treat the path as found if stopped on the first two way signal(s)
|
||||
/* tell controller that the path was only 'guessed'
|
||||
* treat the path as found if stopped on the first two way signal(s) */
|
||||
*path_not_found = !(path_found || Yapf().m_stopped_on_first_two_way_signal);
|
||||
}
|
||||
|
||||
// if path not found - return INVALID_TRACKDIR
|
||||
/* if path not found - return INVALID_TRACKDIR */
|
||||
Trackdir next_trackdir = INVALID_TRACKDIR;
|
||||
Node *pNode = Yapf().GetBestNode();
|
||||
if (pNode != NULL) {
|
||||
// reserve till end of path
|
||||
/* reserve till end of path */
|
||||
this->SetReservationTarget(pNode, pNode->GetLastTile(), pNode->GetLastTrackdir());
|
||||
|
||||
// path was found or at least suggested
|
||||
// walk through the path back to the origin
|
||||
/* path was found or at least suggested
|
||||
* walk through the path back to the origin */
|
||||
Node *pPrev = NULL;
|
||||
while (pNode->m_parent != NULL) {
|
||||
pPrev = pNode;
|
||||
@@ -429,7 +429,7 @@ public:
|
||||
|
||||
this->FindSafePositionOnNode(pPrev);
|
||||
}
|
||||
// return trackdir from the best origin node (one of start nodes)
|
||||
/* return trackdir from the best origin node (one of start nodes) */
|
||||
Node& best_next_node = *pPrev;
|
||||
next_trackdir = best_next_node.GetTrackdir();
|
||||
|
||||
@@ -457,24 +457,24 @@ public:
|
||||
|
||||
FORCEINLINE bool CheckReverseTrain(const Vehicle *v, TileIndex t1, Trackdir td1, TileIndex t2, Trackdir td2, int reverse_penalty)
|
||||
{
|
||||
// create pathfinder instance
|
||||
// set origin and destination nodes
|
||||
/* create pathfinder instance
|
||||
* set origin and destination nodes */
|
||||
Yapf().SetOrigin(t1, td1, t2, td2, reverse_penalty, false);
|
||||
Yapf().SetDestination(v);
|
||||
|
||||
// find the best path
|
||||
/* find the best path */
|
||||
bool bFound = Yapf().FindPath(v);
|
||||
|
||||
if (!bFound) return false;
|
||||
|
||||
// path was found
|
||||
// walk through the path back to the origin
|
||||
/* path was found
|
||||
* walk through the path back to the origin */
|
||||
Node *pNode = Yapf().GetBestNode();
|
||||
while (pNode->m_parent != NULL) {
|
||||
pNode = pNode->m_parent;
|
||||
}
|
||||
|
||||
// check if it was reversed origin
|
||||
/* check if it was reversed origin */
|
||||
Node& best_org_node = *pNode;
|
||||
bool reversed = (best_org_node.m_cost != 0);
|
||||
return reversed;
|
||||
@@ -509,11 +509,11 @@ struct CYapfAnySafeTileRail2 : CYapfT<CYapfRail_TypesT<CYapfAnySafeTileRail2, CF
|
||||
|
||||
Trackdir YapfChooseRailTrack(const Vehicle *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool *path_not_found, bool reserve_track, PBSTileInfo *target)
|
||||
{
|
||||
// default is YAPF type 2
|
||||
/* default is YAPF type 2 */
|
||||
typedef Trackdir (*PfnChooseRailTrack)(const Vehicle*, TileIndex, DiagDirection, TrackBits, bool*, bool, PBSTileInfo*);
|
||||
PfnChooseRailTrack pfnChooseRailTrack = &CYapfRail1::stChooseRailTrack;
|
||||
|
||||
// check if non-default YAPF type needed
|
||||
/* check if non-default YAPF type needed */
|
||||
if (_settings_game.pf.forbid_90_deg) {
|
||||
pfnChooseRailTrack = &CYapfRail2::stChooseRailTrack; // Trackdir, forbid 90-deg
|
||||
}
|
||||
@@ -528,7 +528,7 @@ bool YapfCheckReverseTrain(const Vehicle *v)
|
||||
/* last wagon */
|
||||
const Vehicle *last_veh = GetLastVehicleInChain(v);
|
||||
|
||||
// get trackdirs of both ends
|
||||
/* get trackdirs of both ends */
|
||||
Trackdir td = GetVehicleTrackdir(v);
|
||||
Trackdir td_rev = ReverseTrackdir(GetVehicleTrackdir(last_veh));
|
||||
|
||||
@@ -570,7 +570,7 @@ bool YapfCheckReverseTrain(const Vehicle *v)
|
||||
typedef bool (*PfnCheckReverseTrain)(const Vehicle*, TileIndex, Trackdir, TileIndex, Trackdir, int);
|
||||
PfnCheckReverseTrain pfnCheckReverseTrain = CYapfRail1::stCheckReverseTrain;
|
||||
|
||||
// check if non-default YAPF type needed
|
||||
/* check if non-default YAPF type needed */
|
||||
if (_settings_game.pf.forbid_90_deg) {
|
||||
pfnCheckReverseTrain = &CYapfRail2::stCheckReverseTrain; // Trackdir, forbid 90-deg
|
||||
}
|
||||
@@ -597,7 +597,7 @@ bool YapfFindNearestRailDepotTwoWay(const Vehicle *v, int max_distance, int reve
|
||||
typedef bool (*PfnFindNearestDepotTwoWay)(const Vehicle*, TileIndex, Trackdir, TileIndex, Trackdir, int, int, TileIndex*, bool*);
|
||||
PfnFindNearestDepotTwoWay pfnFindNearestDepotTwoWay = &CYapfAnyDepotRail1::stFindNearestDepotTwoWay;
|
||||
|
||||
// check if non-default YAPF type needed
|
||||
/* check if non-default YAPF type needed */
|
||||
if (_settings_game.pf.forbid_90_deg) {
|
||||
pfnFindNearestDepotTwoWay = &CYapfAnyDepotRail2::stFindNearestDepotTwoWay; // Trackdir, forbid 90-deg
|
||||
}
|
||||
|
@@ -19,7 +19,7 @@ public:
|
||||
typedef typename Node::Key Key; ///< key to hash tables
|
||||
|
||||
protected:
|
||||
/// to access inherited path finder
|
||||
/** to access inherited path finder */
|
||||
Tpf& Yapf()
|
||||
{
|
||||
return *static_cast<Tpf*>(this);
|
||||
@@ -27,12 +27,12 @@ protected:
|
||||
|
||||
int SlopeCost(TileIndex tile, TileIndex next_tile, Trackdir trackdir)
|
||||
{
|
||||
// height of the center of the current tile
|
||||
/* height of the center of the current tile */
|
||||
int x1 = TileX(tile) * TILE_SIZE;
|
||||
int y1 = TileY(tile) * TILE_SIZE;
|
||||
int z1 = GetSlopeZ(x1 + TILE_SIZE / 2, y1 + TILE_SIZE / 2);
|
||||
|
||||
// height of the center of the next tile
|
||||
/* height of the center of the next tile */
|
||||
int x2 = TileX(next_tile) * TILE_SIZE;
|
||||
int y2 = TileY(next_tile) * TILE_SIZE;
|
||||
int z2 = GetSlopeZ(x2 + TILE_SIZE / 2, y2 + TILE_SIZE / 2);
|
||||
@@ -48,7 +48,7 @@ protected:
|
||||
FORCEINLINE int OneTileCost(TileIndex tile, Trackdir trackdir)
|
||||
{
|
||||
int cost = 0;
|
||||
// set base cost
|
||||
/* set base cost */
|
||||
if (IsDiagonalTrackdir(trackdir)) {
|
||||
cost += YAPF_TILE_LENGTH;
|
||||
switch (GetTileType(tile)) {
|
||||
@@ -69,7 +69,7 @@ protected:
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
// non-diagonal trackdir
|
||||
/* non-diagonal trackdir */
|
||||
cost = YAPF_TILE_CORNER_LENGTH + Yapf().PfGetSettings().road_curve_penalty;
|
||||
}
|
||||
return cost;
|
||||
@@ -82,57 +82,57 @@ public:
|
||||
FORCEINLINE bool PfCalcCost(Node& n, const TrackFollower *tf)
|
||||
{
|
||||
int segment_cost = 0;
|
||||
// start at n.m_key.m_tile / n.m_key.m_td and walk to the end of segment
|
||||
/* start at n.m_key.m_tile / n.m_key.m_td and walk to the end of segment */
|
||||
TileIndex tile = n.m_key.m_tile;
|
||||
Trackdir trackdir = n.m_key.m_td;
|
||||
while (true) {
|
||||
// base tile cost depending on distance between edges
|
||||
/* base tile cost depending on distance between edges */
|
||||
segment_cost += Yapf().OneTileCost(tile, trackdir);
|
||||
|
||||
const Vehicle *v = Yapf().GetVehicle();
|
||||
// we have reached the vehicle's destination - segment should end here to avoid target skipping
|
||||
/* we have reached the vehicle's destination - segment should end here to avoid target skipping */
|
||||
if (Yapf().PfDetectDestinationTile(tile, trackdir)) break;
|
||||
|
||||
// stop if we have just entered the depot
|
||||
/* stop if we have just entered the depot */
|
||||
if (IsRoadDepotTile(tile) && trackdir == DiagDirToDiagTrackdir(ReverseDiagDir(GetRoadDepotDirection(tile)))) {
|
||||
// next time we will reverse and leave the depot
|
||||
/* next time we will reverse and leave the depot */
|
||||
break;
|
||||
}
|
||||
|
||||
// if there are no reachable trackdirs on new tile, we have end of road
|
||||
/* if there are no reachable trackdirs on new tile, we have end of road */
|
||||
TrackFollower F(Yapf().GetVehicle());
|
||||
if (!F.Follow(tile, trackdir)) break;
|
||||
|
||||
// if there are more trackdirs available & reachable, we are at the end of segment
|
||||
/* if there are more trackdirs available & reachable, we are at the end of segment */
|
||||
if (KillFirstBit(F.m_new_td_bits) != TRACKDIR_BIT_NONE) break;
|
||||
|
||||
Trackdir new_td = (Trackdir)FindFirstBit2x64(F.m_new_td_bits);
|
||||
|
||||
// stop if RV is on simple loop with no junctions
|
||||
/* stop if RV is on simple loop with no junctions */
|
||||
if (F.m_new_tile == n.m_key.m_tile && new_td == n.m_key.m_td) return false;
|
||||
|
||||
// if we skipped some tunnel tiles, add their cost
|
||||
/* if we skipped some tunnel tiles, add their cost */
|
||||
segment_cost += F.m_tiles_skipped * YAPF_TILE_LENGTH;
|
||||
|
||||
// add hilly terrain penalty
|
||||
/* add hilly terrain penalty */
|
||||
segment_cost += Yapf().SlopeCost(tile, F.m_new_tile, trackdir);
|
||||
|
||||
// add min/max speed penalties
|
||||
/* add min/max speed penalties */
|
||||
int min_speed = 0;
|
||||
int max_speed = F.GetSpeedLimit(&min_speed);
|
||||
if (max_speed < v->max_speed) segment_cost += 1 * (v->max_speed - max_speed);
|
||||
if (min_speed > v->max_speed) segment_cost += 10 * (min_speed - v->max_speed);
|
||||
|
||||
// move to the next tile
|
||||
/* move to the next tile */
|
||||
tile = F.m_new_tile;
|
||||
trackdir = new_td;
|
||||
};
|
||||
|
||||
// save end of segment back to the node
|
||||
/* save end of segment back to the node */
|
||||
n.m_segment_last_tile = tile;
|
||||
n.m_segment_last_td = trackdir;
|
||||
|
||||
// save also tile cost
|
||||
/* save also tile cost */
|
||||
int parent_cost = (n.m_parent != NULL) ? n.m_parent->m_cost : 0;
|
||||
n.m_cost = parent_cost + segment_cost;
|
||||
return true;
|
||||
@@ -149,13 +149,13 @@ public:
|
||||
typedef typename Types::NodeList::Titem Node; ///< this will be our node type
|
||||
typedef typename Node::Key Key; ///< key to hash tables
|
||||
|
||||
/// to access inherited path finder
|
||||
/** to access inherited path finder */
|
||||
Tpf& Yapf()
|
||||
{
|
||||
return *static_cast<Tpf*>(this);
|
||||
}
|
||||
|
||||
/// Called by YAPF to detect if node ends in the desired destination
|
||||
/** Called by YAPF to detect if node ends in the desired destination */
|
||||
FORCEINLINE bool PfDetectDestination(Node& n)
|
||||
{
|
||||
bool bDest = IsRoadDepotTile(n.m_segment_last_tile);
|
||||
@@ -198,14 +198,14 @@ public:
|
||||
}
|
||||
|
||||
protected:
|
||||
/// to access inherited path finder
|
||||
/** to access inherited path finder */
|
||||
Tpf& Yapf()
|
||||
{
|
||||
return *static_cast<Tpf*>(this);
|
||||
}
|
||||
|
||||
public:
|
||||
/// Called by YAPF to detect if node ends in the desired destination
|
||||
/** Called by YAPF to detect if node ends in the desired destination */
|
||||
FORCEINLINE bool PfDetectDestination(Node& n)
|
||||
{
|
||||
bool bDest = (n.m_segment_last_tile == m_destTile) && ((m_destTrackdirs & TrackdirToTrackdirBits(n.m_segment_last_td)) != TRACKDIR_BIT_NONE);
|
||||
@@ -257,7 +257,7 @@ public:
|
||||
typedef typename Node::Key Key; ///< key to hash tables
|
||||
|
||||
protected:
|
||||
/// to access inherited path finder
|
||||
/** to access inherited path finder */
|
||||
FORCEINLINE Tpf& Yapf()
|
||||
{
|
||||
return *static_cast<Tpf*>(this);
|
||||
@@ -276,7 +276,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
/// return debug report character to identify the transportation type
|
||||
/** return debug report character to identify the transportation type */
|
||||
FORCEINLINE char TransportTypeChar() const
|
||||
{
|
||||
return 'r';
|
||||
@@ -290,39 +290,39 @@ public:
|
||||
|
||||
FORCEINLINE Trackdir ChooseRoadTrack(const Vehicle *v, TileIndex tile, DiagDirection enterdir)
|
||||
{
|
||||
// handle special case - when next tile is destination tile
|
||||
/* handle special case - when next tile is destination tile */
|
||||
if (tile == v->dest_tile) {
|
||||
// choose diagonal trackdir reachable from enterdir
|
||||
/* choose diagonal trackdir reachable from enterdir */
|
||||
return DiagDirToDiagTrackdir(enterdir);
|
||||
}
|
||||
// our source tile will be the next vehicle tile (should be the given one)
|
||||
/* our source tile will be the next vehicle tile (should be the given one) */
|
||||
TileIndex src_tile = tile;
|
||||
// get available trackdirs on the start tile
|
||||
/* get available trackdirs on the start tile */
|
||||
TrackdirBits src_trackdirs = TrackStatusToTrackdirBits(GetTileTrackStatus(tile, TRANSPORT_ROAD, v->u.road.compatible_roadtypes));
|
||||
// select reachable trackdirs only
|
||||
/* select reachable trackdirs only */
|
||||
src_trackdirs &= DiagdirReachesTrackdirs(enterdir);
|
||||
|
||||
// get available trackdirs on the destination tile
|
||||
/* get available trackdirs on the destination tile */
|
||||
TileIndex dest_tile = v->dest_tile;
|
||||
TrackdirBits dest_trackdirs = TrackStatusToTrackdirBits(GetTileTrackStatus(dest_tile, TRANSPORT_ROAD, v->u.road.compatible_roadtypes));
|
||||
|
||||
// set origin and destination nodes
|
||||
/* set origin and destination nodes */
|
||||
Yapf().SetOrigin(src_tile, src_trackdirs);
|
||||
Yapf().SetDestination(dest_tile, dest_trackdirs);
|
||||
|
||||
// find the best path
|
||||
/* find the best path */
|
||||
Yapf().FindPath(v);
|
||||
|
||||
// if path not found - return INVALID_TRACKDIR
|
||||
/* if path not found - return INVALID_TRACKDIR */
|
||||
Trackdir next_trackdir = INVALID_TRACKDIR;
|
||||
Node *pNode = Yapf().GetBestNode();
|
||||
if (pNode != NULL) {
|
||||
// path was found or at least suggested
|
||||
// walk through the path back to its origin
|
||||
/* path was found or at least suggested
|
||||
* walk through the path back to its origin */
|
||||
while (pNode->m_parent != NULL) {
|
||||
pNode = pNode->m_parent;
|
||||
}
|
||||
// return trackdir from the best origin node (one of start nodes)
|
||||
/* return trackdir from the best origin node (one of start nodes) */
|
||||
Node& best_next_node = *pNode;
|
||||
assert(best_next_node.GetTile() == tile);
|
||||
next_trackdir = best_next_node.GetTrackdir();
|
||||
@@ -338,29 +338,29 @@ public:
|
||||
|
||||
FORCEINLINE uint DistanceToTile(const Vehicle *v, TileIndex dst_tile)
|
||||
{
|
||||
// handle special case - when current tile is the destination tile
|
||||
/* handle special case - when current tile is the destination tile */
|
||||
if (dst_tile == v->tile) {
|
||||
// distance is zero in this case
|
||||
/* distance is zero in this case */
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!SetOriginFromVehiclePos(v)) return UINT_MAX;
|
||||
|
||||
// set destination tile, trackdir
|
||||
// get available trackdirs on the destination tile
|
||||
/* set destination tile, trackdir
|
||||
* get available trackdirs on the destination tile */
|
||||
TrackdirBits dst_td_bits = TrackStatusToTrackdirBits(GetTileTrackStatus(dst_tile, TRANSPORT_ROAD, v->u.road.compatible_roadtypes));
|
||||
Yapf().SetDestination(dst_tile, dst_td_bits);
|
||||
|
||||
// if path not found - return distance = UINT_MAX
|
||||
/* if path not found - return distance = UINT_MAX */
|
||||
uint dist = UINT_MAX;
|
||||
|
||||
// find the best path
|
||||
/* find the best path */
|
||||
if (!Yapf().FindPath(v)) return dist;
|
||||
|
||||
Node *pNode = Yapf().GetBestNode();
|
||||
if (pNode != NULL) {
|
||||
// path was found
|
||||
// get the path cost estimate
|
||||
/* path was found
|
||||
* get the path cost estimate */
|
||||
dist = pNode->GetCostEstimate();
|
||||
}
|
||||
|
||||
@@ -370,12 +370,12 @@ public:
|
||||
/** Return true if the valid origin (tile/trackdir) was set from the current vehicle position. */
|
||||
FORCEINLINE bool SetOriginFromVehiclePos(const Vehicle *v)
|
||||
{
|
||||
// set origin (tile, trackdir)
|
||||
/* set origin (tile, trackdir) */
|
||||
TileIndex src_tile = v->tile;
|
||||
Trackdir src_td = GetVehicleTrackdir(v);
|
||||
if ((TrackStatusToTrackdirBits(GetTileTrackStatus(src_tile, TRANSPORT_ROAD, v->u.road.compatible_roadtypes)) & TrackdirToTrackdirBits(src_td)) == 0) {
|
||||
// sometimes the roadveh is not on the road (it resides on non-existing track)
|
||||
// how should we handle that situation?
|
||||
/* sometimes the roadveh is not on the road (it resides on non-existing track)
|
||||
* how should we handle that situation? */
|
||||
return false;
|
||||
}
|
||||
Yapf().SetOrigin(src_tile, TrackdirToTrackdirBits(src_td));
|
||||
@@ -390,15 +390,15 @@ public:
|
||||
|
||||
FORCEINLINE Depot *FindNearestDepot(const Vehicle *v, TileIndex tile, Trackdir td)
|
||||
{
|
||||
// set origin and destination nodes
|
||||
/* set origin and destination nodes */
|
||||
Yapf().SetOrigin(tile, TrackdirToTrackdirBits(td));
|
||||
|
||||
// find the best path
|
||||
/* find the best path */
|
||||
bool bFound = Yapf().FindPath(v);
|
||||
if (!bFound) return false;
|
||||
|
||||
// some path found
|
||||
// get found depot tile
|
||||
/* some path found
|
||||
* get found depot tile */
|
||||
Node *n = Yapf().GetBestNode();
|
||||
TileIndex depot_tile = n->m_segment_last_tile;
|
||||
assert(IsRoadDepotTile(depot_tile));
|
||||
@@ -432,11 +432,11 @@ struct CYapfRoadAnyDepot2 : CYapfT<CYapfRoad_TypesT<CYapfRoadAnyDepot2, CRoadNod
|
||||
|
||||
Trackdir YapfChooseRoadTrack(const Vehicle *v, TileIndex tile, DiagDirection enterdir)
|
||||
{
|
||||
// default is YAPF type 2
|
||||
/* default is YAPF type 2 */
|
||||
typedef Trackdir (*PfnChooseRoadTrack)(const Vehicle*, TileIndex, DiagDirection);
|
||||
PfnChooseRoadTrack pfnChooseRoadTrack = &CYapfRoad2::stChooseRoadTrack; // default: ExitDir, allow 90-deg
|
||||
|
||||
// check if non-default YAPF type should be used
|
||||
/* check if non-default YAPF type should be used */
|
||||
if (_settings_game.pf.yapf.disable_node_optimization) {
|
||||
pfnChooseRoadTrack = &CYapfRoad1::stChooseRoadTrack; // Trackdir, allow 90-deg
|
||||
}
|
||||
@@ -447,18 +447,18 @@ Trackdir YapfChooseRoadTrack(const Vehicle *v, TileIndex tile, DiagDirection ent
|
||||
|
||||
uint YapfRoadVehDistanceToTile(const Vehicle *v, TileIndex tile)
|
||||
{
|
||||
// default is YAPF type 2
|
||||
/* default is YAPF type 2 */
|
||||
typedef uint (*PfnDistanceToTile)(const Vehicle*, TileIndex);
|
||||
PfnDistanceToTile pfnDistanceToTile = &CYapfRoad2::stDistanceToTile; // default: ExitDir, allow 90-deg
|
||||
|
||||
// check if non-default YAPF type should be used
|
||||
/* check if non-default YAPF type should be used */
|
||||
if (_settings_game.pf.yapf.disable_node_optimization) {
|
||||
pfnDistanceToTile = &CYapfRoad1::stDistanceToTile; // Trackdir, allow 90-deg
|
||||
}
|
||||
|
||||
// measure distance in YAPF units
|
||||
/* measure distance in YAPF units */
|
||||
uint dist = pfnDistanceToTile(v, tile);
|
||||
// convert distance to tiles
|
||||
/* convert distance to tiles */
|
||||
if (dist != UINT_MAX) {
|
||||
dist = (dist + YAPF_TILE_LENGTH - 1) / YAPF_TILE_LENGTH;
|
||||
}
|
||||
@@ -474,17 +474,17 @@ Depot *YapfFindNearestRoadDepot(const Vehicle *v)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// handle the case when our vehicle is already in the depot tile
|
||||
/* handle the case when our vehicle is already in the depot tile */
|
||||
if (IsRoadDepotTile(tile)) {
|
||||
// only what we need to return is the Depot*
|
||||
/* only what we need to return is the Depot* */
|
||||
return GetDepotByTile(tile);
|
||||
}
|
||||
|
||||
// default is YAPF type 2
|
||||
/* default is YAPF type 2 */
|
||||
typedef Depot *(*PfnFindNearestDepot)(const Vehicle*, TileIndex, Trackdir);
|
||||
PfnFindNearestDepot pfnFindNearestDepot = &CYapfRoadAnyDepot2::stFindNearestDepot;
|
||||
|
||||
// check if non-default YAPF type should be used
|
||||
/* check if non-default YAPF type should be used */
|
||||
if (_settings_game.pf.yapf.disable_node_optimization) {
|
||||
pfnFindNearestDepot = &CYapfRoadAnyDepot1::stFindNearestDepot; // Trackdir, allow 90-deg
|
||||
}
|
||||
|
@@ -17,7 +17,7 @@ public:
|
||||
typedef typename Node::Key Key; ///< key to hash tables
|
||||
|
||||
protected:
|
||||
/// to access inherited path finder
|
||||
/** to access inherited path finder */
|
||||
FORCEINLINE Tpf& Yapf()
|
||||
{
|
||||
return *static_cast<Tpf*>(this);
|
||||
@@ -35,7 +35,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
/// return debug report character to identify the transportation type
|
||||
/** return debug report character to identify the transportation type */
|
||||
FORCEINLINE char TransportTypeChar() const
|
||||
{
|
||||
return 'w';
|
||||
@@ -43,44 +43,44 @@ public:
|
||||
|
||||
static Trackdir ChooseShipTrack(const Vehicle *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks)
|
||||
{
|
||||
// handle special case - when next tile is destination tile
|
||||
/* handle special case - when next tile is destination tile */
|
||||
if (tile == v->dest_tile) {
|
||||
// convert tracks to trackdirs
|
||||
/* convert tracks to trackdirs */
|
||||
TrackdirBits trackdirs = (TrackdirBits)(tracks | ((int)tracks << 8));
|
||||
// choose any trackdir reachable from enterdir
|
||||
/* choose any trackdir reachable from enterdir */
|
||||
trackdirs &= DiagdirReachesTrackdirs(enterdir);
|
||||
return (Trackdir)FindFirstBit2x64(trackdirs);
|
||||
}
|
||||
|
||||
// move back to the old tile/trackdir (where ship is coming from)
|
||||
/* move back to the old tile/trackdir (where ship is coming from) */
|
||||
TileIndex src_tile = TILE_ADD(tile, TileOffsByDiagDir(ReverseDiagDir(enterdir)));
|
||||
Trackdir trackdir = GetVehicleTrackdir(v);
|
||||
assert(IsValidTrackdir(trackdir));
|
||||
|
||||
// convert origin trackdir to TrackdirBits
|
||||
/* convert origin trackdir to TrackdirBits */
|
||||
TrackdirBits trackdirs = TrackdirToTrackdirBits(trackdir);
|
||||
// get available trackdirs on the destination tile
|
||||
/* get available trackdirs on the destination tile */
|
||||
TrackdirBits dest_trackdirs = TrackStatusToTrackdirBits(GetTileTrackStatus(v->dest_tile, TRANSPORT_WATER, 0));
|
||||
|
||||
// create pathfinder instance
|
||||
/* create pathfinder instance */
|
||||
Tpf pf;
|
||||
// set origin and destination nodes
|
||||
/* set origin and destination nodes */
|
||||
pf.SetOrigin(src_tile, trackdirs);
|
||||
pf.SetDestination(v->dest_tile, dest_trackdirs);
|
||||
// find best path
|
||||
/* find best path */
|
||||
pf.FindPath(v);
|
||||
|
||||
Trackdir next_trackdir = INVALID_TRACKDIR; // this would mean "path not found"
|
||||
|
||||
Node *pNode = pf.GetBestNode();
|
||||
if (pNode != NULL) {
|
||||
// walk through the path back to the origin
|
||||
/* walk through the path back to the origin */
|
||||
Node *pPrevNode = NULL;
|
||||
while (pNode->m_parent != NULL) {
|
||||
pPrevNode = pNode;
|
||||
pNode = pNode->m_parent;
|
||||
}
|
||||
// return trackdir from the best next node (direct child of origin)
|
||||
/* return trackdir from the best next node (direct child of origin) */
|
||||
Node& best_next_node = *pPrevNode;
|
||||
assert(best_next_node.GetTile() == tile);
|
||||
next_trackdir = best_next_node.GetTrackdir();
|
||||
@@ -100,7 +100,7 @@ public:
|
||||
typedef typename Node::Key Key; ///< key to hash tables
|
||||
|
||||
protected:
|
||||
/// to access inherited path finder
|
||||
/** to access inherited path finder */
|
||||
Tpf& Yapf()
|
||||
{
|
||||
return *static_cast<Tpf*>(this);
|
||||
@@ -112,9 +112,9 @@ public:
|
||||
* and stores the result into Node::m_cost member */
|
||||
FORCEINLINE bool PfCalcCost(Node& n, const TrackFollower *tf)
|
||||
{
|
||||
// base tile cost depending on distance
|
||||
/* base tile cost depending on distance */
|
||||
int c = IsDiagonalTrackdir(n.GetTrackdir()) ? 10 : 7;
|
||||
// additional penalty for curves
|
||||
/* additional penalty for curves */
|
||||
if (n.m_parent != NULL && n.GetTrackdir() != NextTrackdir(n.m_parent->GetTrackdir())) {
|
||||
/* new trackdir does not match the next one when going straight */
|
||||
c += 10;
|
||||
@@ -122,7 +122,7 @@ public:
|
||||
|
||||
c += YAPF_TILE_LENGTH * tf->m_tiles_skipped;
|
||||
|
||||
// apply it
|
||||
/* apply it */
|
||||
n.m_cost = n.m_parent->m_cost + c;
|
||||
return true;
|
||||
}
|
||||
@@ -152,21 +152,21 @@ struct CYapfShip_TypesT
|
||||
typedef CYapfCostShipT<Types> PfCost; // cost provider
|
||||
};
|
||||
|
||||
// YAPF type 1 - uses TileIndex/Trackdir as Node key, allows 90-deg turns
|
||||
/* YAPF type 1 - uses TileIndex/Trackdir as Node key, allows 90-deg turns */
|
||||
struct CYapfShip1 : CYapfT<CYapfShip_TypesT<CYapfShip1, CFollowTrackWater , CShipNodeListTrackDir> > {};
|
||||
// YAPF type 2 - uses TileIndex/DiagDirection as Node key, allows 90-deg turns
|
||||
/* YAPF type 2 - uses TileIndex/DiagDirection as Node key, allows 90-deg turns */
|
||||
struct CYapfShip2 : CYapfT<CYapfShip_TypesT<CYapfShip2, CFollowTrackWater , CShipNodeListExitDir > > {};
|
||||
// YAPF type 3 - uses TileIndex/Trackdir as Node key, forbids 90-deg turns
|
||||
/* YAPF type 3 - uses TileIndex/Trackdir as Node key, forbids 90-deg turns */
|
||||
struct CYapfShip3 : CYapfT<CYapfShip_TypesT<CYapfShip3, CFollowTrackWaterNo90, CShipNodeListTrackDir> > {};
|
||||
|
||||
/** Ship controller helper - path finder invoker */
|
||||
Trackdir YapfChooseShipTrack(const Vehicle *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks)
|
||||
{
|
||||
// default is YAPF type 2
|
||||
/* default is YAPF type 2 */
|
||||
typedef Trackdir (*PfnChooseShipTrack)(const Vehicle*, TileIndex, DiagDirection, TrackBits);
|
||||
PfnChooseShipTrack pfnChooseShipTrack = CYapfShip2::ChooseShipTrack; // default: ExitDir, allow 90-deg
|
||||
|
||||
// check if non-default YAPF type needed
|
||||
/* check if non-default YAPF type needed */
|
||||
if (_settings_game.pf.forbid_90_deg) {
|
||||
pfnChooseShipTrack = &CYapfShip3::ChooseShipTrack; // Trackdir, forbid 90-deg
|
||||
} else if (_settings_game.pf.yapf.disable_node_optimization) {
|
||||
|
Reference in New Issue
Block a user