summaryrefslogtreecommitdiff
path: root/src/articulated_vehicles.cpp
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2009-02-21 12:52:41 +0000
committerfrosch <frosch@openttd.org>2009-02-21 12:52:41 +0000
commitd3850e101c7deb3d6549dae3dcad9daa90c40946 (patch)
tree62e06798cf27a41c73412fa15906f2df18c9826c /src/articulated_vehicles.cpp
parentb674d1f6f5c680d42c3297f1a79a87a124d0e52d (diff)
downloadopenttd-d3850e101c7deb3d6549dae3dcad9daa90c40946.tar.xz
(svn r15541) -Revert (r15399): 'v->cargo_type' is also used in other places, which cannot accept CT_INVALID.
-Codechange: Add Engine::GetDefaultCargoType() and Engine::CanCarryCargo() and use them. -Fix [FS#2617]: When articulated parts have no available default cargo, use the cargo type of the first part for livery selection. -Change: To decide whether a vehicle is refittable do not test its current capacity for being zero, but always use the 'capacity property'. Note: The property is used unmodifed without calling CB 15/36. By setting it to a non-zero value and returning zero in the callback vehicles can be refitted to/from zero capacity for e.g. livery effects. Note: It is intentional that you cannot control refittability by CB 36.
Diffstat (limited to 'src/articulated_vehicles.cpp')
-rw-r--r--src/articulated_vehicles.cpp68
1 files changed, 34 insertions, 34 deletions
diff --git a/src/articulated_vehicles.cpp b/src/articulated_vehicles.cpp
index 0c4eeec8e..ac894f362 100644
--- a/src/articulated_vehicles.cpp
+++ b/src/articulated_vehicles.cpp
@@ -5,6 +5,7 @@
#include "stdafx.h"
#include "train.h"
#include "roadveh.h"
+#include "aircraft.h"
#include "newgrf_engine.h"
#include "vehicle_func.h"
@@ -45,30 +46,22 @@ uint CountArticulatedParts(EngineID engine_type, bool purchase_window)
*/
static inline uint16 GetVehicleDefaultCapacity(EngineID engine, VehicleType type, CargoID *cargo_type)
{
+ const Engine *e = GetEngine(engine);
+ 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: {
- const RailVehicleInfo *rvi = RailVehInfo(engine);
- if (cargo_type != NULL) *cargo_type = rvi->cargo_type;
- return GetEngineProperty(engine, 0x14, rvi->capacity) + (rvi->railveh_type == RAILVEH_MULTIHEAD ? rvi->capacity : 0);
- }
+ 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: {
- const RoadVehicleInfo *rvi = RoadVehInfo(engine);
- if (cargo_type != NULL) *cargo_type = rvi->cargo_type;
- return GetEngineProperty(engine, 0x0F, rvi->capacity);
- }
+ case VEH_ROAD:
+ return GetEngineProperty(engine, 0x0F, e->u.road.capacity);
- case VEH_SHIP: {
- const ShipVehicleInfo *svi = ShipVehInfo(engine);
- if (cargo_type != NULL) *cargo_type = svi->cargo_type;
- return GetEngineProperty(engine, 0x0D, svi->capacity);
- }
+ case VEH_SHIP:
+ return GetEngineProperty(engine, 0x0D, e->u.ship.capacity);
- case VEH_AIRCRAFT: {
- const AircraftVehicleInfo *avi = AircraftVehInfo(engine);
- if (cargo_type != NULL) *cargo_type = CT_PASSENGERS;
- return avi->passenger_capacity;
- }
+ case VEH_AIRCRAFT:
+ return AircraftDefaultCargoCapacity(cargo, &e->u.air);
default: NOT_REACHED();
}
@@ -264,28 +257,30 @@ void AddArticulatedParts(Vehicle **vl, VehicleType type)
u->cur_image = 0xAC2;
u->random_bits = VehicleRandomBits();
+ const Engine *e_artic = GetEngine(engine_type);
switch (type) {
default: NOT_REACHED();
- case VEH_TRAIN: {
- const RailVehicleInfo *rvi_artic = RailVehInfo(engine_type);
-
+ case VEH_TRAIN:
u = new (u) Train();
previous->SetNext(u);
u->u.rail.track = v->u.rail.track;
u->u.rail.railtype = v->u.rail.railtype;
u->u.rail.first_engine = v->engine_type;
- u->spritenum = rvi_artic->image_index;
- u->cargo_type = rvi_artic->cargo_type;
- u->cargo_cap = rvi_artic->capacity; // Callback 36 is called when the consist is finished
+ u->spritenum = e_artic->u.rail.image_index;
+ if (e_artic->CanCarryCargo()) {
+ u->cargo_type = e_artic->GetDefaultCargoType();
+ u->cargo_cap = e_artic->u.rail.capacity; // Callback 36 is called when the consist is finished
+ } else {
+ u->cargo_type = v->cargo_type; // Needed for livery selection
+ u->cargo_cap = 0;
+ }
SetArticulatedPart(u);
- } break;
-
- case VEH_ROAD: {
- const RoadVehicleInfo *rvi_artic = RoadVehInfo(engine_type);
+ break;
+ case VEH_ROAD:
u = new (u) RoadVehicle();
previous->SetNext(u);
u->u.road.first_engine = v->engine_type;
@@ -295,12 +290,17 @@ void AddArticulatedParts(Vehicle **vl, VehicleType type)
u->u.road.roadtype = v->u.road.roadtype;
u->u.road.compatible_roadtypes = v->u.road.compatible_roadtypes;
- u->spritenum = rvi_artic->image_index;
- u->cargo_type = rvi_artic->cargo_type;
- u->cargo_cap = rvi_artic->capacity; // Callback 36 is called when the consist is finished
+ u->spritenum = e_artic->u.road.image_index;
+ if (e_artic->CanCarryCargo()) {
+ u->cargo_type = e_artic->GetDefaultCargoType();
+ u->cargo_cap = e_artic->u.road.capacity; // Callback 36 is called when the consist is finished
+ } else {
+ u->cargo_type = v->cargo_type; // Needed for livery selection
+ u->cargo_cap = 0;
+ }
SetRoadVehArticPart(u);
- } break;
+ break;
}
if (flip_image) u->spritenum++;