View difference between Paste ID: A3XwvrKE and Mjxy29cy
SHOW: | | - or go back to the newest paste.
1
	/**
2
	 * Get the number of vehicles in a given group.
3
	 * @param group_id The group to get the number of engines in.
4
	 * @param vehicle_type The type of vehicle of the group.
5
	 * @pre IsValidGroup(group_id) || group_id == GROUP_ALL || group_id == GROUP_DEFAULT.
6
	 * @pre IsValidGroup(group_id) || vehicle_type == ScriptVehicle::VT_ROAD || vehicle_type == ScriptVehicle::VT_RAIL ||
7
	 *   vehicle_type == ScriptVehicle::VT_WATER || vehicle_type == ScriptVehicle::VT_AIR
8
	 * @return The number of vehicles in the group with id group_id.
9
	 * @note If the group is valid (neither GROUP_ALL nor GROUP_DEFAULT), the value of
10
	 *  vehicle_type is retrieved from the group itself and not from the input value.
11
	 *  But if the group is invalid, either GROUP_ALL or GROUP_DEFAULT, then a
12
	 *  vehicle type must be specified.
13
	 */
14
	static int32 GetNumVehicles(GroupID group_id, ScriptVehicle::VehicleType vehicle_type);
15
16
/* static */ int32 ScriptGroup::GetNumVehicles(GroupID group_id, ScriptVehicle::VehicleType vehicle_type)
17
{
18
	bool valid_group = IsValidGroup(group_id);
19
	if (!valid_group && group_id != GROUP_DEFAULT && group_id != GROUP_ALL) return -1;
20
	if (!valid_group && (vehicle_type < ScriptVehicle::VT_RAIL || vehicle_type > ScriptVehicle::VT_AIR)) return -1;
21
22
	return GetGroupNumVehicle(ScriptObject::GetCompany(), group_id, valid_group ? ::Group::Get(group_id)->vehicle_type : (::VehicleType)vehicle_type);
23
}