--- a/bin/ai/regression/regression.nut Mon Apr 07 12:43:46 2008 +0000
+++ b/bin/ai/regression/regression.nut Mon Apr 07 14:00:52 2008 +0000
@@ -1054,6 +1054,14 @@
print(" IsInDepot(15): " + AIVehicle.IsInDepot(15));
print(" IsStoppedInDepot(15): " + AIVehicle.IsStoppedInDepot(15));
+ print(" --Errors--");
+ print(" RefitVehicle(): " + AIVehicle.RefitVehicle(11, 0));
+ print(" GetLastErrorString(): " + AIError.GetLastErrorString());
+ print(" SellVehicle(): " + AIVehicle.SellVehicle(11));
+ print(" GetLastErrorString(): " + AIError.GetLastErrorString());
+ print(" SendVehicleToDepot(): " + AIVehicle.SendVehicleToDepot(12));
+ print(" GetLastErrorString(): " + AIError.GetLastErrorString());
+
local list = AIVehicleList();
print("");
--- a/bin/ai/regression/regression.txt Mon Apr 07 12:43:46 2008 +0000
+++ b/bin/ai/regression/regression.txt Mon Apr 07 14:00:52 2008 +0000
@@ -6208,6 +6208,13 @@
IsValidVehicle(15): true
IsInDepot(15): true
IsStoppedInDepot(15): true
+ --Errors--
+ RefitVehicle(): false
+ GetLastErrorString(): ERR_VEHICLE_NOT_IN_DEPOT
+ SellVehicle(): false
+ GetLastErrorString(): ERR_VEHICLE_NOT_IN_DEPOT
+ SendVehicleToDepot(): false
+ GetLastErrorString(): ERR_UNKNOWN
--VehicleList--
Count(): 4
--- a/src/ai/api/ai_vehicle.hpp Mon Apr 07 12:43:46 2008 +0000
+++ b/src/ai/api/ai_vehicle.hpp Mon Apr 07 14:00:52 2008 +0000
@@ -6,6 +6,7 @@
#define AI_VEHICLE_HPP
#include "ai_object.hpp"
+#include "ai_error.hpp"
#include "../../engine_type.h"
/**
@@ -15,6 +16,47 @@
public:
static const char *GetClassName() { return "AIVehicle"; }
+ enum ErrorMessages {
+ /** Base for vehicle related errors */
+ ERR_VEHICLE_BASE = AIError::ERR_CAT_VEHICLE << AIError::ERR_CAT_BIT_SIZE,
+
+ /** Too many vehicles in the game, can't build any more. */
+ ERR_VEHICLE_TOO_MANY, // [STR_00E1_TOO_MANY_VEHICLES_IN_GAME]
+
+ /** Vehicle is not available */
+ ERR_VEHICLE_NOT_AVAILABLE, // [STR_AIRCRAFT_NOT_AVAILABLE, STR_ROAD_VEHICLE_NOT_AVAILABLE, STR_SHIP_NOT_AVAILABLE, STR_RAIL_VEHICLE_NOT_AVAILABLE]
+
+ /** Vehicle can't be build due to game settigns */
+ ERR_VEHICLE_BUILD_DISABLED, // [STR_A008_CAN_T_BUILD_AIRCRAFT, STR_980D_CAN_T_BUILD_SHIP, STR_9009_CAN_T_BUILD_ROAD_VEHICLE, STR_882B_CAN_T_BUILD_RAILROAD_VEHICLE]
+
+ /** Vehicle can't be build in the selected depot */
+ ERR_VEHICLE_WRONG_DEPOT, // [STR_DEPOT_WRONG_DEPOT_TYPE]
+
+ /** Vehicle can't return to the depot */
+ ERR_VEHICLE_CANNOT_SEND_TO_DEPOT, // [STR_8830_CAN_T_SEND_TRAIN_TO_DEPOT, STR_9018_CAN_T_SEND_VEHICLE_TO_DEPOT, STR_9819_CAN_T_SEND_SHIP_TO_DEPOT, STR_A012_CAN_T_SEND_AIRCRAFT_TO]
+
+ /** Vehicle can't start / stop */
+ ERR_VEHICLE_CANNOT_START_STOP, // [STR_883B_CAN_T_STOP_START_TRAIN, STR_9015_CAN_T_STOP_START_ROAD_VEHICLE, STR_9818_CAN_T_STOP_START_SHIP, STR_A016_CAN_T_STOP_START_AIRCRAFT]
+
+ /** Vehicle can't turn */
+ ERR_VEHICLE_CANNOT_TURN, // [STR_8869_CAN_T_REVERSE_DIRECTION, STR_9033_CAN_T_MAKE_VEHICLE_TURN]
+
+ /** Vehicle can't be refit */
+ ERR_VEHICLE_CANNOT_REFIT, // [STR_RAIL_CAN_T_REFIT_VEHICLE, STR_REFIT_ROAD_VEHICLE_CAN_T, STR_9841_CAN_T_REFIT_SHIP, STR_A042_CAN_T_REFIT_AIRCRAFT]
+
+ /** Vehicle is destroyed */
+ ERR_VEHICLE_IS_DESTROYED, // [STR_CAN_T_REFIT_DESTROYED_VEHICLE, STR_CAN_T_SELL_DESTROYED_VEHICLE]
+
+ /** Vehicle is not in a depot */
+ ERR_VEHICLE_NOT_IN_DEPOT, // [STR_A01B_AIRCRAFT_MUST_BE_STOPPED, STR_9013_MUST_BE_STOPPED_INSIDE, STR_TRAIN_MUST_BE_STOPPED, STR_980B_SHIP_MUST_BE_STOPPED_IN]
+
+ /** Vehicle is flying */
+ ERR_VEHICLE_IN_FLIGHT, // [STR_A017_AIRCRAFT_IS_IN_FLIGHT]
+
+ /** Vehicle is without power */
+ ERR_VEHCILE_NO_POWER, // [STR_TRAIN_START_NO_CATENARY]
+
+ };
/**
* The type of a vehicle available in the game. Trams for example are
* road vehicles, as maglev is a rail vehicle.
@@ -163,6 +205,9 @@
* @pre The tile at depot has a depot that can build the engine and
* is owned by you.
* @pre IsValidEngine(engine_id).
+ * @exception AIVehicle::ERR_VEHICLE_TOO_MANY
+ * @exception AIVehicle::ERR_VEHICLE_BUILD_DISABLED
+ * @exception AIVehicle::ERR_VEHICLE_WRONG_DEPOT
* @return The VehicleID of the new vehicle, or an invalid VehicleID when
* it failed. Check the return value using IsValidVehicle. In test-mode
* 0 is returned if it was successful; any other value indicates failure.
@@ -179,6 +224,9 @@
* @param share_orders Should the orders be copied or shared?
* @pre The tile 'depot' has a depot on it, allowing 'vehicle_id'-type vehicles.
* @pre IsValidVehicle(vehicle_id).
+ * @exception AIVehicle::ERR_VEHICLE_TOO_MANY
+ * @exception AIVehicle::ERR_VEHICLE_BUILD_DISABLED
+ * @exception AIVehicle::ERR_VEHICLE_WRONG_DEPOT
* @return The VehicleID of the new vehicle, or an invalid VehicleID when
* it failed. Check the return value using IsValidVehicle. In test-mode
* 0 is returned if it was successful; any other value indicates failure.
@@ -193,6 +241,9 @@
* @pre AICargo::IsValidCargo(cargo).
* @pre You must own the vehicle.
* @pre The vehicle must be stopped in the depot.
+ * @exception AIVehicle::ERR_VEHICLE_CANNOT_REFIT
+ * @exception AIVehicle::ERR_VEHICLE_IS_DESTROYED
+ * @exception AIVehicle::ERR_VEHICLE_NOT_IN_DEPOT
* @return True if and only if the refit succeeded.
*/
static bool RefitVehicle(VehicleID vehicle_id, CargoID cargo);
@@ -203,6 +254,8 @@
* @pre IsValidVehicle(vehicle_id).
* @pre You must own the vehicle.
* @pre The vehicle must be stopped in the depot.
+ * @exception AIVehicle::ERR_VEHICLE_IS_DESTROYED
+ * @exception AIVehicle::ERR_VEHICLE_NOT_IN_DEPOT
* @return True if and only if the vehicle has been sold.
*/
static bool SellVehicle(VehicleID vehicle_id);
@@ -211,6 +264,7 @@
* Sends the given vehicle to a depot.
* @param vehicle_id The vehicle to send to a depot.
* @pre IsValidVehicle(vehicle_id).
+ * @exception AIVehicle::ERR_VEHICLE_CANNOT_SEND_TO_DEPOT
* @return True if and only if the vehicle has been sent to a depot.
*/
static bool SendVehicleToDepot(VehicleID vehicle_id);
@@ -219,6 +273,9 @@
* Starts or stops the given vehicle depending on the current state.
* @param vehicle_id The vehicle to start/stop.
* @pre IsValidVehicle(vehicle_id).
+ * @exception AIVehicle::ERR_VEHICLE_CANNOT_START_STOP
+ * @exception (For aircraft only): AIVehicle::ERR_VEHICLE_IN_FLIGHT
+ * @exception (For trains only): AIVehicle::ERR_VEHICLE_NO_POWER
* @return True if and only if the vehicle has been started or stopped.
*/
static bool StartStopVehicle(VehicleID vehicle_id);
--- a/src/ai/api/ai_vehicle.hpp.sq Mon Apr 07 12:43:46 2008 +0000
+++ b/src/ai/api/ai_vehicle.hpp.sq Mon Apr 07 14:00:52 2008 +0000
@@ -2,6 +2,8 @@
namespace SQConvert {
/* Allow enums to be used as Squirrel parameters */
+ template <> AIVehicle::ErrorMessages GetParam(ForceType<AIVehicle::ErrorMessages>, HSQUIRRELVM vm, int index) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return (AIVehicle::ErrorMessages)tmp; }
+ template <> int Return<AIVehicle::ErrorMessages>(HSQUIRRELVM vm, AIVehicle::ErrorMessages res) { sq_pushinteger(vm, (int32)res); return 1; }
template <> AIVehicle::VehicleType GetParam(ForceType<AIVehicle::VehicleType>, HSQUIRRELVM vm, int index) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return (AIVehicle::VehicleType)tmp; }
template <> int Return<AIVehicle::VehicleType>(HSQUIRRELVM vm, AIVehicle::VehicleType res) { sq_pushinteger(vm, (int32)res); return 1; }
@@ -18,11 +20,70 @@
SQAIVehicle.PreRegister(engine);
SQAIVehicle.AddConstructor<void (AIVehicle::*)(), 1>(engine, "x");
- SQAIVehicle.DefSQConst(engine, AIVehicle::VEHICLE_RAIL, "VEHICLE_RAIL");
- SQAIVehicle.DefSQConst(engine, AIVehicle::VEHICLE_ROAD, "VEHICLE_ROAD");
- SQAIVehicle.DefSQConst(engine, AIVehicle::VEHICLE_WATER, "VEHICLE_WATER");
- SQAIVehicle.DefSQConst(engine, AIVehicle::VEHICLE_AIR, "VEHICLE_AIR");
- SQAIVehicle.DefSQConst(engine, AIVehicle::VEHICLE_INVALID, "VEHICLE_INVALID");
+ SQAIVehicle.DefSQConst(engine, AIVehicle::ERR_VEHICLE_BASE, "ERR_VEHICLE_BASE");
+ SQAIVehicle.DefSQConst(engine, AIVehicle::ERR_VEHICLE_TOO_MANY, "ERR_VEHICLE_TOO_MANY");
+ SQAIVehicle.DefSQConst(engine, AIVehicle::ERR_VEHICLE_NOT_AVAILABLE, "ERR_VEHICLE_NOT_AVAILABLE");
+ SQAIVehicle.DefSQConst(engine, AIVehicle::ERR_VEHICLE_BUILD_DISABLED, "ERR_VEHICLE_BUILD_DISABLED");
+ SQAIVehicle.DefSQConst(engine, AIVehicle::ERR_VEHICLE_WRONG_DEPOT, "ERR_VEHICLE_WRONG_DEPOT");
+ SQAIVehicle.DefSQConst(engine, AIVehicle::ERR_VEHICLE_CANNOT_SEND_TO_DEPOT, "ERR_VEHICLE_CANNOT_SEND_TO_DEPOT");
+ SQAIVehicle.DefSQConst(engine, AIVehicle::ERR_VEHICLE_CANNOT_START_STOP, "ERR_VEHICLE_CANNOT_START_STOP");
+ SQAIVehicle.DefSQConst(engine, AIVehicle::ERR_VEHICLE_CANNOT_TURN, "ERR_VEHICLE_CANNOT_TURN");
+ SQAIVehicle.DefSQConst(engine, AIVehicle::ERR_VEHICLE_CANNOT_REFIT, "ERR_VEHICLE_CANNOT_REFIT");
+ SQAIVehicle.DefSQConst(engine, AIVehicle::ERR_VEHICLE_IS_DESTROYED, "ERR_VEHICLE_IS_DESTROYED");
+ SQAIVehicle.DefSQConst(engine, AIVehicle::ERR_VEHICLE_NOT_IN_DEPOT, "ERR_VEHICLE_NOT_IN_DEPOT");
+ SQAIVehicle.DefSQConst(engine, AIVehicle::ERR_VEHICLE_IN_FLIGHT, "ERR_VEHICLE_IN_FLIGHT");
+ SQAIVehicle.DefSQConst(engine, AIVehicle::ERR_VEHCILE_NO_POWER, "ERR_VEHCILE_NO_POWER");
+ SQAIVehicle.DefSQConst(engine, AIVehicle::VEHICLE_RAIL, "VEHICLE_RAIL");
+ SQAIVehicle.DefSQConst(engine, AIVehicle::VEHICLE_ROAD, "VEHICLE_ROAD");
+ SQAIVehicle.DefSQConst(engine, AIVehicle::VEHICLE_WATER, "VEHICLE_WATER");
+ SQAIVehicle.DefSQConst(engine, AIVehicle::VEHICLE_AIR, "VEHICLE_AIR");
+ SQAIVehicle.DefSQConst(engine, AIVehicle::VEHICLE_INVALID, "VEHICLE_INVALID");
+
+ AIError::RegisterErrorMap(STR_00E1_TOO_MANY_VEHICLES_IN_GAME, AIVehicle::ERR_VEHICLE_TOO_MANY);
+ AIError::RegisterErrorMap(STR_AIRCRAFT_NOT_AVAILABLE, AIVehicle::ERR_VEHICLE_NOT_AVAILABLE);
+ AIError::RegisterErrorMap(STR_ROAD_VEHICLE_NOT_AVAILABLE, AIVehicle::ERR_VEHICLE_NOT_AVAILABLE);
+ AIError::RegisterErrorMap(STR_SHIP_NOT_AVAILABLE, AIVehicle::ERR_VEHICLE_NOT_AVAILABLE);
+ AIError::RegisterErrorMap(STR_RAIL_VEHICLE_NOT_AVAILABLE, AIVehicle::ERR_VEHICLE_NOT_AVAILABLE);
+ AIError::RegisterErrorMap(STR_A008_CAN_T_BUILD_AIRCRAFT, AIVehicle::ERR_VEHICLE_BUILD_DISABLED);
+ AIError::RegisterErrorMap(STR_980D_CAN_T_BUILD_SHIP, AIVehicle::ERR_VEHICLE_BUILD_DISABLED);
+ AIError::RegisterErrorMap(STR_9009_CAN_T_BUILD_ROAD_VEHICLE, AIVehicle::ERR_VEHICLE_BUILD_DISABLED);
+ AIError::RegisterErrorMap(STR_882B_CAN_T_BUILD_RAILROAD_VEHICLE, AIVehicle::ERR_VEHICLE_BUILD_DISABLED);
+ AIError::RegisterErrorMap(STR_DEPOT_WRONG_DEPOT_TYPE, AIVehicle::ERR_VEHICLE_WRONG_DEPOT);
+ AIError::RegisterErrorMap(STR_8830_CAN_T_SEND_TRAIN_TO_DEPOT, AIVehicle::ERR_VEHICLE_CANNOT_SEND_TO_DEPOT);
+ AIError::RegisterErrorMap(STR_9018_CAN_T_SEND_VEHICLE_TO_DEPOT, AIVehicle::ERR_VEHICLE_CANNOT_SEND_TO_DEPOT);
+ AIError::RegisterErrorMap(STR_9819_CAN_T_SEND_SHIP_TO_DEPOT, AIVehicle::ERR_VEHICLE_CANNOT_SEND_TO_DEPOT);
+ AIError::RegisterErrorMap(STR_A012_CAN_T_SEND_AIRCRAFT_TO, AIVehicle::ERR_VEHICLE_CANNOT_SEND_TO_DEPOT);
+ AIError::RegisterErrorMap(STR_883B_CAN_T_STOP_START_TRAIN, AIVehicle::ERR_VEHICLE_CANNOT_START_STOP);
+ AIError::RegisterErrorMap(STR_9015_CAN_T_STOP_START_ROAD_VEHICLE, AIVehicle::ERR_VEHICLE_CANNOT_START_STOP);
+ AIError::RegisterErrorMap(STR_9818_CAN_T_STOP_START_SHIP, AIVehicle::ERR_VEHICLE_CANNOT_START_STOP);
+ AIError::RegisterErrorMap(STR_A016_CAN_T_STOP_START_AIRCRAFT, AIVehicle::ERR_VEHICLE_CANNOT_START_STOP);
+ AIError::RegisterErrorMap(STR_8869_CAN_T_REVERSE_DIRECTION, AIVehicle::ERR_VEHICLE_CANNOT_TURN);
+ AIError::RegisterErrorMap(STR_9033_CAN_T_MAKE_VEHICLE_TURN, AIVehicle::ERR_VEHICLE_CANNOT_TURN);
+ AIError::RegisterErrorMap(STR_RAIL_CAN_T_REFIT_VEHICLE, AIVehicle::ERR_VEHICLE_CANNOT_REFIT);
+ AIError::RegisterErrorMap(STR_REFIT_ROAD_VEHICLE_CAN_T, AIVehicle::ERR_VEHICLE_CANNOT_REFIT);
+ AIError::RegisterErrorMap(STR_9841_CAN_T_REFIT_SHIP, AIVehicle::ERR_VEHICLE_CANNOT_REFIT);
+ AIError::RegisterErrorMap(STR_A042_CAN_T_REFIT_AIRCRAFT, AIVehicle::ERR_VEHICLE_CANNOT_REFIT);
+ AIError::RegisterErrorMap(STR_CAN_T_REFIT_DESTROYED_VEHICLE, AIVehicle::ERR_VEHICLE_IS_DESTROYED);
+ AIError::RegisterErrorMap(STR_CAN_T_SELL_DESTROYED_VEHICLE, AIVehicle::ERR_VEHICLE_IS_DESTROYED);
+ AIError::RegisterErrorMap(STR_A01B_AIRCRAFT_MUST_BE_STOPPED, AIVehicle::ERR_VEHICLE_NOT_IN_DEPOT);
+ AIError::RegisterErrorMap(STR_9013_MUST_BE_STOPPED_INSIDE, AIVehicle::ERR_VEHICLE_NOT_IN_DEPOT);
+ AIError::RegisterErrorMap(STR_TRAIN_MUST_BE_STOPPED, AIVehicle::ERR_VEHICLE_NOT_IN_DEPOT);
+ AIError::RegisterErrorMap(STR_980B_SHIP_MUST_BE_STOPPED_IN, AIVehicle::ERR_VEHICLE_NOT_IN_DEPOT);
+ AIError::RegisterErrorMap(STR_A017_AIRCRAFT_IS_IN_FLIGHT, AIVehicle::ERR_VEHICLE_IN_FLIGHT);
+ AIError::RegisterErrorMap(STR_TRAIN_START_NO_CATENARY, AIVehicle::ERR_VEHCILE_NO_POWER);
+
+ AIError::RegisterErrorMapString(AIVehicle::ERR_VEHICLE_TOO_MANY, "ERR_VEHICLE_TOO_MANY");
+ AIError::RegisterErrorMapString(AIVehicle::ERR_VEHICLE_NOT_AVAILABLE, "ERR_VEHICLE_NOT_AVAILABLE");
+ AIError::RegisterErrorMapString(AIVehicle::ERR_VEHICLE_BUILD_DISABLED, "ERR_VEHICLE_BUILD_DISABLED");
+ AIError::RegisterErrorMapString(AIVehicle::ERR_VEHICLE_WRONG_DEPOT, "ERR_VEHICLE_WRONG_DEPOT");
+ AIError::RegisterErrorMapString(AIVehicle::ERR_VEHICLE_CANNOT_SEND_TO_DEPOT, "ERR_VEHICLE_CANNOT_SEND_TO_DEPOT");
+ AIError::RegisterErrorMapString(AIVehicle::ERR_VEHICLE_CANNOT_START_STOP, "ERR_VEHICLE_CANNOT_START_STOP");
+ AIError::RegisterErrorMapString(AIVehicle::ERR_VEHICLE_CANNOT_TURN, "ERR_VEHICLE_CANNOT_TURN");
+ AIError::RegisterErrorMapString(AIVehicle::ERR_VEHICLE_CANNOT_REFIT, "ERR_VEHICLE_CANNOT_REFIT");
+ AIError::RegisterErrorMapString(AIVehicle::ERR_VEHICLE_IS_DESTROYED, "ERR_VEHICLE_IS_DESTROYED");
+ AIError::RegisterErrorMapString(AIVehicle::ERR_VEHICLE_NOT_IN_DEPOT, "ERR_VEHICLE_NOT_IN_DEPOT");
+ AIError::RegisterErrorMapString(AIVehicle::ERR_VEHICLE_IN_FLIGHT, "ERR_VEHICLE_IN_FLIGHT");
+ AIError::RegisterErrorMapString(AIVehicle::ERR_VEHCILE_NO_POWER, "ERR_VEHCILE_NO_POWER");
SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::GetClassName, "GetClassName", 1, "x");
SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::IsValidVehicle, "IsValidVehicle", 2, "xi");