Changeset - r28738:a3e474bd6627
[Not reviewed]
master
0 2 0
SamuXarick - 10 months ago 2024-02-11 21:09:23
43006711+SamuXarick@users.noreply.github.com
Fix #10405, a3dd750: [Script] Test engine and vehicle type validity for ScriptGroup::GetNumEngines (#11887)
2 files changed with 7 insertions and 2 deletions:
0 comments (0 inline, 0 general)
src/script/api/script_group.cpp
Show inline comments
 
@@ -108,13 +108,16 @@
 
	return HasBit(::Group::Get(group_id)->flags, GroupFlags::GF_REPLACE_PROTECTION);
 
}
 

	
 
/* 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 (!ScriptEngine::IsValidEngine(engine_id)) return -1;
 
	bool valid_group = IsValidGroup(group_id);
 
	if (!valid_group && group_id != GROUP_DEFAULT && group_id != GROUP_ALL) return -1;
 
	if (valid_group && ScriptEngine::GetVehicleType(engine_id) != GetVehicleType(group_id)) return -1;
 

	
 
	return GetGroupNumEngines(ScriptObject::GetCompany(), group_id, engine_id);
 
}
 

	
 
/* static */ SQInteger ScriptGroup::GetNumVehicles(GroupID group_id, ScriptVehicle::VehicleType vehicle_type)
 
{
src/script/api/script_group.hpp
Show inline comments
 
@@ -125,13 +125,15 @@ public:
 
	static bool GetAutoReplaceProtection(GroupID group_id);
 

	
 
	/**
 
	 * Get the number of engines in a given group.
 
	 * @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.
 
	 * @pre ScriptEngine::IsValidEngine(engine_id).
 
	 * @pre (IsValidGroup(group_id) && ScriptEngine::GetVehicleType(engine_id) == GetVehicleType(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);
 

	
 
	/**
0 comments (0 inline, 0 general)