Codechange: [Script] Use helper function over direct casting CompanyID
In the script's API `COMPANY_INVALID` has a value of -1, whereas the internal game's `INVALID_COMPANY` has a value of 255. Since the script's API also has a `COMPANY_SPECTATOR` with a value of 255, these enumerations cannot be easily reconciled by casting. As such, replace all casts in the script API with either ScriptCompany::FromScriptCompanyID or ScriptCompany::ToScriptCompanyID. Also make clear whether CompanyID is ::CompanyID or ScriptCompany::CompanyID by using either one of those over CompanyID in the script's API.
This commit is contained in:
@@ -24,7 +24,7 @@ ScriptVehicleList::ScriptVehicleList(HSQUIRRELVM vm)
|
||||
EnforceDeityOrCompanyModeValid_Void();
|
||||
|
||||
bool is_deity = ScriptCompanyMode::IsDeity();
|
||||
CompanyID owner = ScriptObject::GetCompany();
|
||||
::CompanyID owner = ScriptObject::GetCompany();
|
||||
|
||||
ScriptList::FillList<Vehicle>(vm, this,
|
||||
[is_deity, owner](const Vehicle *v) {
|
||||
@@ -39,7 +39,7 @@ ScriptVehicleList_Station::ScriptVehicleList_Station(StationID station_id)
|
||||
if (!ScriptBaseStation::IsValidBaseStation(station_id)) return;
|
||||
|
||||
bool is_deity = ScriptCompanyMode::IsDeity();
|
||||
CompanyID owner = ScriptObject::GetCompany();
|
||||
::CompanyID owner = ScriptObject::GetCompany();
|
||||
|
||||
FindVehiclesWithOrder(
|
||||
[is_deity, owner](const Vehicle *v) { return is_deity || v->owner == owner; },
|
||||
@@ -86,7 +86,7 @@ ScriptVehicleList_Depot::ScriptVehicleList_Depot(TileIndex tile)
|
||||
}
|
||||
|
||||
bool is_deity = ScriptCompanyMode::IsDeity();
|
||||
CompanyID owner = ScriptObject::GetCompany();
|
||||
::CompanyID owner = ScriptObject::GetCompany();
|
||||
|
||||
FindVehiclesWithOrder(
|
||||
[is_deity, owner, type](const Vehicle *v) { return (is_deity || v->owner == owner) && v->type == type; },
|
||||
@@ -109,7 +109,7 @@ ScriptVehicleList_Group::ScriptVehicleList_Group(GroupID group_id)
|
||||
EnforceCompanyModeValid_Void();
|
||||
if (!ScriptGroup::IsValidGroup(group_id)) return;
|
||||
|
||||
CompanyID owner = ScriptObject::GetCompany();
|
||||
::CompanyID owner = ScriptObject::GetCompany();
|
||||
|
||||
ScriptList::FillList<Vehicle>(this,
|
||||
[owner](const Vehicle *v) { return v->owner == owner && v->IsPrimaryVehicle(); },
|
||||
@@ -122,7 +122,7 @@ ScriptVehicleList_DefaultGroup::ScriptVehicleList_DefaultGroup(ScriptVehicle::Ve
|
||||
EnforceCompanyModeValid_Void();
|
||||
if (vehicle_type < ScriptVehicle::VT_RAIL || vehicle_type > ScriptVehicle::VT_AIR) return;
|
||||
|
||||
CompanyID owner = ScriptObject::GetCompany();
|
||||
::CompanyID owner = ScriptObject::GetCompany();
|
||||
|
||||
ScriptList::FillList<Vehicle>(this,
|
||||
[owner](const Vehicle *v) { return v->owner == owner && v->IsPrimaryVehicle(); },
|
||||
|
||||
Reference in New Issue
Block a user