(svn r6912) - Feature: Show a list of cargo types that a vehicle is refittable to in the purchase information window. (mart3p)

This commit is contained in:
peter1138 2006-10-23 21:39:15 +00:00
parent 552e6de4ce
commit 735c636f6f
7 changed files with 60 additions and 2 deletions

View File

@ -256,6 +256,7 @@ void DrawAircraftPurchaseInfo(int x, int y, uint w, EngineID engine_number)
/* Additional text from NewGRF */
y += ShowAdditionalText(x, y, w, engine_number);
y += ShowRefitOptionsList(x, y, w, engine_number);
}
void DrawAircraftImage(const Vehicle *v, int x, int y, VehicleID selection)

View File

@ -3021,6 +3021,9 @@ STR_PURCHASE_INFO_WEIGHT_CWEIGHT :{BLACK}Weight:
STR_PURCHASE_INFO_COST_SPEED :{BLACK}Cost: {GOLD}{CURRENCY}{BLACK} Speed: {GOLD}{VELOCITY}
STR_PURCHASE_INFO_AIRCRAFT_CAPACITY :{BLACK}Capacity: {GOLD}{COMMA} passengers, {COMMA} bags of mail
STR_PURCHASE_INFO_PWAGPOWER_PWAGWEIGHT :{BLACK}Powered Wagons: {GOLD}+{POWER}{BLACK} Weight: {GOLD}+{WEIGHT_S}
STR_PURCHASE_INFO_REFITTABLE_TO :{BLACK}Refittable to: {GOLD}
STR_PURCHASE_INFO_ALL_TYPES :All cargo types
STR_PURCHASE_INFO_ALL_BUT :All but {GOLD}
########### String for New Landscape Generator

View File

@ -66,6 +66,7 @@ void DrawRoadVehPurchaseInfo(int x, int y, uint w, EngineID engine_number)
/* Additional text from NewGRF */
y += ShowAdditionalText(x, y, w, engine_number);
y += ShowRefitOptionsList(x, y, w, engine_number);
}
void DrawRoadVehImage(const Vehicle *v, int x, int y, VehicleID selection)

View File

@ -66,6 +66,7 @@ void DrawShipPurchaseInfo(int x, int y, uint w, EngineID engine_number)
/* Additional text from NewGRF */
y += ShowAdditionalText(x, y, w, engine_number);
if (svi->refittable) y += ShowRefitOptionsList(x, y, w, engine_number);
}
void DrawShipImage(const Vehicle *v, int x, int y, VehicleID selection)

View File

@ -293,6 +293,7 @@ void DrawTrainEnginePurchaseInfo(int x, int y, uint w, EngineID engine_number)
/* Additional text from NewGRF */
y += ShowAdditionalText(x, y, w, engine_number);
y += ShowRefitOptionsList(x, y, w, engine_number);
}
/**
@ -337,6 +338,7 @@ void DrawTrainWagonPurchaseInfo(int x, int y, uint w, EngineID engine_number)
/* Additional text from NewGRF */
y += ShowAdditionalText(x, y, w, engine_number);
y += ShowRefitOptionsList(x, y, w, engine_number);
}
void CcBuildWagon(bool success, TileIndex tile, uint32 p1, uint32 p2)

View File

@ -482,7 +482,7 @@ void ShowVehicleRefitWindow(const Vehicle *v, VehicleOrderID order)
}
/* Display additional text from NewGRF in the purchase information window */
uint ShowAdditionalText(int x, int y, int w, EngineID engine)
uint ShowAdditionalText(int x, int y, uint w, EngineID engine)
{
uint16 callback = GetVehicleCallback(CBID_VEHICLE_ADDITIONAL_TEXT, 0, 0, engine, NULL);
if (callback == CALLBACK_FAILED) return 0;
@ -492,6 +492,55 @@ uint ShowAdditionalText(int x, int y, int w, EngineID engine)
return DrawStringMultiLine(x, y, STR_02BD, w);
}
/* Count the number of bits that are set in a mask */
static uint CountBits(uint32 mask)
{
uint c = 0;
for (; mask != 0; mask >>= 1) if (HASBIT(mask, 0)) c++;
return c;
}
/* Display list of cargo types of the engine, for the purchase information window */
uint ShowRefitOptionsList(int x, int y, uint w, EngineID engine)
{
/* List of cargo types of this engine */
uint32 cmask = EngInfo(engine)->refit_mask;
/* List of cargo types available in this climate */
uint32 lmask = _landscape_global_cargo_mask[_opt.landscape];
char *b = _userstring;
/* Draw nothing if the engine is not refittable */
if (CountBits(cmask) <= 1) return 0;
b = InlineString(b, STR_PURCHASE_INFO_REFITTABLE_TO);
if (cmask == lmask) {
/* Engine can be refitted to all types in this climate */
b = InlineString(b, STR_PURCHASE_INFO_ALL_TYPES);
} else {
CargoID cid;
/* Check if we are able to refit to more cargo types and unable to. If
* so, invert the cargo types to list those that we can't refit to. */
if (CountBits(cmask ^ lmask) < CountBits(cmask)) {
cmask ^= lmask;
b = InlineString(b, STR_PURCHASE_INFO_ALL_BUT);
}
/* Add each cargo type to the list */
for (cid = 0; cmask != 0; cmask >>= 1, cid++) {
if (!HASBIT(cmask, 0)) continue;
b = InlineString(b, _cargoc.names_s[_local_cargo_id_ctype[cid]]);
if (cmask > 1) b = strecpy(b, ", ", lastof(_userstring));
}
}
/* Terminate and display the completed string */
*b = '\0';
return DrawStringMultiLine(x, y, STR_SPEC_USERSTRING, w);
}
// if the sorting criteria had the same value, sort vehicle by unitnumber
#define VEHICLEUNITNUMBERSORTER(r, a, b) {if (r == 0) {r = a->unitnumber - b->unitnumber;}}

View File

@ -50,7 +50,8 @@ void ShowBuildVehicleWindow(TileIndex tile, byte type);
void ChangeVehicleViewWindow(const Vehicle *from_v, const Vehicle *to_v);
uint ShowAdditionalText(int x, int y, int w, EngineID engine);
uint ShowAdditionalText(int x, int y, uint w, EngineID engine);
uint ShowRefitOptionsList(int x, int y, uint w, EngineID engine);
void ShowVehicleListWindow(PlayerID player, StationID station, byte vehicle_type);
void ShowVehWithSharedOrders(Vehicle *v, byte vehicle_type);