summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ai/api/ai_engine.cpp28
-rw-r--r--src/ai/api/ai_engine.hpp29
-rw-r--r--src/ai/api/ai_engine.hpp.sq41
3 files changed, 79 insertions, 19 deletions
diff --git a/src/ai/api/ai_engine.cpp b/src/ai/api/ai_engine.cpp
index 8c81862ad..c6bee2bb6 100644
--- a/src/ai/api/ai_engine.cpp
+++ b/src/ai/api/ai_engine.cpp
@@ -110,6 +110,7 @@
/* static */ int32 AIEngine::GetReliability(EngineID engine_id)
{
if (!IsValidEngine(engine_id)) return -1;
+ if (GetVehicleType(engine_id) == AIVehicle::VT_RAIL && IsWagon(engine_id)) return -1;
return (::GetEngine(engine_id)->reliability * 100 >> 16);
}
@@ -134,6 +135,7 @@
/* static */ int32 AIEngine::GetMaxAge(EngineID engine_id)
{
if (!IsValidEngine(engine_id)) return -1;
+ if (GetVehicleType(engine_id) == AIVehicle::VT_RAIL && IsWagon(engine_id)) return -1;
return ::GetEngine(engine_id)->lifelength * DAYS_IN_LEAP_YEAR;
}
@@ -145,6 +147,32 @@
return ::GetEngine(engine_id)->GetRunningCost();
}
+/* static */ int32 AIEngine::GetPower(EngineID engine_id)
+{
+ if (!IsValidEngine(engine_id)) return -1;
+ if (GetVehicleType(engine_id) != AIVehicle::VT_RAIL) return -1;
+ if (IsWagon(engine_id)) return -1;
+
+ return ::GetEngine(engine_id)->GetPower();
+}
+
+/* static */ int32 AIEngine::GetWeight(EngineID engine_id)
+{
+ if (!IsValidEngine(engine_id)) return -1;
+ if (GetVehicleType(engine_id) != AIVehicle::VT_RAIL) return -1;
+
+ return ::GetEngine(engine_id)->GetDisplayWeight();
+}
+
+/* static */ int32 AIEngine::GetMaxTractiveEffort(EngineID engine_id)
+{
+ if (!IsValidEngine(engine_id)) return -1;
+ if (GetVehicleType(engine_id) != AIVehicle::VT_RAIL) return -1;
+ if (IsWagon(engine_id)) return -1;
+
+ return ::GetEngine(engine_id)->GetDisplayMaxTractiveEffort();
+}
+
/* static */ AIVehicle::VehicleType AIEngine::GetVehicleType(EngineID engine_id)
{
if (!IsValidEngine(engine_id)) return AIVehicle::VT_INVALID;
diff --git a/src/ai/api/ai_engine.hpp b/src/ai/api/ai_engine.hpp
index f28f4ffcd..93c6f2233 100644
--- a/src/ai/api/ai_engine.hpp
+++ b/src/ai/api/ai_engine.hpp
@@ -82,6 +82,7 @@ public:
* reliability (you most likely don't want to buy it).
* @param engine_id The engine to get the reliability of.
* @pre IsValidEngine(engine_id).
+ * @pre GetVehicleType(engine_id) != AIVehicle::VT_TRAIN || !IsWagon(engine_id).
* @return The reliability the engine has.
*/
static int32 GetReliability(EngineID engine_id);
@@ -90,6 +91,7 @@ public:
* Get the maximum speed of an engine.
* @param engine_id The engine to get the maximum speed of.
* @pre IsValidEngine(engine_id).
+ * @pre GetVehicleType(engine_id) != AIVehicle::VT_TRAIN || !IsWagon(engine_id).
* @return The maximum speed the engine has.
* @note The speed is in OpenTTD's internal speed unit.
* This is mph / 1.6, which is roughly km/h.
@@ -124,6 +126,33 @@ public:
static Money GetRunningCost(EngineID engine_id);
/**
+ * Get the power of an engine.
+ * @param engine_id The engine to get the power of.
+ * @pre IsValidEngine(engine_id).
+ * @pre GetVehicleType(engine_id) == AIVehicle::VT_RAIL && !IsWagon(engine_id).
+ * @return The power of the engine in hp.
+ */
+ static int32 GetPower(EngineID engine_id);
+
+ /**
+ * Get the weight of an engine.
+ * @param engine_id The engine to get the weight of.
+ * @pre IsValidEngine(engine_id).
+ * @pre GetVehicleType(engine_id) == AIVehicle::VT_RAIL.
+ * @return The weight of the engine in metric tons.
+ */
+ static int32 GetWeight(EngineID engine_id);
+
+ /**
+ * Get the maximum tractive effort of an engine.
+ * @param engine_id The engine to get the maximum tractive effort of.
+ * @pre IsValidEngine(engine_id).
+ * @pre GetVehicleType(engine_id) == AIVehicle::VT_RAIL && !IsWagon(engine_id).
+ * @return The maximum tractive effort of the engine in kN.
+ */
+ static int32 GetMaxTractiveEffort(EngineID engine_id);
+
+ /**
* Get the type of an engine.
* @param engine_id The engine to get the type of.
* @pre IsValidEngine(engine_id).
diff --git a/src/ai/api/ai_engine.hpp.sq b/src/ai/api/ai_engine.hpp.sq
index ee2ac37f5..e94d1c6da 100644
--- a/src/ai/api/ai_engine.hpp.sq
+++ b/src/ai/api/ai_engine.hpp.sq
@@ -17,25 +17,28 @@ void SQAIEngine_Register(Squirrel *engine) {
SQAIEngine.PreRegister(engine);
SQAIEngine.AddConstructor<void (AIEngine::*)(), 1>(engine, "x");
- SQAIEngine.DefSQStaticMethod(engine, &AIEngine::IsValidEngine, "IsValidEngine", 2, "?i");
- SQAIEngine.DefSQStaticMethod(engine, &AIEngine::GetName, "GetName", 2, "?i");
- SQAIEngine.DefSQStaticMethod(engine, &AIEngine::GetCargoType, "GetCargoType", 2, "?i");
- SQAIEngine.DefSQStaticMethod(engine, &AIEngine::CanRefitCargo, "CanRefitCargo", 3, "?ii");
- SQAIEngine.DefSQStaticMethod(engine, &AIEngine::CanPullCargo, "CanPullCargo", 3, "?ii");
- SQAIEngine.DefSQStaticMethod(engine, &AIEngine::GetCapacity, "GetCapacity", 2, "?i");
- SQAIEngine.DefSQStaticMethod(engine, &AIEngine::GetReliability, "GetReliability", 2, "?i");
- SQAIEngine.DefSQStaticMethod(engine, &AIEngine::GetMaxSpeed, "GetMaxSpeed", 2, "?i");
- SQAIEngine.DefSQStaticMethod(engine, &AIEngine::GetPrice, "GetPrice", 2, "?i");
- SQAIEngine.DefSQStaticMethod(engine, &AIEngine::GetMaxAge, "GetMaxAge", 2, "?i");
- SQAIEngine.DefSQStaticMethod(engine, &AIEngine::GetRunningCost, "GetRunningCost", 2, "?i");
- SQAIEngine.DefSQStaticMethod(engine, &AIEngine::GetVehicleType, "GetVehicleType", 2, "?i");
- SQAIEngine.DefSQStaticMethod(engine, &AIEngine::IsWagon, "IsWagon", 2, "?i");
- SQAIEngine.DefSQStaticMethod(engine, &AIEngine::CanRunOnRail, "CanRunOnRail", 3, "?ii");
- SQAIEngine.DefSQStaticMethod(engine, &AIEngine::HasPowerOnRail, "HasPowerOnRail", 3, "?ii");
- SQAIEngine.DefSQStaticMethod(engine, &AIEngine::GetRoadType, "GetRoadType", 2, "?i");
- SQAIEngine.DefSQStaticMethod(engine, &AIEngine::GetRailType, "GetRailType", 2, "?i");
- SQAIEngine.DefSQStaticMethod(engine, &AIEngine::IsArticulated, "IsArticulated", 2, "?i");
- SQAIEngine.DefSQStaticMethod(engine, &AIEngine::GetPlaneType, "GetPlaneType", 2, "?i");
+ SQAIEngine.DefSQStaticMethod(engine, &AIEngine::IsValidEngine, "IsValidEngine", 2, "?i");
+ SQAIEngine.DefSQStaticMethod(engine, &AIEngine::GetName, "GetName", 2, "?i");
+ SQAIEngine.DefSQStaticMethod(engine, &AIEngine::GetCargoType, "GetCargoType", 2, "?i");
+ SQAIEngine.DefSQStaticMethod(engine, &AIEngine::CanRefitCargo, "CanRefitCargo", 3, "?ii");
+ SQAIEngine.DefSQStaticMethod(engine, &AIEngine::CanPullCargo, "CanPullCargo", 3, "?ii");
+ SQAIEngine.DefSQStaticMethod(engine, &AIEngine::GetCapacity, "GetCapacity", 2, "?i");
+ SQAIEngine.DefSQStaticMethod(engine, &AIEngine::GetReliability, "GetReliability", 2, "?i");
+ SQAIEngine.DefSQStaticMethod(engine, &AIEngine::GetMaxSpeed, "GetMaxSpeed", 2, "?i");
+ SQAIEngine.DefSQStaticMethod(engine, &AIEngine::GetPrice, "GetPrice", 2, "?i");
+ SQAIEngine.DefSQStaticMethod(engine, &AIEngine::GetMaxAge, "GetMaxAge", 2, "?i");
+ SQAIEngine.DefSQStaticMethod(engine, &AIEngine::GetRunningCost, "GetRunningCost", 2, "?i");
+ SQAIEngine.DefSQStaticMethod(engine, &AIEngine::GetPower, "GetPower", 2, "?i");
+ SQAIEngine.DefSQStaticMethod(engine, &AIEngine::GetWeight, "GetWeight", 2, "?i");
+ SQAIEngine.DefSQStaticMethod(engine, &AIEngine::GetMaxTractiveEffort, "GetMaxTractiveEffort", 2, "?i");
+ SQAIEngine.DefSQStaticMethod(engine, &AIEngine::GetVehicleType, "GetVehicleType", 2, "?i");
+ SQAIEngine.DefSQStaticMethod(engine, &AIEngine::IsWagon, "IsWagon", 2, "?i");
+ SQAIEngine.DefSQStaticMethod(engine, &AIEngine::CanRunOnRail, "CanRunOnRail", 3, "?ii");
+ SQAIEngine.DefSQStaticMethod(engine, &AIEngine::HasPowerOnRail, "HasPowerOnRail", 3, "?ii");
+ SQAIEngine.DefSQStaticMethod(engine, &AIEngine::GetRoadType, "GetRoadType", 2, "?i");
+ SQAIEngine.DefSQStaticMethod(engine, &AIEngine::GetRailType, "GetRailType", 2, "?i");
+ SQAIEngine.DefSQStaticMethod(engine, &AIEngine::IsArticulated, "IsArticulated", 2, "?i");
+ SQAIEngine.DefSQStaticMethod(engine, &AIEngine::GetPlaneType, "GetPlaneType", 2, "?i");
SQAIEngine.PostRegister(engine);
}