1
0
Fork 0

(svn r15592) -Fix: Refit-info in purchase list did only check the first articulated part.

release/0.7
frosch 2009-02-27 20:40:39 +00:00
parent 7299728472
commit e01106f66b
5 changed files with 51 additions and 18 deletions

View File

@ -117,9 +117,33 @@ uint16 *GetCapacityOfArticulatedParts(EngineID engine, VehicleType type)
return capacity; return capacity;
} }
/**
* Checks whether any of the articulated parts is refittable
* @param engine the first part
* @return true if refittable
*/
bool IsArticulatedVehicleRefittable(EngineID engine)
{
if (IsEngineRefittable(engine)) return true;
const Engine *e = GetEngine(engine);
if (e->type != VEH_TRAIN && e->type != VEH_ROAD) return false;
if (!HasBit(e->info.callbackmask, CBM_VEHICLE_ARTIC_ENGINE)) return false;
for (uint i = 1; i < MAX_ARTICULATED_PARTS; i++) {
uint16 callback = GetVehicleCallback(CBID_VEHICLE_ARTIC_ENGINE, i, 0, engine, NULL);
if (callback == CALLBACK_FAILED || GB(callback, 0, 8) == 0xFF) break;
EngineID artic_engine = GetNewEngineID(GetEngineGRF(engine), e->type, GB(callback, 0, 7));
if (IsEngineRefittable(artic_engine)) return true;
}
return false;
}
/** /**
* Ors the refit_masks of all articulated parts. * Ors the refit_masks of all articulated parts.
* Note: Vehicles with a default capacity of zero are ignored.
* @param engine the first part * @param engine the first part
* @param type the vehicle type * @param type the vehicle type
* @param include_initial_cargo_type if true the default cargo type of the vehicle is included; if false only the refit_mask * @param include_initial_cargo_type if true the default cargo type of the vehicle is included; if false only the refit_mask
@ -146,7 +170,6 @@ uint32 GetUnionOfArticulatedRefitMasks(EngineID engine, VehicleType type, bool i
/** /**
* Ands the refit_masks of all articulated parts. * Ands the refit_masks of all articulated parts.
* Note: Vehicles with a default capacity of zero are ignored.
* @param engine the first part * @param engine the first part
* @param type the vehicle type * @param type the vehicle type
* @param include_initial_cargo_type if true the default cargo type of the vehicle is included; if false only the refit_mask * @param include_initial_cargo_type if true the default cargo type of the vehicle is included; if false only the refit_mask

View File

@ -14,5 +14,6 @@ void AddArticulatedParts(Vehicle **vl, VehicleType type);
uint32 GetUnionOfArticulatedRefitMasks(EngineID engine, VehicleType type, bool include_initial_cargo_type); uint32 GetUnionOfArticulatedRefitMasks(EngineID engine, VehicleType type, bool include_initial_cargo_type);
uint32 GetIntersectionOfArticulatedRefitMasks(EngineID engine, VehicleType type, bool include_initial_cargo_type); uint32 GetIntersectionOfArticulatedRefitMasks(EngineID engine, VehicleType type, bool include_initial_cargo_type);
bool IsArticulatedVehicleCarryingDifferentCargos(const Vehicle *v, CargoID *cargo_type); bool IsArticulatedVehicleCarryingDifferentCargos(const Vehicle *v, CargoID *cargo_type);
bool IsArticulatedVehicleRefittable(EngineID engine);
#endif /* ARTICULATED_VEHICLES_H */ #endif /* ARTICULATED_VEHICLES_H */

View File

@ -567,12 +567,11 @@ static int DrawRoadVehPurchaseInfo(int x, int y, EngineID engine_number)
DrawString(x, y, STR_PURCHASE_INFO_RUNNINGCOST, TC_FROMSTRING); DrawString(x, y, STR_PURCHASE_INFO_RUNNINGCOST, TC_FROMSTRING);
y += 10; y += 10;
/* Cargo type + capacity */ return y;
return DrawCargoCapacityInfo(x, y, engine_number, VEH_ROAD, IsEngineRefittable(engine_number));
} }
/* Draw ship specific details */ /* Draw ship specific details */
static int DrawShipPurchaseInfo(int x, int y, EngineID engine_number, const ShipVehicleInfo *svi) static int DrawShipPurchaseInfo(int x, int y, EngineID engine_number, const ShipVehicleInfo *svi, bool refittable)
{ {
const Engine *e = GetEngine(engine_number); const Engine *e = GetEngine(engine_number);
@ -585,7 +584,7 @@ static int DrawShipPurchaseInfo(int x, int y, EngineID engine_number, const Ship
/* Cargo type + capacity */ /* Cargo type + capacity */
SetDParam(0, e->GetDefaultCargoType()); SetDParam(0, e->GetDefaultCargoType());
SetDParam(1, GetEngineProperty(engine_number, 0x0D, svi->capacity)); SetDParam(1, GetEngineProperty(engine_number, 0x0D, svi->capacity));
SetDParam(2, IsEngineRefittable(engine_number) ? STR_9842_REFITTABLE : STR_EMPTY); SetDParam(2, refittable ? STR_9842_REFITTABLE : STR_EMPTY);
DrawString(x, y, STR_PURCHASE_INFO_CAPACITY, TC_FROMSTRING); DrawString(x, y, STR_PURCHASE_INFO_CAPACITY, TC_FROMSTRING);
y += 10; y += 10;
@ -598,7 +597,7 @@ static int DrawShipPurchaseInfo(int x, int y, EngineID engine_number, const Ship
} }
/* Draw aircraft specific details */ /* Draw aircraft specific details */
static int DrawAircraftPurchaseInfo(int x, int y, EngineID engine_number, const AircraftVehicleInfo *avi) static int DrawAircraftPurchaseInfo(int x, int y, EngineID engine_number, const AircraftVehicleInfo *avi, bool refittable)
{ {
const Engine *e = GetEngine(engine_number); const Engine *e = GetEngine(engine_number);
CargoID cargo = e->GetDefaultCargoType(); CargoID cargo = e->GetDefaultCargoType();
@ -619,7 +618,7 @@ static int DrawAircraftPurchaseInfo(int x, int y, EngineID engine_number, const
* callback, then the capacity shown is likely to be incorrect. */ * callback, then the capacity shown is likely to be incorrect. */
SetDParam(0, cargo); SetDParam(0, cargo);
SetDParam(1, AircraftDefaultCargoCapacity(cargo, avi)); SetDParam(1, AircraftDefaultCargoCapacity(cargo, avi));
SetDParam(2, STR_9842_REFITTABLE); SetDParam(2, refittable ? STR_9842_REFITTABLE : STR_EMPTY);
DrawString(x, y, STR_PURCHASE_INFO_CAPACITY, TC_FROMSTRING); DrawString(x, y, STR_PURCHASE_INFO_CAPACITY, TC_FROMSTRING);
} }
y += 10; y += 10;
@ -644,14 +643,12 @@ int DrawVehiclePurchaseInfo(int x, int y, uint w, EngineID engine_number)
const Engine *e = GetEngine(engine_number); const Engine *e = GetEngine(engine_number);
YearMonthDay ymd; YearMonthDay ymd;
ConvertDateToYMD(e->intro_date, &ymd); ConvertDateToYMD(e->intro_date, &ymd);
bool refittable = IsEngineRefittable(engine_number); bool refittable = IsArticulatedVehicleRefittable(engine_number);
switch (e->type) { switch (e->type) {
default: NOT_REACHED(); default: NOT_REACHED();
case VEH_TRAIN: { case VEH_TRAIN: {
const RailVehicleInfo *rvi = RailVehInfo(engine_number); const RailVehicleInfo *rvi = RailVehInfo(engine_number);
refittable &= GetEngineProperty(engine_number, 0x14, rvi->capacity) > 0;
if (rvi->railveh_type == RAILVEH_WAGON) { if (rvi->railveh_type == RAILVEH_WAGON) {
y = DrawRailWagonPurchaseInfo(x, y, engine_number, rvi); y = DrawRailWagonPurchaseInfo(x, y, engine_number, rvi);
} else { } else {
@ -671,14 +668,27 @@ int DrawVehiclePurchaseInfo(int x, int y, uint w, EngineID engine_number)
} }
break; break;
} }
case VEH_ROAD: case VEH_ROAD: {
y = DrawRoadVehPurchaseInfo(x, y, engine_number); y = DrawRoadVehPurchaseInfo(x, y, engine_number);
/* Cargo type + capacity, or N/A */
int new_y = DrawCargoCapacityInfo(x, y, engine_number, VEH_ROAD, refittable);
if (new_y == y) {
SetDParam(0, CT_INVALID);
SetDParam(2, STR_EMPTY);
DrawString(x, y, STR_PURCHASE_INFO_CAPACITY, TC_FROMSTRING);
y += 10;
} else {
y = new_y;
}
break; break;
}
case VEH_SHIP: case VEH_SHIP:
y = DrawShipPurchaseInfo(x, y, engine_number, ShipVehInfo(engine_number)); y = DrawShipPurchaseInfo(x, y, engine_number, ShipVehInfo(engine_number), refittable);
break; break;
case VEH_AIRCRAFT: case VEH_AIRCRAFT:
y = DrawAircraftPurchaseInfo(x, y, engine_number, AircraftVehInfo(engine_number)); y = DrawAircraftPurchaseInfo(x, y, engine_number, AircraftVehInfo(engine_number), refittable);
break; break;
} }

View File

@ -716,6 +716,7 @@ bool IsEngineBuildable(EngineID engine, VehicleType type, CompanyID company)
/** /**
* Check if an engine is refittable. * Check if an engine is refittable.
* Note: Likely you want to use IsArticulatedVehicleRefittable().
* @param engine index of the engine to check. * @param engine index of the engine to check.
* @return true if the engine is refittable. * @return true if the engine is refittable.
*/ */

View File

@ -29,6 +29,7 @@
#include "timetable.h" #include "timetable.h"
#include "vehiclelist.h" #include "vehiclelist.h"
#include "settings_type.h" #include "settings_type.h"
#include "articulated_vehicles.h"
#include "table/sprites.h" #include "table/sprites.h"
#include "table/strings.h" #include "table/strings.h"
@ -447,7 +448,7 @@ uint ShowAdditionalText(int x, int y, uint w, EngineID engine)
uint ShowRefitOptionsList(int x, int y, uint w, EngineID engine) uint ShowRefitOptionsList(int x, int y, uint w, EngineID engine)
{ {
/* List of cargo types of this engine */ /* List of cargo types of this engine */
uint32 cmask = EngInfo(engine)->refit_mask; uint32 cmask = GetUnionOfArticulatedRefitMasks(engine, GetEngine(engine)->type, false);
/* List of cargo types available in this climate */ /* List of cargo types available in this climate */
uint32 lmask = _cargo_mask; uint32 lmask = _cargo_mask;
char string[512]; char string[512];
@ -1667,9 +1668,6 @@ static bool IsVehicleRefitable(const Vehicle *v)
if (!v->IsStoppedInDepot()) return false; if (!v->IsStoppedInDepot()) return false;
do { do {
/* Skip this vehicle if it has no capacity */
if (v->cargo_cap == 0) continue;
if (IsEngineRefittable(v->engine_type)) return true; if (IsEngineRefittable(v->engine_type)) return true;
} while ((v->type == VEH_TRAIN || v->type == VEH_ROAD) && (v = v->Next()) != NULL); } while ((v->type == VEH_TRAIN || v->type == VEH_ROAD) && (v = v->Next()) != NULL);