|
@@ -375,17 +375,17 @@ void SetCachedEngineCounts()
|
|
|
const Vehicle *v;
|
|
|
FOR_ALL_VEHICLES(v) {
|
|
|
if (!IsEngineCountable(v)) continue;
|
|
|
|
|
|
assert(v->engine_type < engines);
|
|
|
|
|
|
GetCompany(v->owner)->num_engines[v->engine_type]++;
|
|
|
Company::Get(v->owner)->num_engines[v->engine_type]++;
|
|
|
|
|
|
if (v->group_id == DEFAULT_GROUP) continue;
|
|
|
|
|
|
g = GetGroup(v->group_id);
|
|
|
g = Group::Get(v->group_id);
|
|
|
assert(v->type == g->vehicle_type);
|
|
|
assert(v->owner == g->owner);
|
|
|
|
|
|
g->num_engines[v->engine_type]++;
|
|
|
}
|
|
|
}
|
|
@@ -407,13 +407,13 @@ void SetupEngines()
|
|
|
|
|
|
void ShowEnginePreviewWindow(EngineID engine);
|
|
|
|
|
|
/* Determine if an engine type is a wagon (and not a loco) */
|
|
|
static bool IsWagon(EngineID index)
|
|
|
{
|
|
|
const Engine *e = GetEngine(index);
|
|
|
const Engine *e = Engine::Get(index);
|
|
|
return e->type == VEH_TRAIN && e->u.rail.railveh_type == RAILVEH_WAGON;
|
|
|
}
|
|
|
|
|
|
static void CalcEngineReliability(Engine *e)
|
|
|
{
|
|
|
uint age = e->age;
|
|
@@ -532,14 +532,14 @@ void StartupEngines()
|
|
|
c->avail_roadtypes = GetCompanyRoadtypes(c->index);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
static void AcceptEnginePreview(EngineID eid, CompanyID company)
|
|
|
{
|
|
|
Engine *e = GetEngine(eid);
|
|
|
Company *c = GetCompany(company);
|
|
|
Engine *e = Engine::Get(eid);
|
|
|
Company *c = Company::Get(company);
|
|
|
|
|
|
SetBit(e->company_avail, company);
|
|
|
if (e->type == VEH_TRAIN) {
|
|
|
const RailVehicleInfo *rvi = RailVehInfo(eid);
|
|
|
|
|
|
assert(rvi->railtype < RAILTYPE_END);
|
|
@@ -620,13 +620,13 @@ void EnginesDailyLoop()
|
|
|
*/
|
|
|
CommandCost CmdWantEnginePreview(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
|
|
{
|
|
|
Engine *e;
|
|
|
|
|
|
if (!IsEngineIndex(p1)) return CMD_ERROR;
|
|
|
e = GetEngine(p1);
|
|
|
e = Engine::Get(p1);
|
|
|
if (GetBestCompany(e->preview_company_rank) != _current_company) return CMD_ERROR;
|
|
|
|
|
|
if (flags & DC_EXEC) AcceptEnginePreview(p1, _current_company);
|
|
|
|
|
|
return CommandCost();
|
|
|
}
|
|
@@ -741,13 +741,13 @@ CommandCost CmdRenameEngine(TileIndex ti
|
|
|
if (!reset) {
|
|
|
if (strlen(text) >= MAX_LENGTH_ENGINE_NAME_BYTES) return CMD_ERROR;
|
|
|
if (!IsUniqueEngineName(text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE);
|
|
|
}
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
|
|
Engine *e = GetEngine(p1);
|
|
|
Engine *e = Engine::Get(p1);
|
|
|
free(e->name);
|
|
|
|
|
|
if (reset) {
|
|
|
e->name = NULL;
|
|
|
} else {
|
|
|
e->name = strdup(text);
|
|
@@ -769,23 +769,23 @@ CommandCost CmdRenameEngine(TileIndex ti
|
|
|
*/
|
|
|
bool IsEngineBuildable(EngineID engine, VehicleType type, CompanyID company)
|
|
|
{
|
|
|
/* check if it's an engine that is in the engine array */
|
|
|
if (!IsEngineIndex(engine)) return false;
|
|
|
|
|
|
const Engine *e = GetEngine(engine);
|
|
|
const Engine *e = Engine::Get(engine);
|
|
|
|
|
|
/* check if it's an engine of specified type */
|
|
|
if (e->type != type) return false;
|
|
|
|
|
|
/* check if it's available */
|
|
|
if (!HasBit(e->company_avail, company)) return false;
|
|
|
|
|
|
if (type == VEH_TRAIN) {
|
|
|
/* Check if the rail type is available to this company */
|
|
|
const Company *c = GetCompany(company);
|
|
|
const Company *c = Company::Get(company);
|
|
|
if (!HasBit(c->avail_railtypes, RailVehInfo(engine)->railtype)) return false;
|
|
|
}
|
|
|
|
|
|
return true;
|
|
|
}
|
|
|
|
|
@@ -797,13 +797,13 @@ bool IsEngineBuildable(EngineID engine,
|
|
|
*/
|
|
|
bool IsEngineRefittable(EngineID engine)
|
|
|
{
|
|
|
/* check if it's an engine that is in the engine array */
|
|
|
if (!IsEngineIndex(engine)) return false;
|
|
|
|
|
|
const Engine *e = GetEngine(engine);
|
|
|
const Engine *e = Engine::Get(engine);
|
|
|
|
|
|
if (e->type == VEH_SHIP && !e->u.ship.refittable) return false;
|
|
|
|
|
|
if (!e->CanCarryCargo()) return false;
|
|
|
|
|
|
const EngineInfo *ei = &e->info;
|