mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-11-11 13:10:45 +00:00
(svn r21519) -Codechange: Allow direct access to the GroundVehicleCache from a Vehicle.
This commit is contained in:
parent
12c86a1391
commit
a4a9274177
@ -52,6 +52,7 @@
|
|||||||
#include "vehiclelist.h"
|
#include "vehiclelist.h"
|
||||||
#include "tunnel_map.h"
|
#include "tunnel_map.h"
|
||||||
#include "depot_map.h"
|
#include "depot_map.h"
|
||||||
|
#include "ground_vehicle.hpp"
|
||||||
|
|
||||||
#include "table/strings.h"
|
#include "table/strings.h"
|
||||||
|
|
||||||
@ -2228,3 +2229,33 @@ bool CanVehicleUseStation(const Vehicle *v, const Station *st)
|
|||||||
|
|
||||||
return CanVehicleUseStation(v->engine_type, 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -98,6 +98,7 @@ extern VehiclePool _vehicle_pool;
|
|||||||
|
|
||||||
/* Some declarations of functions, so we can make them friendly */
|
/* Some declarations of functions, so we can make them friendly */
|
||||||
struct SaveLoad;
|
struct SaveLoad;
|
||||||
|
struct GroundVehicleCache;
|
||||||
extern const SaveLoad *GetVehicleDescription(VehicleType vt);
|
extern const SaveLoad *GetVehicleDescription(VehicleType vt);
|
||||||
struct LoadgameState;
|
struct LoadgameState;
|
||||||
extern bool LoadOldVehicle(LoadgameState *ls, int num);
|
extern bool LoadOldVehicle(LoadgameState *ls, int num);
|
||||||
@ -239,6 +240,9 @@ public:
|
|||||||
void BeginLoading();
|
void BeginLoading();
|
||||||
void LeaveStation();
|
void LeaveStation();
|
||||||
|
|
||||||
|
GroundVehicleCache *GetGroundVehicleCache();
|
||||||
|
const GroundVehicleCache *GetGroundVehicleCache() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle the loading of the vehicle; when not it skips through dummy
|
* Handle the loading of the vehicle; when not it skips through dummy
|
||||||
* orders and does nothing in all other cases.
|
* orders and does nothing in all other cases.
|
||||||
|
@ -1701,34 +1701,25 @@ struct VehicleDetailsWindow : Window {
|
|||||||
y += FONT_HEIGHT_NORMAL;
|
y += FONT_HEIGHT_NORMAL;
|
||||||
|
|
||||||
/* Draw max speed */
|
/* Draw max speed */
|
||||||
switch (v->type) {
|
StringID string;
|
||||||
case VEH_TRAIN:
|
if (v->type == VEH_TRAIN ||
|
||||||
SetDParam(2, v->GetDisplayMaxSpeed());
|
(v->type == VEH_ROAD && _settings_game.vehicle.roadveh_acceleration_model != AM_ORIGINAL)) {
|
||||||
SetDParam(1, Train::From(v)->gcache.cached_power);
|
const GroundVehicleCache *gcache = v->GetGroundVehicleCache();
|
||||||
SetDParam(0, Train::From(v)->gcache.cached_weight);
|
SetDParam(2, v->GetDisplayMaxSpeed());
|
||||||
SetDParam(3, Train::From(v)->gcache.cached_max_te / 1000);
|
SetDParam(1, gcache->cached_power);
|
||||||
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) ?
|
SetDParam(0, gcache->cached_weight);
|
||||||
STR_VEHICLE_INFO_WEIGHT_POWER_MAX_SPEED_MAX_TE : STR_VEHICLE_INFO_WEIGHT_POWER_MAX_SPEED);
|
SetDParam(3, gcache->cached_max_te / 1000);
|
||||||
break;
|
if (v->type == VEH_TRAIN && (_settings_game.vehicle.train_acceleration_model == AM_ORIGINAL ||
|
||||||
|
GetRailTypeInfo(Train::From(v)->railtype)->acceleration_type == 2)) {
|
||||||
case VEH_ROAD:
|
string = STR_VEHICLE_INFO_WEIGHT_POWER_MAX_SPEED;
|
||||||
if (_settings_game.vehicle.roadveh_acceleration_model != AM_ORIGINAL) {
|
} else {
|
||||||
SetDParam(2, v->GetDisplayMaxSpeed());
|
string = STR_VEHICLE_INFO_WEIGHT_POWER_MAX_SPEED_MAX_TE;
|
||||||
SetDParam(1, RoadVehicle::From(v)->gcache.cached_power);
|
}
|
||||||
SetDParam(0, RoadVehicle::From(v)->gcache.cached_weight);
|
} else {
|
||||||
SetDParam(3, RoadVehicle::From(v)->gcache.cached_max_te / 1000);
|
SetDParam(0, v->GetDisplayMaxSpeed());
|
||||||
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_VEHICLE_INFO_WEIGHT_POWER_MAX_SPEED_MAX_TE);
|
string = STR_VEHICLE_INFO_MAX_SPEED;
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, string);
|
||||||
y += FONT_HEIGHT_NORMAL;
|
y += FONT_HEIGHT_NORMAL;
|
||||||
|
|
||||||
/* Draw profit */
|
/* Draw profit */
|
||||||
|
Loading…
Reference in New Issue
Block a user