summaryrefslogtreecommitdiff
path: root/src/newgrf_station.cpp
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2014-03-03 20:02:31 +0000
committerfrosch <frosch@openttd.org>2014-03-03 20:02:31 +0000
commit6b61c4608fab00c7bfc78c296b3c85f611681f59 (patch)
tree9919983ecf008602a497445b2b3e05b5c32892b8 /src/newgrf_station.cpp
parentb935cb84156f18b51196288ff6d12f8ca5b26630 (diff)
downloadopenttd-6b61c4608fab00c7bfc78c296b3c85f611681f59.tar.xz
(svn r26388) -Codechange: Move resolving of Action 3 into ResolverObject constructor.
Diffstat (limited to 'src/newgrf_station.cpp')
-rw-r--r--src/newgrf_station.cpp72
1 files changed, 31 insertions, 41 deletions
diff --git a/src/newgrf_station.cpp b/src/newgrf_station.cpp
index 85277337d..647e8781a 100644
--- a/src/newgrf_station.cpp
+++ b/src/newgrf_station.cpp
@@ -550,6 +550,32 @@ StationResolverObject::StationResolverObject(const StationSpec *statspec, BaseSt
{
/* Invalidate all cached vars */
_svc.valid = 0;
+
+ CargoID ctype = CT_DEFAULT_NA;
+
+ if (this->station_scope.st == NULL) {
+ /* No station, so we are in a purchase list */
+ ctype = CT_PURCHASE;
+ } else if (Station::IsExpected(this->station_scope.st)) {
+ const Station *st = Station::From(this->station_scope.st);
+ /* Pick the first cargo that we have waiting */
+ const CargoSpec *cs;
+ FOR_ALL_CARGOSPECS(cs) {
+ if (this->station_scope.statspec->grf_prop.spritegroup[cs->Index()] != NULL &&
+ st->goods[cs->Index()].cargo.TotalCount() > 0) {
+ ctype = cs->Index();
+ break;
+ }
+ }
+ }
+
+ if (this->station_scope.statspec->grf_prop.spritegroup[ctype] == NULL) {
+ ctype = CT_DEFAULT;
+ }
+
+ /* Remember the cargo type we've picked */
+ this->station_scope.cargo_type = ctype;
+ this->root_spritegroup = this->station_scope.statspec->grf_prop.spritegroup[this->station_scope.cargo_type];
}
StationResolverObject::~StationResolverObject()
@@ -574,39 +600,6 @@ StationScopeResolver::StationScopeResolver(ResolverObject &ro, const StationSpec
this->axis = INVALID_AXIS;
}
-static const SpriteGroup *ResolveStation(StationResolverObject &object)
-{
- CargoID ctype = CT_DEFAULT_NA;
-
- if (object.station_scope.st == NULL) {
- /* No station, so we are in a purchase list */
- ctype = CT_PURCHASE;
- } else if (Station::IsExpected(object.station_scope.st)) {
- const Station *st = Station::From(object.station_scope.st);
- /* Pick the first cargo that we have waiting */
- const CargoSpec *cs;
- FOR_ALL_CARGOSPECS(cs) {
- if (object.station_scope.statspec->grf_prop.spritegroup[cs->Index()] != NULL &&
- st->goods[cs->Index()].cargo.TotalCount() > 0) {
- ctype = cs->Index();
- break;
- }
- }
- }
-
- const SpriteGroup *group = object.station_scope.statspec->grf_prop.spritegroup[ctype];
- if (group == NULL) {
- ctype = CT_DEFAULT;
- group = object.station_scope.statspec->grf_prop.spritegroup[ctype];
- if (group == NULL) return NULL;
- }
-
- /* Remember the cargo type we've picked */
- object.station_scope.cargo_type = ctype;
-
- return SpriteGroup::Resolve(group, object);
-}
-
/**
* Resolve sprites for drawing a station tile.
* @param statspec Station spec
@@ -618,7 +611,7 @@ static const SpriteGroup *ResolveStation(StationResolverObject &object)
SpriteID GetCustomStationRelocation(const StationSpec *statspec, BaseStation *st, TileIndex tile, uint32 var10)
{
StationResolverObject object(statspec, st, tile, CBID_NO_CALLBACK, var10);
- const SpriteGroup *group = ResolveStation(object);
+ const SpriteGroup *group = object.Resolve();
if (group == NULL || group->type != SGT_RESULT) return 0;
return group->GetResult() - 0x42D;
}
@@ -637,7 +630,7 @@ SpriteID GetCustomStationFoundationRelocation(const StationSpec *statspec, BaseS
/* callback_param1 == 2 means we are resolving the foundation sprites. */
StationResolverObject object(statspec, st, tile, CBID_NO_CALLBACK, 2, layout | (edge_info << 16));
- const SpriteGroup *group = ResolveStation(object);
+ const SpriteGroup *group = object.Resolve();
if (group == NULL || group->type != SGT_RESULT) return 0;
/* Note: SpriteGroup::Resolve zeroes all registers, so register 0x100 is initialised to 0. (compatibility) */
@@ -648,9 +641,7 @@ SpriteID GetCustomStationFoundationRelocation(const StationSpec *statspec, BaseS
uint16 GetStationCallback(CallbackID callback, uint32 param1, uint32 param2, const StationSpec *statspec, BaseStation *st, TileIndex tile)
{
StationResolverObject object(statspec, st, tile, callback, param1, param2);
- const SpriteGroup *group = ResolveStation(object);
- if (group == NULL) return CALLBACK_FAILED;
- return group->GetCallbackResult();
+ return object.ResolveCallback();
}
/**
@@ -673,8 +664,7 @@ CommandCost PerformStationTileSlopeCheck(TileIndex north_tile, TileIndex cur_til
(numtracks << 24) | (plat_len << 16) | (axis == AXIS_Y ? TileX(diff) << 8 | TileY(diff) : TileY(diff) << 8 | TileX(diff)));
object.station_scope.axis = axis;
- const SpriteGroup *group = ResolveStation(object);
- uint16 cb_res = group != NULL ? group->GetCallbackResult() : CALLBACK_FAILED;
+ uint16 cb_res = object.ResolveCallback();
/* Failed callback means success. */
if (cb_res == CALLBACK_FAILED) return CommandCost();
@@ -1024,7 +1014,7 @@ void TriggerStationRandomisation(Station *st, TileIndex tile, StationRandomTrigg
StationResolverObject object(ss, st, tile, CBID_RANDOM_TRIGGER, 0);
object.trigger = trigger_bit;
- const SpriteGroup *group = ResolveStation(object);
+ const SpriteGroup *group = object.Resolve();
if (group == NULL) continue;
uint32 reseed = object.GetReseedSum();