Changeset - r18228:6cd8bae37157
[Not reviewed]
master
0 13 0
frosch - 13 years ago 2011-11-01 00:21:08
frosch@openttd.org
(svn r23074) -Codechange: Add Vehicle::GetEngine() to simplify code.
13 files changed with 45 insertions and 33 deletions:
0 comments (0 inline, 0 general)
src/aircraft_cmd.cpp
Show inline comments
 
@@ -151,7 +151,7 @@ SpriteID Aircraft::GetImage(Direction di
 
		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(
 

	
 
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_AtTermi
 
				/* 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);
 
			}
 
		}
src/articulated_vehicles.cpp
Show inline comments
 
@@ -251,7 +251,7 @@ bool IsArticulatedVehicleCarryingDiffere
 
 */
 
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);
src/economy.cpp
Show inline comments
 
@@ -1201,7 +1201,7 @@ static void LoadUnloadVehicle(Vehicle *f
 
	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 */
src/newgrf_engine.cpp
Show inline comments
 
@@ -618,7 +618,7 @@ static uint32 VehicleGetVariable(Vehicle
 
			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
 
		/* 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
 
		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;
src/roadveh_cmd.cpp
Show inline comments
 
@@ -127,7 +127,7 @@ SpriteID RoadVehicle::GetImage(Direction
 
		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(RoadVehicl
 

	
 
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);
src/saveload/vehicle_sl.cpp
Show inline comments
 
@@ -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;
src/ship_cmd.cpp
Show inline comments
 
@@ -107,7 +107,7 @@ SpriteID Ship::GetImage(Direction direct
 
		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);
 
}
src/table/newgrf_debug_data.h
Show inline comments
 
@@ -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); }
 
};
 

	
src/train_cmd.cpp
Show inline comments
 
@@ -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_len
 
	}
 

	
 
	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 *o
 
	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 direc
 
		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);
src/vehicle.cpp
Show inline comments
 
@@ -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 Vehicl
 
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(DoComma
 
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;
src/vehicle_base.h
Show inline comments
 
@@ -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
src/vehicle_cmd.cpp
Show inline comments
 
@@ -273,7 +273,7 @@ static CommandCost RefitVehicle(Vehicle 
 
	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 ti
 
					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) {
src/vehicle_gui.cpp
Show inline comments
 
@@ -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;
 

	
0 comments (0 inline, 0 general)