-
-
Save SamuXarick/60015596edd2d9267a655c6c526e491b to your computer and use it in GitHub Desktop.
How to describe the @preconditions on this function declaration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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 IsValidEngine(engine_id) | |
* @pre IsValidGroup(group_id) && ScriptEngine::GetVehicleType(engine_id) == GetVehicleType(group_id). | |
* @game @pre Valid ScriptCompanyMode active in scope | |
* when group_id == GROUP_ALL || group_id == GROUP_DEFAULT. | |
* @return The number of engines with id engine_id in the group with id group_id. | |
*/ | |
static int32 GetNumEngines(GroupID group_id, EngineID engine_id); | |
/* static */ int32 ScriptGroup::GetNumEngines(GroupID group_id, EngineID engine_id) | |
{ | |
bool valid_group = IsValidGroup(group_id); | |
if (!valid_group && group_id != GROUP_DEFAULT && group_id != GROUP_ALL) return -1; | |
if (ScriptObject::GetCompany() == OWNER_DEITY && (group_id == GROUP_DEFAULT || group_id == GROUP_ALL)) return -1; | |
if (!ScriptEngine::IsValidEngine(engine_id)) return -1; | |
if (valid_group && ScriptEngine::GetVehicleType(engine_id) != ScriptGroup::GetVehicleType(group_id)) return -1; | |
CompanyID company = (valid_group && ScriptObject::GetCompany() == OWNER_DEITY) ? ::Group::Get(group_id)->owner : ScriptObject::GetCompany(); | |
return GetGroupNumEngines(company, group_id, engine_id); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment