diff options
author | frosch <frosch@openttd.org> | 2011-11-01 00:21:08 +0000 |
---|---|---|
committer | frosch <frosch@openttd.org> | 2011-11-01 00:21:08 +0000 |
commit | 72cd855978bf45fd444eae72551a12e13a35b0c8 (patch) | |
tree | b7f4b3cc07022ba32160f5e67f4cb5a527266d12 | |
parent | c366e0d45f87f9ba625ed73cbf5bff61d8483c5c (diff) | |
download | openttd-72cd855978bf45fd444eae72551a12e13a35b0c8.tar.xz |
(svn r23074) -Codechange: Add Vehicle::GetEngine() to simplify code.
-rw-r--r-- | src/aircraft_cmd.cpp | 6 | ||||
-rw-r--r-- | src/articulated_vehicles.cpp | 2 | ||||
-rw-r--r-- | src/economy.cpp | 2 | ||||
-rw-r--r-- | src/newgrf_engine.cpp | 10 | ||||
-rw-r--r-- | src/roadveh_cmd.cpp | 4 | ||||
-rw-r--r-- | src/saveload/vehicle_sl.cpp | 2 | ||||
-rw-r--r-- | src/ship_cmd.cpp | 4 | ||||
-rw-r--r-- | src/table/newgrf_debug_data.h | 6 | ||||
-rw-r--r-- | src/train_cmd.cpp | 10 | ||||
-rw-r--r-- | src/vehicle.cpp | 20 | ||||
-rw-r--r-- | src/vehicle_base.h | 2 | ||||
-rw-r--r-- | src/vehicle_cmd.cpp | 4 | ||||
-rw-r--r-- | src/vehicle_gui.cpp | 6 |
13 files changed, 45 insertions, 33 deletions
diff --git a/src/aircraft_cmd.cpp b/src/aircraft_cmd.cpp index 7475e412f..3996e739d 100644 --- a/src/aircraft_cmd.cpp +++ b/src/aircraft_cmd.cpp @@ -151,7 +151,7 @@ SpriteID Aircraft::GetImage(Direction direction) const SpriteID sprite = GetCustomVehicleSprite(this, direction); if (sprite != 0) return sprite; - spritenum = Engine::Get(this->engine_type)->original_image_index; + spritenum = this->GetEngine()->original_image_index; } return direction + _aircraft_sprite[spritenum]; @@ -389,7 +389,7 @@ static void CheckIfAircraftNeedsService(Aircraft *v) Money Aircraft::GetRunningCost() const { - const Engine *e = Engine::Get(this->engine_type); + const Engine *e = this->GetEngine(); uint cost_factor = GetVehicleProperty(this, PROP_AIRCRAFT_RUNNING_COST_FACTOR, e->u.air.running_cost); return GetPrice(PR_RUNNING_AIRCRAFT, cost_factor, e->grf_prop.grffile); } @@ -1364,7 +1364,7 @@ static void AircraftEventHandler_AtTerminal(Aircraft *v, const AirportFTAClass * /* an exerpt of ServiceAircraft, without the invisibility stuff */ v->date_of_last_service = _date; v->breakdowns_since_last_service = 0; - v->reliability = Engine::Get(v->engine_type)->reliability; + v->reliability = v->GetEngine()->reliability; SetWindowDirty(WC_VEHICLE_DETAILS, v->index); } } diff --git a/src/articulated_vehicles.cpp b/src/articulated_vehicles.cpp index 2350dcb92..f186915b9 100644 --- a/src/articulated_vehicles.cpp +++ b/src/articulated_vehicles.cpp @@ -251,7 +251,7 @@ bool IsArticulatedVehicleCarryingDifferentCargos(const Vehicle *v, CargoID *carg */ void CheckConsistencyOfArticulatedVehicle(const Vehicle *v) { - const Engine *engine = Engine::Get(v->engine_type); + const Engine *engine = v->GetEngine(); uint32 purchase_refit_union, purchase_refit_intersection; GetArticulatedRefitMasks(v->engine_type, true, &purchase_refit_union, &purchase_refit_intersection); diff --git a/src/economy.cpp b/src/economy.cpp index 84b1bc4c5..8da463fa0 100644 --- a/src/economy.cpp +++ b/src/economy.cpp @@ -1201,7 +1201,7 @@ static void LoadUnloadVehicle(Vehicle *front, int *cargo_left) for (Vehicle *v = front; v != NULL; v = v->Next()) { if (v->cargo_cap == 0) continue; - const Engine *e = Engine::Get(v->engine_type); + const Engine *e = v->GetEngine(); byte load_amount = e->info.load_amount; /* The default loadamount for mail is 1/4 of the load amount for passengers */ diff --git a/src/newgrf_engine.cpp b/src/newgrf_engine.cpp index 71737e2ab..060f3b51f 100644 --- a/src/newgrf_engine.cpp +++ b/src/newgrf_engine.cpp @@ -618,7 +618,7 @@ static uint32 VehicleGetVariable(Vehicle *v, const ResolverObject *object, byte return (cs->classes << 16) | (cs->weight << 8) | GetEngineGRF(v->engine_type)->cargo_map[v->cargo_type]; } - case 0x48: return Engine::Get(v->engine_type)->flags; // Vehicle Type Info + case 0x48: return v->GetEngine()->flags; // Vehicle Type Info case 0x49: return v->build_year; case 0x4A: { @@ -633,12 +633,12 @@ static uint32 VehicleGetVariable(Vehicle *v, const ResolverObject *object, byte /* Variables which use the parameter */ case 0x60: // Count consist's engine ID occurance //EngineID engine = GetNewEngineID(GetEngineGRF(v->engine_type), v->type, parameter); - if (v->type != VEH_TRAIN) return Engine::Get(v->engine_type)->grf_prop.local_id == parameter; + if (v->type != VEH_TRAIN) return v->GetEngine()->grf_prop.local_id == parameter; { uint count = 0; for (; v != NULL; v = v->Next()) { - if (Engine::Get(v->engine_type)->grf_prop.local_id == parameter) count++; + if (v->GetEngine()->grf_prop.local_id == parameter) count++; } return count; } @@ -776,8 +776,8 @@ static uint32 VehicleGetVariable(Vehicle *v, const ResolverObject *object, byte case 0x43: return GB(ClampToU16(v->max_age), 8, 8); case 0x44: return Clamp(v->build_year, ORIGINAL_BASE_YEAR, ORIGINAL_MAX_YEAR) - ORIGINAL_BASE_YEAR; case 0x45: return v->unitnumber; - case 0x46: return Engine::Get(v->engine_type)->grf_prop.local_id; - case 0x47: return GB(Engine::Get(v->engine_type)->grf_prop.local_id, 8, 8); + case 0x46: return v->GetEngine()->grf_prop.local_id; + case 0x47: return GB(v->GetEngine()->grf_prop.local_id, 8, 8); case 0x48: if (v->type != VEH_TRAIN || v->spritenum != 0xFD) return v->spritenum; return HasBit(Train::From(v)->flags, VRF_REVERSE_DIRECTION) ? 0xFE : 0xFD; diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp index 15c2bf49a..a77fa38bb 100644 --- a/src/roadveh_cmd.cpp +++ b/src/roadveh_cmd.cpp @@ -127,7 +127,7 @@ SpriteID RoadVehicle::GetImage(Direction direction) const sprite = GetCustomVehicleSprite(this, (Direction)(direction + 4 * IS_CUSTOM_SECONDHEAD_SPRITE(spritenum))); if (sprite != 0) return sprite; - spritenum = Engine::Get(this->engine_type)->original_image_index; + spritenum = this->GetEngine()->original_image_index; } sprite = direction + _roadveh_images[spritenum]; @@ -1527,7 +1527,7 @@ static bool RoadVehController(RoadVehicle *v) Money RoadVehicle::GetRunningCost() const { - const Engine *e = Engine::Get(this->engine_type); + const Engine *e = this->GetEngine(); if (e->u.road.running_cost_class == INVALID_PRICE) return 0; uint cost_factor = GetVehicleProperty(this, PROP_ROADVEH_RUNNING_COST_FACTOR, e->u.road.running_cost); diff --git a/src/saveload/vehicle_sl.cpp b/src/saveload/vehicle_sl.cpp index 14827eb7b..f801e9988 100644 --- a/src/saveload/vehicle_sl.cpp +++ b/src/saveload/vehicle_sl.cpp @@ -226,7 +226,7 @@ static void CheckValidVehicles() case VEH_ROAD: case VEH_SHIP: case VEH_AIRCRAFT: - if (v->engine_type >= total_engines || v->type != Engine::Get(v->engine_type)->type) { + if (v->engine_type >= total_engines || v->type != v->GetEngine()->type) { v->engine_type = first_engine[v->type]; } break; diff --git a/src/ship_cmd.cpp b/src/ship_cmd.cpp index 3ea37f968..bf5e2da7d 100644 --- a/src/ship_cmd.cpp +++ b/src/ship_cmd.cpp @@ -107,7 +107,7 @@ SpriteID Ship::GetImage(Direction direction) const SpriteID sprite = GetCustomVehicleSprite(this, direction); if (sprite != 0) return sprite; - spritenum = Engine::Get(this->engine_type)->original_image_index; + spritenum = this->GetEngine()->original_image_index; } return _ship_sprites[spritenum] + direction; @@ -190,7 +190,7 @@ void Ship::UpdateCache() Money Ship::GetRunningCost() const { - const Engine *e = Engine::Get(this->engine_type); + const Engine *e = this->GetEngine(); uint cost_factor = GetVehicleProperty(this, PROP_SHIP_RUNNING_COST_FACTOR, e->u.ship.running_cost); return GetPrice(PR_RUNNING_SHIP, cost_factor, e->grf_prop.grffile); } diff --git a/src/table/newgrf_debug_data.h b/src/table/newgrf_debug_data.h index 0faf2979b..e7867e3aa 100644 --- a/src/table/newgrf_debug_data.h +++ b/src/table/newgrf_debug_data.h @@ -61,12 +61,12 @@ static const NIVariable _niv_vehicles[] = { }; class NIHVehicle : public NIHelper { - bool IsInspectable(uint index) const { return Engine::Get(Vehicle::Get(index)->engine_type)->grf_prop.grffile != NULL; } + bool IsInspectable(uint index) const { return Vehicle::Get(index)->GetEngine()->grf_prop.grffile != NULL; } uint GetParent(uint index) const { const Vehicle *first = Vehicle::Get(index)->First(); return GetInspectWindowNumber(GetGrfSpecFeature(first->type), first->index); } const void *GetInstance(uint index)const { return Vehicle::Get(index); } - const void *GetSpec(uint index) const { return Engine::Get(Vehicle::Get(index)->engine_type); } + const void *GetSpec(uint index) const { return Vehicle::Get(index)->GetEngine(); } void SetStringParameters(uint index) const { this->SetSimpleStringParameters(STR_VEHICLE_NAME, index); } - uint32 GetGRFID(uint index) const { return (this->IsInspectable(index)) ? Engine::Get(Vehicle::Get(index)->engine_type)->grf_prop.grffile->grfid : 0; } + uint32 GetGRFID(uint index) const { return (this->IsInspectable(index)) ? Vehicle::Get(index)->GetEngine()->grf_prop.grffile->grfid : 0; } void Resolve(ResolverObject *ro, uint32 index) const { extern void GetVehicleResolver(ResolverObject *ro, uint index); GetVehicleResolver(ro, index); } }; diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index a1e1e9d2e..c644b620e 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -92,7 +92,7 @@ byte FreightWagonMult(CargoID cargo) static void RailVehicleLengthChanged(const Train *u) { /* show a warning once for each engine in whole game and once for each GRF after each game load */ - const Engine *engine = Engine::Get(u->engine_type); + const Engine *engine = u->GetEngine(); uint32 grfid = engine->grf_prop.grffile->grfid; GRFConfig *grfconfig = GetGRFConfig(grfid); if (GamelogGRFBugReverse(grfid, engine->grf_prop.local_id) || !HasBit(grfconfig->grf_bugs, GBUG_VEH_LENGTH)) { @@ -189,7 +189,7 @@ void Train::ConsistChanged(bool same_length) } for (Train *u = this; u != NULL; u = u->Next()) { - const Engine *e_u = Engine::Get(u->engine_type); + const Engine *e_u = u->GetEngine(); const RailVehicleInfo *rvi_u = &e_u->u.rail; if (!HasBit(e_u->info.misc_flags, EF_RAIL_TILTS)) train_can_tilt = false; @@ -455,7 +455,7 @@ int Train::GetDisplayImageWidth(Point *offset) const int reference_width = TRAININFO_DEFAULT_VEHICLE_WIDTH; int vehicle_pitch = 0; - const Engine *e = Engine::Get(this->engine_type); + const Engine *e = this->GetEngine(); if (e->grf_prop.grffile != NULL && is_custom_sprite(e->u.rail.image_index)) { reference_width = e->grf_prop.grffile->traininfo_vehicle_width; vehicle_pitch = e->grf_prop.grffile->traininfo_vehicle_pitch; @@ -484,7 +484,7 @@ SpriteID Train::GetImage(Direction direction) const sprite = GetCustomVehicleSprite(this, (Direction)(direction + 4 * IS_CUSTOM_SECONDHEAD_SPRITE(spritenum))); if (sprite != 0) return sprite; - spritenum = Engine::Get(this->engine_type)->original_image_index; + spritenum = this->GetEngine()->original_image_index; } sprite = GetDefaultTrainSprite(spritenum, direction); @@ -3687,7 +3687,7 @@ Money Train::GetRunningCost() const const Train *v = this; do { - const Engine *e = Engine::Get(v->engine_type); + const Engine *e = v->GetEngine(); if (e->u.rail.running_cost_class == INVALID_PRICE) continue; uint cost_factor = GetVehicleProperty(v, PROP_TRAIN_RUNNING_COST_FACTOR, e->u.rail.running_cost); diff --git a/src/vehicle.cpp b/src/vehicle.cpp index e5c239dc8..5827b46da 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -92,7 +92,7 @@ void VehicleServiceInDepot(Vehicle *v) { v->date_of_last_service = _date; v->breakdowns_since_last_service = 0; - v->reliability = Engine::Get(v->engine_type)->reliability; + v->reliability = v->GetEngine()->reliability; SetWindowDirty(WC_VEHICLE_DETAILS, v->index); // ensure that last service date and reliability are updated } @@ -111,7 +111,7 @@ bool Vehicle::NeedsServicing() const /* Are we ready for the next service cycle? */ const Company *c = Company::Get(this->owner); if (c->settings.vehicle.servint_ispercent ? - (this->reliability >= Engine::Get(this->engine_type)->reliability * (100 - this->service_interval) / 100) : + (this->reliability >= this->GetEngine()->reliability * (100 - this->service_interval) / 100) : (this->date_of_last_service + this->service_interval >= _date)) { return false; } @@ -632,6 +632,16 @@ bool Vehicle::HasEngineType() const } /** + * Retrieves the engine of the vehicle. + * @return Engine of the vehicle. + * @pre HasEngineType() == true + */ +const Engine *Vehicle::GetEngine() const +{ + return Engine::Get(this->engine_type); +} + +/** * Handle the pathfinding result, especially the lost status. * If the vehicle is now lost and wasn't previously fire an * event to the AIs and a news message to the user. If the @@ -1158,7 +1168,7 @@ void AgeVehicle(Vehicle *v) if (v->Previous() != NULL || v->owner != _local_company || (v->vehstatus & VS_CRASHED) != 0) return; /* Don't warn if a renew is active */ - if (Company::Get(v->owner)->settings.engine_renew && Engine::Get(v->engine_type)->company_avail != 0) return; + if (Company::Get(v->owner)->settings.engine_renew && v->GetEngine()->company_avail != 0) return; StringID str; if (age == -DAYS_IN_LEAP_YEAR) { @@ -1756,7 +1766,7 @@ PaletteID GetVehiclePalette(const Vehicle *v) uint GetVehicleCapacity(const Vehicle *v, uint16 *mail_capacity) { if (mail_capacity != NULL) *mail_capacity = 0; - const Engine *e = Engine::Get(v->engine_type); + const Engine *e = v->GetEngine(); if (!e->CanCarryCargo()) return 0; @@ -2113,7 +2123,7 @@ CommandCost Vehicle::SendToDepot(DoCommandFlag flags, DepotCommand command) void Vehicle::UpdateVisualEffect(bool allow_power_change) { bool powered_before = HasBit(this->vcache.cached_vis_effect, VE_DISABLE_WAGON_POWER); - const Engine *e = Engine::Get(this->engine_type); + const Engine *e = this->GetEngine(); /* Evaluate properties */ byte visual_effect; diff --git a/src/vehicle_base.h b/src/vehicle_base.h index 5fc2500eb..4bfe59323 100644 --- a/src/vehicle_base.h +++ b/src/vehicle_base.h @@ -338,6 +338,8 @@ public: */ virtual bool IsPrimaryVehicle() const { return false; } + const Engine *GetEngine() const; + /** * Gets the sprite to show for the given direction * @param direction the direction the vehicle is facing diff --git a/src/vehicle_cmd.cpp b/src/vehicle_cmd.cpp index 22ebef2fb..48d8e42bb 100644 --- a/src/vehicle_cmd.cpp +++ b/src/vehicle_cmd.cpp @@ -273,7 +273,7 @@ static CommandCost RefitVehicle(Vehicle *v, bool only_this, uint8 num_vehicles, for (; v != NULL; v = (only_this ? NULL : v->Next())) { if (v->type == VEH_TRAIN && !vehicles_to_refit.Contains(v->index) && !only_this) continue; - const Engine *e = Engine::Get(v->engine_type); + const Engine *e = v->GetEngine(); if (!e->CanCarryCargo()) continue; /* If the vehicle is not refittable, count its capacity nevertheless if the cargo matches */ @@ -789,7 +789,7 @@ CommandCost CmdCloneVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint break; } } else { - const Engine *e = Engine::Get(v->engine_type); + const Engine *e = v->GetEngine(); CargoID initial_cargo = (e->CanCarryCargo() ? e->GetDefaultCargoType() : (CargoID)CT_INVALID); if (v->cargo_type != initial_cargo && initial_cargo != CT_INVALID) { diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp index c3cc8dade..2475b9b1b 100644 --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -217,8 +217,8 @@ static const uint MAX_REFIT_CYCLE = 256; */ byte GetBestFittingSubType(Vehicle *v_from, Vehicle *v_for) { - const Engine *e_from = Engine::Get(v_from->engine_type); - const Engine *e_for = Engine::Get(v_for->engine_type); + const Engine *e_from = v_from->GetEngine(); + const Engine *e_for = v_for->GetEngine(); /* If one them doesn't carry cargo, there's no need to find a sub type */ if (!e_from->CanCarryCargo() || !e_for->CanCarryCargo()) return 0; @@ -386,7 +386,7 @@ struct RefitWindow : public Window { do { if (v->type == VEH_TRAIN && !vehicles_to_refit.Contains(v->index)) continue; - const Engine *e = Engine::Get(v->engine_type); + const Engine *e = v->GetEngine(); uint32 cmask = e->info.refit_mask; byte callback_mask = e->info.callback_mask; |