(svn r12720) [NoAI] -Add: functions to get the capacity/current load of a vehicle given a cargo type.
--- a/src/ai/api/ai_vehicle.cpp Tue Apr 15 15:05:30 2008 +0000
+++ b/src/ai/api/ai_vehicle.cpp Tue Apr 15 15:32:47 2008 +0000
@@ -227,3 +227,28 @@
}
}
+/* static */ int32 AIVehicle::GetCapacity(VehicleID vehicle_id, CargoID cargo)
+{
+ if (!IsValidVehicle(vehicle_id)) return -1;
+ if (!AICargo::IsValidCargo(cargo)) return -1;
+
+ uint32 amount = 0;
+ for (const Vehicle *v = ::GetVehicle(vehicle_id); v != NULL; v = v->Next()) {
+ if (v->cargo_type == cargo) amount += v->cargo_cap;
+ }
+
+ return amount;
+}
+
+/* static */ int32 AIVehicle::GetCargoLoad(VehicleID vehicle_id, CargoID cargo)
+{
+ if (!IsValidVehicle(vehicle_id)) return -1;
+ if (!AICargo::IsValidCargo(cargo)) return -1;
+
+ uint32 amount = 0;
+ for (const Vehicle *v = ::GetVehicle(vehicle_id); v != NULL; v = v->Next()) {
+ if (v->cargo_type == cargo) amount += v->cargo.Count();
+ }
+
+ return amount;
+}
--- a/src/ai/api/ai_vehicle.hpp Tue Apr 15 15:05:30 2008 +0000
+++ b/src/ai/api/ai_vehicle.hpp Tue Apr 15 15:32:47 2008 +0000
@@ -300,6 +300,26 @@
* @return True if and only if the order has been skipped.
*/
static bool SkipToVehicleOrder(VehicleID vehicle_id, uint32 order_id);
+
+ /**
+ * Get the maximum amount of a specific cargo the given vehicle can transport.
+ * @param vehicle_id The vehicle to get the capacity of.
+ * @param cargo The cargo to get the capacity for.
+ * @pre IsValidVehicle(vehicle_id).
+ * @pre AICargo::IsValidCargo(cargo).
+ * @return The maximum amount of the given cargo the vehicle can transport.
+ */
+ static int32 GetCapacity(VehicleID vehicle_id, CargoID cargo);
+
+ /**
+ * Get the amount of a specific cargo the given vehicle transports.
+ * @param vehicle_id The vehicle to get the load amount of.
+ * @param cargo The cargo to get the load amount for.
+ * @pre IsValidVehicle(vehicle_id).
+ * @pre AICargo::IsValidCargo(cargo).
+ * @return The amount of the given cargo the vehicle currently transports.
+ */
+ static int32 GetCargoLoad(VehicleID vehicle_id, CargoID cargo);
};
#endif /* AI_VEHICLE_HPP */
--- a/src/ai/api/ai_vehicle.hpp.sq Tue Apr 15 15:05:30 2008 +0000
+++ b/src/ai/api/ai_vehicle.hpp.sq Tue Apr 15 15:32:47 2008 +0000
@@ -109,6 +109,8 @@
SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::SendVehicleToDepot, "SendVehicleToDepot", 2, "xi");
SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::StartStopVehicle, "StartStopVehicle", 2, "xi");
SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::SkipToVehicleOrder, "SkipToVehicleOrder", 3, "xii");
+ SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::GetCapacity, "GetCapacity", 3, "xii");
+ SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::GetCargoLoad, "GetCargoLoad", 3, "xii");
SQAIVehicle.PostRegister(engine);
}