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

Method UpdateAutoreplace

src/group_cmd.cpp:240–264  ·  view source on GitHub ↗

* Update autoreplace_defined and autoreplace_finished of all statistics of a company. * @param company Company to update statistics for. */ static */

Source from the content-addressed store, hash-verified

238 * @param company Company to update statistics for.
239 */
240/* static */ void GroupStatistics::UpdateAutoreplace(CompanyID company)
241{
242 /* Set up the engine count for all companies */
243 Company *c = Company::Get(company);
244 for (VehicleType type = VEH_BEGIN; type < VEH_COMPANY_END; type++) {
245 c->group_all[type].ClearAutoreplace();
246 c->group_default[type].ClearAutoreplace();
247 }
248
249 /* Recalculate */
250 for (Group *g : Group::Iterate()) {
251 if (g->owner != company) continue;
252 g->statistics.ClearAutoreplace();
253 }
254
255 for (EngineRenewList erl = c->engine_renew_list; erl != nullptr; erl = erl->next) {
256 const Engine *e = Engine::Get(erl->from);
257 GroupStatistics &stats = GroupStatistics::Get(company, erl->group_id, e->type);
258 if (!stats.autoreplace_defined) {
259 stats.autoreplace_defined = true;
260 stats.autoreplace_finished = true;
261 }
262 if (GetGroupNumEngines(company, erl->group_id, erl->from) > 0) stats.autoreplace_finished = false;
263 }
264}
265
266/**
267 * Update the num engines of a groupID. Decrease the old one and increase the new one

Callers

nothing calls this directly

Calls 2

GetGroupNumEnginesFunction · 0.85
ClearAutoreplaceMethod · 0.80

Tested by

no test coverage detected