diff --git a/src/script/api/script_vehicle.cpp b/src/script/api/script_vehicle.cpp index 515509a2e2..fd03d8de0b 100644 --- a/src/script/api/script_vehicle.cpp +++ b/src/script/api/script_vehicle.cpp @@ -48,7 +48,7 @@ return static_cast((int)::Vehicle::Get(vehicle_id)->owner); } -/* static */ int32 ScriptVehicle::GetNumWagons(VehicleID vehicle_id) +/* static */ SQInteger ScriptVehicle::GetNumWagons(VehicleID vehicle_id) { if (!IsValidVehicle(vehicle_id)) return -1; @@ -62,7 +62,7 @@ return num; } -/* static */ int ScriptVehicle::GetLength(VehicleID vehicle_id) +/* static */ SQInteger ScriptVehicle::GetLength(VehicleID vehicle_id) { if (!IsValidVehicle(vehicle_id)) return -1; @@ -97,7 +97,7 @@ return _BuildVehicleInternal(depot, engine_id, cargo); } -/* static */ int ScriptVehicle::GetBuildWithRefitCapacity(TileIndex depot, EngineID engine_id, CargoID cargo) +/* static */ SQInteger ScriptVehicle::GetBuildWithRefitCapacity(TileIndex depot, EngineID engine_id, CargoID cargo) { if (!ScriptEngine::IsBuildable(engine_id)) return -1; if (!ScriptCargo::IsValidCargo(cargo)) return -1; @@ -117,7 +117,7 @@ return 0; } -/* static */ bool ScriptVehicle::_MoveWagonInternal(VehicleID source_vehicle_id, int source_wagon, bool move_attached_wagons, int dest_vehicle_id, int dest_wagon) +/* static */ bool ScriptVehicle::_MoveWagonInternal(VehicleID source_vehicle_id, SQInteger source_wagon, bool move_attached_wagons, SQInteger dest_vehicle_id, SQInteger dest_wagon) { EnforcePrecondition(false, ScriptObject::GetCompany() != OWNER_DEITY); EnforcePrecondition(false, IsValidVehicle(source_vehicle_id) && source_wagon < GetNumWagons(source_vehicle_id)); @@ -136,17 +136,17 @@ return ScriptObject::Command::Do(v->index, w == nullptr ? ::INVALID_VEHICLE : w->index, move_attached_wagons); } -/* static */ bool ScriptVehicle::MoveWagon(VehicleID source_vehicle_id, int source_wagon, int dest_vehicle_id, int dest_wagon) +/* static */ bool ScriptVehicle::MoveWagon(VehicleID source_vehicle_id, SQInteger source_wagon, SQInteger dest_vehicle_id, SQInteger dest_wagon) { return _MoveWagonInternal(source_vehicle_id, source_wagon, false, dest_vehicle_id, dest_wagon); } -/* static */ bool ScriptVehicle::MoveWagonChain(VehicleID source_vehicle_id, int source_wagon, int dest_vehicle_id, int dest_wagon) +/* static */ bool ScriptVehicle::MoveWagonChain(VehicleID source_vehicle_id, SQInteger source_wagon, SQInteger dest_vehicle_id, SQInteger dest_wagon) { return _MoveWagonInternal(source_vehicle_id, source_wagon, true, dest_vehicle_id, dest_wagon); } -/* static */ int ScriptVehicle::GetRefitCapacity(VehicleID vehicle_id, CargoID cargo) +/* static */ SQInteger ScriptVehicle::GetRefitCapacity(VehicleID vehicle_id, CargoID cargo) { if (!IsValidVehicle(vehicle_id)) return -1; if (!ScriptCargo::IsValidCargo(cargo)) return -1; @@ -173,7 +173,7 @@ return ScriptObject::Command::Do(vehicle_id, v->type == VEH_TRAIN, false, INVALID_CLIENT_ID); } -/* static */ bool ScriptVehicle::_SellWagonInternal(VehicleID vehicle_id, int wagon, bool sell_attached_wagons) +/* static */ bool ScriptVehicle::_SellWagonInternal(VehicleID vehicle_id, SQInteger wagon, bool sell_attached_wagons) { EnforcePrecondition(false, ScriptObject::GetCompany() != OWNER_DEITY); EnforcePrecondition(false, IsValidVehicle(vehicle_id) && wagon < GetNumWagons(vehicle_id)); @@ -185,12 +185,12 @@ return ScriptObject::Command::Do(v->index, sell_attached_wagons, false, INVALID_CLIENT_ID); } -/* static */ bool ScriptVehicle::SellWagon(VehicleID vehicle_id, int wagon) +/* static */ bool ScriptVehicle::SellWagon(VehicleID vehicle_id, SQInteger wagon) { return _SellWagonInternal(vehicle_id, wagon, false); } -/* static */ bool ScriptVehicle::SellWagonChain(VehicleID vehicle_id, int wagon) +/* static */ bool ScriptVehicle::SellWagonChain(VehicleID vehicle_id, SQInteger wagon) { return _SellWagonInternal(vehicle_id, wagon, true); } @@ -279,7 +279,7 @@ return ::Vehicle::Get(vehicle_id)->engine_type; } -/* static */ EngineID ScriptVehicle::GetWagonEngineType(VehicleID vehicle_id, int wagon) +/* static */ EngineID ScriptVehicle::GetWagonEngineType(VehicleID vehicle_id, SQInteger wagon) { if (!IsValidVehicle(vehicle_id)) return INVALID_ENGINE; if (wagon >= GetNumWagons(vehicle_id)) return INVALID_ENGINE; @@ -291,7 +291,7 @@ return v->engine_type; } -/* static */ int32 ScriptVehicle::GetUnitNumber(VehicleID vehicle_id) +/* static */ SQInteger ScriptVehicle::GetUnitNumber(VehicleID vehicle_id) { if (!IsPrimaryVehicle(vehicle_id)) return -1; @@ -306,14 +306,14 @@ return GetString(STR_VEHICLE_NAME); } -/* static */ int32 ScriptVehicle::GetAge(VehicleID vehicle_id) +/* static */ SQInteger ScriptVehicle::GetAge(VehicleID vehicle_id) { if (!IsValidVehicle(vehicle_id)) return -1; return ::Vehicle::Get(vehicle_id)->age; } -/* static */ int32 ScriptVehicle::GetWagonAge(VehicleID vehicle_id, int wagon) +/* static */ SQInteger ScriptVehicle::GetWagonAge(VehicleID vehicle_id, SQInteger wagon) { if (!IsValidVehicle(vehicle_id)) return -1; if (wagon >= GetNumWagons(vehicle_id)) return -1; @@ -325,21 +325,21 @@ return v->age; } -/* static */ int32 ScriptVehicle::GetMaxAge(VehicleID vehicle_id) +/* static */ SQInteger ScriptVehicle::GetMaxAge(VehicleID vehicle_id) { if (!IsPrimaryVehicle(vehicle_id)) return -1; return ::Vehicle::Get(vehicle_id)->max_age; } -/* static */ int32 ScriptVehicle::GetAgeLeft(VehicleID vehicle_id) +/* static */ SQInteger ScriptVehicle::GetAgeLeft(VehicleID vehicle_id) { if (!IsPrimaryVehicle(vehicle_id)) return -1; return ::Vehicle::Get(vehicle_id)->max_age - ::Vehicle::Get(vehicle_id)->age; } -/* static */ int32 ScriptVehicle::GetCurrentSpeed(VehicleID vehicle_id) +/* static */ SQInteger ScriptVehicle::GetCurrentSpeed(VehicleID vehicle_id) { if (!IsPrimaryVehicle(vehicle_id)) return -1; @@ -411,7 +411,7 @@ return (ScriptRoad::RoadType)(int)(::RoadVehicle::Get(vehicle_id))->roadtype; } -/* static */ int32 ScriptVehicle::GetCapacity(VehicleID vehicle_id, CargoID cargo) +/* static */ SQInteger ScriptVehicle::GetCapacity(VehicleID vehicle_id, CargoID cargo) { if (!IsValidVehicle(vehicle_id)) return -1; if (!ScriptCargo::IsValidCargo(cargo)) return -1; @@ -424,7 +424,7 @@ return amount; } -/* static */ int32 ScriptVehicle::GetCargoLoad(VehicleID vehicle_id, CargoID cargo) +/* static */ SQInteger ScriptVehicle::GetCargoLoad(VehicleID vehicle_id, CargoID cargo) { if (!IsValidVehicle(vehicle_id)) return -1; if (!ScriptCargo::IsValidCargo(cargo)) return -1; @@ -465,7 +465,7 @@ return v->orders != nullptr && v->orders->GetNumVehicles() > 1; } -/* static */ int ScriptVehicle::GetReliability(VehicleID vehicle_id) +/* static */ SQInteger ScriptVehicle::GetReliability(VehicleID vehicle_id) { if (!IsPrimaryVehicle(vehicle_id)) return -1; @@ -473,16 +473,11 @@ return ::ToPercent16(v->reliability); } -/* static */ uint ScriptVehicle::GetMaximumOrderDistance(VehicleID vehicle_id) +/* static */ SQInteger ScriptVehicle::GetMaximumOrderDistance(VehicleID vehicle_id) { if (!IsPrimaryVehicle(vehicle_id)) return 0; const ::Vehicle *v = ::Vehicle::Get(vehicle_id); - switch (v->type) { - case VEH_AIRCRAFT: - return ::Aircraft::From(v)->acache.cached_max_range_sqr; - - default: - return 0; - } + if (v->type != VEH_AIRCRAFT) return 0; + return ::Aircraft::From(v)->acache.cached_max_range_sqr; } diff --git a/src/script/api/script_vehicle.hpp b/src/script/api/script_vehicle.hpp index 6041c091d7..cae8a34d8a 100644 --- a/src/script/api/script_vehicle.hpp +++ b/src/script/api/script_vehicle.hpp @@ -117,7 +117,7 @@ public: * @pre IsValidVehicle(vehicle_id). * @return The number of wagons the vehicle has. */ - static int32 GetNumWagons(VehicleID vehicle_id); + static SQInteger GetNumWagons(VehicleID vehicle_id); /** * Set the name of a vehicle. @@ -172,7 +172,7 @@ public: * @pre wagon < GetNumWagons(vehicle_id). * @return The engine type the vehicle has. */ - static EngineID GetWagonEngineType(VehicleID vehicle_id, int wagon); + static EngineID GetWagonEngineType(VehicleID vehicle_id, SQInteger wagon); /** * Get the unitnumber of a vehicle. @@ -180,7 +180,7 @@ public: * @pre IsPrimaryVehicle(vehicle_id). * @return The unitnumber the vehicle has. */ - static int32 GetUnitNumber(VehicleID vehicle_id); + static SQInteger GetUnitNumber(VehicleID vehicle_id); /** * Get the current age of a vehicle. @@ -189,7 +189,7 @@ public: * @return The current age the vehicle has. * @note The age is in days. */ - static int32 GetAge(VehicleID vehicle_id); + static SQInteger GetAge(VehicleID vehicle_id); /** * Get the current age of a second (or third, etc.) engine in a train vehicle. @@ -200,7 +200,7 @@ public: * @return The current age the vehicle has. * @note The age is in days. */ - static int32 GetWagonAge(VehicleID vehicle_id, int wagon); + static SQInteger GetWagonAge(VehicleID vehicle_id, SQInteger wagon); /** * Get the maximum age of a vehicle. @@ -209,7 +209,7 @@ public: * @return The maximum age the vehicle has. * @note The age is in days. */ - static int32 GetMaxAge(VehicleID vehicle_id); + static SQInteger GetMaxAge(VehicleID vehicle_id); /** * Get the age a vehicle has left (maximum - current). @@ -218,7 +218,7 @@ public: * @return The age the vehicle has left. * @note The age is in days. */ - static int32 GetAgeLeft(VehicleID vehicle_id); + static SQInteger GetAgeLeft(VehicleID vehicle_id); /** * Get the current speed of a vehicle. @@ -229,7 +229,7 @@ public: * This is mph / 1.6, which is roughly km/h. * To get km/h multiply this number by 1.00584. */ - static int32 GetCurrentSpeed(VehicleID vehicle_id); + static SQInteger GetCurrentSpeed(VehicleID vehicle_id); /** * Get the current state of a vehicle. @@ -366,7 +366,7 @@ public: * @pre ScriptCargo::IsValidCargo(cargo). * @return The capacity the vehicle will have when refited. */ - static int GetBuildWithRefitCapacity(TileIndex depot, EngineID engine_id, CargoID cargo); + static SQInteger GetBuildWithRefitCapacity(TileIndex depot, EngineID engine_id, CargoID cargo); /** * Clones a vehicle at the given depot, copying or cloning its orders. @@ -399,7 +399,7 @@ public: * @game @pre Valid ScriptCompanyMode active in scope. * @return Whether or not moving the wagon succeeded. */ - static bool MoveWagon(VehicleID source_vehicle_id, int source_wagon, int dest_vehicle_id, int dest_wagon); + static bool MoveWagon(VehicleID source_vehicle_id, SQInteger source_wagon, SQInteger dest_vehicle_id, SQInteger dest_wagon); /** * Move a chain of wagons after another wagon. @@ -415,7 +415,7 @@ public: * @game @pre Valid ScriptCompanyMode active in scope. * @return Whether or not moving the wagons succeeded. */ - static bool MoveWagonChain(VehicleID source_vehicle_id, int source_wagon, int dest_vehicle_id, int dest_wagon); + static bool MoveWagonChain(VehicleID source_vehicle_id, SQInteger source_wagon, SQInteger dest_vehicle_id, SQInteger dest_wagon); /** * Gets the capacity of the given vehicle when refitted to the given cargo type. @@ -427,7 +427,7 @@ public: * @pre The vehicle must be stopped in the depot. * @return The capacity the vehicle will have when refited. */ - static int GetRefitCapacity(VehicleID vehicle_id, CargoID cargo); + static SQInteger GetRefitCapacity(VehicleID vehicle_id, CargoID cargo); /** * Refits a vehicle to the given cargo type. @@ -471,7 +471,7 @@ public: * @exception ScriptVehicle::ERR_VEHICLE_NOT_IN_DEPOT * @return True if and only if the wagon has been sold. */ - static bool SellWagon(VehicleID vehicle_id, int wagon); + static bool SellWagon(VehicleID vehicle_id, SQInteger wagon); /** * Sells all wagons from the vehicle starting from a given position. @@ -486,7 +486,7 @@ public: * @exception ScriptVehicle::ERR_VEHICLE_NOT_IN_DEPOT * @return True if and only if the wagons have been sold. */ - static bool SellWagonChain(VehicleID vehicle_id, int wagon); + static bool SellWagonChain(VehicleID vehicle_id, SQInteger wagon); /** * Sends the given vehicle to a depot. If the vehicle has already been @@ -542,7 +542,7 @@ public: * @pre ScriptCargo::IsValidCargo(cargo). * @return The maximum amount of the given cargo the vehicle can transport. */ - static int32 GetCapacity(VehicleID vehicle_id, CargoID cargo); + static SQInteger GetCapacity(VehicleID vehicle_id, CargoID cargo); /** * Get the length of a the total vehicle in 1/16's of a tile. @@ -551,7 +551,7 @@ public: * @pre GetVehicleType(vehicle_id) == VT_ROAD || GetVehicleType(vehicle_id) == VT_RAIL. * @return The length of the engine. */ - static int GetLength(VehicleID vehicle_id); + static SQInteger GetLength(VehicleID vehicle_id); /** * Get the amount of a specific cargo the given vehicle is transporting. @@ -561,7 +561,7 @@ public: * @pre ScriptCargo::IsValidCargo(cargo). * @return The amount of the given cargo the vehicle is currently transporting. */ - static int32 GetCargoLoad(VehicleID vehicle_id, CargoID cargo); + static SQInteger GetCargoLoad(VehicleID vehicle_id, CargoID cargo); /** * Get the group of a given vehicle. @@ -594,7 +594,7 @@ public: * @pre IsPrimaryVehicle(vehicle_id). * @return The current reliability (0-100%). */ - static int GetReliability(VehicleID vehicle_id); + static SQInteger GetReliability(VehicleID vehicle_id); /** * Get the maximum allowed distance between two orders for a vehicle. @@ -609,7 +609,7 @@ public: * not be compared with map distances * @see ScriptOrder::GetOrderDistance */ - static uint GetMaximumOrderDistance(VehicleID vehicle_id); + static SQInteger GetMaximumOrderDistance(VehicleID vehicle_id); private: /** @@ -620,12 +620,12 @@ private: /** * Internal function used by SellWagon(Chain). */ - static bool _SellWagonInternal(VehicleID vehicle_id, int wagon, bool sell_attached_wagons); + static bool _SellWagonInternal(VehicleID vehicle_id, SQInteger wagon, bool sell_attached_wagons); /** * Internal function used by MoveWagon(Chain). */ - static bool _MoveWagonInternal(VehicleID source_vehicle_id, int source_wagon, bool move_attached_wagons, int dest_vehicle_id, int dest_wagon); + static bool _MoveWagonInternal(VehicleID source_vehicle_id, SQInteger source_wagon, bool move_attached_wagons, SQInteger dest_vehicle_id, SQInteger dest_wagon); }; #endif /* SCRIPT_VEHICLE_HPP */