diff options
author | KUDr <kudr@openttd.org> | 2006-06-01 21:39:35 +0000 |
---|---|---|
committer | KUDr <kudr@openttd.org> | 2006-06-01 21:39:35 +0000 |
commit | bd25f49d3f5252ba473759320b86f581be9c79fd (patch) | |
tree | 62d7336add925121331528ae4303d15bda9672ac /yapf/yapf_costrail.hpp | |
parent | 76a8f036df11a961a286dc4d5447a090a35bf4aa (diff) | |
download | openttd-bd25f49d3f5252ba473759320b86f581be9c79fd.tar.xz |
(svn r5066) -Feature: [YAPF] Train selects the best station platform by length
Diffstat (limited to 'yapf/yapf_costrail.hpp')
-rw-r--r-- | yapf/yapf_costrail.hpp | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/yapf/yapf_costrail.hpp b/yapf/yapf_costrail.hpp index 6085197ab..76af3652b 100644 --- a/yapf/yapf_costrail.hpp +++ b/yapf/yapf_costrail.hpp @@ -138,6 +138,24 @@ public: return cost; } + FORCEINLINE int PlatformLengthPenalty(int platform_length) + { + int cost = 0; + const Vehicle* v = Yapf().GetVehicle(); + assert(v != NULL); + assert(v->type == VEH_Train); + assert(v->u.rail.cached_total_length != 0); + int needed_platform_length = (v->u.rail.cached_total_length + TILE_SIZE - 1) / TILE_SIZE; + if (platform_length > needed_platform_length) { + // apply penalty for longer platform than needed + cost += Yapf().PfGetSettings().rail_longer_platform_penalty * (platform_length - needed_platform_length); + } else { + // apply penalty for shorter platform than needed + cost += Yapf().PfGetSettings().rail_shorter_platform_penalty * (needed_platform_length - platform_length); + } + return cost; + } + public: FORCEINLINE void SetMaxCost(int max_cost) {m_max_cost = max_cost;} @@ -245,7 +263,20 @@ public: } // if we skipped some tunnel tiles, add their cost - segment_cost += YAPF_TILE_LENGTH * F.m_tunnel_tiles_skipped; + segment_cost += YAPF_TILE_LENGTH * F.m_tiles_skipped; + + // add penalty for skipped station tiles + if (F.m_is_station) + { + if (target_seen) { + // it is our destination station + uint platform_length = F.m_tiles_skipped + 1; + segment_cost += PlatformLengthPenalty(platform_length); + } else { + // station is not our destination station, apply penalty for skipped platform tiles + segment_cost += Yapf().PfGetSettings().rail_station_penalty * F.m_tiles_skipped; + } + } // add min/max speed penalties int min_speed = 0; |