summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/aircraft_cmd.cpp12
-rw-r--r--src/build_vehicle_gui.cpp31
-rw-r--r--src/engine.cpp25
-rw-r--r--src/engine_base.h2
-rw-r--r--src/engine_gui.cpp14
-rw-r--r--src/vehicle.cpp11
-rw-r--r--src/vehicle_cmd.cpp8
-rw-r--r--src/vehicle_func.h2
8 files changed, 60 insertions, 45 deletions
diff --git a/src/aircraft_cmd.cpp b/src/aircraft_cmd.cpp
index 65c3f6ff1..d90320f07 100644
--- a/src/aircraft_cmd.cpp
+++ b/src/aircraft_cmd.cpp
@@ -360,11 +360,7 @@ CommandCost CmdBuildAircraft(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
v->InvalidateNewGRFCacheOfChain();
- v->cargo_cap = GetVehicleCapacity(v);
- if (v->cargo_type != CT_PASSENGERS) {
- /* Set the 'second compartent' capacity to none */
- u->cargo_cap = 0;
- }
+ v->cargo_cap = GetVehicleCapacity(v, &u->cargo_cap);
v->InvalidateNewGRFCacheOfChain();
@@ -505,12 +501,6 @@ CommandCost CmdRefitAircraft(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
CommandCost cost = RefitVehicle(v, true, new_cid, new_subtype, flags);
if (flags & DC_EXEC) {
- const Engine *e = Engine::Get(v->engine_type);
- Vehicle *u = v->Next();
- uint mail = IsCargoInClass(new_cid, CC_PASSENGERS) ? e->u.air.mail_capacity : 0;
- u->cargo_cap = mail;
- u->cargo.Truncate(v->cargo_type == new_cid ? mail : 0);
-
v->colourmap = PAL_NONE; // invalidate vehicle colour map
SetWindowDirty(WC_VEHICLE_DETAILS, v->index);
SetWindowDirty(WC_VEHICLE_DEPOT, v->tile);
diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp
index 917250cb0..8a1c204a3 100644
--- a/src/build_vehicle_gui.cpp
+++ b/src/build_vehicle_gui.cpp
@@ -277,15 +277,14 @@ static int CDECL AircraftEngineCargoSorter(const EngineID *a, const EngineID *b)
const Engine *e_a = Engine::Get(*a);
const Engine *e_b = Engine::Get(*b);
- int va = e_a->GetDisplayDefaultCapacity();
- int vb = e_b->GetDisplayDefaultCapacity();
+ uint16 mail_a, mail_b;
+ int va = e_a->GetDisplayDefaultCapacity(&mail_a);
+ int vb = e_b->GetDisplayDefaultCapacity(&mail_b);
int r = va - vb;
if (r == 0) {
- /* The planes has the same passenger capacity. Check mail capacity instead */
- va = e_a->u.air.mail_capacity;
- vb = e_b->u.air.mail_capacity;
- r = va - vb;
+ /* The planes have the same passenger capacity. Check mail capacity instead */
+ r = mail_a - mail_b;
if (r == 0) {
/* Use EngineID to sort instead since we want consistent sorting */
@@ -519,7 +518,7 @@ static int DrawRoadVehPurchaseInfo(int left, int right, int y, EngineID engine_n
}
/* Draw ship specific details */
-static int DrawShipPurchaseInfo(int left, int right, int y, EngineID engine_number, const ShipVehicleInfo *svi, bool refittable)
+static int DrawShipPurchaseInfo(int left, int right, int y, EngineID engine_number, bool refittable)
{
const Engine *e = Engine::Get(engine_number);
@@ -545,7 +544,7 @@ static int DrawShipPurchaseInfo(int left, int right, int y, EngineID engine_numb
}
/* Draw aircraft specific details */
-static int DrawAircraftPurchaseInfo(int left, int right, int y, EngineID engine_number, const AircraftVehicleInfo *avi, bool refittable)
+static int DrawAircraftPurchaseInfo(int left, int right, int y, EngineID engine_number, bool refittable)
{
const Engine *e = Engine::Get(engine_number);
CargoID cargo = e->GetDefaultCargoType();
@@ -557,17 +556,19 @@ static int DrawAircraftPurchaseInfo(int left, int right, int y, EngineID engine_
y += FONT_HEIGHT_NORMAL;
/* Cargo capacity */
- if (cargo == CT_INVALID || cargo == CT_PASSENGERS) {
- SetDParam(0, CT_PASSENGERS);
- SetDParam(1, e->GetDisplayDefaultCapacity());
+ uint16 mail_capacity;
+ uint capacity = e->GetDisplayDefaultCapacity(&mail_capacity);
+ if (mail_capacity > 0) {
+ SetDParam(0, cargo);
+ SetDParam(1, capacity);
SetDParam(2, CT_MAIL);
- SetDParam(3, avi->mail_capacity);
+ SetDParam(3, mail_capacity);
DrawString(left, right, y, STR_PURCHASE_INFO_AIRCRAFT_CAPACITY);
} 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, e->GetDisplayDefaultCapacity());
+ SetDParam(1, capacity);
SetDParam(2, refittable ? STR_PURCHASE_INFO_REFITTABLE : STR_EMPTY);
DrawString(left, right, y, STR_PURCHASE_INFO_CAPACITY);
}
@@ -633,11 +634,11 @@ int DrawVehiclePurchaseInfo(int left, int right, int y, EngineID engine_number)
break;
case VEH_SHIP:
- y = DrawShipPurchaseInfo(left, right, y, engine_number, &e->u.ship, refittable);
+ y = DrawShipPurchaseInfo(left, right, y, engine_number, refittable);
break;
case VEH_AIRCRAFT:
- y = DrawAircraftPurchaseInfo(left, right, y, engine_number, &e->u.air, refittable);
+ y = DrawAircraftPurchaseInfo(left, right, y, engine_number, refittable);
break;
}
diff --git a/src/engine.cpp b/src/engine.cpp
index 5ea56efdb..45cdb8a40 100644
--- a/src/engine.cpp
+++ b/src/engine.cpp
@@ -16,6 +16,7 @@
#include "aircraft.h"
#include "newgrf.h"
#include "newgrf_engine.h"
+#include "newgrf_cargo.h"
#include "group.h"
#include "strings_func.h"
#include "gfx_func.h"
@@ -163,11 +164,13 @@ bool Engine::CanCarryCargo() const
* For articulated engines use GetCapacityOfArticulatedParts
*
* @note Keep this function consistent with GetVehicleCapacity().
+ * @param mail_capacity returns secondary cargo (mail) capacity of aircraft
* @return The default capacity
* @see GetDefaultCargoType
*/
-uint Engine::GetDisplayDefaultCapacity() const
+uint Engine::GetDisplayDefaultCapacity(uint16 *mail_capacity) const
{
+ if (mail_capacity != NULL) *mail_capacity = 0;
if (!this->CanCarryCargo()) return 0;
switch (type) {
case VEH_TRAIN:
@@ -179,13 +182,21 @@ uint Engine::GetDisplayDefaultCapacity() const
case VEH_SHIP:
return GetEngineProperty(this->index, PROP_SHIP_CARGO_CAPACITY, this->u.ship.capacity);
- case VEH_AIRCRAFT:
- switch (this->GetDefaultCargoType()) {
- case CT_PASSENGERS: return this->u.air.passenger_capacity;
- case CT_MAIL: return this->u.air.passenger_capacity + this->u.air.mail_capacity;
- case CT_GOODS: return (this->u.air.passenger_capacity + this->u.air.mail_capacity) / 2;
- default: return (this->u.air.passenger_capacity + this->u.air.mail_capacity) / 4;
+ case VEH_AIRCRAFT: {
+ uint capacity = this->u.air.passenger_capacity;
+ CargoID cargo = this->GetDefaultCargoType();
+ if (IsCargoInClass(cargo, CC_PASSENGERS)) {
+ if (mail_capacity != NULL) *mail_capacity = this->u.air.mail_capacity;
+ } else {
+ capacity += this->u.air.mail_capacity;
}
+ switch (cargo) {
+ case CT_PASSENGERS:
+ case CT_MAIL: return capacity;
+ case CT_GOODS: return capacity / 2;
+ default: return capacity / 4;
+ }
+ }
default: NOT_REACHED();
}
diff --git a/src/engine_base.h b/src/engine_base.h
index 82022a145..f3a819277 100644
--- a/src/engine_base.h
+++ b/src/engine_base.h
@@ -73,7 +73,7 @@ struct Engine : EnginePool::PoolItem<&_engine_pool> {
}
bool CanCarryCargo() const;
- uint GetDisplayDefaultCapacity() const;
+ uint GetDisplayDefaultCapacity(uint16 *mail_capacity = NULL) const;
Money GetRunningCost() const;
Money GetCost() const;
uint GetDisplayMaxSpeed() const;
diff --git a/src/engine_gui.cpp b/src/engine_gui.cpp
index 280513063..9af3ca3c1 100644
--- a/src/engine_gui.cpp
+++ b/src/engine_gui.cpp
@@ -158,21 +158,23 @@ static StringID GetTrainEngineInfoString(const Engine *e)
static StringID GetAircraftEngineInfoString(const Engine *e)
{
CargoID cargo = e->GetDefaultCargoType();
+ uint16 mail_capacity;
+ uint capacity = e->GetDisplayDefaultCapacity(&mail_capacity);
- if (cargo == CT_INVALID || cargo == CT_PASSENGERS) {
+ if (mail_capacity > 0) {
SetDParam(0, e->GetCost());
SetDParam(1, e->GetDisplayMaxSpeed());
- SetDParam(2, CT_PASSENGERS),
- SetDParam(3, e->GetDisplayDefaultCapacity());
- SetDParam(4, CT_MAIL),
- SetDParam(5, e->u.air.mail_capacity);
+ SetDParam(2, cargo);
+ SetDParam(3, capacity);
+ SetDParam(4, CT_MAIL);
+ SetDParam(5, mail_capacity);
SetDParam(6, e->GetRunningCost());
return STR_ENGINE_PREVIEW_COST_MAX_SPEED_CAPACITY_CAPACITY_RUNCOST;
} else {
SetDParam(0, e->GetCost());
SetDParam(1, e->GetDisplayMaxSpeed());
SetDParam(2, cargo);
- SetDParam(3, e->GetDisplayDefaultCapacity());
+ SetDParam(3, capacity);
SetDParam(4, e->GetRunningCost());
return STR_ENGINE_PREVIEW_COST_MAX_SPEED_CAPACITY_RUNCOST;
}
diff --git a/src/vehicle.cpp b/src/vehicle.cpp
index 174cc6aa0..2914c4393 100644
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -1377,10 +1377,12 @@ SpriteID GetVehiclePalette(const Vehicle *v)
* For aircraft the main capacity is determined. Mail might be present as well.
* @note Keep this function consistent with Engine::GetDisplayDefaultCapacity().
* @param v Vehicle of interest
+ * @param mail_capacity returns secondary cargo (mail) capacity of aircraft
* @return Capacity
*/
-uint GetVehicleCapacity(const Vehicle *v)
+uint GetVehicleCapacity(const Vehicle *v, uint16 *mail_capacity)
{
+ if (mail_capacity != NULL) *mail_capacity = 0;
const Engine *e = Engine::Get(v->engine_type);
if (!e->CanCarryCargo()) return 0;
@@ -1409,8 +1411,11 @@ uint GetVehicleCapacity(const Vehicle *v)
* Note: This might change to become more consistent/flexible. */
if (e->type != VEH_SHIP) {
if (e->type == VEH_AIRCRAFT) {
- if (v->cargo_type == CT_PASSENGERS) return capacity;
- capacity += e->u.air.mail_capacity;
+ if (IsCargoInClass(v->cargo_type, CT_PASSENGERS)) {
+ if (mail_capacity != NULL) *mail_capacity = e->u.air.mail_capacity;
+ } else {
+ capacity += e->u.air.mail_capacity;
+ }
if (v->cargo_type == CT_MAIL) return capacity;
} else {
switch (default_cargo) {
diff --git a/src/vehicle_cmd.cpp b/src/vehicle_cmd.cpp
index 58d8dabc2..9bd27ad60 100644
--- a/src/vehicle_cmd.cpp
+++ b/src/vehicle_cmd.cpp
@@ -320,7 +320,8 @@ CommandCost RefitVehicle(Vehicle *v, bool only_this, CargoID new_cid, byte new_s
v->cargo_type = new_cid;
v->cargo_subtype = new_subtype;
- uint amount = GetVehicleCapacity(v);
+ uint16 mail_capacity;
+ uint amount = GetVehicleCapacity(v, &mail_capacity);
total_capacity += amount;
/* Restore the original cargo type */
@@ -336,6 +337,11 @@ CommandCost RefitVehicle(Vehicle *v, bool only_this, CargoID new_cid, byte new_s
v->cargo_type = new_cid;
v->cargo_cap = amount;
v->cargo_subtype = new_subtype;
+ if (v->type == VEH_AIRCRAFT) {
+ Vehicle *u = v->Next();
+ u->cargo_cap = mail_capacity;
+ u->cargo.Truncate(mail_capacity);
+ }
}
}
diff --git a/src/vehicle_func.h b/src/vehicle_func.h
index 1d46abd45..b709dba14 100644
--- a/src/vehicle_func.h
+++ b/src/vehicle_func.h
@@ -111,7 +111,7 @@ SpriteID GetEnginePalette(EngineID engine_type, CompanyID company);
*/
SpriteID GetVehiclePalette(const Vehicle *v);
-uint GetVehicleCapacity(const Vehicle *v);
+uint GetVehicleCapacity(const Vehicle *v, uint16 *mail_capacity = NULL);
extern const uint32 _veh_build_proc_table[];
extern const uint32 _veh_sell_proc_table[];