1
0
Fork 0

(svn r17725) -Codechange: Reduce usage of EngInfo and XxxVehInfo, esp. when a Engine * is already present.

release/1.0
frosch 2009-10-06 19:17:07 +00:00
parent 95dfee1c60
commit f3aacb8fe3
12 changed files with 88 additions and 68 deletions

View File

@ -111,6 +111,7 @@ static StationID FindNearestHangar(const Aircraft *v)
uint best = 0; uint best = 0;
StationID index = INVALID_STATION; StationID index = INVALID_STATION;
TileIndex vtile = TileVirtXY(v->x_pos, v->y_pos); TileIndex vtile = TileVirtXY(v->x_pos, v->y_pos);
const AircraftVehicleInfo *avi = AircraftVehInfo(v->engine_type);
FOR_ALL_STATIONS(st) { FOR_ALL_STATIONS(st) {
if (st->owner != v->owner || !(st->facilities & FACIL_AIRPORT)) continue; 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 || ( if (afc->nof_depots == 0 || (
/* don't crash the plane if we know it can't land at the airport */ /* don't crash the plane if we know it can't land at the airport */
(afc->flags & AirportFTAClass::SHORT_STRIP) && (afc->flags & AirportFTAClass::SHORT_STRIP) &&
(AircraftVehInfo(v->engine_type)->subtype & AIR_FAST) && (avi->subtype & AIR_FAST) &&
!_cheats.no_jetcrash.value)) { !_cheats.no_jetcrash.value)) {
continue; continue;
} }
@ -185,13 +186,14 @@ SpriteID GetRotorImage(const Aircraft *v)
static SpriteID GetAircraftIcon(EngineID engine) 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)) { if (is_custom_sprite(spritenum)) {
SpriteID sprite = GetCustomVehicleIcon(engine, DIR_W); SpriteID sprite = GetCustomVehicleIcon(engine, DIR_W);
if (sprite != 0) return sprite; if (sprite != 0) return sprite;
spritenum = Engine::Get(engine)->original_image_index; spritenum = e->original_image_index;
} }
return DIR_W + _aircraft_sprite[spritenum]; 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); 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 Engine *e = Engine::Get(p1);
const AircraftVehicleInfo *avi = &e->u.air;
CommandCost value(EXPENSES_NEW_VEHICLES, e->GetCost()); CommandCost value(EXPENSES_NEW_VEHICLES, e->GetCost());
/* Engines without valid cargo should not be available */ /* 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) { if (v->cargo_type != CT_PASSENGERS) {
uint16 callback = CALLBACK_FAILED; 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); 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); CargoID new_cid = GB(p2, 0, 8);
if (new_cid >= NUM_CARGO || !CanRefitTo(v->engine_type, new_cid)) return CMD_ERROR; 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 */ /* Check the refit capacity callback */
uint16 callback = CALLBACK_FAILED; 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 */ /* Back up the existing cargo type */
CargoID temp_cid = v->cargo_type; CargoID temp_cid = v->cargo_type;
byte temp_subtype = v->cargo_subtype; byte temp_subtype = v->cargo_subtype;
@ -553,13 +557,11 @@ CommandCost CmdRefitAircraft(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
v->cargo_subtype = temp_subtype; v->cargo_subtype = temp_subtype;
} }
const AircraftVehicleInfo *avi = AircraftVehInfo(v->engine_type);
uint pass; uint pass;
if (callback == CALLBACK_FAILED) { if (callback == CALLBACK_FAILED) {
/* If the callback failed, or wasn't executed, use the aircraft's /* If the callback failed, or wasn't executed, use the aircraft's
* default cargo capacity */ * default cargo capacity */
pass = AircraftDefaultCargoCapacity(new_cid, avi); pass = AircraftDefaultCargoCapacity(new_cid, &e->u.air);
} else { } else {
pass = callback; pass = callback;
} }
@ -574,7 +576,7 @@ CommandCost CmdRefitAircraft(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
v->cargo_cap = pass; v->cargo_cap = pass;
Vehicle *u = v->Next(); 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; u->cargo_cap = mail;
v->cargo.Truncate(v->cargo_type == new_cid ? pass : 0); v->cargo.Truncate(v->cargo_type == new_cid ? pass : 0);
u->cargo.Truncate(v->cargo_type == new_cid ? mail : 0); u->cargo.Truncate(v->cargo_type == new_cid ? mail : 0);

View File

@ -56,32 +56,31 @@ bool CheckAutoreplaceValidity(EngineID from, EngineID to, CompanyID company)
/* we can't replace an engine into itself (that would be autorenew) */ /* we can't replace an engine into itself (that would be autorenew) */
if (from == to) return false; 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 */ /* 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; if (!IsEngineBuildable(to, type, company)) return false;
switch (type) { switch (type) {
case VEH_TRAIN: { case VEH_TRAIN: {
const RailVehicleInfo *rvi_from = RailVehInfo(from);
const RailVehicleInfo *rvi_to = RailVehInfo(to);
/* make sure the railtypes are compatible */ /* 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 */ /* 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; break;
} }
case VEH_ROAD: case VEH_ROAD:
/* make sure that we do not replace a tram with a normal road vehicles or vise versa */ /* 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; break;
case VEH_AIRCRAFT: case VEH_AIRCRAFT:
/* make sure that we do not replace a plane with a helicopter or vise versa */ /* 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; break;
default: break; default: break;

View File

@ -298,8 +298,8 @@ static int CDECL AircraftEngineCargoSorter(const EngineID *a, const EngineID *b)
if (r == 0) { if (r == 0) {
/* The planes has the same passenger capacity. Check mail capacity instead */ /* The planes has the same passenger capacity. Check mail capacity instead */
va = AircraftVehInfo(*a)->mail_capacity; va = e_a->u.air.mail_capacity;
vb = AircraftVehInfo(*b)->mail_capacity; vb = e_b->u.air.mail_capacity;
r = va - vb; r = va - vb;
if (r == 0) { if (r == 0) {
@ -633,11 +633,10 @@ int DrawVehiclePurchaseInfo(int left, int right, int y, EngineID engine_number)
switch (e->type) { switch (e->type) {
default: NOT_REACHED(); default: NOT_REACHED();
case VEH_TRAIN: { case VEH_TRAIN: {
const RailVehicleInfo *rvi = RailVehInfo(engine_number); if (e->u.rail.railveh_type == RAILVEH_WAGON) {
if (rvi->railveh_type == RAILVEH_WAGON) { y = DrawRailWagonPurchaseInfo(left, right, y, engine_number, &e->u.rail);
y = DrawRailWagonPurchaseInfo(left, right, y, engine_number, rvi);
} else { } 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 */ /* Cargo type + capacity, or N/A */
@ -670,15 +669,15 @@ int DrawVehiclePurchaseInfo(int left, int right, int y, EngineID engine_number)
break; break;
} }
case VEH_SHIP: 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; break;
case VEH_AIRCRAFT: 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; break;
} }
/* Draw details, that applies to all types except rail wagons */ /* 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 */ /* Design date - Life length */
SetDParam(0, ymd.year); SetDParam(0, ymd.year);
SetDParam(1, e->GetLifeLengthInDays() / DAYS_IN_LEAP_YEAR); SetDParam(1, e->GetLifeLengthInDays() / DAYS_IN_LEAP_YEAR);

View File

@ -1139,12 +1139,13 @@ static void LoadUnloadVehicle(Vehicle *v, int *cargo_left)
for (; v != NULL; v = v->Next()) { for (; v != NULL; v = v->Next()) {
if (v->cargo_cap == 0) continue; 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 */ /* 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 (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); 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); if (cb_load_amount != CALLBACK_FAILED && GB(cb_load_amount, 0, 8) != 0) load_amount = GB(cb_load_amount, 0, 8);
} }

View File

@ -523,12 +523,10 @@ static void AcceptEnginePreview(EngineID eid, CompanyID company)
SetBit(e->company_avail, company); SetBit(e->company_avail, company);
if (e->type == VEH_TRAIN) { if (e->type == VEH_TRAIN) {
const RailVehicleInfo *rvi = RailVehInfo(eid); assert(e->u.rail.railtype < RAILTYPE_END);
SetBit(c->avail_railtypes, e->u.rail.railtype);
assert(rvi->railtype < RAILTYPE_END);
SetBit(c->avail_railtypes, rvi->railtype);
} else if (e->type == VEH_ROAD) { } 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; e->preview_company_rank = 0xFF;
@ -765,7 +763,7 @@ bool IsEngineBuildable(EngineID engine, VehicleType type, CompanyID company)
if (type == VEH_TRAIN) { if (type == VEH_TRAIN) {
/* Check if the rail type is available to this company */ /* Check if the rail type is available to this company */
const Company *c = Company::Get(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; return true;

View File

@ -30,13 +30,14 @@
*/ */
StringID GetEngineCategoryName(EngineID engine) StringID GetEngineCategoryName(EngineID engine)
{ {
switch (Engine::Get(engine)->type) { const Engine *e = Engine::Get(engine);
switch (e->type) {
default: NOT_REACHED(); default: NOT_REACHED();
case VEH_ROAD: return STR_ENGINE_PREVIEW_ROAD_VEHICLE; case VEH_ROAD: return STR_ENGINE_PREVIEW_ROAD_VEHICLE;
case VEH_AIRCRAFT: return STR_ENGINE_PREVIEW_AIRCRAFT; case VEH_AIRCRAFT: return STR_ENGINE_PREVIEW_AIRCRAFT;
case VEH_SHIP: return STR_ENGINE_PREVIEW_SHIP; case VEH_SHIP: return STR_ENGINE_PREVIEW_SHIP;
case VEH_TRAIN: case VEH_TRAIN:
return GetRailTypeInfo(RailVehInfo(engine)->railtype)->strings.new_loco; return GetRailTypeInfo(e->u.rail.railtype)->strings.new_loco;
} }
} }

View File

@ -123,7 +123,13 @@ struct RoadVehicle : public SpecializedVehicle<RoadVehicle, VEH_ROAD> {
SpriteID GetImage(Direction direction) const; SpriteID GetImage(Direction direction) const;
int GetDisplaySpeed() const { return this->cur_speed / 2; } int GetDisplaySpeed() const { return this->cur_speed / 2; }
int GetDisplayMaxSpeed() const { return this->max_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; int GetDisplayImageWidth(Point *offset = NULL) const;
bool IsInDepot() const { return this->state == RVSB_IN_DEPOT; } bool IsInDepot() const { return this->state == RVSB_IN_DEPOT; }
bool IsStoppedInDepot() const; bool IsStoppedInDepot() const;

View File

@ -107,13 +107,14 @@ int RoadVehicle::GetDisplayImageWidth(Point *offset) const
static SpriteID GetRoadVehIcon(EngineID engine) 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)) { if (is_custom_sprite(spritenum)) {
SpriteID sprite = GetCustomVehicleIcon(engine, DIR_W); SpriteID sprite = GetCustomVehicleIcon(engine, DIR_W);
if (sprite != 0) return sprite; if (sprite != 0) return sprite;
spritenum = Engine::Get(engine)->original_image_index; spritenum = e->original_image_index;
} }
return DIR_W + _roadveh_images[spritenum]; 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 (!IsRoadDepotTile(tile)) return CMD_ERROR;
if (!IsTileOwner(tile, _current_company)) 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); uint num_vehicles = 1 + CountArticulatedParts(p1, false);
@ -217,7 +218,7 @@ CommandCost CmdBuildRoadVeh(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
} }
if (flags & DC_EXEC) { if (flags & DC_EXEC) {
const RoadVehicleInfo *rvi = RoadVehInfo(p1); const RoadVehicleInfo *rvi = &e->u.road;
RoadVehicle *v = new RoadVehicle(); RoadVehicle *v = new RoadVehicle();
v->unitnumber = unit_num; v->unitnumber = unit_num;
@ -270,7 +271,7 @@ CommandCost CmdBuildRoadVeh(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
v->random_bits = VehicleRandomBits(); v->random_bits = VehicleRandomBits();
v->SetRoadVehFront(); 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->compatible_roadtypes = RoadTypeToRoadTypes(v->roadtype);
v->rcache.cached_veh_length = 8; 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); const Engine *e = Engine::Get(v->engine_type);
if (!e->CanCarryCargo()) continue; 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 */ /* Back up the cargo type */
CargoID temp_cid = v->cargo_type; CargoID temp_cid = v->cargo_type;
byte temp_subtype = v->cargo_subtype; byte temp_subtype = v->cargo_subtype;

View File

@ -55,13 +55,14 @@ static inline TrackBits GetTileShipTrackStatus(TileIndex tile)
static SpriteID GetShipIcon(EngineID engine) 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)) { if (is_custom_sprite(spritenum)) {
SpriteID sprite = GetCustomVehicleIcon(engine, DIR_W); SpriteID sprite = GetCustomVehicleIcon(engine, DIR_W);
if (sprite != 0) return sprite; if (sprite != 0) return sprite;
spritenum = Engine::Get(engine)->original_image_index; spritenum = e->original_image_index;
} }
return DIR_W + _ship_sprites[spritenum]; return DIR_W + _ship_sprites[spritenum];
@ -765,7 +766,7 @@ CommandCost CmdBuildShip(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
int x; int x;
int y; int y;
const ShipVehicleInfo *svi = ShipVehInfo(p1); const ShipVehicleInfo *svi = &e->u.ship;
Ship *v = new Ship(); Ship *v = new Ship();
v->unitnumber = unit_num; 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->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); 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 */ /* Check cargo */
if (new_cid >= NUM_CARGO || !CanRefitTo(v->engine_type, new_cid)) return CMD_ERROR; if (new_cid >= NUM_CARGO || !CanRefitTo(v->engine_type, new_cid)) return CMD_ERROR;
/* Check the refit capacity callback */ /* 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 */ /* Back up the existing cargo type */
CargoID temp_cid = v->cargo_type; CargoID temp_cid = v->cargo_type;
byte temp_subtype = v->cargo_subtype; byte temp_subtype = v->cargo_subtype;
@ -938,7 +941,7 @@ CommandCost CmdRefitShip(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
} }
if (capacity == CALLBACK_FAILED) { 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; _returned_refit_capacity = capacity;

View File

@ -257,7 +257,7 @@ void TrainConsistChanged(Train *v, bool same_length)
const Engine *e_u = Engine::Get(u->engine_type); const Engine *e_u = Engine::Get(u->engine_type);
const RailVehicleInfo *rvi_u = &e_u->u.rail; 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 */ /* 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); 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 */ /* 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); 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); 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) */ /* check the vehicle length (callback) */
uint16 veh_len = CALLBACK_FAILED; 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); veh_len = GetVehicleCallback(CBID_VEHICLE_LENGTH, 0, 0, u->engine_type, u);
} }
if (veh_len == CALLBACK_FAILED) veh_len = rvi_u->shorten_factor; 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); if (!IsEngineBuildable(p1, VEH_TRAIN, _current_company)) return_cmd_error(STR_ERROR_RAIL_VEHICLE_NOT_AVAILABLE);
const Engine *e = Engine::Get(p1); const Engine *e = Engine::Get(p1);
const RailVehicleInfo *rvi = &e->u.rail;
CommandCost value(EXPENSES_NEW_VEHICLES, e->GetCost()); CommandCost value(EXPENSES_NEW_VEHICLES, e->GetCost());
/* Engines with CT_INVALID should not be available */ /* 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 (!IsRailDepotTile(tile)) return CMD_ERROR;
if (!IsTileOwner(tile, _current_company)) 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); if (rvi->railveh_type == RAILVEH_WAGON) return CmdBuildRailWagon(p1, tile, flags);
uint num_vehicles = uint num_vehicles =
@ -2121,7 +2121,7 @@ CommandCost CmdRefitRailVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1,
if (e->CanCarryCargo()) { if (e->CanCarryCargo()) {
uint16 amount = CALLBACK_FAILED; 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 */ /* Back up the vehicle's cargo type */
CargoID temp_cid = v->cargo_type; CargoID temp_cid = v->cargo_type;
byte temp_subtype = v->cargo_subtype; byte temp_subtype = v->cargo_subtype;

View File

@ -701,7 +701,8 @@ CommandCost GetRefitCost(EngineID engine_type)
{ {
Money base_cost; Money base_cost;
ExpensesType expense_type; ExpensesType expense_type;
switch (Engine::Get(engine_type)->type) { const Engine *e = Engine::Get(engine_type);
switch (e->type) {
case VEH_SHIP: case VEH_SHIP:
base_cost = _price.ship_base; base_cost = _price.ship_base;
expense_type = EXPENSES_SHIP_RUN; expense_type = EXPENSES_SHIP_RUN;
@ -718,14 +719,14 @@ CommandCost GetRefitCost(EngineID engine_type)
break; break;
case VEH_TRAIN: 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); _price.build_railwagon : _price.build_railvehicle);
expense_type = EXPENSES_TRAIN_RUN; expense_type = EXPENSES_TRAIN_RUN;
break; break;
default: NOT_REACHED(); 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) 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 Livery *GetEngineLivery(EngineID engine_type, CompanyID company, EngineID parent_engine_type, const Vehicle *v)
{ {
const Company *c = Company::Get(company); const Company *c = Company::Get(company);
@ -1262,19 +1271,17 @@ const Livery *GetEngineLivery(EngineID engine_type, CompanyID company, EngineID
switch (e->type) { switch (e->type) {
default: NOT_REACHED(); default: NOT_REACHED();
case VEH_TRAIN: { case VEH_TRAIN: {
const RailVehicleInfo *rvi = RailVehInfo(engine_type); if (v != NULL && parent_engine_type != INVALID_ENGINE && (UsesWagonOverride(v) || (Train::From(v)->IsArticulatedPart() && e->u.rail.railveh_type != RAILVEH_WAGON))) {
if (v != NULL && parent_engine_type != INVALID_ENGINE && (UsesWagonOverride(v) || (Train::From(v)->IsArticulatedPart() && rvi->railveh_type != RAILVEH_WAGON))) {
/* Wagonoverrides use the coloir scheme of the front engine. /* Wagonoverrides use the coloir scheme of the front engine.
* Articulated parts use the colour scheme of the first part. (Not supported for articulated wagons) */ * Articulated parts use the colour scheme of the first part. (Not supported for articulated wagons) */
engine_type = parent_engine_type; engine_type = parent_engine_type;
e = Engine::Get(engine_type); e = Engine::Get(engine_type);
rvi = RailVehInfo(engine_type);
/* Note: Luckily cargo_type is not needed for engines */ /* 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 = e->GetDefaultCargoType();
if (cargo_type == CT_INVALID) cargo_type = CT_GOODS; // The vehicle does not carry anything, let's pick some freight cargo 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 (!CargoSpec::Get(cargo_type)->is_freight) {
if (parent_engine_type == INVALID_ENGINE) { if (parent_engine_type == INVALID_ENGINE) {
scheme = LS_PASSENGER_WAGON_STEAM; scheme = LS_PASSENGER_WAGON_STEAM;
@ -1292,9 +1299,9 @@ const Livery *GetEngineLivery(EngineID engine_type, CompanyID company, EngineID
scheme = LS_FREIGHT_WAGON; scheme = LS_FREIGHT_WAGON;
} }
} else { } 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(); default: NOT_REACHED();
case EC_STEAM: scheme = LS_STEAM; break; case EC_STEAM: scheme = LS_STEAM; break;
case EC_DIESEL: scheme = is_mu ? LS_DMU : LS_DIESEL; 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 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. */ /* 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 */ /* Tram */
scheme = IsCargoInClass(cargo_type, CC_PASSENGERS) ? LS_PASSENGER_TRAM : LS_FREIGHT_TRAM; scheme = IsCargoInClass(cargo_type, CC_PASSENGERS) ? LS_PASSENGER_TRAM : LS_FREIGHT_TRAM;
} else { } else {
@ -1359,8 +1366,10 @@ static SpriteID GetEngineColourMap(EngineID engine_type, CompanyID company, Engi
/* Return cached value if any */ /* Return cached value if any */
if (map != PAL_NONE) return map; if (map != PAL_NONE) return map;
const Engine *e = Engine::Get(engine_type);
/* Check if we should use the colour map callback */ /* 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); 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 /* A return value of 0xC000 is stated to "use the default two-colour
* maps" which happens to be the failure action too... */ * 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; if (map == PAL_NONE) map = twocc ? (SpriteID)SPR_2CCMAP_BASE : (SpriteID)PALETTE_RECOLOUR_START;

View File

@ -161,8 +161,9 @@ static RefitList *BuildRefitList(const Vehicle *v)
uint i; uint i;
do { do {
uint32 cmask = EngInfo(u->engine_type)->refit_mask; const Engine *e = Engine::Get(u->engine_type);
byte callback_mask = EngInfo(u->engine_type)->callback_mask; uint32 cmask = e->info.refit_mask;
byte callback_mask = e->info.callback_mask;
/* Skip this engine if it has no capacity */ /* Skip this engine if it has no capacity */
if (u->cargo_cap == 0) continue; if (u->cargo_cap == 0) continue;