mirror of
https://github.com/OpenTTD/OpenTTD
synced 2025-12-10 06:52:05 +01:00
Fix 313c6c45aa: [Script] Return rail types as list instead of bitmask. (#14617)
This is more idiomatic for scripts, and avoids exposing internal representation.
This commit is contained in:
@@ -487,6 +487,13 @@ function Regression::Engine()
|
||||
print(" GetRailType(): " + AIEngine.GetRailType(i));
|
||||
print(" GetRoadType(): " + AIEngine.GetRoadType(i));
|
||||
print(" GetPlaneType(): " + AIEngine.GetPlaneType(i));
|
||||
local railtypes = AIEngine.GetAllRailTypes(i);
|
||||
print(" GetAllRailTypes(): " + (railtypes == null ? "null" : "instance"));
|
||||
if (railtypes != null) {
|
||||
foreach(t in railtypes) {
|
||||
print(" " + t);
|
||||
}
|
||||
}
|
||||
}
|
||||
print(" Valid Engines: " + j);
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -245,12 +245,17 @@
|
||||
return static_cast<ScriptRail::RailType>(::RailVehInfo(engine_id)->railtypes.GetNthSetBit(0).value_or(::RailType::INVALID_RAILTYPE));
|
||||
}
|
||||
|
||||
/* static */ ScriptRail::RailTypes ScriptEngine::GetAllRailTypes(EngineID engine_id)
|
||||
/* static */ ScriptList *ScriptEngine::GetAllRailTypes(EngineID engine_id)
|
||||
{
|
||||
if (!IsValidEngine(engine_id)) return ScriptRail::INVALID_RAILTYPES;
|
||||
if (GetVehicleType(engine_id) != ScriptVehicle::VT_RAIL) return ScriptRail::INVALID_RAILTYPES;
|
||||
if (!IsValidEngine(engine_id)) return nullptr;
|
||||
if (GetVehicleType(engine_id) != ScriptVehicle::VT_RAIL) return nullptr;
|
||||
|
||||
return static_cast<ScriptRail::RailTypes>(::RailVehInfo(engine_id)->railtypes.base());
|
||||
ScriptList *list = new ScriptList();
|
||||
for (::RailType railtype : ::RailVehInfo(engine_id)->railtypes) {
|
||||
list->AddItem(railtype);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
/* static */ bool ScriptEngine::IsArticulated(EngineID engine_id)
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#ifndef SCRIPT_ENGINE_HPP
|
||||
#define SCRIPT_ENGINE_HPP
|
||||
|
||||
#include "script_list.hpp"
|
||||
#include "script_vehicle.hpp"
|
||||
#include "script_rail.hpp"
|
||||
#include "script_airport.hpp"
|
||||
@@ -258,13 +259,13 @@ public:
|
||||
static ScriptRail::RailType GetRailType(EngineID engine_id);
|
||||
|
||||
/**
|
||||
* Get all RailType's of the engine.
|
||||
* Get a list of all RailTypes 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);
|
||||
static ScriptList *GetAllRailTypes(EngineID engine_id);
|
||||
|
||||
/**
|
||||
* Check if the engine is articulated.
|
||||
|
||||
@@ -49,14 +49,6 @@ 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.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user