summaryrefslogtreecommitdiff
path: root/src/pathfinder/yapf
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/yapf
parentec2656ab7ef6d924f3c30624bf1d3c7449403c6f (diff)
downloadopenttd-31db4f8d5ef61e49e006b39864e38584fc2f485d.tar.xz
Add: Penalty for occupied docking points.
Diffstat (limited to 'src/pathfinder/yapf')
-rw-r--r--src/pathfinder/yapf/yapf_ship.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/pathfinder/yapf/yapf_ship.cpp b/src/pathfinder/yapf/yapf_ship.cpp
index c665fc53e..6e0775505 100644
--- a/src/pathfinder/yapf/yapf_ship.cpp
+++ b/src/pathfinder/yapf/yapf_ship.cpp
@@ -12,6 +12,7 @@
#include "../../stdafx.h"
#include "../../ship.h"
#include "../../industry.h"
+#include "../../vehicle_func.h"
#include "yapf.hpp"
#include "yapf_node_ship.hpp"
@@ -261,6 +262,15 @@ public:
return 0;
}
+ 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;
+ }
+
/**
* Called by YAPF to calculate the cost from the origin to the given node.
* Calculates only the cost of given node, adds it to the parent node cost
@@ -273,6 +283,13 @@ public:
/* additional penalty for curves */
c += CurveCost(n.m_parent->GetTrackdir(), n.GetTrackdir());
+ if (IsDockingTile(n.GetTile())) {
+ /* Check docking tile for occupancy */
+ uint count = 1;
+ HasVehicleOnPos(n.GetTile(), &count, &CountShipProc);
+ c += count * 3 * YAPF_TILE_LENGTH;
+ }
+
/* Skipped tile cost for aqueducts. */
c += YAPF_TILE_LENGTH * tf->m_tiles_skipped;