Index: src/ai/api/ai_vehicle.hpp =================================================================== --- src/ai/api/ai_vehicle.hpp (revision 12187) +++ src/ai/api/ai_vehicle.hpp (working copy) @@ -52,7 +52,7 @@ * as the vehicle isn't really built yet. Build it for real first before * assigning orders. */ - VehicleID BuildVehicle(TileIndex depot, EngineID engine_id); + static VehicleID BuildVehicle(TileIndex depot, EngineID engine_id); /** * Clones a vehicle at the given depot, copying or cloning it's orders. @@ -65,7 +65,7 @@ * it failed. Check the return value using IsValidVehicle. In test-mode * 0 is returned if it was successful; any other value indicates failure. */ - VehicleID CloneVehicle(TileIndex depot, VehicleID vehicle_id, bool share_orders); + static VehicleID CloneVehicle(TileIndex depot, VehicleID vehicle_id, bool share_orders); /** * Refits a vehicle to the given cargo type @@ -77,7 +77,7 @@ * @pre the vehicle must be stopped in the depot * @return true if and only if the refit succeeded. */ - bool RefitVehicle(VehicleID vehicle_id, CargoID cargo); + static bool RefitVehicle(VehicleID vehicle_id, CargoID cargo); /** * Sells the given vehicle. @@ -87,7 +87,7 @@ * @pre the vehicle must be stopped in the depot * @return true if and only if the vehicle has been sold. */ - bool SellVehicle(VehicleID vehicle_id); + static bool SellVehicle(VehicleID vehicle_id); /** * Sends the given vehicle to a depot. @@ -95,7 +95,7 @@ * @pre IsValidVehicle(vehicle_id). * @return true if and only if the vehicle has been sent to a depot. */ - bool SendVehicleToDepot(VehicleID vehicle_id); + static bool SendVehicleToDepot(VehicleID vehicle_id); /** * Check if a vehicle is in a depot. @@ -103,7 +103,7 @@ * @pre isValidVehicle(vehicle_id). * @return true if and only if the vehicle is in a depot. */ - bool IsInDepot(VehicleID vehicle_id); + static bool IsInDepot(VehicleID vehicle_id); /** * Check if a vehicle is in a depot and stopped. @@ -111,7 +111,7 @@ * @pre isValidVehicle(vehicle_id). * @return true if and only if the vehicle is in a depot and stopped. */ - bool IsStoppedInDepot(VehicleID vehicle_id); + static bool IsStoppedInDepot(VehicleID vehicle_id); /** * Starts or stops the given vehicle depending on the current state. @@ -119,7 +119,7 @@ * @pre IsValidVehicle(vehicle_id). * @return true if and only if the vehicle has been started or stopped. */ - bool StartStopVehicle(VehicleID vehicle_id); + static bool StartStopVehicle(VehicleID vehicle_id); /** * Skips the current order of the given vehicle. @@ -128,7 +128,7 @@ * @pre IsValidVehicleOrder(vehicle_id, order_id). * @return true if and only if the order has been skipped. */ - bool SkipToVehicleOrder(VehicleID vehicle_id, uint32 order_id); + static bool SkipToVehicleOrder(VehicleID vehicle_id, uint32 order_id); /** * Set the name of a vehicle. @@ -139,7 +139,7 @@ * @pre You have to own the vehicle. * @return true if and only if the name was changed. */ - bool SetName(VehicleID vehicle_id, const char *name); + static bool SetName(VehicleID vehicle_id, const char *name); /** * Get the current location of a vehicle. @@ -223,6 +223,7 @@ * @return the vehicle type. */ static AIVehicle::VehicleType GetVehicleType(VehicleID vehicle_id); + }; #endif /* AI_VEHICLE_HPP */ Index: src/ai/api/ai_vehicle.hpp.sq =================================================================== --- src/ai/api/ai_vehicle.hpp.sq (revision 12187) +++ src/ai/api/ai_vehicle.hpp.sq (working copy) @@ -24,29 +24,28 @@ SQAIVehicle.DefSQConst(engine, AIVehicle::VEHICLE_AIR, "VEHICLE_AIR"); SQAIVehicle.DefSQConst(engine, AIVehicle::VEHICLE_INVALID, "VEHICLE_INVALID"); - SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::GetClassName, "GetClassName", 1, "x"); - 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::GetName, "GetName", 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.DefSQStaticMethod(engine, &AIVehicle::GetVehicleType, "GetVehicleType", 2, "xi"); + SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::GetClassName, "GetClassName", 1, "x"); + SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::IsValidVehicle, "IsValidVehicle", 2, "xi"); + SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::BuildVehicle, "BuildVehicle", 3, "xii"); + SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::CloneVehicle, "CloneVehicle", 4, "xiib"); + SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::RefitVehicle, "RefitVehicle", 3, "xii"); + SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::SellVehicle, "SellVehicle", 2, "xi"); + SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::SendVehicleToDepot, "SendVehicleToDepot", 2, "xi"); + SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::IsInDepot, "IsInDepot", 2, "xi"); + SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::IsStoppedInDepot, "IsStoppedInDepot", 2, "xi"); + SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::StartStopVehicle, "StartStopVehicle", 2, "xi"); + SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::SkipToVehicleOrder, "SkipToVehicleOrder", 3, "xii"); + SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::SetName, "SetName", 3, "xis"); + 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::GetName, "GetName", 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.DefSQStaticMethod(engine, &AIVehicle::GetVehicleType, "GetVehicleType", 2, "xi"); - SQAIVehicle.DefSQMethod(engine, &AIVehicle::BuildVehicle, "BuildVehicle", 3, "xii"); - SQAIVehicle.DefSQMethod(engine, &AIVehicle::CloneVehicle, "CloneVehicle", 4, "xiib"); - SQAIVehicle.DefSQMethod(engine, &AIVehicle::RefitVehicle, "RefitVehicle", 3, "xii"); - SQAIVehicle.DefSQMethod(engine, &AIVehicle::SellVehicle, "SellVehicle", 2, "xi"); - SQAIVehicle.DefSQMethod(engine, &AIVehicle::SendVehicleToDepot, "SendVehicleToDepot", 2, "xi"); - SQAIVehicle.DefSQMethod(engine, &AIVehicle::IsInDepot, "IsInDepot", 2, "xi"); - SQAIVehicle.DefSQMethod(engine, &AIVehicle::IsStoppedInDepot, "IsStoppedInDepot", 2, "xi"); - SQAIVehicle.DefSQMethod(engine, &AIVehicle::StartStopVehicle, "StartStopVehicle", 2, "xi"); - SQAIVehicle.DefSQMethod(engine, &AIVehicle::SkipToVehicleOrder, "SkipToVehicleOrder", 3, "xii"); - SQAIVehicle.DefSQMethod(engine, &AIVehicle::SetName, "SetName", 3, "xis"); - SQAIVehicle.PostRegister(engine); } Index: src/ai/api/ai_vehicle.cpp =================================================================== --- src/ai/api/ai_vehicle.cpp (revision 12187) +++ src/ai/api/ai_vehicle.cpp (working copy) @@ -13,6 +13,8 @@ #include "../../aircraft.h" #include "../../strings_func.h" #include "../../core/alloc_func.hpp" +#include "../../command_type.h" +#include "../../command_func.h" #include "table/strings.h" /* static */ bool AIVehicle::IsValidVehicle(VehicleID vehicle_id) @@ -20,7 +22,7 @@ return ::IsValidVehicleID(vehicle_id) && ::GetVehicle(vehicle_id)->owner == _current_player && GetVehicle(vehicle_id)->IsPrimaryVehicle(); } -VehicleID AIVehicle::BuildVehicle(TileIndex depot, EngineID engine_id) +/* static */ VehicleID AIVehicle::BuildVehicle(TileIndex depot, EngineID engine_id) { if (!AIEngine::IsValidEngine(engine_id)) return false; @@ -29,106 +31,106 @@ bool ret; switch (::GetEngine(engine_id)->type) { - case VEH_ROAD: ret = this->DoCommand(depot, engine_id, 0, CMD_BUILD_ROAD_VEH); break; - case VEH_TRAIN: ret = this->DoCommand(depot, engine_id, 0, CMD_BUILD_RAIL_VEHICLE); break; - case VEH_SHIP: ret = this->DoCommand(depot, engine_id, 0, CMD_BUILD_SHIP); break; - case VEH_AIRCRAFT: ret = this->DoCommand(depot, engine_id, 0, CMD_BUILD_AIRCRAFT); break; + case VEH_ROAD: ret = DoCommand(depot, engine_id, 0, CMD_BUILD_ROAD_VEH); break; + case VEH_TRAIN: ret = DoCommand(depot, engine_id, 0, CMD_BUILD_RAIL_VEHICLE); break; + case VEH_SHIP: ret = DoCommand(depot, engine_id, 0, CMD_BUILD_SHIP); break; + case VEH_AIRCRAFT: ret = DoCommand(depot, engine_id, 0, CMD_BUILD_AIRCRAFT); break; default: NOT_REACHED(); return INVALID_VEHICLE; } return ret ? AIObject::GetNewVehicleID() : INVALID_VEHICLE; } -VehicleID AIVehicle::CloneVehicle(TileIndex depot, VehicleID vehicle_id, bool share_orders) +/* static */ VehicleID AIVehicle::CloneVehicle(TileIndex depot, VehicleID vehicle_id, bool share_orders) { - if (!this->IsValidVehicle(vehicle_id)) return false; + if (!IsValidVehicle(vehicle_id)) return false; /* Reset the internal NewVehicleID in case we are in TestMode */ AIObject::SetNewVehicleID(0); - bool ret = this->DoCommand(depot, vehicle_id, share_orders, CMD_CLONE_VEHICLE); + bool ret = DoCommand(depot, vehicle_id, share_orders, CMD_CLONE_VEHICLE); return ret ? AIObject::GetNewVehicleID() : INVALID_VEHICLE; } -bool AIVehicle::RefitVehicle(VehicleID vehicle_id, CargoID cargo) +/* static */ bool AIVehicle::RefitVehicle(VehicleID vehicle_id, CargoID cargo) { - if (!this->IsValidVehicle(vehicle_id) || !AICargo::IsValidCargo(cargo)) return false; + if (!IsValidVehicle(vehicle_id) || !AICargo::IsValidCargo(cargo)) return false; switch (::GetVehicle(vehicle_id)->type) { - case VEH_ROAD: return this->DoCommand(0, vehicle_id, cargo, CMD_REFIT_ROAD_VEH); - case VEH_TRAIN: return this->DoCommand(0, vehicle_id, cargo, CMD_REFIT_RAIL_VEHICLE); - case VEH_SHIP: return this->DoCommand(0, vehicle_id, cargo, CMD_REFIT_SHIP); - case VEH_AIRCRAFT: return this->DoCommand(0, vehicle_id, cargo, CMD_REFIT_AIRCRAFT); + case VEH_ROAD: return DoCommand(0, vehicle_id, cargo, CMD_REFIT_ROAD_VEH); + case VEH_TRAIN: return DoCommand(0, vehicle_id, cargo, CMD_REFIT_RAIL_VEHICLE); + case VEH_SHIP: return DoCommand(0, vehicle_id, cargo, CMD_REFIT_SHIP); + case VEH_AIRCRAFT: return DoCommand(0, vehicle_id, cargo, CMD_REFIT_AIRCRAFT); default: return false; } } -bool AIVehicle::SellVehicle(VehicleID vehicle_id) +/* static */ bool AIVehicle::SellVehicle(VehicleID vehicle_id) { - if (!this->IsValidVehicle(vehicle_id)) return false; + if (!IsValidVehicle(vehicle_id)) return false; switch (::GetVehicle(vehicle_id)->type) { - case VEH_ROAD: return this->DoCommand(0, vehicle_id, 0, CMD_SELL_ROAD_VEH); - case VEH_TRAIN: return this->DoCommand(0, vehicle_id, 0, CMD_SELL_RAIL_WAGON); - case VEH_SHIP: return this->DoCommand(0, vehicle_id, 0, CMD_SELL_SHIP); - case VEH_AIRCRAFT: return this->DoCommand(0, vehicle_id, 0, CMD_SELL_AIRCRAFT); + case VEH_ROAD: return DoCommand(0, vehicle_id, 0, CMD_SELL_ROAD_VEH); + case VEH_TRAIN: return DoCommand(0, vehicle_id, 0, CMD_SELL_RAIL_WAGON); + case VEH_SHIP: return DoCommand(0, vehicle_id, 0, CMD_SELL_SHIP); + case VEH_AIRCRAFT: return DoCommand(0, vehicle_id, 0, CMD_SELL_AIRCRAFT); default: return false; } } -bool AIVehicle::SendVehicleToDepot(VehicleID vehicle_id) +/* static */ bool AIVehicle::SendVehicleToDepot(VehicleID vehicle_id) { - if (!this->IsValidVehicle(vehicle_id)) return false; + if (!IsValidVehicle(vehicle_id)) return false; switch (::GetVehicle(vehicle_id)->type) { - case VEH_ROAD: return this->DoCommand(0, vehicle_id, 0, CMD_SEND_ROADVEH_TO_DEPOT); - case VEH_TRAIN: return this->DoCommand(0, vehicle_id, 0, CMD_SEND_TRAIN_TO_DEPOT); - case VEH_SHIP: return this->DoCommand(0, vehicle_id, 0, CMD_SEND_SHIP_TO_DEPOT); - case VEH_AIRCRAFT: return this->DoCommand(0, vehicle_id, 0, CMD_SEND_AIRCRAFT_TO_HANGAR); + case VEH_ROAD: return DoCommand(0, vehicle_id, 0, CMD_SEND_ROADVEH_TO_DEPOT); + case VEH_TRAIN: return DoCommand(0, vehicle_id, 0, CMD_SEND_TRAIN_TO_DEPOT); + case VEH_SHIP: return DoCommand(0, vehicle_id, 0, CMD_SEND_SHIP_TO_DEPOT); + case VEH_AIRCRAFT: return DoCommand(0, vehicle_id, 0, CMD_SEND_AIRCRAFT_TO_HANGAR); default: return false; } } -bool AIVehicle::IsInDepot(VehicleID vehicle_id) +/* static */ bool AIVehicle::IsInDepot(VehicleID vehicle_id) { - if (!this->IsValidVehicle(vehicle_id)) return false; + if (!IsValidVehicle(vehicle_id)) return false; return ::GetVehicle(vehicle_id)->IsInDepot(); } -bool AIVehicle::IsStoppedInDepot(VehicleID vehicle_id) +/* static */ bool AIVehicle::IsStoppedInDepot(VehicleID vehicle_id) { - if (!this->IsValidVehicle(vehicle_id)) return false; + if (!IsValidVehicle(vehicle_id)) return false; return ::GetVehicle(vehicle_id)->IsStoppedInDepot(); } -bool AIVehicle::StartStopVehicle(VehicleID vehicle_id) +/* static */ bool AIVehicle::StartStopVehicle(VehicleID vehicle_id) { - if (!this->IsValidVehicle(vehicle_id)) return false; + if (!IsValidVehicle(vehicle_id)) return false; switch (::GetVehicle(vehicle_id)->type) { - case VEH_ROAD: return this->DoCommand(0, vehicle_id, 0, CMD_START_STOP_ROADVEH); - case VEH_TRAIN: return this->DoCommand(0, vehicle_id, 0, CMD_START_STOP_TRAIN); - case VEH_SHIP: return this->DoCommand(0, vehicle_id, 0, CMD_START_STOP_SHIP); - case VEH_AIRCRAFT: return this->DoCommand(0, vehicle_id, 0, CMD_START_STOP_AIRCRAFT); + case VEH_ROAD: return DoCommand(0, vehicle_id, 0, CMD_START_STOP_ROADVEH); + case VEH_TRAIN: return DoCommand(0, vehicle_id, 0, CMD_START_STOP_TRAIN); + case VEH_SHIP: return DoCommand(0, vehicle_id, 0, CMD_START_STOP_SHIP); + case VEH_AIRCRAFT: return DoCommand(0, vehicle_id, 0, CMD_START_STOP_AIRCRAFT); default: return false; } } -bool AIVehicle::SkipToVehicleOrder(VehicleID vehicle_id, uint32 order_id) +/* static */ bool AIVehicle::SkipToVehicleOrder(VehicleID vehicle_id, uint32 order_id) { if (!AIOrder::IsValidVehicleOrder(vehicle_id, order_id)) return false; - return this->DoCommand(0, vehicle_id, order_id, CMD_SKIP_TO_ORDER); + return DoCommand(0, vehicle_id, order_id, CMD_SKIP_TO_ORDER); } -bool AIVehicle::SetName(VehicleID vehicle_id, const char *name) +/* static */ bool AIVehicle::SetName(VehicleID vehicle_id, const char *name) { - if (!this->IsValidVehicle(vehicle_id)) return false; + if (!IsValidVehicle(vehicle_id)) return false; if (name == NULL) return false; _cmd_text = name; - return this->DoCommand(0, vehicle_id, 0, CMD_NAME_VEHICLE); + return DoCommand(0, vehicle_id, 0, CMD_NAME_VEHICLE); } /* static */ TileIndex AIVehicle::GetLocation(VehicleID vehicle_id) @@ -211,3 +213,4 @@ default: return VEHICLE_INVALID; } } +