diff options
author | smatz <smatz@openttd.org> | 2009-07-01 21:33:06 +0000 |
---|---|---|
committer | smatz <smatz@openttd.org> | 2009-07-01 21:33:06 +0000 |
commit | 15990079ce2bb53446305c5b61c7a620cd58b2dc (patch) | |
tree | 558f5d4484007e4fa135c79fd36fb11913daadb5 /src | |
parent | 93c5300fc5cf8041b4e57eac0c714d5f55a6ed8b (diff) | |
download | openttd-15990079ce2bb53446305c5b61c7a620cd58b2dc.tar.xz |
(svn r16716) -Codechange: reduce code duplication in DrawCompanyVehiclesAmount()
Diffstat (limited to 'src')
-rw-r--r-- | src/company_gui.cpp | 48 |
1 files changed, 16 insertions, 32 deletions
diff --git a/src/company_gui.cpp b/src/company_gui.cpp index 04f280a73..e71d86585 100644 --- a/src/company_gui.cpp +++ b/src/company_gui.cpp @@ -1485,50 +1485,34 @@ static void DrawCompanyVehiclesAmount(CompanyID company, int right) { const int x = 110; int y = 63; - const Vehicle *v; - uint train = 0; - uint road = 0; - uint air = 0; - uint ship = 0; + uint amounts[] = { 0, 0, 0, 0 }; DrawString(x, right, y, STR_COMPANY_VIEW_VEHICLES_TITLE); + const Vehicle *v; FOR_ALL_VEHICLES(v) { if (v->owner == company) { - switch (v->type) { - case VEH_TRAIN: if (IsFrontEngine(v)) train++; break; - case VEH_ROAD: if (IsRoadVehFront(v)) road++; break; - case VEH_AIRCRAFT: if (IsNormalAircraft(v)) air++; break; - case VEH_SHIP: ship++; break; - default: break; + if (v->IsPrimaryVehicle()) { + assert((size_t)v->type < lengthof(amounts)); + amounts[v->type]++; } } } - 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); } else { - if (train != 0) { - SetDParam(0, train); - DrawString(x + 70, right, y, STR_TRAINS); - 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; - } + static const StringID strings[] = { + STR_TRAINS, STR_ROAD_VEHICLES, STR_SHIPS, STR_AIRCRAFT + }; + assert_compile(lengthof(amounts) == lengthof(strings)); - if (ship != 0) { - SetDParam(0, ship); - DrawString(x + 70, right, y, STR_SHIPS); + 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; + } } } } |