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:
@@ -36,9 +36,8 @@
|
||||
(ref_type == NR_INDUSTRY && ScriptIndustry::IsValidIndustry(reference)) ||
|
||||
(ref_type == NR_TOWN && ScriptTown::IsValidTown(reference)));
|
||||
|
||||
uint8_t c = company;
|
||||
if (company == ScriptCompany::COMPANY_INVALID) c = INVALID_COMPANY;
|
||||
::CompanyID c = ScriptCompany::FromScriptCompanyID(company);
|
||||
|
||||
if (ref_type == NR_NONE) reference = 0;
|
||||
return ScriptObject::Command<CMD_CUSTOM_NEWS_ITEM>::Do((::NewsType)type, (::NewsReferenceType)ref_type, (::CompanyID)c, reference, encoded);
|
||||
return ScriptObject::Command<CMD_CUSTOM_NEWS_ITEM>::Do((::NewsType)type, (::NewsReferenceType)ref_type, c, reference, encoded);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user