1
0
Fork 0

Change: [Script] Move GSStation::GetOwner to GSBaseStation::GetOwner (#13406)

* Add: [Script] GSBaseStation::GetOwner

Added method for Game Scripts to retrieve the owner of a basestation.

* Cleanup: [Script] Remove ScriptStation::GetOwner

Due to class inheritance, GSStation::GetOwner and GSWaypoint::GetOwner can both reach GetOwner defined at GSBaseStation.
pull/14267/head
SamuXarick 2025-05-22 12:47:04 +01:00 committed by GitHub
parent 467f832c2f
commit 5fef32bde7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 17 additions and 16 deletions

View File

@ -28,6 +28,7 @@
* \li GSCargo::CC_POTABLE
* \li GSCargo::CC_NON_POTABLE
* \li GSVehicleList_Waypoint
* \li GSBaseStation::GetOwner
*
* Other changes:
* \li GSBridge::GetBridgeID renamed to GSBridge::GetBridgeType

View File

@ -28,6 +28,12 @@
return st != nullptr && (st->owner == ScriptObject::GetCompany() || ScriptCompanyMode::IsDeity() || st->owner == OWNER_NONE);
}
/* static */ ScriptCompany::CompanyID ScriptBaseStation::GetOwner(StationID station_id)
{
if (!IsValidBaseStation(station_id)) return ScriptCompany::COMPANY_INVALID;
return ScriptCompany::ToScriptCompanyID(::BaseStation::Get(station_id)->owner);
}
/* static */ std::optional<std::string> ScriptBaseStation::GetName(StationID station_id)
{
if (!IsValidBaseStation(station_id)) return std::nullopt;

View File

@ -11,6 +11,7 @@
#define SCRIPT_BASESTATION_HPP
#include "script_text.hpp"
#include "script_company.hpp"
#include "script_date.hpp"
#include "../../station_type.h"
@ -32,6 +33,15 @@ public:
*/
static bool IsValidBaseStation(StationID station_id);
/**
* Get the owner of a basestation.
* @param station_id The basestation to get the owner of.
* @pre IsValidBaseStation(station_id).
* @return The owner the basestation has.
* @api -ai
*/
static ScriptCompany::CompanyID GetOwner(StationID station_id);
/**
* Get the name of a basestation.
* @param station_id The basestation to get the name of.

View File

@ -26,13 +26,6 @@
return st != nullptr && (st->owner == ScriptObject::GetCompany() || ScriptCompanyMode::IsDeity() || st->owner == OWNER_NONE);
}
/* static */ ScriptCompany::CompanyID ScriptStation::GetOwner(StationID station_id)
{
if (!IsValidStation(station_id)) return ScriptCompany::COMPANY_INVALID;
return ScriptCompany::ToScriptCompanyID(::Station::Get(station_id)->owner);
}
/* static */ StationID ScriptStation::GetStationID(TileIndex tile)
{
if (!::IsValidTile(tile) || !::IsTileType(tile, MP_STATION)) return StationID::Invalid();

View File

@ -59,15 +59,6 @@ public:
*/
static bool IsValidStation(StationID station_id);
/**
* Get the owner of a station.
* @param station_id The station to get the owner of.
* @pre IsValidStation(station_id).
* @return The owner the station has.
* @api -ai
*/
static ScriptCompany::CompanyID GetOwner(StationID station_id);
/**
* Get the StationID of a tile, if there is a station.
* @param tile The tile to find the stationID of