mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-11-04 06:00:15 +00:00
(svn r15763) -Codechange/Fix: Add Engine::GetDisplayDefaultCapacity() and use it everywhere, so CB 36 is also used everywhere.
This commit is contained in:
parent
6d9b2ac76a
commit
c297a99eff
@ -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();
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user