Changeset - r11238:1abc5ab40770
[Not reviewed]
master
0 5 0
frosch - 16 years ago 2009-02-27 20:40:39
frosch@openttd.org
(svn r15592) -Fix: Refit-info in purchase list did only check the first articulated part.
5 files changed with 51 insertions and 18 deletions:
0 comments (0 inline, 0 general)
src/articulated_vehicles.cpp
Show inline comments
 
@@ -118,8 +118,32 @@ uint16 *GetCapacityOfArticulatedParts(En
 
}
 

	
 
/**
 
 * 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.
 
 * Note: Vehicles with a default capacity of zero are ignored.
 
 * @param engine the first part
 
 * @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
 
@@ -146,7 +170,6 @@ uint32 GetUnionOfArticulatedRefitMasks(E
 

	
 
/**
 
 * Ands the refit_masks of all articulated parts.
 
 * Note: Vehicles with a default capacity of zero are ignored.
 
 * @param engine the first part
 
 * @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
src/articulated_vehicles.h
Show inline comments
 
@@ -14,5 +14,6 @@ void AddArticulatedParts(Vehicle **vl, V
 
uint32 GetUnionOfArticulatedRefitMasks(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 IsArticulatedVehicleRefittable(EngineID engine);
 

	
 
#endif /* ARTICULATED_VEHICLES_H */
src/build_vehicle_gui.cpp
Show inline comments
 
@@ -567,12 +567,11 @@ static int DrawRoadVehPurchaseInfo(int x
 
	DrawString(x, y, STR_PURCHASE_INFO_RUNNINGCOST, TC_FROMSTRING);
 
	y += 10;
 

	
 
	/* Cargo type + capacity */
 
	return DrawCargoCapacityInfo(x, y, engine_number, VEH_ROAD, IsEngineRefittable(engine_number));
 
	return y;
 
}
 

	
 
/* 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);
 

	
 
@@ -585,7 +584,7 @@ static int DrawShipPurchaseInfo(int x, i
 
	/* Cargo type + capacity */
 
	SetDParam(0, e->GetDefaultCargoType());
 
	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);
 
	y += 10;
 

	
 
@@ -598,7 +597,7 @@ static int DrawShipPurchaseInfo(int x, i
 
}
 

	
 
/* 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);
 
	CargoID cargo = e->GetDefaultCargoType();
 
@@ -619,7 +618,7 @@ static int DrawAircraftPurchaseInfo(int 
 
		* callback, then the capacity shown is likely to be incorrect. */
 
		SetDParam(0, cargo);
 
		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);
 
	}
 
	y += 10;
 
@@ -644,14 +643,12 @@ int DrawVehiclePurchaseInfo(int x, int y
 
	const Engine *e = GetEngine(engine_number);
 
	YearMonthDay ymd;
 
	ConvertDateToYMD(e->intro_date, &ymd);
 
	bool refittable = IsEngineRefittable(engine_number);
 
	bool refittable = IsArticulatedVehicleRefittable(engine_number);
 

	
 
	switch (e->type) {
 
		default: NOT_REACHED();
 
		case VEH_TRAIN: {
 
			const RailVehicleInfo *rvi = RailVehInfo(engine_number);
 
			refittable &= GetEngineProperty(engine_number, 0x14, rvi->capacity) > 0;
 

	
 
			if (rvi->railveh_type == RAILVEH_WAGON) {
 
				y = DrawRailWagonPurchaseInfo(x, y, engine_number, rvi);
 
			} else {
 
@@ -671,14 +668,27 @@ int DrawVehiclePurchaseInfo(int x, int y
 
			}
 
			break;
 
		}
 
		case VEH_ROAD:
 
		case VEH_ROAD: {
 
			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;
 
		}
 
		case VEH_SHIP:
 
			y = DrawShipPurchaseInfo(x, y, engine_number, ShipVehInfo(engine_number));
 
			y = DrawShipPurchaseInfo(x, y, engine_number, ShipVehInfo(engine_number), refittable);
 
			break;
 
		case VEH_AIRCRAFT:
 
			y = DrawAircraftPurchaseInfo(x, y, engine_number, AircraftVehInfo(engine_number));
 
			y = DrawAircraftPurchaseInfo(x, y, engine_number, AircraftVehInfo(engine_number), refittable);
 
			break;
 
	}
 

	
src/engine.cpp
Show inline comments
 
@@ -716,6 +716,7 @@ bool IsEngineBuildable(EngineID engine, 
 

	
 
/**
 
 * Check if an engine is refittable.
 
 * Note: Likely you want to use IsArticulatedVehicleRefittable().
 
 * @param engine index of the engine to check.
 
 * @return true if the engine is refittable.
 
 */
src/vehicle_gui.cpp
Show inline comments
 
@@ -29,6 +29,7 @@
 
#include "timetable.h"
 
#include "vehiclelist.h"
 
#include "settings_type.h"
 
#include "articulated_vehicles.h"
 

	
 
#include "table/sprites.h"
 
#include "table/strings.h"
 
@@ -447,7 +448,7 @@ uint ShowAdditionalText(int x, int y, ui
 
uint ShowRefitOptionsList(int x, int y, uint w, EngineID 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 */
 
	uint32 lmask = _cargo_mask;
 
	char string[512];
 
@@ -1667,9 +1668,6 @@ static bool IsVehicleRefitable(const Veh
 
	if (!v->IsStoppedInDepot()) return false;
 

	
 
	do {
 
		/* Skip this vehicle if it has no capacity */
 
		if (v->cargo_cap == 0) continue;
 

	
 
		if (IsEngineRefittable(v->engine_type)) return true;
 
	} while ((v->type == VEH_TRAIN || v->type == VEH_ROAD) && (v = v->Next()) != NULL);
 

	
0 comments (0 inline, 0 general)