summaryrefslogtreecommitdiff
path: root/src/pathfinder/npf/npf.cpp
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2019-03-11 13:08:11 +0000
committerNiels Martin Hansen <nielsm@indvikleren.dk>2019-06-30 16:46:32 +0200
commit31db4f8d5ef61e49e006b39864e38584fc2f485d (patch)
tree63d1b0351764e97add1e6b65fd2231f231ffb699 /src/pathfinder/npf/npf.cpp
parentec2656ab7ef6d924f3c30624bf1d3c7449403c6f (diff)
downloadopenttd-31db4f8d5ef61e49e006b39864e38584fc2f485d.tar.xz
Add: Penalty for occupied docking points.
Diffstat (limited to 'src/pathfinder/npf/npf.cpp')
-rw-r--r--src/pathfinder/npf/npf.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/pathfinder/npf/npf.cpp b/src/pathfinder/npf/npf.cpp
index 53f84f2a7..f10e4cd9e 100644
--- a/src/pathfinder/npf/npf.cpp
+++ b/src/pathfinder/npf/npf.cpp
@@ -14,6 +14,7 @@
#include "../../viewport_func.h"
#include "../../ship.h"
#include "../../roadstop_base.h"
+#include "../../vehicle_func.h"
#include "../pathfinder_func.h"
#include "../pathfinder_type.h"
#include "../follow_track.hpp"
@@ -303,6 +304,15 @@ static void NPFMarkTile(TileIndex tile)
}
}
+static Vehicle *CountShipProc(Vehicle *v, void *data)
+{
+ uint *count = (uint *)data;
+ /* Ignore other vehicles (aircraft) and ships inside depot. */
+ if (v->type == VEH_SHIP && (v->vehstatus & VS_HIDDEN) == 0) (*count)++;
+
+ return nullptr;
+}
+
static int32 NPFWaterPathCost(AyStar *as, AyStarNode *current, OpenListNode *parent)
{
/* TileIndex tile = current->tile; */
@@ -319,6 +329,13 @@ static int32 NPFWaterPathCost(AyStar *as, AyStarNode *current, OpenListNode *par
cost += _settings_game.pf.npf.npf_water_curve_penalty;
}
+ if (IsDockingTile(current->tile)) {
+ /* Check docking tile for occupancy */
+ uint count = 1;
+ HasVehicleOnPos(current->tile, &count, &CountShipProc);
+ cost += count * 3 * _trackdir_length[trackdir];
+ }
+
/* @todo More penalties? */
return cost;