Add "Freight" type to vehicle list cargo type filter

This commit is contained in:
Jonathan G Rennison
2017-10-17 23:08:23 +01:00
parent 71c133e203
commit 1defb8aafd
3 changed files with 22 additions and 2 deletions

View File

@@ -162,6 +162,18 @@ static bool CDECL CargoFilter(const Vehicle * const *vid, const CargoID cid)
}
}
return true;
} else if (cid == BaseVehicleListWindow::CF_FREIGHT) {
bool have_capacity = false;
for (const Vehicle *w = (*vid); w != NULL; w = w->Next()) {
if (w->cargo_cap) {
if (IsCargoInClass(w->cargo_type, CC_PASSENGERS)) {
return false;
} else {
have_capacity = true;
}
}
}
return have_capacity;
} else {
for (const Vehicle *w = (*vid); w != NULL; w = w->Next()) {
if (w->cargo_cap > 0 && w->cargo_type == cid) {
@@ -199,6 +211,11 @@ void BaseVehicleListWindow::SetCargoFilterArray()
this->cargo_filter_criteria = filter_items;
filter_items++;
/* Add item for freight (i.e. vehicles with cargo capacity and with no passenger capacity) */
this->cargo_filter[filter_items] = CF_FREIGHT;
this->cargo_filter_texts[filter_items] = STR_CARGO_TYPE_FREIGHT;
filter_items++;
/* Add item for vehicles not carrying anything, e.g. train engines.
* This could also be useful for eyecandy vehicles of other types, but is likely too confusing for joe, */
this->cargo_filter[filter_items] = CF_NONE;