diff --git a/src/script/api/ai_changelog.hpp b/src/script/api/ai_changelog.hpp index f76a586f07..6ac3bac4bb 100644 --- a/src/script/api/ai_changelog.hpp +++ b/src/script/api/ai_changelog.hpp @@ -28,6 +28,7 @@ * \li AICargo::CC_POTABLE * \li AICargo::CC_NON_POTABLE * \li AIVehicleList_Waypoint + * \li AIRail::GetAllRailTypes * * Other changes: * \li AIBridge::GetBridgeID renamed to AIBridge::GetBridgeType @@ -35,6 +36,7 @@ * \li AIList instances can now be saved * \li AIVehicleList_Station accepts an optional AIVehicle::VehicleType parameter * \li AIList instances can now be cloned + * \li AIRail::GetRailType will only return the first RailType of an engine, use AIRail::GetAllRailTypes instead * * \b 14.0 * diff --git a/src/script/api/game_changelog.hpp b/src/script/api/game_changelog.hpp index 7bb7203d20..00beafe55f 100644 --- a/src/script/api/game_changelog.hpp +++ b/src/script/api/game_changelog.hpp @@ -29,6 +29,7 @@ * \li GSCargo::CC_NON_POTABLE * \li GSVehicleList_Waypoint * \li GSBaseStation::GetOwner + * \li GSRail::GetAllRailTypes * * Other changes: * \li GSBridge::GetBridgeID renamed to GSBridge::GetBridgeType @@ -36,6 +37,7 @@ * \li GSList instances can now be saved * \li GSVehicleList_Station accepts an optional GSVehicle::VehicleType parameter * \li GSList instances can now be cloned + * \li GSRail::GetRailType will only return the first RailType of an engine, use GSRail::GetAllRailTypes instead * * \b 14.0 * diff --git a/src/script/api/script_engine.cpp b/src/script/api/script_engine.cpp index 92e72522ed..5b6ced3e13 100644 --- a/src/script/api/script_engine.cpp +++ b/src/script/api/script_engine.cpp @@ -245,6 +245,14 @@ return static_cast(::RailVehInfo(engine_id)->railtypes.GetNthSetBit(0).value_or(::RailType::INVALID_RAILTYPE)); } +/* static */ ScriptRail::RailTypes ScriptEngine::GetAllRailTypes(EngineID engine_id) +{ + if (!IsValidEngine(engine_id)) return ScriptRail::INVALID_RAILTYPES; + if (GetVehicleType(engine_id) != ScriptVehicle::VT_RAIL) return ScriptRail::INVALID_RAILTYPES; + + return static_cast(::RailVehInfo(engine_id)->railtypes.base()); +} + /* static */ bool ScriptEngine::IsArticulated(EngineID engine_id) { if (!IsValidEngine(engine_id)) return false; diff --git a/src/script/api/script_engine.hpp b/src/script/api/script_engine.hpp index 84bf229efa..01eaa03509 100644 --- a/src/script/api/script_engine.hpp +++ b/src/script/api/script_engine.hpp @@ -249,6 +249,7 @@ public: /** * Get the first RailType of the engine. + * @note This will only return the first RailType of a multi-system engine. Use GetAllRailTypes to get all rail types of the engine. * @param engine_id The engine to get the RailType of. * @pre IsValidEngine(engine_id). * @pre GetVehicleType(engine_id) == ScriptVehicle::VT_RAIL. @@ -256,6 +257,15 @@ public: */ static ScriptRail::RailType GetRailType(EngineID engine_id); + /** + * Get all RailType's of the engine. + * @param engine_id The engine to get all RailTypes of. + * @pre IsValidEngine(engine_id). + * @pre GetVehicleType(engine_id) == ScriptVehicle::VT_RAIL. + * @return All rail types of the engine. + */ + static ScriptRail::RailTypes GetAllRailTypes(EngineID engine_id); + /** * Check if the engine is articulated. * @param engine_id The engine to check. diff --git a/src/script/api/script_rail.hpp b/src/script/api/script_rail.hpp index 5ef7e70e49..dbc5942c2a 100644 --- a/src/script/api/script_rail.hpp +++ b/src/script/api/script_rail.hpp @@ -49,6 +49,14 @@ public: RAILTYPE_INVALID = ::INVALID_RAILTYPE, ///< Invalid RailType. }; + /** + * A bitmap with all possible rail types. + */ + enum RailTypes : int64_t { + /* Note: these values represent part of the in-game RailTypes enum */ + INVALID_RAILTYPES = INT64_MAX, ///< Invalid RailTypes. + }; + /** * A bitmap with all possible rail tracks on a tile. */ diff --git a/src/script/squirrel.cpp b/src/script/squirrel.cpp index 2086e74f75..36e699220e 100644 --- a/src/script/squirrel.cpp +++ b/src/script/squirrel.cpp @@ -270,7 +270,7 @@ void Squirrel::AddMethod(std::string_view method_name, SQFUNCTION proc, std::str sq_newslot(this->vm, -3, SQFalse); } -void Squirrel::AddConst(std::string_view var_name, int value) +void Squirrel::AddConst(std::string_view var_name, SQInteger value) { ScriptAllocatorScope alloc_scope(this); diff --git a/src/script/squirrel.hpp b/src/script/squirrel.hpp index 415f75ca10..847c8f38ba 100644 --- a/src/script/squirrel.hpp +++ b/src/script/squirrel.hpp @@ -104,15 +104,21 @@ public: * Adds a const to the stack. Depending on the current state this means * either a const to a class or to the global space. */ - void AddConst(std::string_view var_name, int value); + void AddConst(std::string_view var_name, SQInteger value); /** * Adds a const to the stack. Depending on the current state this means * either a const to a class or to the global space. */ - void AddConst(std::string_view var_name, uint value) { this->AddConst(var_name, (int)value); } + void AddConst(std::string_view var_name, uint value) { this->AddConst(var_name, (SQInteger)value); } - void AddConst(std::string_view var_name, const ConvertibleThroughBase auto &value) { this->AddConst(var_name, static_cast(value.base())); } + /** + * Adds a const to the stack. Depending on the current state this means + * either a const to a class or to the global space. + */ + void AddConst(std::string_view var_name, int value) { this->AddConst(var_name, (SQInteger)value); } + + void AddConst(std::string_view var_name, const ConvertibleThroughBase auto &value) { this->AddConst(var_name, static_cast(value.base())); } /** * Adds a const to the stack. Depending on the current state this means