Mercurial > hg > openttd
changeset 17992:05ecda28efc6 draft
(svn r22801) -Feature: [YAPF] Take canal/ocean speed fraction of ships into account.
author | michi_cc <michi_cc@openttd.org> |
---|---|
date | Sun, 21 Aug 2011 14:13:22 +0000 |
parents | ba8f20e7b16d |
children | aac454b5ae05 |
files | src/pathfinder/yapf/yapf_ship.cpp src/ship.h src/ship_cmd.cpp |
diffstat | 3 files changed, 9 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/pathfinder/yapf/yapf_ship.cpp +++ b/src/pathfinder/yapf/yapf_ship.cpp @@ -133,8 +133,14 @@ 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;
--- 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.
--- 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)) {