(svn r21519) -Codechange: Allow direct access to the GroundVehicleCache from a Vehicle.

This commit is contained in:
terkhen 2010-12-14 21:31:00 +00:00
parent 12c86a1391
commit a4a9274177
3 changed files with 53 additions and 27 deletions

View File

@ -52,6 +52,7 @@
#include "vehiclelist.h"
#include "tunnel_map.h"
#include "depot_map.h"
#include "ground_vehicle.hpp"
#include "table/strings.h"
@ -2228,3 +2229,33 @@ bool CanVehicleUseStation(const Vehicle *v, const Station *st)
return CanVehicleUseStation(v->engine_type, st);
}
/**
* Access the ground vehicle cache of the vehicle.
* @pre The vehicle is a #GroundVehicle.
* @return #GroundVehicleCache of the vehicle.
*/
GroundVehicleCache *Vehicle::GetGroundVehicleCache()
{
assert(this->IsGroundVehicle());
if (this->type == VEH_TRAIN) {
return &Train::From(this)->gcache;
} else {
return &RoadVehicle::From(this)->gcache;
}
}
/**
* Access the ground vehicle cache of the vehicle.
* @pre The vehicle is a #GroundVehicle.
* @return #GroundVehicleCache of the vehicle.
*/
const GroundVehicleCache *Vehicle::GetGroundVehicleCache() const
{
assert(this->IsGroundVehicle());
if (this->type == VEH_TRAIN) {
return &Train::From(this)->gcache;
} else {
return &RoadVehicle::From(this)->gcache;
}
}

View File

@ -98,6 +98,7 @@ extern VehiclePool _vehicle_pool;
/* Some declarations of functions, so we can make them friendly */
struct SaveLoad;
struct GroundVehicleCache;
extern const SaveLoad *GetVehicleDescription(VehicleType vt);
struct LoadgameState;
extern bool LoadOldVehicle(LoadgameState *ls, int num);
@ -239,6 +240,9 @@ public:
void BeginLoading();
void LeaveStation();
GroundVehicleCache *GetGroundVehicleCache();
const GroundVehicleCache *GetGroundVehicleCache() const;
/**
* Handle the loading of the vehicle; when not it skips through dummy
* orders and does nothing in all other cases.

View File

@ -1701,34 +1701,25 @@ struct VehicleDetailsWindow : Window {
y += FONT_HEIGHT_NORMAL;
/* Draw max speed */
switch (v->type) {
case VEH_TRAIN:
SetDParam(2, v->GetDisplayMaxSpeed());
SetDParam(1, Train::From(v)->gcache.cached_power);
SetDParam(0, Train::From(v)->gcache.cached_weight);
SetDParam(3, Train::From(v)->gcache.cached_max_te / 1000);
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, (_settings_game.vehicle.train_acceleration_model != AM_ORIGINAL && GetRailTypeInfo(Train::From(v)->railtype)->acceleration_type != 2) ?
STR_VEHICLE_INFO_WEIGHT_POWER_MAX_SPEED_MAX_TE : STR_VEHICLE_INFO_WEIGHT_POWER_MAX_SPEED);
break;
case VEH_ROAD:
if (_settings_game.vehicle.roadveh_acceleration_model != AM_ORIGINAL) {
SetDParam(2, v->GetDisplayMaxSpeed());
SetDParam(1, RoadVehicle::From(v)->gcache.cached_power);
SetDParam(0, RoadVehicle::From(v)->gcache.cached_weight);
SetDParam(3, RoadVehicle::From(v)->gcache.cached_max_te / 1000);
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_VEHICLE_INFO_WEIGHT_POWER_MAX_SPEED_MAX_TE);
break;
}
/* FALL THROUGH */
case VEH_SHIP:
case VEH_AIRCRAFT:
SetDParam(0, v->GetDisplayMaxSpeed());
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_VEHICLE_INFO_MAX_SPEED);
break;
default: NOT_REACHED();
StringID string;
if (v->type == VEH_TRAIN ||
(v->type == VEH_ROAD && _settings_game.vehicle.roadveh_acceleration_model != AM_ORIGINAL)) {
const GroundVehicleCache *gcache = v->GetGroundVehicleCache();
SetDParam(2, v->GetDisplayMaxSpeed());
SetDParam(1, gcache->cached_power);
SetDParam(0, gcache->cached_weight);
SetDParam(3, gcache->cached_max_te / 1000);
if (v->type == VEH_TRAIN && (_settings_game.vehicle.train_acceleration_model == AM_ORIGINAL ||
GetRailTypeInfo(Train::From(v)->railtype)->acceleration_type == 2)) {
string = STR_VEHICLE_INFO_WEIGHT_POWER_MAX_SPEED;
} else {
string = STR_VEHICLE_INFO_WEIGHT_POWER_MAX_SPEED_MAX_TE;
}
} else {
SetDParam(0, v->GetDisplayMaxSpeed());
string = STR_VEHICLE_INFO_MAX_SPEED;
}
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, string);
y += FONT_HEIGHT_NORMAL;
/* Draw profit */