Changeset - r16776:bc50cd8a147c
[Not reviewed]
master
0 3 0
terkhen - 13 years ago 2010-12-14 21:31:00
terkhen@openttd.org
(svn r21519) -Codechange: Allow direct access to the GroundVehicleCache from a Vehicle.
3 files changed with 53 insertions and 27 deletions:
0 comments (0 inline, 0 general)
src/vehicle.cpp
Show inline comments
 
@@ -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 
 

	
 
	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;
 
	}
 
}
src/vehicle_base.h
Show inline comments
 
@@ -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.
src/vehicle_gui.cpp
Show inline comments
 
@@ -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 */
0 comments (0 inline, 0 general)