changeset 13881:693e91b02346 draft

(svn r18410) -Codechange: Move GetCargoSprite() to CargoSpec::GetCargoIcon().
author alberth <alberth@openttd.org>
date Sat, 05 Dec 2009 16:00:58 +0000
parents bde850c86447
children e3efddacc9f6
files src/cargotype.cpp src/cargotype.h src/station_gui.cpp
diffstat 3 files changed, 20 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/src/cargotype.cpp
+++ b/src/cargotype.cpp
@@ -12,6 +12,7 @@
 #include "stdafx.h"
 #include "cargotype.h"
 #include "core/bitmath_func.hpp"
+#include "newgrf_cargo.h"
 
 #include "table/sprites.h"
 #include "table/strings.h"
@@ -89,3 +90,19 @@
 	return CT_INVALID;
 }
 
+/** Get sprite for showing cargo of this type.
+ * @return Sprite number to use.
+ */
+SpriteID CargoSpec::GetCargoIcon() const
+{
+	SpriteID sprite = this->sprite;
+	if (sprite == 0xFFFF) {
+		/* A value of 0xFFFF indicates we should draw a custom icon */
+		sprite = GetCustomCargoSprite(this);
+	}
+
+	if (sprite == 0) sprite = SPR_CARGO_GOODS;
+
+	return sprite;
+}
+
--- a/src/cargotype.h
+++ b/src/cargotype.h
@@ -113,6 +113,8 @@
 		return &CargoSpec::array[index];
 	}
 
+	SpriteID GetCargoIcon() const;
+
 private:
 	static CargoSpec array[NUM_CARGO]; ///< Array holding all CargoSpecs
 
@@ -123,8 +125,6 @@
 
 /* Set up the default cargo types for the given landscape type */
 void SetupCargoForClimate(LandscapeID l);
-/* Get the cargo icon for a given cargo ID */
-SpriteID GetCargoSprite(CargoID i);
 /* Get the cargo ID with the cargo label */
 CargoID GetCargoIDByLabel(CargoLabel cl);
 CargoID GetCargoIDByBitnum(uint8 bitnum);
--- a/src/station_gui.cpp
+++ b/src/station_gui.cpp
@@ -25,7 +25,6 @@
 #include "viewport_func.h"
 #include "gfx_func.h"
 #include "widgets/dropdown_func.h"
-#include "newgrf_cargo.h"
 #include "station_base.h"
 #include "waypoint_base.h"
 #include "tilehighlight_func.h"
@@ -751,23 +750,6 @@
 	EndContainer(),
 };
 
-SpriteID GetCargoSprite(CargoID i)
-{
-	const CargoSpec *cs = CargoSpec::Get(i);
-	SpriteID sprite;
-
-	if (cs->sprite == 0xFFFF) {
-		/* A value of 0xFFFF indicates we should draw a custom icon */
-		sprite = GetCustomCargoSprite(cs);
-	} else {
-		sprite = cs->sprite;
-	}
-
-	if (sprite == 0) sprite = SPR_CARGO_GOODS;
-
-	return sprite;
-}
-
 /**
  * Draws icons of waiting cargo in the StationView window
  *
@@ -783,7 +765,7 @@
 	uint num = min((waiting + 5) / 10, (right - left) / 10); // maximum is width / 10 icons so it won't overflow
 	if (num == 0) return;
 
-	SpriteID sprite = GetCargoSprite(i);
+	SpriteID sprite = CargoSpec::Get(i)->GetCargoIcon();
 
 	int x = _dynlang.text_dir == TD_RTL ? right - num * 10 : left;
 	do {