--- a/src/station_gui.cpp Mon Mar 26 21:31:37 2007 +0000
+++ b/src/station_gui.cpp Mon Mar 26 22:15:38 2007 +0000
@@ -267,7 +267,8 @@
sl->flags &= ~SL_RESORT;
}
-static uint32 _cargo_filter = std::numeric_limits<uint32>::max();
+static const uint32 _cargo_filter_max = ~0;
+static uint32 _cargo_filter = _cargo_filter_max;
static void PlayerStationsWndProc(BaseWindow *w, WindowEvent *e)
{
@@ -280,7 +281,7 @@
switch (e->event) {
case WE_CREATE: /* set up resort timer */
- if (_cargo_filter == std::numeric_limits<uint32>::max()) _cargo_filter = _cargo_mask;
+ if (_cargo_filter == _cargo_filter_max) _cargo_filter = _cargo_mask;
for (uint i = 0; i < 5; i++) {
if (HASBIT(facilities, i)) w->LowerWidget(i + STATIONLIST_WIDGET_TRAIN);
@@ -362,7 +363,7 @@
x = DrawString(xb, y, STR_3049_0, 0) + 5;
// show cargo waiting and station ratings
- for (CargoID j = 0; j != NUM_CARGO; j++) {
+ for (CargoID j = 0; j < NUM_CARGO; j++) {
uint amount = GB(st->goods[j].waiting_acceptance, 0, 12);
if (amount != 0) {
StationsWndShowStationRating(x, y, j, amount, st->goods[j].rating);
@@ -665,6 +666,30 @@
{ WIDGETS_END},
};
+
+static void DrawCargoIcons(CargoID i, uint waiting, int x, int y)
+{
+ uint num = min((waiting + 5) / 10, 23);
+ if (num == 0) return;
+
+ const CargoSpec *cs = GetCargo(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) return;
+
+ do {
+ DrawSprite(sprite, PAL_NONE, x, y);
+ x += 10;
+ } while (--num);
+}
+
static void DrawStationViewWindow(BaseWindow *w)
{
StationID station_id = w->window_number;
@@ -675,7 +700,7 @@
StringID str;
num = 1;
- for (CargoID i = 0; i != NUM_CARGO; i++) {
+ for (CargoID i = 0; i < NUM_CARGO; i++) {
if (GB(st->goods[i].waiting_acceptance, 0, 12) != 0) {
num++;
if (st->goods[i].enroute_from != station_id) num++;
@@ -699,7 +724,7 @@
if (--pos < 0) {
str = STR_00D0_NOTHING;
- for (CargoID i = 0; i != NUM_CARGO; i++) {
+ for (CargoID i = 0; i < NUM_CARGO; i++) {
if (GB(st->goods[i].waiting_acceptance, 0, 12) != 0) str = STR_EMPTY;
}
SetDParam(0, str);
@@ -707,22 +732,13 @@
y += 10;
}
- for (CargoID i = 0; i != NUM_CARGO && pos > -5; i++) {
+ for (CargoID i = 0; i < NUM_CARGO && pos > -5; i++) {
uint waiting = GB(st->goods[i].waiting_acceptance, 0, 12);
if (waiting == 0) continue;
- num = (waiting + 5) / 10;
- if (num != 0) {
- int cur_x = x;
- num = min(num, 23);
- do {
- DrawSprite(GetCargo(i)->sprite, PAL_NONE, cur_x, y);
- cur_x += 10;
- } while (--num);
- }
-
if (st->goods[i].enroute_from == station_id) {
if (--pos < 0) {
+ DrawCargoIcons(i, waiting, x, y);
SetDParam(1, waiting);
SetDParam(0, i);
DrawStringRightAligned(x + 234, y, STR_0009, 0);
@@ -731,6 +747,7 @@
} else {
/* enroute */
if (--pos < 0) {
+ DrawCargoIcons(i, waiting, x, y);
SetDParam(1, waiting);
SetDParam(0, i);
DrawStringRightAligned(x + 234, y, STR_000A_EN_ROUTE_FROM, 0);
@@ -751,7 +768,7 @@
b = InlineString(b, STR_000C_ACCEPTS);
- for (CargoID i = 0; i != NUM_CARGO; i++) {
+ for (CargoID i = 0; i < NUM_CARGO; i++) {
if (b >= endof(_userstring) - 5 - 1) break;
if (st->goods[i].waiting_acceptance & 0x8000) {
if (first) {
@@ -774,14 +791,18 @@
DrawString(2, 67, STR_3034_LOCAL_RATING_OF_TRANSPORT, 0);
y = 77;
- for (CargoID i = 0; i != NUM_CARGO; i++) {
- if (st->goods[i].enroute_from != INVALID_STATION) {
- SetDParam(0, GetCargo(i)->name);
- SetDParam(2, st->goods[i].rating * 101 >> 8);
- SetDParam(1, STR_3035_APPALLING + (st->goods[i].rating >> 5));
- DrawString(8, y, STR_303D, 0);
- y += 10;
- }
+ for (CargoID i = 0; i < NUM_CARGO; i++) {
+ const CargoSpec *cs = GetCargo(i);
+ if (!cs->IsValid()) continue;
+
+ const GoodsEntry *ge = &st->goods[i];
+ if (ge->enroute_from == INVALID_STATION) continue;
+
+ SetDParam(0, cs->name);
+ SetDParam(2, ge->rating * 101 >> 8);
+ SetDParam(1, STR_3035_APPALLING + (ge->rating >> 5));
+ DrawString(8, y, STR_303D, 0);
+ y += 10;
}
}
}