diff options
Diffstat (limited to 'src/group_cmd.cpp')
-rw-r--r-- | src/group_cmd.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/group_cmd.cpp b/src/group_cmd.cpp index 0656d98ed..9ae39025c 100644 --- a/src/group_cmd.cpp +++ b/src/group_cmd.cpp @@ -125,6 +125,10 @@ void GroupStatistics::Clear() GroupStatistics::CountEngine(v, 1); if (v->IsPrimaryVehicle()) GroupStatistics::CountVehicle(v, 1); } + + FOR_ALL_COMPANIES(c) { + GroupStatistics::UpdateAutoreplace(c->index); + } } /** @@ -203,6 +207,37 @@ void GroupStatistics::Clear() } /** + * Update autoreplace_defined and autoreplace_finished of all statistics of a company. + * @param company Company to update statistics for. + */ +/* static */ void GroupStatistics::UpdateAutoreplace(CompanyID company) +{ + /* Set up the engine count for all companies */ + Company *c = Company::Get(company); + for (VehicleType type = VEH_BEGIN; type < VEH_COMPANY_END; type++) { + c->group_all[type].ClearAutoreplace(); + c->group_default[type].ClearAutoreplace(); + } + + /* Recalculate */ + Group *g; + FOR_ALL_GROUPS(g) { + if (g->owner != company) continue; + g->statistics.ClearAutoreplace(); + } + + for (EngineRenewList erl = c->engine_renew_list; erl != NULL; erl = erl->next) { + const Engine *e = Engine::Get(erl->from); + GroupStatistics &stats = GroupStatistics::Get(company, erl->group_id, e->type); + if (!stats.autoreplace_defined) { + stats.autoreplace_defined = true; + stats.autoreplace_finished = true; + } + if (stats.num_engines[erl->from] > 0) stats.autoreplace_finished = false; + } +} + +/** * Update the num engines of a groupID. Decrease the old one and increase the new one * @note called in SetTrainGroupID and UpdateTrainGroupID * @param v Vehicle we have to update @@ -400,6 +435,7 @@ CommandCost CmdAddVehicleGroup(TileIndex tile, DoCommandFlag flags, uint32 p1, u } GroupStatistics::CountVehicle(v, 1); + GroupStatistics::UpdateAutoreplace(v->owner); /* Update the Replace Vehicle Windows */ SetWindowDirty(WC_REPLACE_VEHICLE, v->type); @@ -544,6 +580,7 @@ void SetTrainGroupID(Train *v, GroupID new_g) } /* Update the Replace Vehicle Windows */ + GroupStatistics::UpdateAutoreplace(v->owner); SetWindowDirty(WC_REPLACE_VEHICLE, VEH_TRAIN); } @@ -567,6 +604,7 @@ void UpdateTrainGroupID(Train *v) } /* Update the Replace Vehicle Windows */ + GroupStatistics::UpdateAutoreplace(v->owner); SetWindowDirty(WC_REPLACE_VEHICLE, VEH_TRAIN); } |