(svn r9782) [NoAI] -Add: add information functions to AIVehicle, like the valuators of AIVehicleList
--- a/bin/ai/regression/regression.nut Fri May 04 19:55:35 2007 +0000
+++ b/bin/ai/regression/regression.nut Fri May 04 21:26:42 2007 +0000
@@ -461,6 +461,16 @@
print(" CloneVehicle(): " + vehicle.CloneVehicle(33417, 1024, true));
+ print(" --VehicleData--");
+ print(" GetLocation(): " + vehicle.GetLocation(1024));
+ print(" GetEngineType(): " + vehicle.GetEngineType(1024));
+ print(" GetUnitNumber(): " + vehicle.GetUnitNumber(1024));
+ print(" GetAge(): " + vehicle.GetAge(1024));
+ print(" GetMaxAge(): " + vehicle.GetMaxAge(1024));
+ print(" GetAgeLeft(): " + vehicle.GetAgeLeft(1024));
+ print(" GetProfitThisYear(): " + vehicle.GetProfitThisYear(1024));
+ print(" GetProfitLastYear(): " + vehicle.GetProfitLastYear(1024));
+
local list = AIVehicleList();
print("");
--- a/bin/ai/regression/regression.txt Fri May 04 19:55:35 2007 +0000
+++ b/bin/ai/regression/regression.txt Fri May 04 21:26:42 2007 +0000
@@ -1573,6 +1573,15 @@
GetCosts(): -5945
Should be: -5945
CloneVehicle(): 1025
+ --VehicleData--
+ GetLocation(): 33417
+ GetEngineType(): 153
+ GetUnitNumber(): 1
+ GetAge(): 1
+ GetMaxAge(): 5490
+ GetAgeLeft(): 5489
+ GetProfitThisYear(): 0
+ GetProfitLastYear(): 0
--VehicleList--
Count(): 2
--- a/src/ai/api/ai_vehicle.cpp Fri May 04 19:55:35 2007 +0000
+++ b/src/ai/api/ai_vehicle.cpp Fri May 04 21:26:42 2007 +0000
@@ -118,3 +118,59 @@
return this->DoCommand(0, vehicle_id, 0, CMD_SKIP_ORDER);
}
+
+TileIndex AIVehicle::GetLocation(VehicleID vehicle_id)
+{
+ if (!AIVehicle::IsValidVehicle(vehicle_id)) return INVALID_TILE;
+
+ return ::GetVehicle(vehicle_id)->tile;
+}
+
+EngineID AIVehicle::GetEngineType(VehicleID vehicle_id)
+{
+ if (!AIVehicle::IsValidVehicle(vehicle_id)) return INVALID_ENGINE;
+
+ return ::GetVehicle(vehicle_id)->engine_type;
+}
+
+int32 AIVehicle::GetUnitNumber(VehicleID vehicle_id)
+{
+ if (!AIVehicle::IsValidVehicle(vehicle_id)) return -1;
+
+ return ::GetVehicle(vehicle_id)->unitnumber;
+}
+
+int32 AIVehicle::GetAge(VehicleID vehicle_id)
+{
+ if (!AIVehicle::IsValidVehicle(vehicle_id)) return -1;
+
+ return ::GetVehicle(vehicle_id)->age;
+}
+
+int32 AIVehicle::GetMaxAge(VehicleID vehicle_id)
+{
+ if (!AIVehicle::IsValidVehicle(vehicle_id)) return -1;
+
+ return ::GetVehicle(vehicle_id)->max_age;
+}
+
+int32 AIVehicle::GetAgeLeft(VehicleID vehicle_id)
+{
+ if (!AIVehicle::IsValidVehicle(vehicle_id)) return -1;
+
+ return ::GetVehicle(vehicle_id)->max_age - ::GetVehicle(vehicle_id)->age;
+}
+
+int32 AIVehicle::GetProfitThisYear(VehicleID vehicle_id)
+{
+ if (!AIVehicle::IsValidVehicle(vehicle_id)) return -1;
+
+ return ::GetVehicle(vehicle_id)->profit_this_year;
+}
+
+int32 AIVehicle::GetProfitLastYear(VehicleID vehicle_id)
+{
+ if (!AIVehicle::IsValidVehicle(vehicle_id)) return -1;
+
+ return ::GetVehicle(vehicle_id)->profit_last_year;
+}
--- a/src/ai/api/ai_vehicle.hpp Fri May 04 19:55:35 2007 +0000
+++ b/src/ai/api/ai_vehicle.hpp Fri May 04 21:26:42 2007 +0000
@@ -121,6 +121,73 @@
* @return true if and only if the order has been skipped.
*/
bool SkipVehicleOrder(VehicleID vehicle_id);
+
+ /**
+ * Get the current location of a vehicle.
+ * @param vehicle_id the vehicle to get the location of.
+ * @pre IsValidVehicle(vehicle_id).
+ * @return the tile the vehicle is currently on.
+ */
+ static TileIndex GetLocation(VehicleID vehicle_id);
+
+ /**
+ * Get the engine-type of a vehicle.
+ * @param vehicle_id the vehicle to get the engine-type of.
+ * @pre IsValidVehicle(vehicle_id).
+ * @return the engine type the vehicle has.
+ */
+ static EngineID GetEngineType(VehicleID vehicle_id);
+
+ /**
+ * Get the unitnumber of a vehicle.
+ * @param vehicle_id the vehicle to get the unitnumber of.
+ * @pre IsValidVehicle(vehicle_id).
+ * @return the unitnumber the vehicle has.
+ */
+ static int32 GetUnitNumber(VehicleID vehicle_id);
+
+ /**
+ * Get the current age of a vehicle.
+ * @note age is in days.
+ * @param vehicle_id the vehicle to get the age of.
+ * @pre IsValidVehicle(vehicle_id).
+ * @return the current age the vehicle has.
+ */
+ static int32 GetAge(VehicleID vehicle_id);
+
+ /**
+ * Get the max age of a vehicle.
+ * @note age is in days.
+ * @param vehicle_id the vehicle to get the age of.
+ * @pre IsValidVehicle(vehicle_id).
+ * @return the max age the vehicle has.
+ */
+ static int32 GetMaxAge(VehicleID vehicle_id);
+
+ /**
+ * Get the age a vehicle has left (max - current).
+ * @note age is in days.
+ * @param vehicle_id the vehicle to get the age of.
+ * @pre IsValidVehicle(vehicle_id).
+ * @return the age the vehicle has left.
+ */
+ static int32 GetAgeLeft(VehicleID vehicle_id);
+
+ /**
+ * Get the current profit of a vehicle.
+ * @param vehicle_id the vehicle to get the profit of.
+ * @pre IsValidVehicle(vehicle_id).
+ * @return the current profit the vehicle has.
+ */
+ static int32 GetProfitThisYear(VehicleID vehicle_id);
+
+ /**
+ * Get the profit of last year of a vehicle.
+ * @param vehicle_id the vehicle to get the profit of.
+ * @pre IsValidVehicle(vehicle_id).
+ * @return the profit the vehicle had last year.
+ */
+ static int32 GetProfitLastYear(VehicleID vehicle_id);
};
#endif /* AI_VEHICLE_HPP */
--- a/src/ai/api/ai_vehicle.hpp.sq Fri May 04 19:55:35 2007 +0000
+++ b/src/ai/api/ai_vehicle.hpp.sq Fri May 04 21:26:42 2007 +0000
@@ -13,9 +13,17 @@
SQAIVehicle.PreRegister(engine);
SQAIVehicle.AddConstructor<void (AIVehicle::*)()>(engine, 1, "x");
- SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::GetClassName, "GetClassName", 1, "x");
- SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::IsValidEngine, "IsValidEngine", 2, "xi");
- SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::IsValidVehicle, "IsValidVehicle", 2, "xi");
+ SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::GetClassName, "GetClassName", 1, "x");
+ SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::IsValidEngine, "IsValidEngine", 2, "xi");
+ SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::IsValidVehicle, "IsValidVehicle", 2, "xi");
+ SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::GetLocation, "GetLocation", 2, "xi");
+ SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::GetEngineType, "GetEngineType", 2, "xi");
+ SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::GetUnitNumber, "GetUnitNumber", 2, "xi");
+ SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::GetAge, "GetAge", 2, "xi");
+ SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::GetMaxAge, "GetMaxAge", 2, "xi");
+ SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::GetAgeLeft, "GetAgeLeft", 2, "xi");
+ SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::GetProfitThisYear, "GetProfitThisYear", 2, "xi");
+ SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::GetProfitLastYear, "GetProfitLastYear", 2, "xi");
SQAIVehicle.DefSQMethod(engine, &AIVehicle::FindBestRoadVehicle, "FindBestRoadVehicle", 3, "xii");
SQAIVehicle.DefSQMethod(engine, &AIVehicle::BuildVehicle, "BuildVehicle", 3, "xii");
--- a/src/ai/api/ai_vehiclelist_valuator.cpp Fri May 04 19:55:35 2007 +0000
+++ b/src/ai/api/ai_vehiclelist_valuator.cpp Fri May 04 21:26:42 2007 +0000
@@ -1,50 +1,42 @@
#include "ai_vehiclelist_valuator.hpp"
-#include "../../vehicle.h"
+#include "ai_vehicle.hpp"
int32 AIVehicleListLocation::Valuate(int32 vehicle) const
{
- if (!IsValidVehicleID(vehicle)) return 0;
- return GetVehicle(vehicle)->tile;
+ return AIVehicle::GetLocation(vehicle);
}
int32 AIVehicleListEngineType::Valuate(int32 vehicle) const
{
- if (!IsValidVehicleID(vehicle)) return 0;
- return GetVehicle(vehicle)->engine_type;
+ return AIVehicle::GetEngineType(vehicle);
}
int32 AIVehicleListUnitNumber::Valuate(int32 vehicle) const
{
- if (!IsValidVehicleID(vehicle)) return 0;
- return GetVehicle(vehicle)->unitnumber;
+ return AIVehicle::GetUnitNumber(vehicle);
}
int32 AIVehicleListAge::Valuate(int32 vehicle) const
{
- if (!IsValidVehicleID(vehicle)) return 0;
- return GetVehicle(vehicle)->age;
+ return AIVehicle::GetAge(vehicle);
}
int32 AIVehicleListMaxAge::Valuate(int32 vehicle) const
{
- if (!IsValidVehicleID(vehicle)) return 0;
- return GetVehicle(vehicle)->max_age;
+ return AIVehicle::GetMaxAge(vehicle);
}
int32 AIVehicleListAgeLeft::Valuate(int32 vehicle) const
{
- if (!IsValidVehicleID(vehicle)) return 0;
- return GetVehicle(vehicle)->max_age - GetVehicle(vehicle)->age;
+ return AIVehicle::GetAgeLeft(vehicle);
}
int32 AIVehicleListProfitThisYear::Valuate(int32 vehicle) const
{
- if (!IsValidVehicleID(vehicle)) return 0;
- return GetVehicle(vehicle)->profit_this_year;
+ return AIVehicle::GetProfitThisYear(vehicle);
}
int32 AIVehicleListProfitLastYear::Valuate(int32 vehicle) const
{
- if (!IsValidVehicleID(vehicle)) return 0;
- return GetVehicle(vehicle)->profit_last_year;
+ return AIVehicle::GetProfitLastYear(vehicle);
}