summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormichi_cc <michi_cc@openttd.org>2011-08-21 14:13:22 +0000
committermichi_cc <michi_cc@openttd.org>2011-08-21 14:13:22 +0000
commit45b95ed62950678b677c555cec558b009e0b8d3e (patch)
tree15fb97a4babf447c25b84d5afe67b938e57722a8 /src
parentc10d4157233109aab8794d2455481d45bd44b019 (diff)
downloadopenttd-45b95ed62950678b677c555cec558b009e0b8d3e.tar.xz
(svn r22801) -Feature: [YAPF] Take canal/ocean speed fraction of ships into account.
Diffstat (limited to 'src')
-rw-r--r--src/pathfinder/yapf/yapf_ship.cpp6
-rw-r--r--src/ship.h2
-rw-r--r--src/ship_cmd.cpp2
3 files changed, 9 insertions, 1 deletions
diff --git a/src/pathfinder/yapf/yapf_ship.cpp b/src/pathfinder/yapf/yapf_ship.cpp
index 69f1ce2c5..46b3e9bf7 100644
--- a/src/pathfinder/yapf/yapf_ship.cpp
+++ b/src/pathfinder/yapf/yapf_ship.cpp
@@ -133,8 +133,14 @@ public:
c += YAPF_TILE_LENGTH;
}
+ /* Skipped tile cost for aqueducts. */
c += YAPF_TILE_LENGTH * tf->m_tiles_skipped;
+ /* Ocean/canal speed penalty. */
+ const ShipVehicleInfo *svi = ShipVehInfo(Yapf().GetVehicle()->engine_type);
+ byte speed_frac = (GetEffectiveWaterClass(n.GetTile()) == WATER_CLASS_SEA) ? svi->ocean_speed_frac : svi->canal_speed_frac;
+ if (speed_frac > 0) c += YAPF_TILE_LENGTH * (1 + tf->m_tiles_skipped) * speed_frac / (256 - speed_frac);
+
/* apply it */
n.m_cost = n.m_parent->m_cost + c;
return true;
diff --git a/src/ship.h b/src/ship.h
index 3a7e21d58..b40697087 100644
--- a/src/ship.h
+++ b/src/ship.h
@@ -13,8 +13,10 @@
#define SHIP_H
#include "vehicle_base.h"
+#include "water_map.h"
void GetShipSpriteSize(EngineID engine, uint &width, uint &height);
+WaterClass GetEffectiveWaterClass(TileIndex tile);
/**
* All ships have this type.
diff --git a/src/ship_cmd.cpp b/src/ship_cmd.cpp
index 222d48994..f38a83c25 100644
--- a/src/ship_cmd.cpp
+++ b/src/ship_cmd.cpp
@@ -41,7 +41,7 @@
* @param tile Tile of interest
* @return the waterclass to be used by the ship.
*/
-static WaterClass GetEffectiveWaterClass(TileIndex tile)
+WaterClass GetEffectiveWaterClass(TileIndex tile)
{
if (HasTileWaterClass(tile)) return GetWaterClass(tile);
if (IsTileType(tile, MP_TUNNELBRIDGE)) {