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.
This commit is contained in:
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

@@ -41,6 +41,7 @@ public:
* Create a new group.
* @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.
* @game @pre ScriptCompanyMode::IsValid().
* @return The GroupID of the new group, or an invalid GroupID when
* it failed. Check the return value using IsValidGroup(). In test-mode
* 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.
* @param group_id The group to delete.
* @pre IsValidGroup(group_id).
* @game @pre ScriptCompanyMode::IsValid().
* @return True if and only if the group was successfully deleted.
*/
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).
* @pre IsValidGroup(group_id).
* @pre name != null && len(name) != 0
* @game @pre ScriptCompanyMode::IsValid().
* @exception ScriptError::ERR_NAME_IS_NOT_UNIQUE
* @return True if and only if the name was changed.
*/
@@ -89,6 +92,7 @@ public:
* @param parent_group_id The parent group to set.
* @pre IsValidGroup(group_id).
* @pre IsValidGroup(parent_group_id).
* @game @pre ScriptCompanyMode::IsValid().
* @return True if and only if the parent group was changed.
*/
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 enable True if protection should be enabled.
* @pre IsValidGroup(group_id).
* @game @pre ScriptCompanyMode::IsValid().
* @return True if and only if the protection was successfully changed.
*/
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 engine_id The engine id to count.
* @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.
*/
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) || vehicle_type == ScriptVehicle::VT_ROAD || vehicle_type == ScriptVehicle::VT_RAIL ||
* 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.
* @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.
@@ -148,6 +155,7 @@ public:
* @param vehicle_id The vehicle to move to the group.
* @pre IsValidGroup(group_id) || group_id == GROUP_DEFAULT.
* @pre ScriptVehicle::IsPrimaryVehicle(vehicle_id).
* @game @pre ScriptCompanyMode::IsValid().
* @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
* 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
* 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.
* @game @pre ScriptCompanyMode::IsValid().
* @return True if and only if the value was successfully changed.
*/
static bool EnableWagonRemoval(bool keep_length);
/**
* Get the current status of wagon removal.
* @game @pre ScriptCompanyMode::IsValid().
* @return Whether or not wagon removal is enabled.
*/
static bool HasWagonRemoval();
@@ -179,6 +189,7 @@ public:
* @param engine_id_new The engine id to replace with.
* @pre IsValidGroup(group_id) || group_id == GROUP_DEFAULT || group_id == GROUP_ALL.
* @pre ScriptEngine.IsBuildable(engine_id_new).
* @game @pre ScriptCompanyMode::IsValid().
* @return True if and if the replacing was successfully started.
* @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 engine_id The engine that is being replaced.
* @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
* 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 engine_id The engine id to stop replacing with another engine.
* @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.
*/
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 colour Colour to set.
* @pre IsValidGroup(group_id).
* @game @pre ScriptCompanyMode::IsValid().
* @return True iff the colour was set successfully.
*/
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 colour Colour to set.
* @pre IsValidGroup(group_id).
* @game @pre ScriptCompanyMode::IsValid().
* @return True iff the colour was set successfully.
*/
static bool SetSecondaryColour(GroupID group_id, ScriptCompany::Colours colour);