summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2009-10-06 19:17:07 +0000
committerfrosch <frosch@openttd.org>2009-10-06 19:17:07 +0000
commitf3aacb8fe3e96efd90b0ab93dbf8fb33a8842434 (patch)
tree373048e110915c31097d4e056da5f54833620492 /src
parent95dfee1c604d420df9f0d5860fcddf29e657fc32 (diff)
downloadopenttd-f3aacb8fe3e96efd90b0ab93dbf8fb33a8842434.tar.xz
(svn r17725) -Codechange: Reduce usage of EngInfo and XxxVehInfo, esp. when a Engine * is already present.
Diffstat (limited to 'src')
-rw-r--r--src/aircraft_cmd.cpp22
-rw-r--r--src/autoreplace_cmd.cpp15
-rw-r--r--src/build_vehicle_gui.cpp17
-rw-r--r--src/economy.cpp5
-rw-r--r--src/engine.cpp10
-rw-r--r--src/engine_gui.cpp5
-rw-r--r--src/roadveh.h8
-rw-r--r--src/roadveh_cmd.cpp13
-rw-r--r--src/ship_cmd.cpp13
-rw-r--r--src/train_cmd.cpp10
-rw-r--r--src/vehicle.cpp33
-rw-r--r--src/vehicle_gui.cpp5
12 files changed, 88 insertions, 68 deletions
diff --git a/src/aircraft_cmd.cpp b/src/aircraft_cmd.cpp
index 03756aed8..c5a596da3 100644
--- a/src/aircraft_cmd.cpp
+++ b/src/aircraft_cmd.cpp
@@ -111,6 +111,7 @@ static StationID FindNearestHangar(const Aircraft *v)
uint best = 0;
StationID index = INVALID_STATION;
TileIndex vtile = TileVirtXY(v->x_pos, v->y_pos);
+ const AircraftVehicleInfo *avi = AircraftVehInfo(v->engine_type);
FOR_ALL_STATIONS(st) {
if (st->owner != v->owner || !(st->facilities & FACIL_AIRPORT)) continue;
@@ -119,7 +120,7 @@ static StationID FindNearestHangar(const Aircraft *v)
if (afc->nof_depots == 0 || (
/* don't crash the plane if we know it can't land at the airport */
(afc->flags & AirportFTAClass::SHORT_STRIP) &&
- (AircraftVehInfo(v->engine_type)->subtype & AIR_FAST) &&
+ (avi->subtype & AIR_FAST) &&
!_cheats.no_jetcrash.value)) {
continue;
}
@@ -185,13 +186,14 @@ SpriteID GetRotorImage(const Aircraft *v)
static SpriteID GetAircraftIcon(EngineID engine)
{
- uint8 spritenum = AircraftVehInfo(engine)->image_index;
+ const Engine *e = Engine::Get(engine);
+ uint8 spritenum = e->u.air.image_index;
if (is_custom_sprite(spritenum)) {
SpriteID sprite = GetCustomVehicleIcon(engine, DIR_W);
if (sprite != 0) return sprite;
- spritenum = Engine::Get(engine)->original_image_index;
+ spritenum = e->original_image_index;
}
return DIR_W + _aircraft_sprite[spritenum];
@@ -258,8 +260,8 @@ CommandCost CmdBuildAircraft(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
{
if (!IsEngineBuildable(p1, VEH_AIRCRAFT, _current_company)) return_cmd_error(STR_ERROR_AIRCRAFT_NOT_AVAILABLE);
- const AircraftVehicleInfo *avi = AircraftVehInfo(p1);
const Engine *e = Engine::Get(p1);
+ const AircraftVehicleInfo *avi = &e->u.air;
CommandCost value(EXPENSES_NEW_VEHICLES, e->GetCost());
/* Engines without valid cargo should not be available */
@@ -386,7 +388,7 @@ CommandCost CmdBuildAircraft(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
if (v->cargo_type != CT_PASSENGERS) {
uint16 callback = CALLBACK_FAILED;
- if (HasBit(EngInfo(p1)->callback_mask, CBM_VEHICLE_REFIT_CAPACITY)) {
+ if (HasBit(e->info.callback_mask, CBM_VEHICLE_REFIT_CAPACITY)) {
callback = GetVehicleCallback(CBID_VEHICLE_REFIT_CAPACITY, 0, 0, v->engine_type, v);
}
@@ -537,9 +539,11 @@ CommandCost CmdRefitAircraft(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
CargoID new_cid = GB(p2, 0, 8);
if (new_cid >= NUM_CARGO || !CanRefitTo(v->engine_type, new_cid)) return CMD_ERROR;
+ const Engine *e = Engine::Get(v->engine_type);
+
/* Check the refit capacity callback */
uint16 callback = CALLBACK_FAILED;
- if (HasBit(EngInfo(v->engine_type)->callback_mask, CBM_VEHICLE_REFIT_CAPACITY)) {
+ if (HasBit(e->info.callback_mask, CBM_VEHICLE_REFIT_CAPACITY)) {
/* Back up the existing cargo type */
CargoID temp_cid = v->cargo_type;
byte temp_subtype = v->cargo_subtype;
@@ -553,13 +557,11 @@ CommandCost CmdRefitAircraft(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
v->cargo_subtype = temp_subtype;
}
- const AircraftVehicleInfo *avi = AircraftVehInfo(v->engine_type);
-
uint pass;
if (callback == CALLBACK_FAILED) {
/* If the callback failed, or wasn't executed, use the aircraft's
* default cargo capacity */
- pass = AircraftDefaultCargoCapacity(new_cid, avi);
+ pass = AircraftDefaultCargoCapacity(new_cid, &e->u.air);
} else {
pass = callback;
}
@@ -574,7 +576,7 @@ CommandCost CmdRefitAircraft(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
v->cargo_cap = pass;
Vehicle *u = v->Next();
- uint mail = IsCargoInClass(new_cid, CC_PASSENGERS) ? avi->mail_capacity : 0;
+ uint mail = IsCargoInClass(new_cid, CC_PASSENGERS) ? e->u.air.mail_capacity : 0;
u->cargo_cap = mail;
v->cargo.Truncate(v->cargo_type == new_cid ? pass : 0);
u->cargo.Truncate(v->cargo_type == new_cid ? mail : 0);
diff --git a/src/autoreplace_cmd.cpp b/src/autoreplace_cmd.cpp
index 6bef8dcc8..2c3f973f8 100644
--- a/src/autoreplace_cmd.cpp
+++ b/src/autoreplace_cmd.cpp
@@ -56,32 +56,31 @@ bool CheckAutoreplaceValidity(EngineID from, EngineID to, CompanyID company)
/* we can't replace an engine into itself (that would be autorenew) */
if (from == to) return false;
- VehicleType type = Engine::Get(from)->type;
+ const Engine *e_from = Engine::Get(from);
+ const Engine *e_to = Engine::Get(to);
+ VehicleType type = e_from->type;
/* check that the new vehicle type is available to the company and its type is the same as the original one */
if (!IsEngineBuildable(to, type, company)) return false;
switch (type) {
case VEH_TRAIN: {
- const RailVehicleInfo *rvi_from = RailVehInfo(from);
- const RailVehicleInfo *rvi_to = RailVehInfo(to);
-
/* make sure the railtypes are compatible */
- if ((GetRailTypeInfo(rvi_from->railtype)->compatible_railtypes & GetRailTypeInfo(rvi_to->railtype)->compatible_railtypes) == 0) return false;
+ if ((GetRailTypeInfo(e_from->u.rail.railtype)->compatible_railtypes & GetRailTypeInfo(e_to->u.rail.railtype)->compatible_railtypes) == 0) return false;
/* make sure we do not replace wagons with engines or vise versa */
- if ((rvi_from->railveh_type == RAILVEH_WAGON) != (rvi_to->railveh_type == RAILVEH_WAGON)) return false;
+ if ((e_from->u.rail.railveh_type == RAILVEH_WAGON) != (e_to->u.rail.railveh_type == RAILVEH_WAGON)) return false;
break;
}
case VEH_ROAD:
/* make sure that we do not replace a tram with a normal road vehicles or vise versa */
- if (HasBit(EngInfo(from)->misc_flags, EF_ROAD_TRAM) != HasBit(EngInfo(to)->misc_flags, EF_ROAD_TRAM)) return false;
+ if (HasBit(e_from->info.misc_flags, EF_ROAD_TRAM) != HasBit(e_to->info.misc_flags, EF_ROAD_TRAM)) return false;
break;
case VEH_AIRCRAFT:
/* make sure that we do not replace a plane with a helicopter or vise versa */
- if ((AircraftVehInfo(from)->subtype & AIR_CTOL) != (AircraftVehInfo(to)->subtype & AIR_CTOL)) return false;
+ if ((e_from->u.air.subtype & AIR_CTOL) != (e_to->u.air.subtype & AIR_CTOL)) return false;
break;
default: break;
diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp
index bcdb8fb55..34d432011 100644
--- a/src/build_vehicle_gui.cpp
+++ b/src/build_vehicle_gui.cpp
@@ -298,8 +298,8 @@ static int CDECL AircraftEngineCargoSorter(const EngineID *a, const EngineID *b)
if (r == 0) {
/* The planes has the same passenger capacity. Check mail capacity instead */
- va = AircraftVehInfo(*a)->mail_capacity;
- vb = AircraftVehInfo(*b)->mail_capacity;
+ va = e_a->u.air.mail_capacity;
+ vb = e_b->u.air.mail_capacity;
r = va - vb;
if (r == 0) {
@@ -633,11 +633,10 @@ int DrawVehiclePurchaseInfo(int left, int right, int y, EngineID engine_number)
switch (e->type) {
default: NOT_REACHED();
case VEH_TRAIN: {
- const RailVehicleInfo *rvi = RailVehInfo(engine_number);
- if (rvi->railveh_type == RAILVEH_WAGON) {
- y = DrawRailWagonPurchaseInfo(left, right, y, engine_number, rvi);
+ if (e->u.rail.railveh_type == RAILVEH_WAGON) {
+ y = DrawRailWagonPurchaseInfo(left, right, y, engine_number, &e->u.rail);
} else {
- y = DrawRailEnginePurchaseInfo(left, right, y, engine_number, rvi);
+ y = DrawRailEnginePurchaseInfo(left, right, y, engine_number, &e->u.rail);
}
/* Cargo type + capacity, or N/A */
@@ -670,15 +669,15 @@ int DrawVehiclePurchaseInfo(int left, int right, int y, EngineID engine_number)
break;
}
case VEH_SHIP:
- y = DrawShipPurchaseInfo(left, right, y, engine_number, ShipVehInfo(engine_number), refittable);
+ y = DrawShipPurchaseInfo(left, right, y, engine_number, &e->u.ship, refittable);
break;
case VEH_AIRCRAFT:
- y = DrawAircraftPurchaseInfo(left, right, y, engine_number, AircraftVehInfo(engine_number), refittable);
+ y = DrawAircraftPurchaseInfo(left, right, y, engine_number, &e->u.air, refittable);
break;
}
/* Draw details, that applies to all types except rail wagons */
- if (e->type != VEH_TRAIN || RailVehInfo(engine_number)->railveh_type != RAILVEH_WAGON) {
+ if (e->type != VEH_TRAIN || e->u.rail.railveh_type != RAILVEH_WAGON) {
/* Design date - Life length */
SetDParam(0, ymd.year);
SetDParam(1, e->GetLifeLengthInDays() / DAYS_IN_LEAP_YEAR);
diff --git a/src/economy.cpp b/src/economy.cpp
index 15951bafe..95a772cfc 100644
--- a/src/economy.cpp
+++ b/src/economy.cpp
@@ -1139,12 +1139,13 @@ static void LoadUnloadVehicle(Vehicle *v, int *cargo_left)
for (; v != NULL; v = v->Next()) {
if (v->cargo_cap == 0) continue;
- byte load_amount = EngInfo(v->engine_type)->load_amount;
+ const Engine *e = Engine::Get(v->engine_type);
+ byte load_amount = e->info.load_amount;
/* The default loadamount for mail is 1/4 of the load amount for passengers */
if (v->type == VEH_AIRCRAFT && !Aircraft::From(v)->IsNormalAircraft()) load_amount = (load_amount + 3) / 4;
- if (_settings_game.order.gradual_loading && HasBit(EngInfo(v->engine_type)->callback_mask, CBM_VEHICLE_LOAD_AMOUNT)) {
+ if (_settings_game.order.gradual_loading && HasBit(e->info.callback_mask, CBM_VEHICLE_LOAD_AMOUNT)) {
uint16 cb_load_amount = GetVehicleCallback(CBID_VEHICLE_LOAD_AMOUNT, 0, 0, v->engine_type, v);
if (cb_load_amount != CALLBACK_FAILED && GB(cb_load_amount, 0, 8) != 0) load_amount = GB(cb_load_amount, 0, 8);
}
diff --git a/src/engine.cpp b/src/engine.cpp
index 95ac02828..94199a602 100644
--- a/src/engine.cpp
+++ b/src/engine.cpp
@@ -523,12 +523,10 @@ static void AcceptEnginePreview(EngineID eid, CompanyID company)
SetBit(e->company_avail, company);
if (e->type == VEH_TRAIN) {
- const RailVehicleInfo *rvi = RailVehInfo(eid);
-
- assert(rvi->railtype < RAILTYPE_END);
- SetBit(c->avail_railtypes, rvi->railtype);
+ assert(e->u.rail.railtype < RAILTYPE_END);
+ SetBit(c->avail_railtypes, e->u.rail.railtype);
} else if (e->type == VEH_ROAD) {
- SetBit(c->avail_roadtypes, HasBit(EngInfo(eid)->misc_flags, EF_ROAD_TRAM) ? ROADTYPE_TRAM : ROADTYPE_ROAD);
+ SetBit(c->avail_roadtypes, HasBit(e->info.misc_flags, EF_ROAD_TRAM) ? ROADTYPE_TRAM : ROADTYPE_ROAD);
}
e->preview_company_rank = 0xFF;
@@ -765,7 +763,7 @@ bool IsEngineBuildable(EngineID engine, VehicleType type, CompanyID company)
if (type == VEH_TRAIN) {
/* Check if the rail type is available to this company */
const Company *c = Company::Get(company);
- if (((GetRailTypeInfo(RailVehInfo(engine)->railtype))->compatible_railtypes & c->avail_railtypes) == 0) return false;
+ if (((GetRailTypeInfo(e->u.rail.railtype))->compatible_railtypes & c->avail_railtypes) == 0) return false;
}
return true;
diff --git a/src/engine_gui.cpp b/src/engine_gui.cpp
index 15df2de24..43125c4d4 100644
--- a/src/engine_gui.cpp
+++ b/src/engine_gui.cpp
@@ -30,13 +30,14 @@
*/
StringID GetEngineCategoryName(EngineID engine)
{
- switch (Engine::Get(engine)->type) {
+ const Engine *e = Engine::Get(engine);
+ switch (e->type) {
default: NOT_REACHED();
case VEH_ROAD: return STR_ENGINE_PREVIEW_ROAD_VEHICLE;
case VEH_AIRCRAFT: return STR_ENGINE_PREVIEW_AIRCRAFT;
case VEH_SHIP: return STR_ENGINE_PREVIEW_SHIP;
case VEH_TRAIN:
- return GetRailTypeInfo(RailVehInfo(engine)->railtype)->strings.new_loco;
+ return GetRailTypeInfo(e->u.rail.railtype)->strings.new_loco;
}
}
diff --git a/src/roadveh.h b/src/roadveh.h
index e7b05d988..44062a3eb 100644
--- a/src/roadveh.h
+++ b/src/roadveh.h
@@ -123,7 +123,13 @@ struct RoadVehicle : public SpecializedVehicle<RoadVehicle, VEH_ROAD> {
SpriteID GetImage(Direction direction) const;
int GetDisplaySpeed() const { return this->cur_speed / 2; }
int GetDisplayMaxSpeed() const { return this->max_speed / 2; }
- Money GetRunningCost() const { return RoadVehInfo(this->engine_type)->running_cost * GetPriceByIndex(RoadVehInfo(this->engine_type)->running_cost_class); }
+
+ Money GetRunningCost() const
+ {
+ const RoadVehicleInfo *rvi = RoadVehInfo(this->engine_type);
+ return rvi->running_cost * GetPriceByIndex(rvi->running_cost_class);
+ }
+
int GetDisplayImageWidth(Point *offset = NULL) const;
bool IsInDepot() const { return this->state == RVSB_IN_DEPOT; }
bool IsStoppedInDepot() const;
diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp
index ef265a675..b23986b93 100644
--- a/src/roadveh_cmd.cpp
+++ b/src/roadveh_cmd.cpp
@@ -107,13 +107,14 @@ int RoadVehicle::GetDisplayImageWidth(Point *offset) const
static SpriteID GetRoadVehIcon(EngineID engine)
{
- uint8 spritenum = RoadVehInfo(engine)->image_index;
+ const Engine *e = Engine::Get(engine);
+ uint8 spritenum = e->u.road.image_index;
if (is_custom_sprite(spritenum)) {
SpriteID sprite = GetCustomVehicleIcon(engine, DIR_W);
if (sprite != 0) return sprite;
- spritenum = Engine::Get(engine)->original_image_index;
+ spritenum = e->original_image_index;
}
return DIR_W + _roadveh_images[spritenum];
@@ -201,7 +202,7 @@ CommandCost CmdBuildRoadVeh(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
if (!IsRoadDepotTile(tile)) return CMD_ERROR;
if (!IsTileOwner(tile, _current_company)) return CMD_ERROR;
- if (HasTileRoadType(tile, ROADTYPE_TRAM) != HasBit(EngInfo(p1)->misc_flags, EF_ROAD_TRAM)) return_cmd_error(STR_ERROR_DEPOT_WRONG_DEPOT_TYPE);
+ if (HasTileRoadType(tile, ROADTYPE_TRAM) != HasBit(e->info.misc_flags, EF_ROAD_TRAM)) return_cmd_error(STR_ERROR_DEPOT_WRONG_DEPOT_TYPE);
uint num_vehicles = 1 + CountArticulatedParts(p1, false);
@@ -217,7 +218,7 @@ CommandCost CmdBuildRoadVeh(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
}
if (flags & DC_EXEC) {
- const RoadVehicleInfo *rvi = RoadVehInfo(p1);
+ const RoadVehicleInfo *rvi = &e->u.road;
RoadVehicle *v = new RoadVehicle();
v->unitnumber = unit_num;
@@ -270,7 +271,7 @@ CommandCost CmdBuildRoadVeh(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
v->random_bits = VehicleRandomBits();
v->SetRoadVehFront();
- v->roadtype = HasBit(EngInfo(v->engine_type)->misc_flags, EF_ROAD_TRAM) ? ROADTYPE_TRAM : ROADTYPE_ROAD;
+ v->roadtype = HasBit(e->info.misc_flags, EF_ROAD_TRAM) ? ROADTYPE_TRAM : ROADTYPE_ROAD;
v->compatible_roadtypes = RoadTypeToRoadTypes(v->roadtype);
v->rcache.cached_veh_length = 8;
@@ -2029,7 +2030,7 @@ CommandCost CmdRefitRoadVeh(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
const Engine *e = Engine::Get(v->engine_type);
if (!e->CanCarryCargo()) continue;
- if (HasBit(EngInfo(v->engine_type)->callback_mask, CBM_VEHICLE_REFIT_CAPACITY)) {
+ if (HasBit(e->info.callback_mask, CBM_VEHICLE_REFIT_CAPACITY)) {
/* Back up the cargo type */
CargoID temp_cid = v->cargo_type;
byte temp_subtype = v->cargo_subtype;
diff --git a/src/ship_cmd.cpp b/src/ship_cmd.cpp
index 2971b35c1..d6818e46e 100644
--- a/src/ship_cmd.cpp
+++ b/src/ship_cmd.cpp
@@ -55,13 +55,14 @@ static inline TrackBits GetTileShipTrackStatus(TileIndex tile)
static SpriteID GetShipIcon(EngineID engine)
{
- uint8 spritenum = ShipVehInfo(engine)->image_index;
+ const Engine *e = Engine::Get(engine);
+ uint8 spritenum = e->u.ship.image_index;
if (is_custom_sprite(spritenum)) {
SpriteID sprite = GetCustomVehicleIcon(engine, DIR_W);
if (sprite != 0) return sprite;
- spritenum = Engine::Get(engine)->original_image_index;
+ spritenum = e->original_image_index;
}
return DIR_W + _ship_sprites[spritenum];
@@ -765,7 +766,7 @@ CommandCost CmdBuildShip(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
int x;
int y;
- const ShipVehicleInfo *svi = ShipVehInfo(p1);
+ const ShipVehicleInfo *svi = &e->u.ship;
Ship *v = new Ship();
v->unitnumber = unit_num;
@@ -919,11 +920,13 @@ CommandCost CmdRefitShip(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
if (!v->IsStoppedInDepot()) return_cmd_error(STR_ERROR_SHIP_MUST_BE_STOPPED_IN_DEPOT);
if (v->vehstatus & VS_CRASHED) return_cmd_error(STR_ERROR_CAN_T_REFIT_DESTROYED_VEHICLE);
+ const Engine *e = Engine::Get(v->engine_type);
+
/* Check cargo */
if (new_cid >= NUM_CARGO || !CanRefitTo(v->engine_type, new_cid)) return CMD_ERROR;
/* Check the refit capacity callback */
- if (HasBit(EngInfo(v->engine_type)->callback_mask, CBM_VEHICLE_REFIT_CAPACITY)) {
+ if (HasBit(e->info.callback_mask, CBM_VEHICLE_REFIT_CAPACITY)) {
/* Back up the existing cargo type */
CargoID temp_cid = v->cargo_type;
byte temp_subtype = v->cargo_subtype;
@@ -938,7 +941,7 @@ CommandCost CmdRefitShip(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
}
if (capacity == CALLBACK_FAILED) {
- capacity = GetVehicleProperty(v, PROP_SHIP_CARGO_CAPACITY, ShipVehInfo(v->engine_type)->capacity);
+ capacity = GetVehicleProperty(v, PROP_SHIP_CARGO_CAPACITY, e->u.ship.capacity);
}
_returned_refit_capacity = capacity;
diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp
index eaaf92524..d430bb817 100644
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -257,7 +257,7 @@ void TrainConsistChanged(Train *v, bool same_length)
const Engine *e_u = Engine::Get(u->engine_type);
const RailVehicleInfo *rvi_u = &e_u->u.rail;
- if (!HasBit(EngInfo(u->engine_type)->misc_flags, EF_RAIL_TILTS)) train_can_tilt = false;
+ if (!HasBit(e_u->info.misc_flags, EF_RAIL_TILTS)) train_can_tilt = false;
/* Cache wagon override sprite group. NULL is returned if there is none */
u->tcache.cached_override = GetWagonOverrideSpriteSet(u->engine_type, u->cargo_type, u->tcache.first_engine);
@@ -281,7 +281,7 @@ void TrainConsistChanged(Train *v, bool same_length)
}
/* Check powered wagon / visual effect callback */
- if (HasBit(EngInfo(u->engine_type)->callback_mask, CBM_TRAIN_WAGON_POWER)) {
+ if (HasBit(e_u->info.callback_mask, CBM_TRAIN_WAGON_POWER)) {
uint16 callback = GetVehicleCallback(CBID_TRAIN_WAGON_POWER, 0, 0, u->engine_type, u);
if (callback != CALLBACK_FAILED) u->tcache.cached_vis_effect = GB(callback, 0, 8);
@@ -323,7 +323,7 @@ void TrainConsistChanged(Train *v, bool same_length)
/* check the vehicle length (callback) */
uint16 veh_len = CALLBACK_FAILED;
- if (HasBit(EngInfo(u->engine_type)->callback_mask, CBM_VEHICLE_LENGTH)) {
+ if (HasBit(e_u->info.callback_mask, CBM_VEHICLE_LENGTH)) {
veh_len = GetVehicleCallback(CBID_VEHICLE_LENGTH, 0, 0, u->engine_type, u);
}
if (veh_len == CALLBACK_FAILED) veh_len = rvi_u->shorten_factor;
@@ -837,6 +837,7 @@ CommandCost CmdBuildRailVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1,
if (!IsEngineBuildable(p1, VEH_TRAIN, _current_company)) return_cmd_error(STR_ERROR_RAIL_VEHICLE_NOT_AVAILABLE);
const Engine *e = Engine::Get(p1);
+ const RailVehicleInfo *rvi = &e->u.rail;
CommandCost value(EXPENSES_NEW_VEHICLES, e->GetCost());
/* Engines with CT_INVALID should not be available */
@@ -849,7 +850,6 @@ CommandCost CmdBuildRailVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1,
if (!IsRailDepotTile(tile)) return CMD_ERROR;
if (!IsTileOwner(tile, _current_company)) return CMD_ERROR;
- const RailVehicleInfo *rvi = RailVehInfo(p1);
if (rvi->railveh_type == RAILVEH_WAGON) return CmdBuildRailWagon(p1, tile, flags);
uint num_vehicles =
@@ -2121,7 +2121,7 @@ CommandCost CmdRefitRailVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1,
if (e->CanCarryCargo()) {
uint16 amount = CALLBACK_FAILED;
- if (HasBit(EngInfo(v->engine_type)->callback_mask, CBM_VEHICLE_REFIT_CAPACITY)) {
+ if (HasBit(e->info.callback_mask, CBM_VEHICLE_REFIT_CAPACITY)) {
/* Back up the vehicle's cargo type */
CargoID temp_cid = v->cargo_type;
byte temp_subtype = v->cargo_subtype;
diff --git a/src/vehicle.cpp b/src/vehicle.cpp
index 2bde108f5..c1e99f85b 100644
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -701,7 +701,8 @@ CommandCost GetRefitCost(EngineID engine_type)
{
Money base_cost;
ExpensesType expense_type;
- switch (Engine::Get(engine_type)->type) {
+ const Engine *e = Engine::Get(engine_type);
+ switch (e->type) {
case VEH_SHIP:
base_cost = _price.ship_base;
expense_type = EXPENSES_SHIP_RUN;
@@ -718,14 +719,14 @@ CommandCost GetRefitCost(EngineID engine_type)
break;
case VEH_TRAIN:
- base_cost = 2 * ((RailVehInfo(engine_type)->railveh_type == RAILVEH_WAGON) ?
+ base_cost = 2 * ((e->u.rail.railveh_type == RAILVEH_WAGON) ?
_price.build_railwagon : _price.build_railvehicle);
expense_type = EXPENSES_TRAIN_RUN;
break;
default: NOT_REACHED();
}
- return CommandCost(expense_type, (EngInfo(engine_type)->refit_cost * base_cost) >> 10);
+ return CommandCost(expense_type, (e->info.refit_cost * base_cost) >> 10);
}
static void DoDrawVehicle(const Vehicle *v)
@@ -1248,6 +1249,14 @@ bool CanBuildVehicleInfrastructure(VehicleType type)
}
+/**
+ * Determines the livery for a vehicle.
+ * @param engine_type EngineID of the vehicle
+ * @param company Owner of the vehicle
+ * @param parent_engine_type EngineID of the front vehicle. INVALID_VEHICLE if vehicle is at front itself.
+ * @param v the vehicle. NULL if in purchase list etc.
+ * @return livery to use
+ */
const Livery *GetEngineLivery(EngineID engine_type, CompanyID company, EngineID parent_engine_type, const Vehicle *v)
{
const Company *c = Company::Get(company);
@@ -1262,19 +1271,17 @@ const Livery *GetEngineLivery(EngineID engine_type, CompanyID company, EngineID
switch (e->type) {
default: NOT_REACHED();
case VEH_TRAIN: {
- const RailVehicleInfo *rvi = RailVehInfo(engine_type);
- if (v != NULL && parent_engine_type != INVALID_ENGINE && (UsesWagonOverride(v) || (Train::From(v)->IsArticulatedPart() && rvi->railveh_type != RAILVEH_WAGON))) {
+ if (v != NULL && parent_engine_type != INVALID_ENGINE && (UsesWagonOverride(v) || (Train::From(v)->IsArticulatedPart() && e->u.rail.railveh_type != RAILVEH_WAGON))) {
/* Wagonoverrides use the coloir scheme of the front engine.
* Articulated parts use the colour scheme of the first part. (Not supported for articulated wagons) */
engine_type = parent_engine_type;
e = Engine::Get(engine_type);
- rvi = RailVehInfo(engine_type);
/* Note: Luckily cargo_type is not needed for engines */
}
if (cargo_type == CT_INVALID) cargo_type = e->GetDefaultCargoType();
if (cargo_type == CT_INVALID) cargo_type = CT_GOODS; // The vehicle does not carry anything, let's pick some freight cargo
- if (rvi->railveh_type == RAILVEH_WAGON) {
+ if (e->u.rail.railveh_type == RAILVEH_WAGON) {
if (!CargoSpec::Get(cargo_type)->is_freight) {
if (parent_engine_type == INVALID_ENGINE) {
scheme = LS_PASSENGER_WAGON_STEAM;
@@ -1292,9 +1299,9 @@ const Livery *GetEngineLivery(EngineID engine_type, CompanyID company, EngineID
scheme = LS_FREIGHT_WAGON;
}
} else {
- bool is_mu = HasBit(EngInfo(engine_type)->misc_flags, EF_RAIL_IS_MU);
+ bool is_mu = HasBit(e->info.misc_flags, EF_RAIL_IS_MU);
- switch (rvi->engclass) {
+ switch (e->u.rail.engclass) {
default: NOT_REACHED();
case EC_STEAM: scheme = LS_STEAM; break;
case EC_DIESEL: scheme = is_mu ? LS_DMU : LS_DIESEL; break;
@@ -1317,7 +1324,7 @@ const Livery *GetEngineLivery(EngineID engine_type, CompanyID company, EngineID
if (cargo_type == CT_INVALID) cargo_type = CT_GOODS; // The vehicle does not carry anything, let's pick some freight cargo
/* Important: Use Tram Flag of front part. Luckily engine_type refers to the front part here. */
- if (HasBit(EngInfo(engine_type)->misc_flags, EF_ROAD_TRAM)) {
+ if (HasBit(e->info.misc_flags, EF_ROAD_TRAM)) {
/* Tram */
scheme = IsCargoInClass(cargo_type, CC_PASSENGERS) ? LS_PASSENGER_TRAM : LS_FREIGHT_TRAM;
} else {
@@ -1359,8 +1366,10 @@ static SpriteID GetEngineColourMap(EngineID engine_type, CompanyID company, Engi
/* Return cached value if any */
if (map != PAL_NONE) return map;
+ const Engine *e = Engine::Get(engine_type);
+
/* Check if we should use the colour map callback */
- if (HasBit(EngInfo(engine_type)->callback_mask, CBM_VEHICLE_COLOUR_REMAP)) {
+ if (HasBit(e->info.callback_mask, CBM_VEHICLE_COLOUR_REMAP)) {
uint16 callback = GetVehicleCallback(CBID_VEHICLE_COLOUR_MAPPING, 0, 0, engine_type, v);
/* A return value of 0xC000 is stated to "use the default two-colour
* maps" which happens to be the failure action too... */
@@ -1376,7 +1385,7 @@ static SpriteID GetEngineColourMap(EngineID engine_type, CompanyID company, Engi
}
}
- bool twocc = HasBit(EngInfo(engine_type)->misc_flags, EF_USES_2CC);
+ bool twocc = HasBit(e->info.misc_flags, EF_USES_2CC);
if (map == PAL_NONE) map = twocc ? (SpriteID)SPR_2CCMAP_BASE : (SpriteID)PALETTE_RECOLOUR_START;
diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp
index 9184e778d..fc1e4abb3 100644
--- a/src/vehicle_gui.cpp
+++ b/src/vehicle_gui.cpp
@@ -161,8 +161,9 @@ static RefitList *BuildRefitList(const Vehicle *v)
uint i;
do {
- uint32 cmask = EngInfo(u->engine_type)->refit_mask;
- byte callback_mask = EngInfo(u->engine_type)->callback_mask;
+ const Engine *e = Engine::Get(u->engine_type);
+ uint32 cmask = e->info.refit_mask;
+ byte callback_mask = e->info.callback_mask;
/* Skip this engine if it has no capacity */
if (u->cargo_cap == 0) continue;