1
0
Fork 0

Add: company mode enforcement checks to functions with command or company access

Command functions are those that call ScriptObject::Command, and functions
with company access are any that call ScriptObject::GetCompany. This is a bit
over-protective, but having the check everywhere makes it easier to validate
that no check is missing automatically instead of by review.
pull/10559/head
Rubidium 2023-03-02 21:22:37 +01:00 committed by rubidium42
parent 534f2419ad
commit 8d443d1379
10 changed files with 87 additions and 0 deletions

View File

@ -47,6 +47,7 @@
{ {
CCountedPtr<Text> counter(name); CCountedPtr<Text> counter(name);
EnforceCompanyModeValid(false);
EnforcePrecondition(false, name != nullptr); EnforcePrecondition(false, name != nullptr);
const std::string &text = name->GetDecodedText(); const std::string &text = name->GetDecodedText();
EnforcePreconditionEncodedText(false, text); EnforcePreconditionEncodedText(false, text);
@ -68,6 +69,7 @@
{ {
CCountedPtr<Text> counter(name); CCountedPtr<Text> counter(name);
EnforceCompanyModeValid(false);
EnforcePrecondition(false, name != nullptr); EnforcePrecondition(false, name != nullptr);
const std::string &text = name->GetDecodedText(); const std::string &text = name->GetDecodedText();
EnforcePreconditionEncodedText(false, text); EnforcePreconditionEncodedText(false, text);
@ -94,6 +96,7 @@
/* static */ bool ScriptCompany::SetPresidentGender(Gender gender) /* static */ bool ScriptCompany::SetPresidentGender(Gender gender)
{ {
EnforceCompanyModeValid(false);
EnforcePrecondition(false, gender == GENDER_MALE || gender == GENDER_FEMALE); EnforcePrecondition(false, gender == GENDER_MALE || gender == GENDER_FEMALE);
EnforcePrecondition(false, GetPresidentGender(ScriptCompany::COMPANY_SELF) != gender); EnforcePrecondition(false, GetPresidentGender(ScriptCompany::COMPANY_SELF) != gender);
@ -269,6 +272,7 @@
/* static */ bool ScriptCompany::SetAutoRenewStatus(bool autorenew) /* static */ bool ScriptCompany::SetAutoRenewStatus(bool autorenew)
{ {
EnforceCompanyModeValid(false);
return ScriptObject::Command<CMD_CHANGE_COMPANY_SETTING>::Do("company.engine_renew", autorenew ? 1 : 0); return ScriptObject::Command<CMD_CHANGE_COMPANY_SETTING>::Do("company.engine_renew", autorenew ? 1 : 0);
} }
@ -282,7 +286,9 @@
/* static */ bool ScriptCompany::SetAutoRenewMonths(SQInteger months) /* static */ bool ScriptCompany::SetAutoRenewMonths(SQInteger months)
{ {
EnforceCompanyModeValid(false);
months = Clamp<SQInteger>(months, INT16_MIN, INT16_MAX); months = Clamp<SQInteger>(months, INT16_MIN, INT16_MAX);
return ScriptObject::Command<CMD_CHANGE_COMPANY_SETTING>::Do("company.engine_renew_months", months); return ScriptObject::Command<CMD_CHANGE_COMPANY_SETTING>::Do("company.engine_renew_months", months);
} }
@ -296,6 +302,7 @@
/* static */ bool ScriptCompany::SetAutoRenewMoney(Money money) /* static */ bool ScriptCompany::SetAutoRenewMoney(Money money)
{ {
EnforceCompanyModeValid(false);
EnforcePrecondition(false, money >= 0); EnforcePrecondition(false, money >= 0);
EnforcePrecondition(false, (int64)money <= UINT32_MAX); EnforcePrecondition(false, (int64)money <= UINT32_MAX);
return ScriptObject::Command<CMD_CHANGE_COMPANY_SETTING>::Do("company.engine_renew_money", money); return ScriptObject::Command<CMD_CHANGE_COMPANY_SETTING>::Do("company.engine_renew_money", money);
@ -311,11 +318,13 @@
/* static */ bool ScriptCompany::SetPrimaryLiveryColour(LiveryScheme scheme, Colours colour) /* static */ bool ScriptCompany::SetPrimaryLiveryColour(LiveryScheme scheme, Colours colour)
{ {
EnforceCompanyModeValid(false);
return ScriptObject::Command<CMD_SET_COMPANY_COLOUR>::Do((::LiveryScheme)scheme, true, (::Colours)colour); return ScriptObject::Command<CMD_SET_COMPANY_COLOUR>::Do((::LiveryScheme)scheme, true, (::Colours)colour);
} }
/* static */ bool ScriptCompany::SetSecondaryLiveryColour(LiveryScheme scheme, Colours colour) /* static */ bool ScriptCompany::SetSecondaryLiveryColour(LiveryScheme scheme, Colours colour)
{ {
EnforceCompanyModeValid(false);
return ScriptObject::Command<CMD_SET_COMPANY_COLOUR>::Do((::LiveryScheme)scheme, false, (::Colours)colour); return ScriptObject::Command<CMD_SET_COMPANY_COLOUR>::Do((::LiveryScheme)scheme, false, (::Colours)colour);
} }

View File

@ -138,6 +138,7 @@ public:
* Set the name of your company. * Set the name of your company.
* @param name The new name of the company (can be either a raw string, or a ScriptText object). * @param name The new name of the company (can be either a raw string, or a ScriptText object).
* @pre name != null && len(name) != 0. * @pre name != null && len(name) != 0.
* @game @pre ScriptCompanyMode::IsValid().
* @exception ScriptError::ERR_NAME_IS_NOT_UNIQUE * @exception ScriptError::ERR_NAME_IS_NOT_UNIQUE
* @return True if the name was changed. * @return True if the name was changed.
*/ */
@ -155,6 +156,7 @@ public:
* Set the name of your president. * Set the name of your president.
* @param name The new name of the president (can be either a raw string, or a ScriptText object). * @param name The new name of the president (can be either a raw string, or a ScriptText object).
* @pre name != null && len(name) != 0. * @pre name != null && len(name) != 0.
* @game @pre ScriptCompanyMode::IsValid().
* @exception ScriptError::ERR_NAME_IS_NOT_UNIQUE * @exception ScriptError::ERR_NAME_IS_NOT_UNIQUE
* @return True if the name was changed. * @return True if the name was changed.
*/ */
@ -172,6 +174,7 @@ public:
* Set the gender of the president of your company. * Set the gender of the president of your company.
* @param gender The new gender for your president. * @param gender The new gender for your president.
* @pre GetPresidentGender(ScriptCompany.COMPANY_SELF) != gender. * @pre GetPresidentGender(ScriptCompany.COMPANY_SELF) != gender.
* @game @pre ScriptCompanyMode::IsValid().
* @return True if the gender was changed. * @return True if the gender was changed.
* @note When successful a random face will be created. * @note When successful a random face will be created.
* @api -game * @api -game
@ -333,6 +336,7 @@ public:
/** /**
* Set whether autorenew is enabled for your company. * Set whether autorenew is enabled for your company.
* @param autorenew The new autorenew status. * @param autorenew The new autorenew status.
* @game @pre ScriptCompanyMode::IsValid().
* @return True if autorenew status has been modified. * @return True if autorenew status has been modified.
* @api -game * @api -game
*/ */
@ -350,6 +354,7 @@ public:
* Set the number of months before/after max age to autorenew an engine for your company. * Set the number of months before/after max age to autorenew an engine for your company.
* @param months The new months between autorenew. * @param months The new months between autorenew.
* The value will be clamped to MIN(int16) .. MAX(int16). * The value will be clamped to MIN(int16) .. MAX(int16).
* @game @pre ScriptCompanyMode::IsValid().
* @return True if autorenew months has been modified. * @return True if autorenew months has been modified.
* @api -game * @api -game
*/ */
@ -366,6 +371,7 @@ public:
/** /**
* Set the minimum money needed to autorenew an engine for your company. * Set the minimum money needed to autorenew an engine for your company.
* @param money The new minimum required money for autorenew to work. * @param money The new minimum required money for autorenew to work.
* @game @pre ScriptCompanyMode::IsValid().
* @return True if autorenew money has been modified. * @return True if autorenew money has been modified.
* @pre money >= 0 * @pre money >= 0
* @pre money < 2**32 * @pre money < 2**32
@ -385,6 +391,7 @@ public:
* Set primary colour for your company. * Set primary colour for your company.
* @param scheme Livery scheme to set. * @param scheme Livery scheme to set.
* @param colour Colour to set. * @param colour Colour to set.
* @game @pre ScriptCompanyMode::IsValid().
* @return False if unable to set primary colour of the livery scheme (e.g. colour in use). * @return False if unable to set primary colour of the livery scheme (e.g. colour in use).
*/ */
static bool SetPrimaryLiveryColour(LiveryScheme scheme, Colours colour); static bool SetPrimaryLiveryColour(LiveryScheme scheme, Colours colour);
@ -393,6 +400,7 @@ public:
* Set secondary colour for your company. * Set secondary colour for your company.
* @param scheme Livery scheme to set. * @param scheme Livery scheme to set.
* @param colour Colour to set. * @param colour Colour to set.
* @game @pre ScriptCompanyMode::IsValid().
* @return False if unable to set secondary colour of the livery scheme. * @return False if unable to set secondary colour of the livery scheme.
*/ */
static bool SetSecondaryLiveryColour(LiveryScheme scheme, Colours colour); static bool SetSecondaryLiveryColour(LiveryScheme scheme, Colours colour);

View File

@ -111,12 +111,14 @@ int32 ScriptEventEnginePreview::GetVehicleType()
bool ScriptEventEnginePreview::AcceptPreview() bool ScriptEventEnginePreview::AcceptPreview()
{ {
EnforceCompanyModeValid(false);
if (!this->IsEngineValid()) return false; if (!this->IsEngineValid()) return false;
return ScriptObject::Command<CMD_WANT_ENGINE_PREVIEW>::Do(this->engine); return ScriptObject::Command<CMD_WANT_ENGINE_PREVIEW>::Do(this->engine);
} }
bool ScriptEventCompanyAskMerger::AcceptMerger() bool ScriptEventCompanyAskMerger::AcceptMerger()
{ {
EnforceCompanyModeValid(false);
return ScriptObject::Command<CMD_BUY_COMPANY>::Do((::CompanyID)this->owner); return ScriptObject::Command<CMD_BUY_COMPANY>::Do((::CompanyID)this->owner);
} }

View File

@ -289,6 +289,7 @@ public:
/** /**
* Accept the engine preview. * Accept the engine preview.
* @game @pre ScriptCompanyMode::IsValid().
* @return True when the accepting succeeded. * @return True when the accepting succeeded.
*/ */
bool AcceptPreview(); bool AcceptPreview();
@ -410,6 +411,7 @@ public:
/** /**
* Take over the company for this merger. * Take over the company for this merger.
* @game @pre ScriptCompanyMode::IsValid().
* @return true if the merger was a success. * @return true if the merger was a success.
*/ */
bool AcceptMerger(); bool AcceptMerger();

View File

@ -32,6 +32,7 @@
/* static */ ScriptGroup::GroupID ScriptGroup::CreateGroup(ScriptVehicle::VehicleType vehicle_type, GroupID parent_group_id) /* static */ ScriptGroup::GroupID ScriptGroup::CreateGroup(ScriptVehicle::VehicleType vehicle_type, GroupID parent_group_id)
{ {
EnforceCompanyModeValid(GROUP_INVALID);
if (!ScriptObject::Command<CMD_CREATE_GROUP>::Do(&ScriptInstance::DoCommandReturnGroupID, (::VehicleType)vehicle_type, parent_group_id)) return GROUP_INVALID; if (!ScriptObject::Command<CMD_CREATE_GROUP>::Do(&ScriptInstance::DoCommandReturnGroupID, (::VehicleType)vehicle_type, parent_group_id)) return GROUP_INVALID;
/* In case of test-mode, we return GroupID 0 */ /* In case of test-mode, we return GroupID 0 */
@ -40,6 +41,7 @@
/* static */ bool ScriptGroup::DeleteGroup(GroupID group_id) /* static */ bool ScriptGroup::DeleteGroup(GroupID group_id)
{ {
EnforceCompanyModeValid(false);
EnforcePrecondition(false, IsValidGroup(group_id)); EnforcePrecondition(false, IsValidGroup(group_id));
return ScriptObject::Command<CMD_DELETE_GROUP>::Do(group_id); return ScriptObject::Command<CMD_DELETE_GROUP>::Do(group_id);
@ -56,6 +58,7 @@
{ {
CCountedPtr<Text> counter(name); CCountedPtr<Text> counter(name);
EnforceCompanyModeValid(false);
EnforcePrecondition(false, IsValidGroup(group_id)); EnforcePrecondition(false, IsValidGroup(group_id));
EnforcePrecondition(false, name != nullptr); EnforcePrecondition(false, name != nullptr);
const std::string &text = name->GetDecodedText(); const std::string &text = name->GetDecodedText();
@ -75,6 +78,7 @@
/* static */ bool ScriptGroup::SetParent(GroupID group_id, GroupID parent_group_id) /* static */ bool ScriptGroup::SetParent(GroupID group_id, GroupID parent_group_id)
{ {
EnforceCompanyModeValid(false);
EnforcePrecondition(false, IsValidGroup(group_id)); EnforcePrecondition(false, IsValidGroup(group_id));
EnforcePrecondition(false, IsValidGroup(parent_group_id)); EnforcePrecondition(false, IsValidGroup(parent_group_id));
@ -91,6 +95,7 @@
/* static */ bool ScriptGroup::EnableAutoReplaceProtection(GroupID group_id, bool enable) /* static */ bool ScriptGroup::EnableAutoReplaceProtection(GroupID group_id, bool enable)
{ {
EnforceCompanyModeValid(false);
EnforcePrecondition(false, IsValidGroup(group_id)); EnforcePrecondition(false, IsValidGroup(group_id));
return ScriptObject::Command<CMD_SET_GROUP_FLAG>::Do(group_id, GroupFlags::GF_REPLACE_PROTECTION, enable, false); return ScriptObject::Command<CMD_SET_GROUP_FLAG>::Do(group_id, GroupFlags::GF_REPLACE_PROTECTION, enable, false);
@ -105,6 +110,7 @@
/* static */ SQInteger ScriptGroup::GetNumEngines(GroupID group_id, EngineID engine_id) /* static */ SQInteger ScriptGroup::GetNumEngines(GroupID group_id, EngineID engine_id)
{ {
EnforceCompanyModeValid(-1);
if (!IsValidGroup(group_id) && group_id != GROUP_DEFAULT && group_id != GROUP_ALL) return -1; if (!IsValidGroup(group_id) && group_id != GROUP_DEFAULT && group_id != GROUP_ALL) return -1;
return GetGroupNumEngines(ScriptObject::GetCompany(), group_id, engine_id); return GetGroupNumEngines(ScriptObject::GetCompany(), group_id, engine_id);
@ -112,6 +118,7 @@
/* static */ SQInteger ScriptGroup::GetNumVehicles(GroupID group_id, ScriptVehicle::VehicleType vehicle_type) /* static */ SQInteger ScriptGroup::GetNumVehicles(GroupID group_id, ScriptVehicle::VehicleType vehicle_type)
{ {
EnforceCompanyModeValid(-1);
bool valid_group = IsValidGroup(group_id); bool valid_group = IsValidGroup(group_id);
if (!valid_group && group_id != GROUP_DEFAULT && group_id != GROUP_ALL) return -1; if (!valid_group && group_id != GROUP_DEFAULT && group_id != GROUP_ALL) return -1;
if (!valid_group && (vehicle_type < ScriptVehicle::VT_RAIL || vehicle_type > ScriptVehicle::VT_AIR)) return -1; if (!valid_group && (vehicle_type < ScriptVehicle::VT_RAIL || vehicle_type > ScriptVehicle::VT_AIR)) return -1;
@ -121,6 +128,7 @@
/* static */ bool ScriptGroup::MoveVehicle(GroupID group_id, VehicleID vehicle_id) /* static */ bool ScriptGroup::MoveVehicle(GroupID group_id, VehicleID vehicle_id)
{ {
EnforceCompanyModeValid(false);
EnforcePrecondition(false, IsValidGroup(group_id) || group_id == GROUP_DEFAULT); EnforcePrecondition(false, IsValidGroup(group_id) || group_id == GROUP_DEFAULT);
EnforcePrecondition(false, ScriptVehicle::IsPrimaryVehicle(vehicle_id)); EnforcePrecondition(false, ScriptVehicle::IsPrimaryVehicle(vehicle_id));
@ -129,6 +137,7 @@
/* static */ bool ScriptGroup::EnableWagonRemoval(bool enable_removal) /* static */ bool ScriptGroup::EnableWagonRemoval(bool enable_removal)
{ {
EnforceCompanyModeValid(false);
if (HasWagonRemoval() == enable_removal) return true; if (HasWagonRemoval() == enable_removal) return true;
return ScriptObject::Command<CMD_CHANGE_COMPANY_SETTING>::Do("company.renew_keep_length", enable_removal ? 1 : 0); return ScriptObject::Command<CMD_CHANGE_COMPANY_SETTING>::Do("company.renew_keep_length", enable_removal ? 1 : 0);
@ -136,11 +145,13 @@
/* static */ bool ScriptGroup::HasWagonRemoval() /* static */ bool ScriptGroup::HasWagonRemoval()
{ {
EnforceCompanyModeValid(false);
return ::Company::Get(ScriptObject::GetCompany())->settings.renew_keep_length; return ::Company::Get(ScriptObject::GetCompany())->settings.renew_keep_length;
} }
/* static */ bool ScriptGroup::SetAutoReplace(GroupID group_id, EngineID engine_id_old, EngineID engine_id_new) /* static */ bool ScriptGroup::SetAutoReplace(GroupID group_id, EngineID engine_id_old, EngineID engine_id_new)
{ {
EnforceCompanyModeValid(false);
EnforcePrecondition(false, IsValidGroup(group_id) || group_id == GROUP_DEFAULT || group_id == GROUP_ALL); EnforcePrecondition(false, IsValidGroup(group_id) || group_id == GROUP_DEFAULT || group_id == GROUP_ALL);
EnforcePrecondition(false, ScriptEngine::IsBuildable(engine_id_new)); EnforcePrecondition(false, ScriptEngine::IsBuildable(engine_id_new));
@ -149,6 +160,7 @@
/* static */ EngineID ScriptGroup::GetEngineReplacement(GroupID group_id, EngineID engine_id) /* static */ EngineID ScriptGroup::GetEngineReplacement(GroupID group_id, EngineID engine_id)
{ {
EnforceCompanyModeValid(::INVALID_ENGINE);
if (!IsValidGroup(group_id) && group_id != GROUP_DEFAULT && group_id != GROUP_ALL) return ::INVALID_ENGINE; if (!IsValidGroup(group_id) && group_id != GROUP_DEFAULT && group_id != GROUP_ALL) return ::INVALID_ENGINE;
return ::EngineReplacementForCompany(Company::Get(ScriptObject::GetCompany()), engine_id, group_id); return ::EngineReplacementForCompany(Company::Get(ScriptObject::GetCompany()), engine_id, group_id);
@ -156,6 +168,7 @@
/* static */ bool ScriptGroup::StopAutoReplace(GroupID group_id, EngineID engine_id) /* static */ bool ScriptGroup::StopAutoReplace(GroupID group_id, EngineID engine_id)
{ {
EnforceCompanyModeValid(false);
EnforcePrecondition(false, IsValidGroup(group_id) || group_id == GROUP_DEFAULT || group_id == GROUP_ALL); EnforcePrecondition(false, IsValidGroup(group_id) || group_id == GROUP_DEFAULT || group_id == GROUP_ALL);
return ScriptObject::Command<CMD_SET_AUTOREPLACE>::Do(group_id, engine_id, ::INVALID_ENGINE, false); return ScriptObject::Command<CMD_SET_AUTOREPLACE>::Do(group_id, engine_id, ::INVALID_ENGINE, false);
@ -206,6 +219,7 @@
/* static */ bool ScriptGroup::SetPrimaryColour(GroupID group_id, ScriptCompany::Colours colour) /* static */ bool ScriptGroup::SetPrimaryColour(GroupID group_id, ScriptCompany::Colours colour)
{ {
EnforceCompanyModeValid(false);
EnforcePrecondition(false, IsValidGroup(group_id)); EnforcePrecondition(false, IsValidGroup(group_id));
return ScriptObject::Command<CMD_SET_GROUP_LIVERY>::Do(group_id, true, (::Colours)colour); return ScriptObject::Command<CMD_SET_GROUP_LIVERY>::Do(group_id, true, (::Colours)colour);
@ -213,6 +227,7 @@
/* static */ bool ScriptGroup::SetSecondaryColour(GroupID group_id, ScriptCompany::Colours colour) /* static */ bool ScriptGroup::SetSecondaryColour(GroupID group_id, ScriptCompany::Colours colour)
{ {
EnforceCompanyModeValid(false);
EnforcePrecondition(false, IsValidGroup(group_id)); EnforcePrecondition(false, IsValidGroup(group_id));
return ScriptObject::Command<CMD_SET_GROUP_LIVERY>::Do(group_id, false, (::Colours)colour); return ScriptObject::Command<CMD_SET_GROUP_LIVERY>::Do(group_id, false, (::Colours)colour);

View File

@ -41,6 +41,7 @@ public:
* Create a new group. * Create a new group.
* @param vehicle_type The type of vehicle to create a group for. * @param vehicle_type The type of vehicle to create a group for.
* @param parent_group_id The parent group id to create this group under, INVALID_GROUP for top-level. * @param parent_group_id The parent group id to create this group under, INVALID_GROUP for top-level.
* @game @pre ScriptCompanyMode::IsValid().
* @return The GroupID of the new group, or an invalid GroupID when * @return The GroupID of the new group, or an invalid GroupID when
* it failed. Check the return value using IsValidGroup(). In test-mode * it failed. Check the return value using IsValidGroup(). In test-mode
* 0 is returned if it was successful; any other value indicates failure. * 0 is returned if it was successful; any other value indicates failure.
@ -52,6 +53,7 @@ public:
* given group will move to the GROUP_DEFAULT. * given group will move to the GROUP_DEFAULT.
* @param group_id The group to delete. * @param group_id The group to delete.
* @pre IsValidGroup(group_id). * @pre IsValidGroup(group_id).
* @game @pre ScriptCompanyMode::IsValid().
* @return True if and only if the group was successfully deleted. * @return True if and only if the group was successfully deleted.
*/ */
static bool DeleteGroup(GroupID group_id); static bool DeleteGroup(GroupID group_id);
@ -70,6 +72,7 @@ public:
* @param name The name for the group (can be either a raw string, or a ScriptText object). * @param name The name for the group (can be either a raw string, or a ScriptText object).
* @pre IsValidGroup(group_id). * @pre IsValidGroup(group_id).
* @pre name != null && len(name) != 0 * @pre name != null && len(name) != 0
* @game @pre ScriptCompanyMode::IsValid().
* @exception ScriptError::ERR_NAME_IS_NOT_UNIQUE * @exception ScriptError::ERR_NAME_IS_NOT_UNIQUE
* @return True if and only if the name was changed. * @return True if and only if the name was changed.
*/ */
@ -89,6 +92,7 @@ public:
* @param parent_group_id The parent group to set. * @param parent_group_id The parent group to set.
* @pre IsValidGroup(group_id). * @pre IsValidGroup(group_id).
* @pre IsValidGroup(parent_group_id). * @pre IsValidGroup(parent_group_id).
* @game @pre ScriptCompanyMode::IsValid().
* @return True if and only if the parent group was changed. * @return True if and only if the parent group was changed.
*/ */
static bool SetParent(GroupID group_id, GroupID parent_group_id); static bool SetParent(GroupID group_id, GroupID parent_group_id);
@ -107,6 +111,7 @@ public:
* @param group_id The group to change the protection for. * @param group_id The group to change the protection for.
* @param enable True if protection should be enabled. * @param enable True if protection should be enabled.
* @pre IsValidGroup(group_id). * @pre IsValidGroup(group_id).
* @game @pre ScriptCompanyMode::IsValid().
* @return True if and only if the protection was successfully changed. * @return True if and only if the protection was successfully changed.
*/ */
static bool EnableAutoReplaceProtection(GroupID group_id, bool enable); static bool EnableAutoReplaceProtection(GroupID group_id, bool enable);
@ -124,6 +129,7 @@ public:
* @param group_id The group to get the number of engines in. * @param group_id The group to get the number of engines in.
* @param engine_id The engine id to count. * @param engine_id The engine id to count.
* @pre IsValidGroup(group_id) || group_id == GROUP_ALL || group_id == GROUP_DEFAULT. * @pre IsValidGroup(group_id) || group_id == GROUP_ALL || group_id == GROUP_DEFAULT.
* @game @pre ScriptCompanyMode::IsValid().
* @return The number of engines with id engine_id in the group with id group_id. * @return The number of engines with id engine_id in the group with id group_id.
*/ */
static SQInteger GetNumEngines(GroupID group_id, EngineID engine_id); static SQInteger GetNumEngines(GroupID group_id, EngineID engine_id);
@ -135,6 +141,7 @@ public:
* @pre IsValidGroup(group_id) || group_id == GROUP_ALL || group_id == GROUP_DEFAULT. * @pre IsValidGroup(group_id) || group_id == GROUP_ALL || group_id == GROUP_DEFAULT.
* @pre IsValidGroup(group_id) || vehicle_type == ScriptVehicle::VT_ROAD || vehicle_type == ScriptVehicle::VT_RAIL || * @pre IsValidGroup(group_id) || vehicle_type == ScriptVehicle::VT_ROAD || vehicle_type == ScriptVehicle::VT_RAIL ||
* vehicle_type == ScriptVehicle::VT_WATER || vehicle_type == ScriptVehicle::VT_AIR * vehicle_type == ScriptVehicle::VT_WATER || vehicle_type == ScriptVehicle::VT_AIR
* @game @pre ScriptCompanyMode::IsValid().
* @return The total number of vehicles in the group with id group_id and it's sub-groups. * @return The total number of vehicles in the group with id group_id and it's sub-groups.
* @note If the group is valid (neither GROUP_ALL nor GROUP_DEFAULT), the value of * @note If the group is valid (neither GROUP_ALL nor GROUP_DEFAULT), the value of
* vehicle_type is retrieved from the group itself and not from the input value. * vehicle_type is retrieved from the group itself and not from the input value.
@ -148,6 +155,7 @@ public:
* @param vehicle_id The vehicle to move to the group. * @param vehicle_id The vehicle to move to the group.
* @pre IsValidGroup(group_id) || group_id == GROUP_DEFAULT. * @pre IsValidGroup(group_id) || group_id == GROUP_DEFAULT.
* @pre ScriptVehicle::IsPrimaryVehicle(vehicle_id). * @pre ScriptVehicle::IsPrimaryVehicle(vehicle_id).
* @game @pre ScriptCompanyMode::IsValid().
* @return True if and only if the vehicle was successfully moved to the group. * @return True if and only if the vehicle was successfully moved to the group.
* @note A vehicle can be in only one group at the same time. To remove it from * @note A vehicle can be in only one group at the same time. To remove it from
* a group, move it to another or to GROUP_DEFAULT. Moving the vehicle to the * a group, move it to another or to GROUP_DEFAULT. Moving the vehicle to the
@ -161,12 +169,14 @@ public:
* If enabled, wagons are removed from the end of the vehicle until it * If enabled, wagons are removed from the end of the vehicle until it
* fits in the same number of tiles as it did before. * fits in the same number of tiles as it did before.
* @param keep_length If true, wagons will be removed if the new engine is longer. * @param keep_length If true, wagons will be removed if the new engine is longer.
* @game @pre ScriptCompanyMode::IsValid().
* @return True if and only if the value was successfully changed. * @return True if and only if the value was successfully changed.
*/ */
static bool EnableWagonRemoval(bool keep_length); static bool EnableWagonRemoval(bool keep_length);
/** /**
* Get the current status of wagon removal. * Get the current status of wagon removal.
* @game @pre ScriptCompanyMode::IsValid().
* @return Whether or not wagon removal is enabled. * @return Whether or not wagon removal is enabled.
*/ */
static bool HasWagonRemoval(); static bool HasWagonRemoval();
@ -179,6 +189,7 @@ public:
* @param engine_id_new The engine id to replace with. * @param engine_id_new The engine id to replace with.
* @pre IsValidGroup(group_id) || group_id == GROUP_DEFAULT || group_id == GROUP_ALL. * @pre IsValidGroup(group_id) || group_id == GROUP_DEFAULT || group_id == GROUP_ALL.
* @pre ScriptEngine.IsBuildable(engine_id_new). * @pre ScriptEngine.IsBuildable(engine_id_new).
* @game @pre ScriptCompanyMode::IsValid().
* @return True if and if the replacing was successfully started. * @return True if and if the replacing was successfully started.
* @note To stop autoreplacing engine_id_old, call StopAutoReplace(group_id, engine_id_old). * @note To stop autoreplacing engine_id_old, call StopAutoReplace(group_id, engine_id_old).
*/ */
@ -189,6 +200,7 @@ public:
* @param group_id The group to get the replacement from. * @param group_id The group to get the replacement from.
* @param engine_id The engine that is being replaced. * @param engine_id The engine that is being replaced.
* @pre IsValidGroup(group_id) || group_id == GROUP_DEFAULT || group_id == GROUP_ALL. * @pre IsValidGroup(group_id) || group_id == GROUP_DEFAULT || group_id == GROUP_ALL.
* @game @pre ScriptCompanyMode::IsValid().
* @return The EngineID that is replacing engine_id or an invalid EngineID * @return The EngineID that is replacing engine_id or an invalid EngineID
* in case engine_id is not begin replaced. * in case engine_id is not begin replaced.
*/ */
@ -199,6 +211,7 @@ public:
* @param group_id The group to stop replacing the engine in. * @param group_id The group to stop replacing the engine in.
* @param engine_id The engine id to stop replacing with another engine. * @param engine_id The engine id to stop replacing with another engine.
* @pre IsValidGroup(group_id) || group_id == GROUP_DEFAULT || group_id == GROUP_ALL. * @pre IsValidGroup(group_id) || group_id == GROUP_DEFAULT || group_id == GROUP_ALL.
* @game @pre ScriptCompanyMode::IsValid().
* @return True if and if the replacing was successfully stopped. * @return True if and if the replacing was successfully stopped.
*/ */
static bool StopAutoReplace(GroupID group_id, EngineID engine_id); static bool StopAutoReplace(GroupID group_id, EngineID engine_id);
@ -232,6 +245,7 @@ public:
* @param group_id The group id to set the colour of. * @param group_id The group id to set the colour of.
* @param colour Colour to set. * @param colour Colour to set.
* @pre IsValidGroup(group_id). * @pre IsValidGroup(group_id).
* @game @pre ScriptCompanyMode::IsValid().
* @return True iff the colour was set successfully. * @return True iff the colour was set successfully.
*/ */
static bool SetPrimaryColour(GroupID group_id, ScriptCompany::Colours colour); static bool SetPrimaryColour(GroupID group_id, ScriptCompany::Colours colour);
@ -241,6 +255,7 @@ public:
* @param group_id The group id to set the colour of. * @param group_id The group id to set the colour of.
* @param colour Colour to set. * @param colour Colour to set.
* @pre IsValidGroup(group_id). * @pre IsValidGroup(group_id).
* @game @pre ScriptCompanyMode::IsValid().
* @return True iff the colour was set successfully. * @return True iff the colour was set successfully.
*/ */
static bool SetSecondaryColour(GroupID group_id, ScriptCompany::Colours colour); static bool SetSecondaryColour(GroupID group_id, ScriptCompany::Colours colour);

View File

@ -381,6 +381,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr
/* static */ bool ScriptOrder::SetOrderJumpTo(VehicleID vehicle_id, OrderPosition order_position, OrderPosition jump_to) /* static */ bool ScriptOrder::SetOrderJumpTo(VehicleID vehicle_id, OrderPosition order_position, OrderPosition jump_to)
{ {
EnforceCompanyModeValid(false);
EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_position)); EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_position));
EnforcePrecondition(false, order_position != ORDER_CURRENT && IsConditionalOrder(vehicle_id, order_position)); EnforcePrecondition(false, order_position != ORDER_CURRENT && IsConditionalOrder(vehicle_id, order_position));
EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, jump_to) && jump_to != ORDER_CURRENT); EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, jump_to) && jump_to != ORDER_CURRENT);
@ -390,6 +391,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr
/* static */ bool ScriptOrder::SetOrderCondition(VehicleID vehicle_id, OrderPosition order_position, OrderCondition condition) /* static */ bool ScriptOrder::SetOrderCondition(VehicleID vehicle_id, OrderPosition order_position, OrderCondition condition)
{ {
EnforceCompanyModeValid(false);
EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_position)); EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_position));
EnforcePrecondition(false, order_position != ORDER_CURRENT && IsConditionalOrder(vehicle_id, order_position)); EnforcePrecondition(false, order_position != ORDER_CURRENT && IsConditionalOrder(vehicle_id, order_position));
EnforcePrecondition(false, condition >= OC_LOAD_PERCENTAGE && condition <= OC_REMAINING_LIFETIME); EnforcePrecondition(false, condition >= OC_LOAD_PERCENTAGE && condition <= OC_REMAINING_LIFETIME);
@ -400,6 +402,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr
/* static */ bool ScriptOrder::SetOrderCompareFunction(VehicleID vehicle_id, OrderPosition order_position, CompareFunction compare) /* static */ bool ScriptOrder::SetOrderCompareFunction(VehicleID vehicle_id, OrderPosition order_position, CompareFunction compare)
{ {
EnforceCompanyModeValid(false);
EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_position)); EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_position));
EnforcePrecondition(false, order_position != ORDER_CURRENT && IsConditionalOrder(vehicle_id, order_position)); EnforcePrecondition(false, order_position != ORDER_CURRENT && IsConditionalOrder(vehicle_id, order_position));
EnforcePrecondition(false, compare >= CF_EQUALS && compare <= CF_IS_FALSE); EnforcePrecondition(false, compare >= CF_EQUALS && compare <= CF_IS_FALSE);
@ -410,6 +413,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr
/* static */ bool ScriptOrder::SetOrderCompareValue(VehicleID vehicle_id, OrderPosition order_position, SQInteger value) /* static */ bool ScriptOrder::SetOrderCompareValue(VehicleID vehicle_id, OrderPosition order_position, SQInteger value)
{ {
EnforceCompanyModeValid(false);
EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_position)); EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_position));
EnforcePrecondition(false, order_position != ORDER_CURRENT && IsConditionalOrder(vehicle_id, order_position)); EnforcePrecondition(false, order_position != ORDER_CURRENT && IsConditionalOrder(vehicle_id, order_position));
EnforcePrecondition(false, value >= 0 && value < 2048); EnforcePrecondition(false, value >= 0 && value < 2048);
@ -421,6 +425,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr
/* static */ bool ScriptOrder::SetStopLocation(VehicleID vehicle_id, OrderPosition order_position, StopLocation stop_location) /* static */ bool ScriptOrder::SetStopLocation(VehicleID vehicle_id, OrderPosition order_position, StopLocation stop_location)
{ {
EnforceCompanyModeValid(false);
EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_position)); EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_position));
EnforcePrecondition(false, ScriptVehicle::GetVehicleType(vehicle_id) == ScriptVehicle::VT_RAIL); EnforcePrecondition(false, ScriptVehicle::GetVehicleType(vehicle_id) == ScriptVehicle::VT_RAIL);
EnforcePrecondition(false, IsGotoStationOrder(vehicle_id, order_position)); EnforcePrecondition(false, IsGotoStationOrder(vehicle_id, order_position));
@ -434,6 +439,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr
/* static */ bool ScriptOrder::SetOrderRefit(VehicleID vehicle_id, OrderPosition order_position, CargoID refit_cargo) /* static */ bool ScriptOrder::SetOrderRefit(VehicleID vehicle_id, OrderPosition order_position, CargoID refit_cargo)
{ {
EnforceCompanyModeValid(false);
EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_position)); EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_position));
EnforcePrecondition(false, IsGotoStationOrder(vehicle_id, order_position) || (IsGotoDepotOrder(vehicle_id, order_position) && refit_cargo != CT_AUTO_REFIT)); EnforcePrecondition(false, IsGotoStationOrder(vehicle_id, order_position) || (IsGotoDepotOrder(vehicle_id, order_position) && refit_cargo != CT_AUTO_REFIT));
EnforcePrecondition(false, ScriptCargo::IsValidCargo(refit_cargo) || refit_cargo == CT_AUTO_REFIT || refit_cargo == CT_NO_REFIT); EnforcePrecondition(false, ScriptCargo::IsValidCargo(refit_cargo) || refit_cargo == CT_AUTO_REFIT || refit_cargo == CT_NO_REFIT);
@ -443,6 +449,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr
/* static */ bool ScriptOrder::AppendOrder(VehicleID vehicle_id, TileIndex destination, ScriptOrderFlags order_flags) /* static */ bool ScriptOrder::AppendOrder(VehicleID vehicle_id, TileIndex destination, ScriptOrderFlags order_flags)
{ {
EnforceCompanyModeValid(false);
EnforcePrecondition(false, ScriptVehicle::IsPrimaryVehicle(vehicle_id)); EnforcePrecondition(false, ScriptVehicle::IsPrimaryVehicle(vehicle_id));
EnforcePrecondition(false, AreOrderFlagsValid(destination, order_flags)); EnforcePrecondition(false, AreOrderFlagsValid(destination, order_flags));
@ -451,6 +458,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr
/* static */ bool ScriptOrder::AppendConditionalOrder(VehicleID vehicle_id, OrderPosition jump_to) /* static */ bool ScriptOrder::AppendConditionalOrder(VehicleID vehicle_id, OrderPosition jump_to)
{ {
EnforceCompanyModeValid(false);
EnforcePrecondition(false, ScriptVehicle::IsPrimaryVehicle(vehicle_id)); EnforcePrecondition(false, ScriptVehicle::IsPrimaryVehicle(vehicle_id));
EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, jump_to)); EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, jump_to));
@ -462,6 +470,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr
/* IsValidVehicleOrder is not good enough because it does not allow appending. */ /* IsValidVehicleOrder is not good enough because it does not allow appending. */
if (order_position == ORDER_CURRENT) order_position = ScriptOrder::ResolveOrderPosition(vehicle_id, order_position); if (order_position == ORDER_CURRENT) order_position = ScriptOrder::ResolveOrderPosition(vehicle_id, order_position);
EnforceCompanyModeValid(false);
EnforcePrecondition(false, ScriptVehicle::IsPrimaryVehicle(vehicle_id)); EnforcePrecondition(false, ScriptVehicle::IsPrimaryVehicle(vehicle_id));
EnforcePrecondition(false, order_position >= 0 && order_position <= ::Vehicle::Get(vehicle_id)->GetNumManualOrders()); EnforcePrecondition(false, order_position >= 0 && order_position <= ::Vehicle::Get(vehicle_id)->GetNumManualOrders());
EnforcePrecondition(false, AreOrderFlagsValid(destination, order_flags)); EnforcePrecondition(false, AreOrderFlagsValid(destination, order_flags));
@ -516,6 +525,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr
/* IsValidVehicleOrder is not good enough because it does not allow appending. */ /* IsValidVehicleOrder is not good enough because it does not allow appending. */
if (order_position == ORDER_CURRENT) order_position = ScriptOrder::ResolveOrderPosition(vehicle_id, order_position); if (order_position == ORDER_CURRENT) order_position = ScriptOrder::ResolveOrderPosition(vehicle_id, order_position);
EnforceCompanyModeValid(false);
EnforcePrecondition(false, ScriptVehicle::IsPrimaryVehicle(vehicle_id)); EnforcePrecondition(false, ScriptVehicle::IsPrimaryVehicle(vehicle_id));
EnforcePrecondition(false, order_position >= 0 && order_position <= ::Vehicle::Get(vehicle_id)->GetNumManualOrders()); EnforcePrecondition(false, order_position >= 0 && order_position <= ::Vehicle::Get(vehicle_id)->GetNumManualOrders());
EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, jump_to) && jump_to != ORDER_CURRENT); EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, jump_to) && jump_to != ORDER_CURRENT);
@ -531,6 +541,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr
{ {
order_position = ScriptOrder::ResolveOrderPosition(vehicle_id, order_position); order_position = ScriptOrder::ResolveOrderPosition(vehicle_id, order_position);
EnforceCompanyModeValid(false);
EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_position)); EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_position));
int order_pos = ScriptOrderPositionToRealOrderPosition(vehicle_id, order_position); int order_pos = ScriptOrderPositionToRealOrderPosition(vehicle_id, order_position);
@ -541,6 +552,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr
{ {
next_order = ScriptOrder::ResolveOrderPosition(vehicle_id, next_order); next_order = ScriptOrder::ResolveOrderPosition(vehicle_id, next_order);
EnforceCompanyModeValid(false);
EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, next_order)); EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, next_order));
int order_pos = ScriptOrderPositionToRealOrderPosition(vehicle_id, next_order); int order_pos = ScriptOrderPositionToRealOrderPosition(vehicle_id, next_order);
@ -577,6 +589,7 @@ static void _DoCommandReturnSetOrderFlags(class ScriptInstance *instance)
order_position = ScriptOrder::ResolveOrderPosition(vehicle_id, order_position); order_position = ScriptOrder::ResolveOrderPosition(vehicle_id, order_position);
EnforceCompanyModeValid(false);
EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_position)); EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_position));
EnforcePrecondition(false, AreOrderFlagsValid(GetOrderDestination(vehicle_id, order_position), order_flags)); EnforcePrecondition(false, AreOrderFlagsValid(GetOrderDestination(vehicle_id, order_position), order_flags));
@ -634,6 +647,7 @@ static void _DoCommandReturnSetOrderFlags(class ScriptInstance *instance)
order_position_move = ScriptOrder::ResolveOrderPosition(vehicle_id, order_position_move); order_position_move = ScriptOrder::ResolveOrderPosition(vehicle_id, order_position_move);
order_position_target = ScriptOrder::ResolveOrderPosition(vehicle_id, order_position_target); order_position_target = ScriptOrder::ResolveOrderPosition(vehicle_id, order_position_target);
EnforceCompanyModeValid(false);
EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_position_move)); EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_position_move));
EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_position_target)); EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_position_target));
EnforcePrecondition(false, order_position_move != order_position_target); EnforcePrecondition(false, order_position_move != order_position_target);
@ -645,6 +659,7 @@ static void _DoCommandReturnSetOrderFlags(class ScriptInstance *instance)
/* static */ bool ScriptOrder::CopyOrders(VehicleID vehicle_id, VehicleID main_vehicle_id) /* static */ bool ScriptOrder::CopyOrders(VehicleID vehicle_id, VehicleID main_vehicle_id)
{ {
EnforceCompanyModeValid(false);
EnforcePrecondition(false, ScriptVehicle::IsPrimaryVehicle(vehicle_id)); EnforcePrecondition(false, ScriptVehicle::IsPrimaryVehicle(vehicle_id));
EnforcePrecondition(false, ScriptVehicle::IsPrimaryVehicle(main_vehicle_id)); EnforcePrecondition(false, ScriptVehicle::IsPrimaryVehicle(main_vehicle_id));
@ -653,6 +668,7 @@ static void _DoCommandReturnSetOrderFlags(class ScriptInstance *instance)
/* static */ bool ScriptOrder::ShareOrders(VehicleID vehicle_id, VehicleID main_vehicle_id) /* static */ bool ScriptOrder::ShareOrders(VehicleID vehicle_id, VehicleID main_vehicle_id)
{ {
EnforceCompanyModeValid(false);
EnforcePrecondition(false, ScriptVehicle::IsPrimaryVehicle(vehicle_id)); EnforcePrecondition(false, ScriptVehicle::IsPrimaryVehicle(vehicle_id));
EnforcePrecondition(false, ScriptVehicle::IsPrimaryVehicle(main_vehicle_id)); EnforcePrecondition(false, ScriptVehicle::IsPrimaryVehicle(main_vehicle_id));
@ -661,6 +677,7 @@ static void _DoCommandReturnSetOrderFlags(class ScriptInstance *instance)
/* static */ bool ScriptOrder::UnshareOrders(VehicleID vehicle_id) /* static */ bool ScriptOrder::UnshareOrders(VehicleID vehicle_id)
{ {
EnforceCompanyModeValid(false);
EnforcePrecondition(false, ScriptVehicle::IsPrimaryVehicle(vehicle_id)); EnforcePrecondition(false, ScriptVehicle::IsPrimaryVehicle(vehicle_id));
return ScriptObject::Command<CMD_CLONE_ORDER>::Do(0, CO_UNSHARE, vehicle_id, 0); return ScriptObject::Command<CMD_CLONE_ORDER>::Do(0, CO_UNSHARE, vehicle_id, 0);

View File

@ -356,6 +356,7 @@ public:
* @pre IsValidVehicleOrder(vehicle_id, order_position). * @pre IsValidVehicleOrder(vehicle_id, order_position).
* @pre IsValidVehicleOrder(vehicle_id, jump_to). * @pre IsValidVehicleOrder(vehicle_id, jump_to).
* @pre order_position != ORDER_CURRENT && IsConditionalOrder(vehicle_id, order_position). * @pre order_position != ORDER_CURRENT && IsConditionalOrder(vehicle_id, order_position).
* @game @pre ScriptCompanyMode::IsValid().
* @return Whether the order has been/can be changed. * @return Whether the order has been/can be changed.
* @api -game * @api -game
*/ */
@ -369,6 +370,7 @@ public:
* @pre IsValidVehicleOrder(vehicle_id, order_position). * @pre IsValidVehicleOrder(vehicle_id, order_position).
* @pre order_position != ORDER_CURRENT && IsConditionalOrder(vehicle_id, order_position). * @pre order_position != ORDER_CURRENT && IsConditionalOrder(vehicle_id, order_position).
* @pre condition >= OC_LOAD_PERCENTAGE && condition <= OC_UNCONDITIONALLY. * @pre condition >= OC_LOAD_PERCENTAGE && condition <= OC_UNCONDITIONALLY.
* @game @pre ScriptCompanyMode::IsValid().
* @return Whether the order has been/can be changed. * @return Whether the order has been/can be changed.
* @api -game * @api -game
*/ */
@ -382,6 +384,7 @@ public:
* @pre IsValidVehicleOrder(vehicle_id, order_position). * @pre IsValidVehicleOrder(vehicle_id, order_position).
* @pre order_position != ORDER_CURRENT && IsConditionalOrder(vehicle_id, order_position). * @pre order_position != ORDER_CURRENT && IsConditionalOrder(vehicle_id, order_position).
* @pre compare >= CF_EQUALS && compare <= CF_IS_FALSE. * @pre compare >= CF_EQUALS && compare <= CF_IS_FALSE.
* @game @pre ScriptCompanyMode::IsValid().
* @return Whether the order has been/can be changed. * @return Whether the order has been/can be changed.
* @api -game * @api -game
*/ */
@ -395,6 +398,7 @@ public:
* @pre IsValidVehicleOrder(vehicle_id, order_position). * @pre IsValidVehicleOrder(vehicle_id, order_position).
* @pre order_position != ORDER_CURRENT && IsConditionalOrder(vehicle_id, order_position). * @pre order_position != ORDER_CURRENT && IsConditionalOrder(vehicle_id, order_position).
* @pre value >= 0 && value < 2048. * @pre value >= 0 && value < 2048.
* @game @pre ScriptCompanyMode::IsValid().
* @return Whether the order has been/can be changed. * @return Whether the order has been/can be changed.
* @api -game * @api -game
*/ */
@ -409,6 +413,7 @@ public:
* @pre ScriptVehicle::GetVehicleType(vehicle_id) == ScriptVehicle::VT_RAIL. * @pre ScriptVehicle::GetVehicleType(vehicle_id) == ScriptVehicle::VT_RAIL.
* @pre IsGotoStationOrder(vehicle_id, order_position). * @pre IsGotoStationOrder(vehicle_id, order_position).
* @pre stop_location >= STOPLOCATION_NEAR && stop_location <= STOPLOCATION_FAR * @pre stop_location >= STOPLOCATION_NEAR && stop_location <= STOPLOCATION_FAR
* @game @pre ScriptCompanyMode::IsValid().
* @return Whether the order has been/can be changed. * @return Whether the order has been/can be changed.
* @api -game * @api -game
*/ */
@ -422,6 +427,7 @@ public:
* @pre IsValidVehicleOrder(vehicle_id, order_position). * @pre IsValidVehicleOrder(vehicle_id, order_position).
* @pre IsGotoStationOrder(vehicle_id, order_position) || (IsGotoDepotOrder(vehicle_id, order_position) && refit_cargo != CT_AUTO_REFIT). * @pre IsGotoStationOrder(vehicle_id, order_position) || (IsGotoDepotOrder(vehicle_id, order_position) && refit_cargo != CT_AUTO_REFIT).
* @pre ScriptCargo::IsValidCargo(refit_cargo) || refit_cargo == CT_AUTO_REFIT || refit_cargo == CT_NO_REFIT * @pre ScriptCargo::IsValidCargo(refit_cargo) || refit_cargo == CT_AUTO_REFIT || refit_cargo == CT_NO_REFIT
* @game @pre ScriptCompanyMode::IsValid().
* @return Whether the order has been/can be changed. * @return Whether the order has been/can be changed.
* @api -game * @api -game
*/ */
@ -434,6 +440,7 @@ public:
* @param order_flags The flags given to the order. * @param order_flags The flags given to the order.
* @pre ScriptVehicle::IsPrimaryVehicle(vehicle_id). * @pre ScriptVehicle::IsPrimaryVehicle(vehicle_id).
* @pre AreOrderFlagsValid(destination, order_flags). * @pre AreOrderFlagsValid(destination, order_flags).
* @game @pre ScriptCompanyMode::IsValid().
* @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY * @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY
* @exception ScriptOrder::ERR_ORDER_TOO_MANY * @exception ScriptOrder::ERR_ORDER_TOO_MANY
* @exception ScriptOrder::ERR_ORDER_TOO_FAR_AWAY_FROM_PREVIOUS_DESTINATION * @exception ScriptOrder::ERR_ORDER_TOO_FAR_AWAY_FROM_PREVIOUS_DESTINATION
@ -448,6 +455,7 @@ public:
* @param jump_to The OrderPosition to jump to if the condition is true. * @param jump_to The OrderPosition to jump to if the condition is true.
* @pre ScriptVehicle::IsPrimaryVehicle(vehicle_id). * @pre ScriptVehicle::IsPrimaryVehicle(vehicle_id).
* @pre IsValidVehicleOrder(vehicle_id, jump_to). * @pre IsValidVehicleOrder(vehicle_id, jump_to).
* @game @pre ScriptCompanyMode::IsValid().
* @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY * @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY
* @exception ScriptOrder::ERR_ORDER_TOO_MANY * @exception ScriptOrder::ERR_ORDER_TOO_MANY
* @return True if and only if the order was appended. * @return True if and only if the order was appended.
@ -464,6 +472,7 @@ public:
* @pre ScriptVehicle::IsPrimaryVehicle(vehicle_id) * @pre ScriptVehicle::IsPrimaryVehicle(vehicle_id)
* @pre IsValidVehicleOrder(vehicle_id, order_position). * @pre IsValidVehicleOrder(vehicle_id, order_position).
* @pre AreOrderFlagsValid(destination, order_flags). * @pre AreOrderFlagsValid(destination, order_flags).
* @game @pre ScriptCompanyMode::IsValid().
* @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY * @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY
* @exception ScriptOrder::ERR_ORDER_TOO_MANY * @exception ScriptOrder::ERR_ORDER_TOO_MANY
* @exception ScriptOrder::ERR_ORDER_TOO_FAR_AWAY_FROM_PREVIOUS_DESTINATION * @exception ScriptOrder::ERR_ORDER_TOO_FAR_AWAY_FROM_PREVIOUS_DESTINATION
@ -480,6 +489,7 @@ public:
* @pre ScriptVehicle::IsPrimaryVehicle(vehicle_id). * @pre ScriptVehicle::IsPrimaryVehicle(vehicle_id).
* @pre IsValidVehicleOrder(vehicle_id, order_position). * @pre IsValidVehicleOrder(vehicle_id, order_position).
* @pre IsValidVehicleOrder(vehicle_id, jump_to). * @pre IsValidVehicleOrder(vehicle_id, jump_to).
* @game @pre ScriptCompanyMode::IsValid().
* @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY * @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY
* @exception ScriptOrder::ERR_ORDER_TOO_MANY * @exception ScriptOrder::ERR_ORDER_TOO_MANY
* @return True if and only if the order was inserted. * @return True if and only if the order was inserted.
@ -492,6 +502,7 @@ public:
* @param vehicle_id The vehicle to remove the order from. * @param vehicle_id The vehicle to remove the order from.
* @param order_position The order to remove from the order list. * @param order_position The order to remove from the order list.
* @pre IsValidVehicleOrder(vehicle_id, order_position). * @pre IsValidVehicleOrder(vehicle_id, order_position).
* @game @pre ScriptCompanyMode::IsValid().
* @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY * @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY
* @return True if and only if the order was removed. * @return True if and only if the order was removed.
* @api -game * @api -game
@ -512,6 +523,7 @@ public:
* @pre IsValidVehicleOrder(vehicle_id, order_position). * @pre IsValidVehicleOrder(vehicle_id, order_position).
* @pre AreOrderFlagsValid(GetOrderDestination(vehicle_id, order_position), order_flags). * @pre AreOrderFlagsValid(GetOrderDestination(vehicle_id, order_position), order_flags).
* @pre (order_flags & OF_GOTO_NEAREST_DEPOT) == (GetOrderFlags(vehicle_id, order_position) & OF_GOTO_NEAREST_DEPOT). * @pre (order_flags & OF_GOTO_NEAREST_DEPOT) == (GetOrderFlags(vehicle_id, order_position) & OF_GOTO_NEAREST_DEPOT).
* @game @pre ScriptCompanyMode::IsValid().
* @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY * @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY
* @return True if and only if the order was changed. * @return True if and only if the order was changed.
* @api -game * @api -game
@ -526,6 +538,7 @@ public:
* @pre IsValidVehicleOrder(vehicle_id, order_position_move). * @pre IsValidVehicleOrder(vehicle_id, order_position_move).
* @pre IsValidVehicleOrder(vehicle_id, order_position_target). * @pre IsValidVehicleOrder(vehicle_id, order_position_target).
* @pre order_position_move != order_position_target. * @pre order_position_move != order_position_target.
* @game @pre ScriptCompanyMode::IsValid().
* @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY * @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY
* @return True if and only if the order was moved. * @return True if and only if the order was moved.
* @note If the order is moved to a lower place (e.g. from 7 to 2) * @note If the order is moved to a lower place (e.g. from 7 to 2)
@ -541,6 +554,7 @@ public:
* @param vehicle_id The vehicle that should skip some orders. * @param vehicle_id The vehicle that should skip some orders.
* @param next_order The order the vehicle should skip to. * @param next_order The order the vehicle should skip to.
* @pre IsValidVehicleOrder(vehicle_id, next_order). * @pre IsValidVehicleOrder(vehicle_id, next_order).
* @game @pre ScriptCompanyMode::IsValid().
* @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY * @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY
* @return True if and only the current order was changed. * @return True if and only the current order was changed.
* @api -game * @api -game
@ -554,6 +568,7 @@ public:
* @param main_vehicle_id The vehicle to copy the orders from. * @param main_vehicle_id The vehicle to copy the orders from.
* @pre ScriptVehicle::IsPrimaryVehicle(vehicle_id). * @pre ScriptVehicle::IsPrimaryVehicle(vehicle_id).
* @pre ScriptVehicle::IsPrimaryVehicle(main_vehicle_id). * @pre ScriptVehicle::IsPrimaryVehicle(main_vehicle_id).
* @game @pre ScriptCompanyMode::IsValid().
* @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY * @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY
* @exception ScriptOrder::ERR_ORDER_TOO_MANY * @exception ScriptOrder::ERR_ORDER_TOO_MANY
* @exception ScriptOrder::ERR_ORDER_AIRCRAFT_NOT_ENOUGH_RANGE * @exception ScriptOrder::ERR_ORDER_AIRCRAFT_NOT_ENOUGH_RANGE
@ -569,6 +584,7 @@ public:
* @param main_vehicle_id The vehicle to share the orders with. * @param main_vehicle_id The vehicle to share the orders with.
* @pre ScriptVehicle::IsPrimaryVehicle(vehicle_id). * @pre ScriptVehicle::IsPrimaryVehicle(vehicle_id).
* @pre ScriptVehicle::IsPrimaryVehicle(main_vehicle_id). * @pre ScriptVehicle::IsPrimaryVehicle(main_vehicle_id).
* @game @pre ScriptCompanyMode::IsValid().
* @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY * @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY
* @exception ScriptOrder::ERR_ORDER_AIRCRAFT_NOT_ENOUGH_RANGE * @exception ScriptOrder::ERR_ORDER_AIRCRAFT_NOT_ENOUGH_RANGE
* @return True if and only if the sharing succeeded. * @return True if and only if the sharing succeeded.
@ -581,6 +597,7 @@ public:
* After unsharing orders, the orders list of the vehicle is empty. * After unsharing orders, the orders list of the vehicle is empty.
* @param vehicle_id The vehicle to remove from the shared order list. * @param vehicle_id The vehicle to remove from the shared order list.
* @pre ScriptVehicle::IsPrimaryVehicle(vehicle_id). * @pre ScriptVehicle::IsPrimaryVehicle(vehicle_id).
* @game @pre ScriptCompanyMode::IsValid().
* @return True if and only if the unsharing succeeded. * @return True if and only if the unsharing succeeded.
* @api -game * @api -game
*/ */

View File

@ -238,6 +238,7 @@ template<bool Tfrom, bool Tvia>
/* static */ bool ScriptStation::OpenCloseAirport(StationID station_id) /* static */ bool ScriptStation::OpenCloseAirport(StationID station_id)
{ {
EnforceCompanyModeValid(false);
EnforcePrecondition(false, IsValidStation(station_id)); EnforcePrecondition(false, IsValidStation(station_id));
EnforcePrecondition(false, HasStationType(station_id, STATION_AIRPORT)); EnforcePrecondition(false, HasStationType(station_id, STATION_AIRPORT));

View File

@ -287,6 +287,7 @@ public:
/** /**
* Toggle the open/closed state of an airport. * Toggle the open/closed state of an airport.
* @param station_id The airport to modify. * @param station_id The airport to modify.
* @game @pre ScriptCompanyMode::IsValid().
* @pre IsValidStation(station_id). * @pre IsValidStation(station_id).
* @pre HasStationType(station_id, STATION_AIRPORT). * @pre HasStationType(station_id, STATION_AIRPORT).
* @return True if the state was toggled successfully. * @return True if the state was toggled successfully.