summaryrefslogtreecommitdiff
path: root/src/group_cmd.cpp
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2011-10-03 17:26:37 +0000
committerfrosch <frosch@openttd.org>2011-10-03 17:26:37 +0000
commitd071eefc54849a4dade4d71c8c8f7b0ca568deab (patch)
treea101fc4f2e9fa1ee7f52e635c3b1a03b8a5f1bc4 /src/group_cmd.cpp
parent23a2f23eb35cec39f7a31fe6b541c95a11e0102f (diff)
downloadopenttd-d071eefc54849a4dade4d71c8c8f7b0ca568deab.tar.xz
(svn r22985) -Feature: Display autoreplace status in group GUI.
Diffstat (limited to 'src/group_cmd.cpp')
-rw-r--r--src/group_cmd.cpp38
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);
}