MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / GetCurrentUsage

Method GetCurrentUsage

src/script/api/script_group.cpp:203–221  ·  view source on GitHub ↗

static */

Source from the content-addressed store, hash-verified

201}
202
203/* static */ SQInteger ScriptGroup::GetCurrentUsage(GroupID group_id)
204{
205 if (!IsValidGroup(group_id)) return -1;
206
207 uint32_t occupancy = 0;
208 uint32_t vehicle_count = 0;
209
210 for (const Vehicle *v : Vehicle::Iterate()) {
211 if (v->group_id != group_id) continue;
212 if (!v->IsPrimaryVehicle()) continue;
213
214 occupancy += v->trip_occupancy;
215 vehicle_count++;
216 }
217
218 if (vehicle_count == 0) return -1;
219
220 return occupancy / vehicle_count;
221}
222
223/* static */ bool ScriptGroup::SetPrimaryColour(GroupID group_id, ScriptCompany::Colours colour)
224{

Callers

nothing calls this directly

Calls 1

IsPrimaryVehicleMethod · 0.45

Tested by

no test coverage detected