summaryrefslogtreecommitdiff
path: root/src/town_gui.cpp
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2009-12-06 16:15:58 +0000
committerfrosch <frosch@openttd.org>2009-12-06 16:15:58 +0000
commit7d905fae222b5c657138ba384519e3d033abc9ef (patch)
tree56db02b1d03a3729e7c9fa475c3d532dd778852e /src/town_gui.cpp
parenta68849fb56bc0d27f26ba7f514255d8f6e0b4bcc (diff)
downloadopenttd-7d905fae222b5c657138ba384519e3d033abc9ef.tar.xz
(svn r18416) -Fix (r15559): Only consider valid cargos in town GUI.
Diffstat (limited to 'src/town_gui.cpp')
-rw-r--r--src/town_gui.cpp36
1 files changed, 21 insertions, 15 deletions
diff --git a/src/town_gui.cpp b/src/town_gui.cpp
index d5aedddee..4951254ca 100644
--- a/src/town_gui.cpp
+++ b/src/town_gui.cpp
@@ -342,6 +342,20 @@ public:
if (widget == TVW_CAPTION) SetDParam(0, this->town->index);
}
+ /**
+ * Determines the first cargo with a certain town effect
+ * @param effect Town effect of interest
+ * @return first active cargo slot with that effect
+ */
+ const CargoSpec *FindFirstCargoWithTownEffect(TownEffect effect) const
+ {
+ const CargoSpec *cs;
+ FOR_ALL_CARGOSPECS(cs) {
+ if (cs->town_effect == effect) return cs;
+ }
+ return NULL;
+ }
+
virtual void DrawWidget(const Rect &r, int widget) const
{
if (widget != TVW_INFOPANEL) return;
@@ -380,21 +394,13 @@ public:
uint cargo_text_left = r.left + WD_FRAMERECT_LEFT + (rtl ? 0 : 20);
uint cargo_text_right = r.right - WD_FRAMERECT_RIGHT - (rtl ? 20 : 0);
- CargoID first_food_cargo = CT_INVALID;
- StringID food_name = STR_CARGO_PLURAL_FOOD;
- CargoID first_water_cargo = CT_INVALID;
- StringID water_name = STR_CARGO_PLURAL_WATER;
- for (CargoID cid = 0; cid < NUM_CARGO; cid++) {
- const CargoSpec *cs = CargoSpec::Get(cid);
- if (first_food_cargo == CT_INVALID && cs->town_effect == TE_FOOD) {
- first_food_cargo = cid;
- food_name = cs->name;
- }
- if (first_water_cargo == CT_INVALID && cs->town_effect == TE_WATER) {
- first_water_cargo = cid;
- water_name = cs->name;
- }
- }
+ const CargoSpec *food = FindFirstCargoWithTownEffect(TE_FOOD);
+ CargoID first_food_cargo = (food != NULL) ? food->Index() : (CargoID)CT_INVALID;
+ StringID food_name = (food != NULL) ? food->name : STR_CARGO_PLURAL_FOOD;
+
+ const CargoSpec *water = FindFirstCargoWithTownEffect(TE_WATER);
+ CargoID first_water_cargo = (water != NULL) ? water->Index() : (CargoID)CT_INVALID;
+ StringID water_name = (water != NULL) ? water->name : STR_CARGO_PLURAL_WATER;
if (first_food_cargo != CT_INVALID && this->town->act_food > 0) {
SetDParam(0, first_food_cargo);