summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2009-03-18 19:32:13 +0000
committerfrosch <frosch@openttd.org>2009-03-18 19:32:13 +0000
commit6dd04a9a7804e0d4cecb74dc88dab1fd8c8382a6 (patch)
tree5b3edf89230e9a4cf637194daab09e36914f83e4 /src
parentea2c50281e34c8c0ade102552fc3d0f336496de9 (diff)
downloadopenttd-6dd04a9a7804e0d4cecb74dc88dab1fd8c8382a6.tar.xz
(svn r15763) -Codechange/Fix: Add Engine::GetDisplayDefaultCapacity() and use it everywhere, so CB 36 is also used everywhere.
Diffstat (limited to 'src')
-rw-r--r--src/ai/api/ai_engine.cpp8
-rw-r--r--src/ai/api/ai_event_types.cpp9
-rw-r--r--src/articulated_vehicles.cpp18
-rw-r--r--src/build_vehicle_gui.cpp19
-rw-r--r--src/engine.cpp30
-rw-r--r--src/engine_base.h1
-rw-r--r--src/engine_gui.cpp8
7 files changed, 53 insertions, 40 deletions
diff --git a/src/ai/api/ai_engine.cpp b/src/ai/api/ai_engine.cpp
index 3948a406a..669c44ec5 100644
--- a/src/ai/api/ai_engine.cpp
+++ b/src/ai/api/ai_engine.cpp
@@ -6,9 +6,10 @@
#include "ai_cargo.hpp"
#include "../../company_func.h"
#include "../../strings_func.h"
-#include "../../aircraft.h"
#include "../../vehicle_func.h"
#include "../../settings_type.h"
+#include "../../rail.h"
+#include "../../engine_base.h"
#include "../../articulated_vehicles.h"
#include "table/strings.h"
@@ -77,11 +78,8 @@
} break;
case VEH_SHIP:
- return e->u.ship.capacity;
- break;
-
case VEH_AIRCRAFT:
- return AircraftDefaultCargoCapacity(e->GetDefaultCargoType(), &e->u.air);
+ return e->GetDisplayDefaultCapacity();
break;
default: NOT_REACHED();
diff --git a/src/ai/api/ai_event_types.cpp b/src/ai/api/ai_event_types.cpp
index 469d53776..f02cfc957 100644
--- a/src/ai/api/ai_event_types.cpp
+++ b/src/ai/api/ai_event_types.cpp
@@ -3,9 +3,11 @@
/** @file ai_event_types.cpp Implementation of all EventTypes. */
#include "ai_event_types.hpp"
+#include "../../command_type.h"
#include "../../strings_func.h"
#include "../../settings_type.h"
-#include "../../aircraft.h"
+#include "../../rail.h"
+#include "../../engine_base.h"
#include "../../articulated_vehicles.h"
#include "table/strings.h"
@@ -41,11 +43,8 @@ int32 AIEventEnginePreview::GetCapacity()
} break;
case VEH_SHIP:
- return e->u.ship.capacity;
- break;
-
case VEH_AIRCRAFT:
- return AircraftDefaultCargoCapacity(e->GetDefaultCargoType(), &e->u.air);
+ return e->GetDisplayDefaultCapacity();
break;
default: NOT_REACHED();
diff --git a/src/articulated_vehicles.cpp b/src/articulated_vehicles.cpp
index 2a6fb6b2c..fd710795b 100644
--- a/src/articulated_vehicles.cpp
+++ b/src/articulated_vehicles.cpp
@@ -5,7 +5,6 @@
#include "stdafx.h"
#include "train.h"
#include "roadveh.h"
-#include "aircraft.h"
#include "newgrf_engine.h"
#include "vehicle_func.h"
@@ -52,22 +51,7 @@ static inline uint16 GetVehicleDefaultCapacity(EngineID engine, VehicleType type
CargoID cargo = (e->CanCarryCargo() ? e->GetDefaultCargoType() : (CargoID)CT_INVALID);
if (cargo_type != NULL) *cargo_type = cargo;
if (cargo == CT_INVALID) return 0;
- switch (type) {
- case VEH_TRAIN:
- return GetEngineProperty(engine, 0x14, e->u.rail.capacity) + (e->u.rail.railveh_type == RAILVEH_MULTIHEAD ? e->u.rail.capacity : 0);
-
- case VEH_ROAD:
- return GetEngineProperty(engine, 0x0F, e->u.road.capacity);
-
- case VEH_SHIP:
- return GetEngineProperty(engine, 0x0D, e->u.ship.capacity);
-
- case VEH_AIRCRAFT:
- return AircraftDefaultCargoCapacity(cargo, &e->u.air);
-
- default: NOT_REACHED();
- }
-
+ return e->GetDisplayDefaultCapacity();
}
/**
diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp
index a2b6783b6..b4f617adb 100644
--- a/src/build_vehicle_gui.cpp
+++ b/src/build_vehicle_gui.cpp
@@ -225,8 +225,11 @@ static int CDECL RoadVehEngineCapacitySorter(const void *a, const void *b)
/* Ship vehicle sorting functions */
static int CDECL ShipEngineCapacitySorter(const void *a, const void *b)
{
- int va = ShipVehInfo(*(const EngineID*)a)->capacity;
- int vb = ShipVehInfo(*(const EngineID*)b)->capacity;
+ const Engine *e_a = GetEngine(*(const EngineID*)a);
+ const Engine *e_b = GetEngine(*(const EngineID*)b);
+
+ int va = e_a->GetDisplayDefaultCapacity();
+ int vb = e_b->GetDisplayDefaultCapacity();
int r = va - vb;
/* Use EngineID to sort instead since we want consistent sorting */
@@ -240,8 +243,8 @@ static int CDECL AircraftEngineCargoSorter(const void *a, const void *b)
const Engine *e_a = GetEngine(*(const EngineID*)a);
const Engine *e_b = GetEngine(*(const EngineID*)b);
- int va = AircraftDefaultCargoCapacity(e_a->GetDefaultCargoType(), &e_a->u.air);
- int vb = AircraftDefaultCargoCapacity(e_b->GetDefaultCargoType(), &e_b->u.air);
+ int va = e_a->GetDisplayDefaultCapacity();
+ int vb = e_b->GetDisplayDefaultCapacity();
int r = va - vb;
if (r == 0) {
@@ -383,7 +386,7 @@ static int DrawRailWagonPurchaseInfo(int x, int y, EngineID engine_number, const
/* Wagon weight - (including cargo) */
uint weight = e->GetDisplayWeight();
SetDParam(0, weight);
- uint cargo_weight = (e->CanCarryCargo() ? GetCargo(e->GetDefaultCargoType())->weight * GetEngineProperty(engine_number, 0x14, rvi->capacity) >> 4 : 0);
+ uint cargo_weight = (e->CanCarryCargo() ? GetCargo(e->GetDefaultCargoType())->weight * e->GetDisplayDefaultCapacity() >> 4 : 0);
SetDParam(1, cargo_weight + weight);
DrawString(x, y, STR_PURCHASE_INFO_WEIGHT_CWEIGHT, TC_FROMSTRING);
y += 10;
@@ -482,7 +485,7 @@ static int DrawShipPurchaseInfo(int x, int y, EngineID engine_number, const Ship
/* Cargo type + capacity */
SetDParam(0, e->GetDefaultCargoType());
- SetDParam(1, GetEngineProperty(engine_number, 0x0D, svi->capacity));
+ SetDParam(1, e->GetDisplayDefaultCapacity());
SetDParam(2, refittable ? STR_9842_REFITTABLE : STR_EMPTY);
DrawString(x, y, STR_PURCHASE_INFO_CAPACITY, TC_FROMSTRING);
y += 10;
@@ -509,14 +512,14 @@ static int DrawAircraftPurchaseInfo(int x, int y, EngineID engine_number, const
/* Cargo capacity */
if (cargo == CT_INVALID || cargo == CT_PASSENGERS) {
- SetDParam(0, avi->passenger_capacity);
+ SetDParam(0, e->GetDisplayDefaultCapacity());
SetDParam(1, avi->mail_capacity);
DrawString(x, y, STR_PURCHASE_INFO_AIRCRAFT_CAPACITY, TC_FROMSTRING);
} else {
/* Note, if the default capacity is selected by the refit capacity
* callback, then the capacity shown is likely to be incorrect. */
SetDParam(0, cargo);
- SetDParam(1, AircraftDefaultCargoCapacity(cargo, avi));
+ SetDParam(1, e->GetDisplayDefaultCapacity());
SetDParam(2, refittable ? STR_9842_REFITTABLE : STR_EMPTY);
DrawString(x, y, STR_PURCHASE_INFO_CAPACITY, TC_FROMSTRING);
}
diff --git a/src/engine.cpp b/src/engine.cpp
index 19e1f589d..9b639bf2b 100644
--- a/src/engine.cpp
+++ b/src/engine.cpp
@@ -177,6 +177,36 @@ bool Engine::CanCarryCargo() const
return this->GetDefaultCargoType() != CT_INVALID;
}
+/**
+ * Determines the default cargo capacity of an engine for display purposes.
+ *
+ * For planes carrying both passenger and mail this is the passenger capacity.
+ * For multiheaded engines this is the capacity of both heads.
+ * For articulated engines use GetCapacityOfArticulatedParts
+ *
+ * @return The default capacity
+ * @see GetDefaultCargoType
+ */
+uint Engine::GetDisplayDefaultCapacity() const
+{
+ if (!this->CanCarryCargo()) return 0;
+ switch (type) {
+ case VEH_TRAIN:
+ return GetEngineProperty(this->index, 0x14, this->u.rail.capacity) + (this->u.rail.railveh_type == RAILVEH_MULTIHEAD ? this->u.rail.capacity : 0);
+
+ case VEH_ROAD:
+ return GetEngineProperty(this->index, 0x0F, this->u.road.capacity);
+
+ case VEH_SHIP:
+ return GetEngineProperty(this->index, 0x0D, this->u.ship.capacity);
+
+ case VEH_AIRCRAFT:
+ return AircraftDefaultCargoCapacity(this->GetDefaultCargoType(), &this->u.air);
+
+ default: NOT_REACHED();
+ }
+}
+
Money Engine::GetRunningCost() const
{
switch (this->type) {
diff --git a/src/engine_base.h b/src/engine_base.h
index a008539b6..3e81ce9aa 100644
--- a/src/engine_base.h
+++ b/src/engine_base.h
@@ -53,6 +53,7 @@ struct Engine : PoolItem<Engine, EngineID, &_Engine_pool> {
CargoID GetDefaultCargoType() const;
bool CanCarryCargo() const;
+ uint GetDisplayDefaultCapacity() const;
Money GetRunningCost() const;
Money GetCost() const;
uint GetDisplayMaxSpeed() const;
diff --git a/src/engine_gui.cpp b/src/engine_gui.cpp
index 94f2b4452..2a5d0f1d5 100644
--- a/src/engine_gui.cpp
+++ b/src/engine_gui.cpp
@@ -14,7 +14,6 @@
#include "engine_gui.h"
#include "articulated_vehicles.h"
#include "rail.h"
-#include "aircraft.h"
#include "table/strings.h"
#include "table/sprites.h"
@@ -151,7 +150,7 @@ static void DrawAircraftEngineInfo(EngineID engine, int x, int y, int maxw)
if (cargo == CT_INVALID || cargo == CT_PASSENGERS) {
SetDParam(0, e->GetCost());
SetDParam(1, e->GetDisplayMaxSpeed());
- SetDParam(2, e->u.air.passenger_capacity);
+ SetDParam(2, e->GetDisplayDefaultCapacity());
SetDParam(3, e->u.air.mail_capacity);
SetDParam(4, e->GetRunningCost());
@@ -160,7 +159,7 @@ static void DrawAircraftEngineInfo(EngineID engine, int x, int y, int maxw)
SetDParam(0, e->GetCost());
SetDParam(1, e->GetDisplayMaxSpeed());
SetDParam(2, cargo);
- SetDParam(3, AircraftDefaultCargoCapacity(cargo, &e->u.air));
+ SetDParam(3, e->GetDisplayDefaultCapacity());
SetDParam(4, e->GetRunningCost());
DrawStringMultiCenter(x, y, STR_982E_COST_MAX_SPEED_CAPACITY, maxw);
@@ -187,13 +186,12 @@ static void DrawRoadVehEngineInfo(EngineID engine, int x, int y, int maxw)
static void DrawShipEngineInfo(EngineID engine, int x, int y, int maxw)
{
- const ShipVehicleInfo *svi = ShipVehInfo(engine);
const Engine *e = GetEngine(engine);
SetDParam(0, e->GetCost());
SetDParam(1, e->GetDisplayMaxSpeed());
SetDParam(2, e->GetDefaultCargoType());
- SetDParam(3, GetEngineProperty(engine, 0x0D, svi->capacity));
+ SetDParam(3, e->GetDisplayDefaultCapacity());
SetDParam(4, e->GetRunningCost());
DrawStringMultiCenter(x, y, STR_982E_COST_MAX_SPEED_CAPACITY, maxw);
}