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:
@@ -17,7 +17,7 @@
|
||||
|
||||
/* static */ SQInteger ScriptCargoMonitor::GetTownDeliveryAmount(ScriptCompany::CompanyID company, CargoType cargo, TownID town_id, bool keep_monitoring)
|
||||
{
|
||||
CompanyID cid = static_cast<CompanyID>(company);
|
||||
::CompanyID cid = ScriptCompany::FromScriptCompanyID(ScriptCompany::ResolveCompanyID((company)));
|
||||
if (cid >= MAX_COMPANIES) return -1;
|
||||
if (!ScriptCargo::IsValidCargo(cargo)) return -1;
|
||||
if (!::Town::IsValidID(town_id)) return -1;
|
||||
@@ -28,7 +28,7 @@
|
||||
|
||||
/* static */ SQInteger ScriptCargoMonitor::GetIndustryDeliveryAmount(ScriptCompany::CompanyID company, CargoType cargo, IndustryID industry_id, bool keep_monitoring)
|
||||
{
|
||||
CompanyID cid = static_cast<CompanyID>(company);
|
||||
::CompanyID cid = ScriptCompany::FromScriptCompanyID(ScriptCompany::ResolveCompanyID((company)));
|
||||
if (cid >= MAX_COMPANIES) return -1;
|
||||
if (!ScriptCargo::IsValidCargo(cargo)) return -1;
|
||||
if (!::Industry::IsValidID(industry_id)) return -1;
|
||||
@@ -39,7 +39,7 @@
|
||||
|
||||
/* static */ SQInteger ScriptCargoMonitor::GetTownPickupAmount(ScriptCompany::CompanyID company, CargoType cargo, TownID town_id, bool keep_monitoring)
|
||||
{
|
||||
CompanyID cid = static_cast<CompanyID>(company);
|
||||
::CompanyID cid = ScriptCompany::FromScriptCompanyID(ScriptCompany::ResolveCompanyID((company)));
|
||||
if (cid >= MAX_COMPANIES) return -1;
|
||||
if (!ScriptCargo::IsValidCargo(cargo)) return -1;
|
||||
if (!::Town::IsValidID(town_id)) return -1;
|
||||
@@ -50,7 +50,7 @@
|
||||
|
||||
/* static */ SQInteger ScriptCargoMonitor::GetIndustryPickupAmount(ScriptCompany::CompanyID company, CargoType cargo, IndustryID industry_id, bool keep_monitoring)
|
||||
{
|
||||
CompanyID cid = static_cast<CompanyID>(company);
|
||||
::CompanyID cid = ScriptCompany::FromScriptCompanyID(ScriptCompany::ResolveCompanyID((company)));
|
||||
if (cid >= MAX_COMPANIES) return -1;
|
||||
if (!ScriptCargo::IsValidCargo(cargo)) return -1;
|
||||
if (!::Industry::IsValidID(industry_id)) return -1;
|
||||
|
||||
Reference in New Issue
Block a user