(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 74c061c29a
commit f7c4d35f67
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;
}
}