summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--newgrf.c1
-rw-r--r--newgrf_spritegroup.h1
-rw-r--r--newgrf_station.c94
-rw-r--r--newgrf_station.h1
4 files changed, 55 insertions, 42 deletions
diff --git a/newgrf.c b/newgrf.c
index b34292109..61d78910f 100644
--- a/newgrf.c
+++ b/newgrf.c
@@ -1812,7 +1812,6 @@ static void FeatureMapSpriteGroup(byte *buf, int len)
StationSpec *statspec = _cur_grffile->stations[stid];
statspec->spritegroup[GC_DEFAULT] = _cur_grffile->spritegroups[groupid];
- statspec->groundgroup = _cur_grffile->spritegroups[0];
statspec->grfid = _cur_grffile->grfid;
statspec->localidx = stid;
SetCustomStationSpec(statspec);
diff --git a/newgrf_spritegroup.h b/newgrf_spritegroup.h
index 216e2580b..e3c296be9 100644
--- a/newgrf_spritegroup.h
+++ b/newgrf_spritegroup.h
@@ -177,6 +177,7 @@ typedef struct ResolverObject {
TileIndex tile;
const struct Station *st;
const struct StationSpec *statspec;
+ CargoID cargo_type;
} station;
} u;
diff --git a/newgrf_station.c b/newgrf_station.c
index 548727b7d..04688821d 100644
--- a/newgrf_station.c
+++ b/newgrf_station.c
@@ -404,18 +404,28 @@ static const SpriteGroup *StationResolveReal(const ResolverObject *object, const
uint set;
uint cargo = 0;
- CargoID cargo_type = CT_INVALID; /* XXX Pick the correct cargo type */
+ CargoID cargo_type = object->u.station.cargo_type;
if (st == NULL || statspec->sclass == STAT_CLASS_WAYP) {
return group->g.real.loading[0];
}
- if (cargo_type == CT_INVALID) {
- for (cargo_type = 0; cargo_type < NUM_CARGO; cargo_type++) {
- cargo += GB(st->goods[cargo_type].waiting_acceptance, 0, 12);
- }
- } else {
- cargo = GB(st->goods[cargo_type].waiting_acceptance, 0, 12);
+ switch (cargo_type) {
+ case GC_INVALID:
+ case GC_DEFAULT_NA:
+ case GC_PURCHASE:
+ cargo = 0;
+ break;
+
+ case GC_DEFAULT:
+ for (cargo_type = 0; cargo_type < NUM_CARGO; cargo_type++) {
+ cargo += GB(st->goods[cargo_type].waiting_acceptance, 0, 12);
+ }
+ break;
+
+ default:
+ cargo = GB(st->goods[_local_cargo_id_ctype[cargo_type]].waiting_acceptance, 0, 12);
+ break;
}
if (HASBIT(statspec->flags, 1)) cargo /= (st->trainst_w + st->trainst_h);
@@ -457,25 +467,50 @@ static void NewStationResolver(ResolverObject *res, const StationSpec *statspec,
res->reseed = 0;
}
+static const SpriteGroup *ResolveStation(const StationSpec *statspec, const Station *st, ResolverObject *object)
+{
+ const SpriteGroup *group;
+ CargoID ctype = GC_DEFAULT_NA;
+
+ if (st == NULL) {
+ /* No station, so we are in a purchase list */
+ ctype = GC_PURCHASE;
+ } else {
+ CargoID cargo;
+
+ /* Pick the first cargo that we have waiting */
+ for (cargo = 0; cargo < NUM_GLOBAL_CID; cargo++) {
+ CargoID lcid = _local_cargo_id_ctype[cargo];
+ if (lcid != CT_INVALID && statspec->spritegroup[cargo] != NULL && GB(st->goods[lcid].waiting_acceptance, 0, 12) != 0) {
+ ctype = cargo;
+ break;
+ }
+ }
+ }
+
+ group = statspec->spritegroup[ctype];
+ if (group == NULL) {
+ ctype = GC_DEFAULT;
+ group = statspec->spritegroup[ctype];
+ }
+
+ if (group == NULL) return NULL;
+
+ /* Remember the cargo type we've picked */
+ object->u.station.cargo_type = ctype;
+
+ return Resolve(group, object);
+}
SpriteID GetCustomStationRelocation(const StationSpec *statspec, const Station *st, TileIndex tile)
{
const SpriteGroup *group;
ResolverObject object;
- CargoID ctype = (st == NULL) ? GC_PURCHASE : GC_DEFAULT_NA;
NewStationResolver(&object, statspec, st, tile);
- group = Resolve(statspec->spritegroup[ctype], &object);
- if ((group == NULL || group->type != SGT_RESULT) && ctype != GC_DEFAULT_NA) {
- group = Resolve(statspec->spritegroup[GC_DEFAULT_NA], &object);
- }
- if ((group == NULL || group->type != SGT_RESULT) && ctype != GC_DEFAULT) {
- group = Resolve(statspec->spritegroup[GC_DEFAULT], &object);
- }
-
+ group = ResolveStation(statspec, st, &object);
if (group == NULL || group->type != SGT_RESULT) return 0;
-
return group->g.result.sprite - 0x42D;
}
@@ -484,24 +519,12 @@ SpriteID GetCustomStationGroundRelocation(const StationSpec *statspec, const Sta
{
const SpriteGroup *group;
ResolverObject object;
- CargoID ctype = (st == NULL) ? GC_PURCHASE : GC_DEFAULT_NA;
NewStationResolver(&object, statspec, st, tile);
object.callback_param1 = 1; /* Indicate we are resolving the ground sprite */
- group = Resolve(statspec->spritegroup[ctype], &object);
- if ((group == NULL || group->type != SGT_RESULT) && ctype != GC_DEFAULT_NA) {
- group = Resolve(statspec->spritegroup[GC_DEFAULT_NA], &object);
- }
- if ((group == NULL || group->type != SGT_RESULT) && ctype != GC_DEFAULT) {
- group = Resolve(statspec->spritegroup[GC_DEFAULT], &object);
- }
- if ((group == NULL || group->type != SGT_RESULT)) {
- group = Resolve(statspec->groundgroup, &object);
- }
-
+ group = ResolveStation(statspec, st, &object);
if (group == NULL || group->type != SGT_RESULT) return 0;
-
return group->g.result.sprite - 0x42D;
}
@@ -510,7 +533,6 @@ uint16 GetStationCallback(uint16 callback, uint32 param1, uint32 param2, const S
{
const SpriteGroup *group;
ResolverObject object;
- CargoID ctype = (st == NULL) ? GC_PURCHASE : GC_DEFAULT_NA;
NewStationResolver(&object, statspec, st, tile);
@@ -518,16 +540,8 @@ uint16 GetStationCallback(uint16 callback, uint32 param1, uint32 param2, const S
object.callback_param1 = param1;
object.callback_param2 = param2;
- group = Resolve(statspec->spritegroup[ctype], &object);
- if ((group == NULL || group->type != SGT_CALLBACK) && ctype != GC_DEFAULT_NA) {
- group = Resolve(statspec->spritegroup[GC_DEFAULT_NA], &object);
- }
- if ((group == NULL || group->type != SGT_CALLBACK) && ctype != GC_DEFAULT) {
- group = Resolve(statspec->spritegroup[GC_DEFAULT], &object);
- }
-
+ group = ResolveStation(statspec, st, &object);
if (group == NULL || group->type != SGT_CALLBACK) return CALLBACK_FAILED;
-
return group->g.callback.result;
}
diff --git a/newgrf_station.h b/newgrf_station.h
index b1f135e54..e624f9695 100644
--- a/newgrf_station.h
+++ b/newgrf_station.h
@@ -74,7 +74,6 @@ typedef struct StationSpec {
* evaluating callbacks.
*/
struct SpriteGroup *spritegroup[NUM_GLOBAL_CID];
- struct SpriteGroup *groundgroup;
} StationSpec;
/**