summaryrefslogtreecommitdiff
path: root/src/ai/api/ai_rail.cpp
diff options
context:
space:
mode:
authoryexo <yexo@openttd.org>2010-01-29 23:56:42 +0000
committeryexo <yexo@openttd.org>2010-01-29 23:56:42 +0000
commit15016e3511b075e999cdb0db45936d5e6b223aa4 (patch)
treed053d2759a7c64b76e429d0367216567ec051534 /src/ai/api/ai_rail.cpp
parent54f958c8e5c99804d1e46c2fe6b3b5ef5cae3db6 (diff)
downloadopenttd-15016e3511b075e999cdb0db45936d5e6b223aa4.tar.xz
(svn r18955) -Feature: [NoAI] introduce GetBuildCost functions in several classes to get easier cost estimations before you start building
Diffstat (limited to 'src/ai/api/ai_rail.cpp')
-rw-r--r--src/ai/api/ai_rail.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/ai/api/ai_rail.cpp b/src/ai/api/ai_rail.cpp
index eb2e01628..9b2974a30 100644
--- a/src/ai/api/ai_rail.cpp
+++ b/src/ai/api/ai_rail.cpp
@@ -19,6 +19,7 @@
#include "../../newgrf.h"
#include "../../newgrf_generic.h"
#include "../../newgrf_station.h"
+#include "../../economy_func.h"
/* static */ bool AIRail::IsRailTile(TileIndex tile)
{
@@ -454,3 +455,17 @@ static bool IsValidSignalType(int signal_type)
return AIObject::DoCommand(tile, track, 0, CMD_REMOVE_SIGNALS);
}
+
+/* static */ Money AIRail::GetBuildCost(RailType railtype, BuildType build_type)
+{
+ if (!AIRail::IsRailTypeAvailable(railtype)) return -1;
+
+ switch (build_type) {
+ case BT_TRACK: return ::RailBuildCost((::RailType)railtype);
+ case BT_SIGNAL: return ::GetPrice(PR_BUILD_SIGNALS, 1, NULL);
+ case BT_DEPOT: return ::GetPrice(PR_BUILD_DEPOT_TRAIN, 1, NULL);
+ case BT_STATION: return ::GetPrice(PR_BUILD_STATION_RAIL, 1, NULL) + ::GetPrice(PR_BUILD_STATION_RAIL_LENGTH, 1, NULL);
+ case BT_WAYPOINT: return ::GetPrice(PR_BUILD_WAYPOINT_RAIL, 1, NULL);
+ default: return -1;
+ }
+}