summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2011-10-03 17:20:56 +0000
committerfrosch <frosch@openttd.org>2011-10-03 17:20:56 +0000
commitb78a459613320d5c45052ece08de55a574104530 (patch)
tree2f7f748ab13f9368ae53d735f5129ea110c407d5 /src
parentb6766c2ed5fa7e3cb703e1dcfdeacb26cde7d07e (diff)
downloadopenttd-b78a459613320d5c45052ece08de55a574104530.tar.xz
(svn r22977) -Codechange: Rename SetCachedEngineCounts() to GroupStatistics::UpdateAfterLoad().
Diffstat (limited to 'src')
-rw-r--r--src/engine.cpp39
-rw-r--r--src/engine_func.h1
-rw-r--r--src/group.h2
-rw-r--r--src/group_cmd.cpp39
-rw-r--r--src/saveload/afterload.cpp5
5 files changed, 44 insertions, 42 deletions
diff --git a/src/engine.cpp b/src/engine.cpp
index 6f5ea40a8..f4474ea27 100644
--- a/src/engine.cpp
+++ b/src/engine.cpp
@@ -461,45 +461,6 @@ bool EngineOverrideManager::ResetToCurrentNewGRFConfig()
}
/**
- * Sets cached values in Company::num_vehicles and Group::num_vehicles
- */
-void SetCachedEngineCounts()
-{
- size_t engines = Engine::GetPoolSize();
-
- /* Set up the engine count for all companies */
- Company *c;
- FOR_ALL_COMPANIES(c) {
- free(c->num_engines);
- c->num_engines = CallocT<EngineID>(engines);
- }
-
- /* Recalculate */
- Group *g;
- FOR_ALL_GROUPS(g) {
- g->statistics.Clear();
- }
-
- const Vehicle *v;
- FOR_ALL_VEHICLES(v) {
- if (!v->IsEngineCountable()) continue;
-
- assert(v->engine_type < engines);
-
- Company::Get(v->owner)->num_engines[v->engine_type]++;
-
- if (v->group_id == DEFAULT_GROUP) continue;
-
- g = Group::Get(v->group_id);
- assert(v->type == g->vehicle_type);
- assert(v->owner == g->owner);
-
- g->statistics.num_engines[v->engine_type]++;
- if (v->IsPrimaryVehicle()) g->statistics.num_vehicle++;
- }
-}
-
-/**
* Initialise the engine pool with the data from the original vehicles.
*/
void SetupEngines()
diff --git a/src/engine_func.h b/src/engine_func.h
index d8fbeb607..bb7e2fcac 100644
--- a/src/engine_func.h
+++ b/src/engine_func.h
@@ -25,7 +25,6 @@ extern const uint8 _engine_offsets[4];
bool IsEngineBuildable(EngineID engine, VehicleType type, CompanyID company);
bool IsEngineRefittable(EngineID engine);
-void SetCachedEngineCounts();
void SetYearEngineAgingStops();
void StartupOneEngine(Engine *e, Date aging_date);
diff --git a/src/group.h b/src/group.h
index e28d36120..2b6e72492 100644
--- a/src/group.h
+++ b/src/group.h
@@ -30,6 +30,8 @@ struct GroupStatistics {
~GroupStatistics();
void Clear();
+
+ static void UpdateAfterLoad();
};
/** Group data. */
diff --git a/src/group_cmd.cpp b/src/group_cmd.cpp
index 1dfa8e258..d4148474f 100644
--- a/src/group_cmd.cpp
+++ b/src/group_cmd.cpp
@@ -54,6 +54,45 @@ void GroupStatistics::Clear()
this->num_engines = CallocT<uint16>(Engine::GetPoolSize());
}
+/**
+ * Update all caches after loading a game, changing NewGRF etc..
+ */
+/* static */ void GroupStatistics::UpdateAfterLoad()
+{
+ size_t engines = Engine::GetPoolSize();
+
+ /* Set up the engine count for all companies */
+ Company *c;
+ FOR_ALL_COMPANIES(c) {
+ free(c->num_engines);
+ c->num_engines = CallocT<EngineID>(engines);
+ }
+
+ /* Recalculate */
+ Group *g;
+ FOR_ALL_GROUPS(g) {
+ g->statistics.Clear();
+ }
+
+ const Vehicle *v;
+ FOR_ALL_VEHICLES(v) {
+ if (!v->IsEngineCountable()) continue;
+
+ assert(v->engine_type < engines);
+
+ Company::Get(v->owner)->num_engines[v->engine_type]++;
+
+ if (v->group_id == DEFAULT_GROUP) continue;
+
+ g = Group::Get(v->group_id);
+ assert(v->type == g->vehicle_type);
+ assert(v->owner == g->owner);
+
+ g->statistics.num_engines[v->engine_type]++;
+ if (v->IsPrimaryVehicle()) g->statistics.num_vehicle++;
+ }
+}
+
/**
* Update the num engines of a groupID. Decrease the old one and increase the new one
diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp
index 1ad7f5493..52f5e7bb5 100644
--- a/src/saveload/afterload.cpp
+++ b/src/saveload/afterload.cpp
@@ -52,6 +52,7 @@
#include "../core/backup_type.hpp"
#include "../smallmap_gui.h"
#include "../news_func.h"
+#include "../group.h"
#include "table/strings.h"
@@ -252,7 +253,7 @@ static void InitializeWindowsAndCaches()
RecomputePrices();
- SetCachedEngineCounts();
+ GroupStatistics::UpdateAfterLoad();
Station::RecomputeIndustriesNearForAll();
RebuildSubsidisedSourceAndDestinationCache();
@@ -2677,7 +2678,7 @@ void ReloadNewGRFData()
ResetVehiclePosHash();
AfterLoadVehicles(false);
StartupEngines();
- SetCachedEngineCounts();
+ GroupStatistics::UpdateAfterLoad();
/* update station graphics */
AfterLoadStations();
/* Check and update house and town values */