Mercurial > hg > openttd
changeset 4817:e2984d603b59 draft
(svn r6741) - Codechange: Simplify and unify resolving of station groups, and use the first available cargo type instead of only the default.
author | peter1138 <peter1138@openttd.org> |
---|---|
date | Wed, 11 Oct 2006 22:05:59 +0000 |
parents | dd7d453b39ad |
children | d1176489b31f |
files | newgrf.c newgrf_spritegroup.h newgrf_station.c newgrf_station.h |
diffstat | 4 files changed, 55 insertions(+), 42 deletions(-) [+] |
line wrap: on
line diff
--- a/newgrf.c +++ b/newgrf.c @@ -1812,7 +1812,6 @@ 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);
--- a/newgrf_spritegroup.h +++ b/newgrf_spritegroup.h @@ -177,6 +177,7 @@ TileIndex tile; const struct Station *st; const struct StationSpec *statspec; + CargoID cargo_type; } station; } u;
--- a/newgrf_station.c +++ b/newgrf_station.c @@ -404,18 +404,28 @@ 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 @@ 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 @@ { 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 @@ { const SpriteGroup *group; ResolverObject object; - CargoID ctype = (st == NULL) ? GC_PURCHASE : GC_DEFAULT_NA; NewStationResolver(&object, statspec, st, tile); @@ -518,16 +540,8 @@ 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; }