mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-12 02:19:41 +00:00
(svn r22977) -Codechange: Rename SetCachedEngineCounts() to GroupStatistics::UpdateAfterLoad().
This commit is contained in:
parent
b6766c2ed5
commit
b78a459613
@ -460,45 +460,6 @@ bool EngineOverrideManager::ResetToCurrentNewGRFConfig()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 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.
|
* Initialise the engine pool with the data from the original vehicles.
|
||||||
*/
|
*/
|
||||||
|
@ -25,7 +25,6 @@ extern const uint8 _engine_offsets[4];
|
|||||||
|
|
||||||
bool IsEngineBuildable(EngineID engine, VehicleType type, CompanyID company);
|
bool IsEngineBuildable(EngineID engine, VehicleType type, CompanyID company);
|
||||||
bool IsEngineRefittable(EngineID engine);
|
bool IsEngineRefittable(EngineID engine);
|
||||||
void SetCachedEngineCounts();
|
|
||||||
void SetYearEngineAgingStops();
|
void SetYearEngineAgingStops();
|
||||||
void StartupOneEngine(Engine *e, Date aging_date);
|
void StartupOneEngine(Engine *e, Date aging_date);
|
||||||
|
|
||||||
|
@ -30,6 +30,8 @@ struct GroupStatistics {
|
|||||||
~GroupStatistics();
|
~GroupStatistics();
|
||||||
|
|
||||||
void Clear();
|
void Clear();
|
||||||
|
|
||||||
|
static void UpdateAfterLoad();
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Group data. */
|
/** Group data. */
|
||||||
|
@ -54,6 +54,45 @@ void GroupStatistics::Clear()
|
|||||||
this->num_engines = CallocT<uint16>(Engine::GetPoolSize());
|
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
|
* Update the num engines of a groupID. Decrease the old one and increase the new one
|
||||||
|
@ -52,6 +52,7 @@
|
|||||||
#include "../core/backup_type.hpp"
|
#include "../core/backup_type.hpp"
|
||||||
#include "../smallmap_gui.h"
|
#include "../smallmap_gui.h"
|
||||||
#include "../news_func.h"
|
#include "../news_func.h"
|
||||||
|
#include "../group.h"
|
||||||
|
|
||||||
#include "table/strings.h"
|
#include "table/strings.h"
|
||||||
|
|
||||||
@ -252,7 +253,7 @@ static void InitializeWindowsAndCaches()
|
|||||||
|
|
||||||
RecomputePrices();
|
RecomputePrices();
|
||||||
|
|
||||||
SetCachedEngineCounts();
|
GroupStatistics::UpdateAfterLoad();
|
||||||
|
|
||||||
Station::RecomputeIndustriesNearForAll();
|
Station::RecomputeIndustriesNearForAll();
|
||||||
RebuildSubsidisedSourceAndDestinationCache();
|
RebuildSubsidisedSourceAndDestinationCache();
|
||||||
@ -2677,7 +2678,7 @@ void ReloadNewGRFData()
|
|||||||
ResetVehiclePosHash();
|
ResetVehiclePosHash();
|
||||||
AfterLoadVehicles(false);
|
AfterLoadVehicles(false);
|
||||||
StartupEngines();
|
StartupEngines();
|
||||||
SetCachedEngineCounts();
|
GroupStatistics::UpdateAfterLoad();
|
||||||
/* update station graphics */
|
/* update station graphics */
|
||||||
AfterLoadStations();
|
AfterLoadStations();
|
||||||
/* Check and update house and town values */
|
/* Check and update house and town values */
|
||||||
|
Loading…
Reference in New Issue
Block a user