summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2011-07-04 20:31:57 +0000
committerfrosch <frosch@openttd.org>2011-07-04 20:31:57 +0000
commit8b18292a2ec1be31d7c1fe7cfcba26facb9c7ada (patch)
treed7620f4ae011379b988374683f8a38dacb49a2fb /src
parentd2b236802cb202c07aa7586b197935b96dddee7b (diff)
downloadopenttd-8b18292a2ec1be31d7c1fe7cfcba26facb9c7ada.tar.xz
(svn r22634) -Codechange: Deduplicate some code. Note that zeroing 'count' is intentionally removed, it is only used together with 'scope'.
Diffstat (limited to 'src')
-rw-r--r--src/newgrf_airport.cpp5
-rw-r--r--src/newgrf_airporttiles.cpp5
-rw-r--r--src/newgrf_canal.cpp6
-rw-r--r--src/newgrf_cargo.cpp6
-rw-r--r--src/newgrf_engine.cpp5
-rw-r--r--src/newgrf_generic.cpp6
-rw-r--r--src/newgrf_house.cpp5
-rw-r--r--src/newgrf_industries.cpp5
-rw-r--r--src/newgrf_industrytiles.cpp5
-rw-r--r--src/newgrf_object.cpp5
-rw-r--r--src/newgrf_railtype.cpp5
-rw-r--r--src/newgrf_spritegroup.h11
-rw-r--r--src/newgrf_station.cpp6
13 files changed, 27 insertions, 48 deletions
diff --git a/src/newgrf_airport.cpp b/src/newgrf_airport.cpp
index 0b1dd650c..8bf1ff3e8 100644
--- a/src/newgrf_airport.cpp
+++ b/src/newgrf_airport.cpp
@@ -224,10 +224,7 @@ static void NewAirportResolver(ResolverObject *res, TileIndex tile, Station *st,
res->callback = CBID_NO_CALLBACK;
res->callback_param1 = 0;
res->callback_param2 = 0;
- res->last_value = 0;
- res->trigger = 0;
- res->reseed = 0;
- res->count = 0;
+ res->ResetState();
const AirportSpec *as = AirportSpec::Get(airport_id);
res->grffile = as->grf_prop.grffile;
diff --git a/src/newgrf_airporttiles.cpp b/src/newgrf_airporttiles.cpp
index ae387138a..71f882302 100644
--- a/src/newgrf_airporttiles.cpp
+++ b/src/newgrf_airporttiles.cpp
@@ -238,10 +238,7 @@ static void AirportTileResolver(ResolverObject *res, const AirportTileSpec *ats,
res->callback = CBID_NO_CALLBACK;
res->callback_param1 = 0;
res->callback_param2 = 0;
- res->last_value = 0;
- res->trigger = 0;
- res->reseed = 0;
- res->count = 0;
+ res->ResetState();
res->grffile = ats->grf_prop.grffile;
}
diff --git a/src/newgrf_canal.cpp b/src/newgrf_canal.cpp
index 12ffc736a..9f4de9e4a 100644
--- a/src/newgrf_canal.cpp
+++ b/src/newgrf_canal.cpp
@@ -89,10 +89,8 @@ static void NewCanalResolver(ResolverObject *res, TileIndex tile, const GRFFile
res->callback = CBID_NO_CALLBACK;
res->callback_param1 = 0;
res->callback_param2 = 0;
- res->last_value = 0;
- res->trigger = 0;
- res->reseed = 0;
- res->count = 0;
+ res->ResetState();
+
res->grffile = grffile;
}
diff --git a/src/newgrf_cargo.cpp b/src/newgrf_cargo.cpp
index 257e96ee6..7eb397016 100644
--- a/src/newgrf_cargo.cpp
+++ b/src/newgrf_cargo.cpp
@@ -66,10 +66,8 @@ static void NewCargoResolver(ResolverObject *res, const CargoSpec *cs)
res->callback = CBID_NO_CALLBACK;
res->callback_param1 = 0;
res->callback_param2 = 0;
- res->last_value = 0;
- res->trigger = 0;
- res->reseed = 0;
- res->count = 0;
+ res->ResetState();
+
res->grffile = cs->grffile;
}
diff --git a/src/newgrf_engine.cpp b/src/newgrf_engine.cpp
index dc1dffcf4..0491ec762 100644
--- a/src/newgrf_engine.cpp
+++ b/src/newgrf_engine.cpp
@@ -878,10 +878,7 @@ static inline void NewVehicleResolver(ResolverObject *res, EngineID engine_type,
res->callback = CBID_NO_CALLBACK;
res->callback_param1 = 0;
res->callback_param2 = 0;
- res->last_value = 0;
- res->trigger = 0;
- res->reseed = 0;
- res->count = 0;
+ res->ResetState();
const Engine *e = Engine::Get(engine_type);
res->grffile = (e != NULL ? e->grf_prop.grffile : NULL);
diff --git a/src/newgrf_generic.cpp b/src/newgrf_generic.cpp
index 48cab0342..6ca8be71b 100644
--- a/src/newgrf_generic.cpp
+++ b/src/newgrf_generic.cpp
@@ -126,10 +126,8 @@ static inline void NewGenericResolver(ResolverObject *res, const GRFFile *grffil
res->callback = CBID_NO_CALLBACK;
res->callback_param1 = 0;
res->callback_param2 = 0;
- res->last_value = 0;
- res->trigger = 0;
- res->reseed = 0;
- res->count = 0;
+ res->ResetState();
+
res->grffile = grffile;
}
diff --git a/src/newgrf_house.cpp b/src/newgrf_house.cpp
index 1ec391c51..f6e1d3790 100644
--- a/src/newgrf_house.cpp
+++ b/src/newgrf_house.cpp
@@ -397,10 +397,7 @@ static void NewHouseResolver(ResolverObject *res, HouseID house_id, TileIndex ti
res->callback = CBID_NO_CALLBACK;
res->callback_param1 = 0;
res->callback_param2 = 0;
- res->last_value = 0;
- res->trigger = 0;
- res->reseed = 0;
- res->count = 0;
+ res->ResetState();
const HouseSpec *hs = HouseSpec::Get(house_id);
res->grffile = (hs != NULL ? hs->grf_prop.grffile : NULL);
diff --git a/src/newgrf_industries.cpp b/src/newgrf_industries.cpp
index 291d1a20f..a99a58152 100644
--- a/src/newgrf_industries.cpp
+++ b/src/newgrf_industries.cpp
@@ -424,10 +424,7 @@ static void NewIndustryResolver(ResolverObject *res, TileIndex tile, Industry *i
res->callback = CBID_NO_CALLBACK;
res->callback_param1 = 0;
res->callback_param2 = 0;
- res->last_value = 0;
- res->trigger = 0;
- res->reseed = 0;
- res->count = 0;
+ res->ResetState();
const IndustrySpec *indspec = GetIndustrySpec(type);
res->grffile = (indspec != NULL ? indspec->grf_prop.grffile : NULL);
diff --git a/src/newgrf_industrytiles.cpp b/src/newgrf_industrytiles.cpp
index 522296530..74a48cd3b 100644
--- a/src/newgrf_industrytiles.cpp
+++ b/src/newgrf_industrytiles.cpp
@@ -190,10 +190,7 @@ static void NewIndustryTileResolver(ResolverObject *res, IndustryGfx gfx, TileIn
res->callback = CBID_NO_CALLBACK;
res->callback_param1 = 0;
res->callback_param2 = 0;
- res->last_value = 0;
- res->trigger = 0;
- res->reseed = 0;
- res->count = 0;
+ res->ResetState();
const IndustryTileSpec *its = GetIndustryTileSpec(gfx);
res->grffile = (its != NULL ? its->grf_prop.grffile : NULL);
diff --git a/src/newgrf_object.cpp b/src/newgrf_object.cpp
index dcd9c26a4..6582e8eca 100644
--- a/src/newgrf_object.cpp
+++ b/src/newgrf_object.cpp
@@ -393,10 +393,7 @@ static void NewObjectResolver(ResolverObject *res, const ObjectSpec *spec, Objec
res->callback = CBID_NO_CALLBACK;
res->callback_param1 = 0;
res->callback_param2 = 0;
- res->last_value = 0;
- res->trigger = 0;
- res->reseed = 0;
- res->count = 0;
+ res->ResetState();
res->grffile = spec->grf_prop.grffile;
}
diff --git a/src/newgrf_railtype.cpp b/src/newgrf_railtype.cpp
index b01b3b084..9650d0366 100644
--- a/src/newgrf_railtype.cpp
+++ b/src/newgrf_railtype.cpp
@@ -81,10 +81,7 @@ static inline void NewRailTypeResolver(ResolverObject *res, TileIndex tile, Tile
res->callback = CBID_NO_CALLBACK;
res->callback_param1 = 0;
res->callback_param2 = 0;
- res->last_value = 0;
- res->trigger = 0;
- res->reseed = 0;
- res->count = 0;
+ res->ResetState();
res->grffile = grffile;
}
diff --git a/src/newgrf_spritegroup.h b/src/newgrf_spritegroup.h
index 6cc801a74..bf72e96ce 100644
--- a/src/newgrf_spritegroup.h
+++ b/src/newgrf_spritegroup.h
@@ -381,6 +381,17 @@ struct ResolverObject {
uint32 (*GetVariable)(const struct ResolverObject*, byte, byte, bool*);
const SpriteGroup *(*ResolveReal)(const struct ResolverObject*, const RealSpriteGroup*);
void (*StorePSA)(struct ResolverObject*, uint, int32);
+
+ /**
+ * Resets the dynamic state of the resolver object.
+ * To be called before resolving an Action-1-2-3 chain.
+ */
+ void ResetState()
+ {
+ this->last_value = 0;
+ this->trigger = 0;
+ this->reseed = 0;
+ }
};
#endif /* NEWGRF_SPRITEGROUP_H */
diff --git a/src/newgrf_station.cpp b/src/newgrf_station.cpp
index 07ed47af8..e3178feaa 100644
--- a/src/newgrf_station.cpp
+++ b/src/newgrf_station.cpp
@@ -548,10 +548,8 @@ static void NewStationResolver(ResolverObject *res, const StationSpec *statspec,
res->callback = CBID_NO_CALLBACK;
res->callback_param1 = 0;
res->callback_param2 = 0;
- res->last_value = 0;
- res->trigger = 0;
- res->reseed = 0;
- res->count = 0;
+ res->ResetState();
+
res->grffile = (statspec != NULL ? statspec->grf_prop.grffile : NULL);
/* Invalidate all cached vars */