|
@@ -18,24 +18,25 @@
|
|
|
#include "group.h"
|
|
|
#include "strings_func.h"
|
|
|
#include "gfx_func.h"
|
|
|
#include "functions.h"
|
|
|
#include "window_func.h"
|
|
|
#include "date_func.h"
|
|
|
#include "autoreplace_base.h"
|
|
|
#include "autoreplace_gui.h"
|
|
|
#include "string_func.h"
|
|
|
#include "settings_type.h"
|
|
|
#include "oldpool_func.h"
|
|
|
#include "core/alloc_func.hpp"
|
|
|
#include "vehicle_func.h"
|
|
|
#include "map"
|
|
|
|
|
|
#include "table/strings.h"
|
|
|
#include "table/engines.h"
|
|
|
|
|
|
DEFINE_OLD_POOL_GENERIC(Engine, Engine)
|
|
|
|
|
|
enum {
|
|
|
YEAR_ENGINE_AGING_STOPS = 2050,
|
|
|
};
|
|
|
|
|
|
|
|
@@ -131,24 +132,60 @@ void EngList_Sort(EngineList *el, EngLis
|
|
|
* @param el list to be sorted
|
|
|
* @param compare function for evaluation of the quicksort
|
|
|
* @param begin start of sorting
|
|
|
* @param num_items count of items to be sorted
|
|
|
*/
|
|
|
void EngList_SortPartial(EngineList *el, EngList_SortTypeFunction compare, uint begin, uint num_items)
|
|
|
{
|
|
|
assert(begin <= (uint)el->size());
|
|
|
assert(begin + num_items <= (uint)el->size());
|
|
|
qsort(&((*el)[begin]), num_items, sizeof(EngineID), compare);
|
|
|
}
|
|
|
|
|
|
void SetCachedEngineCounts()
|
|
|
{
|
|
|
uint engines = GetEnginePoolSize();
|
|
|
|
|
|
/* Set up the engine count for all players */
|
|
|
Player *p;
|
|
|
FOR_ALL_PLAYERS(p) {
|
|
|
free(p->num_engines);
|
|
|
p->num_engines = CallocT<EngineID>(engines);
|
|
|
}
|
|
|
|
|
|
/* Recalculate */
|
|
|
Group *g;
|
|
|
FOR_ALL_GROUPS(g) {
|
|
|
free(g->num_engines);
|
|
|
g->num_engines = CallocT<EngineID>(engines);
|
|
|
}
|
|
|
|
|
|
const Vehicle *v;
|
|
|
FOR_ALL_VEHICLES(v) {
|
|
|
if (!IsEngineCountable(v)) continue;
|
|
|
|
|
|
assert(v->engine_type < engines);
|
|
|
|
|
|
GetPlayer(v->owner)->num_engines[v->engine_type]++;
|
|
|
|
|
|
if (v->group_id == DEFAULT_GROUP) continue;
|
|
|
|
|
|
g = GetGroup(v->group_id);
|
|
|
assert(v->type == g->vehicle_type);
|
|
|
assert(v->owner == g->owner);
|
|
|
|
|
|
g->num_engines[v->engine_type]++;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void SetupEngines()
|
|
|
{
|
|
|
_Engine_pool.CleanPool();
|
|
|
_Engine_pool.AddBlockToPool();
|
|
|
|
|
|
for (uint i = 0; i < lengthof(_orig_rail_vehicle_info); i++) new Engine(VEH_TRAIN, i);
|
|
|
for (uint i = 0; i < lengthof(_orig_road_vehicle_info); i++) new Engine(VEH_ROAD, i);
|
|
|
for (uint i = 0; i < lengthof(_orig_ship_vehicle_info); i++) new Engine(VEH_SHIP, i);
|
|
|
for (uint i = 0; i < lengthof(_orig_aircraft_vehicle_info); i++) new Engine(VEH_AIRCRAFT, i);
|
|
|
}
|
|
|
|
|
|
|