Merge branch 'master' into infrastructure_sharing
Conflicts: src/aircraft_cmd.cpp src/economy.cpp src/lang/english.txt src/order_gui.cpp src/roadveh_cmd.cpp src/saveload/saveload.cpp src/settings.cpp src/settings_gui.cpp src/train_cmd.cpp
This commit is contained in:
@@ -27,6 +27,8 @@
|
||||
#include "../../core/alloc_func.hpp"
|
||||
#include "aystar.h"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
/**
|
||||
* This looks in the hash whether a node exists in the closed list.
|
||||
* @param node Node to search.
|
||||
@@ -124,7 +126,7 @@ void AyStar::CheckTile(AyStarNode *current, OpenListNode *parent)
|
||||
/* The f-value if g + h */
|
||||
new_f = new_g + new_h;
|
||||
|
||||
/* Get the pointer to the parent in the ClosedList (the currentone is to a copy of the one in the OpenList) */
|
||||
/* Get the pointer to the parent in the ClosedList (the current one is to a copy of the one in the OpenList) */
|
||||
closedlist_parent = this->ClosedListIsInList(&parent->path.node);
|
||||
|
||||
/* Check if this item is already in the OpenList */
|
||||
|
||||
@@ -64,7 +64,7 @@ struct AyStar;
|
||||
/**
|
||||
* Check whether the end-tile is found.
|
||||
* @param aystar %AyStar search algorithm data.
|
||||
* @param current Node to examone.
|
||||
* @param current Node to exam one.
|
||||
* @note The 2nd parameter should be #OpenListNode, and \em not #AyStarNode. #AyStarNode is
|
||||
* part of #OpenListNode and so it could be accessed without any problems.
|
||||
* The good part about #OpenListNode is, and how AIs use it, that you can
|
||||
|
||||
@@ -20,6 +20,8 @@
|
||||
#include "../follow_track.hpp"
|
||||
#include "aystar.h"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
static const uint NPF_HASH_BITS = 12; ///< The size of the hash used in pathfinding. Just changing this value should be sufficient to change the hash size. Should be an even value.
|
||||
/* Do no change below values */
|
||||
static const uint NPF_HASH_SIZE = 1 << NPF_HASH_BITS;
|
||||
@@ -101,7 +103,7 @@ static inline void NPFSetFlag(AyStarNode *node, NPFNodeFlag flag, bool value)
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the minimum distance traveled to get from t0 to t1 when only
|
||||
* Calculates the minimum distance travelled to get from t0 to t1 when only
|
||||
* using tracks (ie, only making 45 degree turns). Returns the distance in the
|
||||
* NPF scale, ie the number of full tiles multiplied by NPF_TILE_LENGTH to
|
||||
* prevent rounding.
|
||||
@@ -146,7 +148,7 @@ static int32 NPFCalcZero(AyStar *as, AyStarNode *current, OpenListNode *parent)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Calcs the heuristic to the target station or tile. For train stations, it
|
||||
/* Calculates the heuristic to the target station or tile. For train stations, it
|
||||
* takes into account the direction of approach.
|
||||
*/
|
||||
static int32 NPFCalcStationOrTileHeuristic(AyStar *as, AyStarNode *current, OpenListNode *parent)
|
||||
@@ -246,7 +248,7 @@ static uint NPFSlopeCost(AyStarNode *current)
|
||||
}
|
||||
return 0;
|
||||
/* Should we give a bonus for slope down? Probably not, we
|
||||
* could just substract that bonus from the penalty, because
|
||||
* could just subtract that bonus from the penalty, because
|
||||
* there is only one level of steepness... */
|
||||
}
|
||||
|
||||
@@ -570,7 +572,7 @@ static int32 NPFFindStationOrTile(AyStar *as, OpenListNode *current)
|
||||
* Find the node containing the first signal on the path.
|
||||
*
|
||||
* If the first signal is on the very first two tiles of the path,
|
||||
* the second signal is returnd. If no suitable signal is present, the
|
||||
* the second signal is returned. If no suitable signal is present, the
|
||||
* last node of the path is returned.
|
||||
*/
|
||||
static const PathNode *FindSafePosition(PathNode *path, const Train *v)
|
||||
@@ -1059,7 +1061,7 @@ static NPFFoundTargetData NPFRouteToStationOrTile(TileIndex tile, Trackdir track
|
||||
/* Search using breadth first. Good for little track choice and inaccurate
|
||||
* heuristic, such as railway/road with two start nodes, the second being the reverse. Call
|
||||
* NPFGetFlag(result.node, NPF_FLAG_REVERSE) to see from which node the path
|
||||
* orginated. All pathfs from the second node will have the given
|
||||
* originated. All paths from the second node will have the given
|
||||
* reverse_penalty applied (NPF_TILE_LENGTH is the equivalent of one full
|
||||
* tile).
|
||||
*/
|
||||
@@ -1185,6 +1187,23 @@ Track NPFShipChooseTrack(const Ship *v, TileIndex tile, DiagDirection enterdir,
|
||||
return TrackdirToTrack(ftd.best_trackdir);
|
||||
}
|
||||
|
||||
bool NPFShipCheckReverse(const Ship *v)
|
||||
{
|
||||
NPFFindStationOrTileData fstd;
|
||||
NPFFoundTargetData ftd;
|
||||
|
||||
NPFFillWithOrderData(&fstd, v);
|
||||
|
||||
Trackdir trackdir = v->GetVehicleTrackdir();
|
||||
Trackdir trackdir_rev = ReverseTrackdir(trackdir);
|
||||
assert(trackdir != INVALID_TRACKDIR);
|
||||
assert(trackdir_rev != INVALID_TRACKDIR);
|
||||
|
||||
ftd = NPFRouteToStationOrTileTwoWay(v->tile, trackdir, false, v->tile, trackdir_rev, false, &fstd, TRANSPORT_WATER, 0, v->owner, INVALID_RAILTYPES);
|
||||
/* If we didn't find anything, just keep on going straight ahead, otherwise take the reverse flag */
|
||||
return ftd.best_bird_dist == 0 && NPFGetFlag(&ftd.node, NPF_FLAG_REVERSE);
|
||||
}
|
||||
|
||||
/*** Trains ***/
|
||||
|
||||
FindDepotData NPFTrainFindNearestDepot(const Train *v, int max_penalty)
|
||||
@@ -1247,7 +1266,7 @@ bool NPFTrainCheckReverse(const Train *v)
|
||||
|
||||
ftd = NPFRouteToStationOrTileTwoWay(v->tile, trackdir, false, last->tile, trackdir_rev, false, &fstd, TRANSPORT_RAIL, 0, v->owner, v->compatible_railtypes);
|
||||
/* If we didn't find anything, just keep on going straight ahead, otherwise take the reverse flag */
|
||||
return ftd.best_bird_dist != 0 && NPFGetFlag(&ftd.node, NPF_FLAG_REVERSE);
|
||||
return ftd.best_bird_dist == 0 && NPFGetFlag(&ftd.node, NPF_FLAG_REVERSE);
|
||||
}
|
||||
|
||||
Track NPFTrainChooseTrack(const Train *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool &path_found, bool reserve_track, struct PBSTileInfo *target)
|
||||
|
||||
@@ -49,6 +49,13 @@ Trackdir NPFRoadVehicleChooseTrack(const RoadVehicle *v, TileIndex tile, DiagDir
|
||||
*/
|
||||
Track NPFShipChooseTrack(const Ship *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool &path_found);
|
||||
|
||||
/**
|
||||
* Returns true if it is better to reverse the ship before leaving depot using NPF.
|
||||
* @param v the ship leaving the depot
|
||||
* @return true if reversing is better
|
||||
*/
|
||||
bool NPFShipCheckReverse(const Ship *v);
|
||||
|
||||
/**
|
||||
* Used when user sends train to the nearest depot or if train needs servicing using NPF
|
||||
* @param v train that needs to go to some depot
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
#include "../../core/alloc_func.hpp"
|
||||
#include "queue.h"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
|
||||
/*
|
||||
* Binary Heap
|
||||
@@ -158,7 +160,7 @@ bool BinaryHeap::Delete(void *item, int priority)
|
||||
|
||||
for (;;) {
|
||||
j = i;
|
||||
/* Check if we have 2 childs */
|
||||
/* Check if we have 2 children */
|
||||
if (2 * j + 1 <= this->size) {
|
||||
/* Is this child smaller than the parent? */
|
||||
if (this->GetElement(j).priority >= this->GetElement(2 * j).priority) i = 2 * j;
|
||||
@@ -170,13 +172,13 @@ bool BinaryHeap::Delete(void *item, int priority)
|
||||
if (this->GetElement(j).priority >= this->GetElement(2 * j).priority) i = 2 * j;
|
||||
}
|
||||
|
||||
/* One of our childs is smaller than we are, switch */
|
||||
/* One of our children is smaller than we are, switch */
|
||||
if (i != j) {
|
||||
temp = this->GetElement(j);
|
||||
this->GetElement(j) = this->GetElement(i);
|
||||
this->GetElement(i) = temp;
|
||||
} else {
|
||||
/* None of our childs is smaller, so we stay here.. stop :) */
|
||||
/* None of our children is smaller, so we stay here.. stop :) */
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user