mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-02-02 12:24:15 +00:00
(svn r16716) -Codechange: reduce code duplication in DrawCompanyVehiclesAmount()
This commit is contained in:
parent
93c5300fc5
commit
15990079ce
@ -1485,50 +1485,34 @@ static void DrawCompanyVehiclesAmount(CompanyID company, int right)
|
|||||||
{
|
{
|
||||||
const int x = 110;
|
const int x = 110;
|
||||||
int y = 63;
|
int y = 63;
|
||||||
const Vehicle *v;
|
uint amounts[] = { 0, 0, 0, 0 };
|
||||||
uint train = 0;
|
|
||||||
uint road = 0;
|
|
||||||
uint air = 0;
|
|
||||||
uint ship = 0;
|
|
||||||
|
|
||||||
DrawString(x, right, y, STR_COMPANY_VIEW_VEHICLES_TITLE);
|
DrawString(x, right, y, STR_COMPANY_VIEW_VEHICLES_TITLE);
|
||||||
|
|
||||||
|
const Vehicle *v;
|
||||||
FOR_ALL_VEHICLES(v) {
|
FOR_ALL_VEHICLES(v) {
|
||||||
if (v->owner == company) {
|
if (v->owner == company) {
|
||||||
switch (v->type) {
|
if (v->IsPrimaryVehicle()) {
|
||||||
case VEH_TRAIN: if (IsFrontEngine(v)) train++; break;
|
assert((size_t)v->type < lengthof(amounts));
|
||||||
case VEH_ROAD: if (IsRoadVehFront(v)) road++; break;
|
amounts[v->type]++;
|
||||||
case VEH_AIRCRAFT: if (IsNormalAircraft(v)) air++; break;
|
|
||||||
case VEH_SHIP: ship++; break;
|
|
||||||
default: break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (train + road + air + ship == 0) {
|
if (amounts[0] + amounts[1] + amounts[2] + amounts[3] == 0) {
|
||||||
DrawString(x + 70, right, y, STR_COMPANY_VIEW_VEHICLES_NONE);
|
DrawString(x + 70, right, y, STR_COMPANY_VIEW_VEHICLES_NONE);
|
||||||
} else {
|
} else {
|
||||||
if (train != 0) {
|
static const StringID strings[] = {
|
||||||
SetDParam(0, train);
|
STR_TRAINS, STR_ROAD_VEHICLES, STR_SHIPS, STR_AIRCRAFT
|
||||||
DrawString(x + 70, right, y, STR_TRAINS);
|
};
|
||||||
|
assert_compile(lengthof(amounts) == lengthof(strings));
|
||||||
|
|
||||||
|
for (uint i = 0; i < lengthof(amounts); i++) {
|
||||||
|
if (amounts[i] != 0) {
|
||||||
|
SetDParam(0, amounts[i]);
|
||||||
|
DrawString(x + 70, right, y, strings[i]);
|
||||||
y += 10;
|
y += 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (road != 0) {
|
|
||||||
SetDParam(0, road);
|
|
||||||
DrawString(x + 70, right, y, STR_ROAD_VEHICLES);
|
|
||||||
y += 10;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (air != 0) {
|
|
||||||
SetDParam(0, air);
|
|
||||||
DrawString(x + 70, right, y, STR_AIRCRAFT);
|
|
||||||
y += 10;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ship != 0) {
|
|
||||||
SetDParam(0, ship);
|
|
||||||
DrawString(x + 70, right, y, STR_SHIPS);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user