1
0
Fork 0

Fix #10405, a3dd750: [Script] Test engine and vehicle type validity for ScriptGroup::GetNumEngines (#11887)

pull/12070/head
SamuXarick 2024-02-11 21:09:23 +00:00 committed by GitHub
parent 5b3bfe4c4c
commit fa64fff4a5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 2 deletions

View File

@ -111,7 +111,10 @@
/* 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);
}

View File

@ -128,7 +128,9 @@ public:
* 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.
*/