summaryrefslogtreecommitdiff
path: root/src/pathfinder
diff options
context:
space:
mode:
authorPeter Nelson <peter1138@openttd.org>2019-02-14 23:12:26 +0000
committerMichael Lutz <michi@icosahedron.de>2019-03-08 16:52:08 +0100
commitb8a0107ad157e946c46a4e65cb3f63bec1812670 (patch)
tree9985a413faa7bad1c59fe9fb0bbc86df323450e7 /src/pathfinder
parenta69eb5f516963f6f7a39f90d959cdff61e8e70b2 (diff)
downloadopenttd-b8a0107ad157e946c46a4e65cb3f63bec1812670.tar.xz
Change: Add configurable curve penalty for ships.
Diffstat (limited to 'src/pathfinder')
-rw-r--r--src/pathfinder/yapf/yapf_ship.cpp20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/pathfinder/yapf/yapf_ship.cpp b/src/pathfinder/yapf/yapf_ship.cpp
index 5a8afc1b9..c71bf8af5 100644
--- a/src/pathfinder/yapf/yapf_ship.cpp
+++ b/src/pathfinder/yapf/yapf_ship.cpp
@@ -169,6 +169,21 @@ protected:
}
public:
+ inline int CurveCost(Trackdir td1, Trackdir td2)
+ {
+ assert(IsValidTrackdir(td1));
+ assert(IsValidTrackdir(td2));
+
+ if (HasTrackdir(TrackdirCrossesTrackdirs(td1), td2)) {
+ /* 90-deg curve penalty */
+ return Yapf().PfGetSettings().ship_curve90_penalty;
+ } else if (td2 != NextTrackdir(td1)) {
+ /* 45-deg curve penalty */
+ return Yapf().PfGetSettings().ship_curve45_penalty;
+ }
+ return 0;
+ }
+
/**
* 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
@@ -179,10 +194,7 @@ public:
/* base tile cost depending on distance */
int c = IsDiagonalTrackdir(n.GetTrackdir()) ? YAPF_TILE_LENGTH : YAPF_TILE_CORNER_LENGTH;
/* additional penalty for curves */
- if (n.GetTrackdir() != NextTrackdir(n.m_parent->GetTrackdir())) {
- /* new trackdir does not match the next one when going straight */
- c += YAPF_TILE_LENGTH;
- }
+ c += CurveCost(n.m_parent->GetTrackdir(), n.GetTrackdir());
/* Skipped tile cost for aqueducts. */
c += YAPF_TILE_LENGTH * tf->m_tiles_skipped;