(svn r15308) -Codechange: Deduplicate km-ish/h -> mph conversions.

This commit is contained in:
frosch 2009-02-01 17:14:39 +00:00
parent 317220c2e4
commit de9a6fc90b
13 changed files with 22 additions and 22 deletions

View File

@ -133,7 +133,7 @@ static void _DoCommandReturnBuildBridge1(class AIInstance *instance)
{
if (!IsValidBridge(bridge_id)) return -1;
return ::GetBridgeSpec(bridge_id)->speed;
return ::GetBridgeSpec(bridge_id)->speed; // km-ish/h
}
/* static */ Money AIBridge::GetPrice(BridgeID bridge_id, uint length)

View File

@ -119,7 +119,7 @@
if (!IsValidEngine(engine_id)) return -1;
const Engine *e = ::GetEngine(engine_id);
int32 max_speed = e->GetDisplayMaxSpeed() * 16 / 10; // convert mph to km-ish/h
int32 max_speed = e->GetDisplayMaxSpeed(); // km-ish/h
if (e->type == VEH_AIRCRAFT) max_speed /= _settings_game.vehicle.plane_speed;
return max_speed;
}

View File

@ -80,7 +80,7 @@ int32 AIEventEnginePreview::GetCapacity()
int32 AIEventEnginePreview::GetMaxSpeed()
{
const Engine *e = ::GetEngine(engine);
int32 max_speed = e->GetDisplayMaxSpeed() * 16 / 10; // convert mph to km-ish/h
int32 max_speed = e->GetDisplayMaxSpeed(); // km-ish/h
if (e->type == VEH_AIRCRAFT) max_speed /= _settings_game.vehicle.plane_speed;
return max_speed;
}

View File

@ -278,7 +278,7 @@
{
if (!IsValidVehicle(vehicle_id)) return -1;
return ::GetVehicle(vehicle_id)->GetDisplaySpeed() * 16 / 10;
return ::GetVehicle(vehicle_id)->GetDisplaySpeed(); // km-ish/h
}
/* static */ AIVehicle::VehicleState AIVehicle::GetState(VehicleID vehicle_id)

View File

@ -102,8 +102,8 @@ struct Aircraft : public Vehicle {
ExpensesType GetExpenseType(bool income) const { return income ? EXPENSES_AIRCRAFT_INC : EXPENSES_AIRCRAFT_RUN; }
bool IsPrimaryVehicle() const { return IsNormalAircraft(this); }
SpriteID GetImage(Direction direction) const;
int GetDisplaySpeed() const { return this->cur_speed * 10 / 16; }
int GetDisplayMaxSpeed() const { return this->max_speed * 10 / 16; }
int GetDisplaySpeed() const { return this->cur_speed; }
int GetDisplayMaxSpeed() const { return this->max_speed; }
Money GetRunningCost() const;
bool IsInDepot() const { return (this->vehstatus & VS_HIDDEN) != 0 && IsHangarTile(this->tile); }
void Tick();

View File

@ -165,7 +165,7 @@ public:
const BridgeSpec *b = this->bridges->Get(i)->spec;
SetDParam(2, this->bridges->Get(i)->cost);
SetDParam(1, b->speed * 10 / 16);
SetDParam(1, b->speed);
SetDParam(0, b->material);
DrawSprite(b->sprite, b->pal, 3, y);

View File

@ -156,22 +156,22 @@ Money Engine::GetCost() const
/**
* Returns max speed for display purposes
* @return max speed in mph
* @return max speed in km-ish/h
*/
uint Engine::GetDisplayMaxSpeed() const
{
switch (this->type) {
case VEH_TRAIN:
return GetEngineProperty(this->index, 0x09, this->u.rail.max_speed) * 10 / 16;
return GetEngineProperty(this->index, 0x09, this->u.rail.max_speed);
case VEH_ROAD:
return this->u.road.max_speed * 10 / 32;
return this->u.road.max_speed / 2;
case VEH_SHIP:
return GetEngineProperty(this->index, 0x0B, this->u.ship.max_speed) * 10 / 32;
return GetEngineProperty(this->index, 0x0B, this->u.ship.max_speed) / 2;
case VEH_AIRCRAFT:
return this->u.air.max_speed * 10 / 16;
return this->u.air.max_speed;
default: NOT_REACHED();
}

View File

@ -1590,7 +1590,7 @@ VehicleOrderID ProcessConditionalOrder(const Order *order, const Vehicle *v)
switch (order->GetConditionVariable()) {
case OCV_LOAD_PERCENTAGE: skip_order = OrderConditionCompare(occ, CalcPercentVehicleFilled(v, NULL), value); break;
case OCV_RELIABILITY: skip_order = OrderConditionCompare(occ, v->reliability * 100 >> 16, value); break;
case OCV_MAX_SPEED: skip_order = OrderConditionCompare(occ, v->GetDisplayMaxSpeed(), value); break;
case OCV_MAX_SPEED: skip_order = OrderConditionCompare(occ, v->GetDisplayMaxSpeed() * 10 / 16, value); break;
case OCV_AGE: skip_order = OrderConditionCompare(occ, v->age / DAYS_IN_LEAP_YEAR, value); break;
case OCV_REQUIRES_SERVICE: skip_order = OrderConditionCompare(occ, v->NeedsServicing(), value); break;
case OCV_UNCONDITIONALLY: skip_order = true; break;

View File

@ -74,8 +74,8 @@ struct RoadVehicle : public Vehicle {
ExpensesType GetExpenseType(bool income) const { return income ? EXPENSES_ROADVEH_INC : EXPENSES_ROADVEH_RUN; }
bool IsPrimaryVehicle() const { return IsRoadVehFront(this); }
SpriteID GetImage(Direction direction) const;
int GetDisplaySpeed() const { return this->cur_speed * 10 / 32; }
int GetDisplayMaxSpeed() const { return this->max_speed * 10 / 32; }
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); }
bool IsInDepot() const { return this->u.road.state == RVSB_IN_DEPOT; }
bool IsStoppedInDepot() const;

View File

@ -36,8 +36,8 @@ struct Ship: public Vehicle {
void PlayLeaveStationSound() const;
bool IsPrimaryVehicle() const { return true; }
SpriteID GetImage(Direction direction) const;
int GetDisplaySpeed() const { return this->cur_speed * 10 / 32; }
int GetDisplayMaxSpeed() const { return this->max_speed * 10 / 32; }
int GetDisplaySpeed() const { return this->cur_speed / 2; }
int GetDisplayMaxSpeed() const { return this->max_speed / 2; }
Money GetRunningCost() const;
bool IsInDepot() const { return this->u.ship.state == TRACK_BIT_DEPOT; }
void Tick();

View File

@ -596,7 +596,7 @@ static char *FormatString(char *buff, const char *str, const int64 *argv, uint c
case SCC_VELOCITY: {// {VELOCITY}
int64 args[1];
assert(_settings_game.locale.units < lengthof(units));
args[0] = ConvertSpeedToDisplaySpeed(GetInt32(&argv));
args[0] = ConvertSpeedToDisplaySpeed(GetInt32(&argv) * 10 / 16);
buff = FormatString(buff, GetStringPtr(units[_settings_game.locale.units].velocity), args, modifier >> 24, last);
modifier = 0;
break;

View File

@ -322,8 +322,8 @@ struct Train : public Vehicle {
void PlayLeaveStationSound() const;
bool IsPrimaryVehicle() const { return IsFrontEngine(this); }
SpriteID GetImage(Direction direction) const;
int GetDisplaySpeed() const { return this->u.rail.last_speed * 10 / 16; }
int GetDisplayMaxSpeed() const { return this->u.rail.cached_max_speed * 10 / 16; }
int GetDisplaySpeed() const { return this->u.rail.last_speed; }
int GetDisplayMaxSpeed() const { return this->u.rail.cached_max_speed; }
Money GetRunningCost() const;
bool IsInDepot() const { return CheckTrainInDepot(this, false) != -1; }
bool IsStoppedInDepot() const { return CheckTrainStoppedInDepot(this) >= 0; }

View File

@ -397,13 +397,13 @@ public:
virtual SpriteID GetImage(Direction direction) const { return 0; }
/**
* Gets the speed in mph that can be sent into SetDParam for string processing.
* Gets the speed in km-ish/h that can be sent into SetDParam for string processing.
* @return the vehicle's speed
*/
virtual int GetDisplaySpeed() const { return 0; }
/**
* Gets the maximum speed in mph that can be sent into SetDParam for string processing.
* Gets the maximum speed in km-ish/h that can be sent into SetDParam for string processing.
* @return the vehicle's maximum speed
*/
virtual int GetDisplayMaxSpeed() const { return 0; }