changeset 7327:0ab2820a1e52 draft

(svn r10690) -Codechange: use the enum that describes all callback IDs in favor of "just" using an untyped integer.
author rubidium <rubidium@openttd.org>
date Wed, 25 Jul 2007 19:06:29 +0000
parents 69b12bd2f61b
children 35cf803fe4b9
files src/newgrf_callbacks.h src/newgrf_canal.cpp src/newgrf_cargo.cpp src/newgrf_cargo.h src/newgrf_engine.cpp src/newgrf_engine.h src/newgrf_house.cpp src/newgrf_house.h src/newgrf_industries.cpp src/newgrf_industries.h src/newgrf_industrytiles.cpp src/newgrf_industrytiles.h src/newgrf_spritegroup.h src/newgrf_station.cpp src/newgrf_station.h
diffstat 15 files changed, 29 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/src/newgrf_callbacks.h
+++ b/src/newgrf_callbacks.h
@@ -15,6 +15,9 @@
  * Names are formatted as CBID_<CLASS>_<CALLBACK>
  */
 enum CallbackID {
+	/** Set when using the callback resolve system, but not to resolve a callback. */
+	CBID_NO_CALLBACK                     = 0x00,
+
 	/** Set when calling a randomizing trigger (almost undocumented). */
 	CBID_RANDOM_TRIGGER                  = 0x01,
 
--- a/src/newgrf_canal.cpp
+++ b/src/newgrf_canal.cpp
@@ -73,7 +73,7 @@
 
 	res->u.canal.tile = tile;
 
-	res->callback        = 0;
+	res->callback        = CBID_NO_CALLBACK;
 	res->callback_param1 = 0;
 	res->callback_param2 = 0;
 	res->last_value      = 0;
--- a/src/newgrf_cargo.cpp
+++ b/src/newgrf_cargo.cpp
@@ -58,7 +58,7 @@
 
 	res->u.cargo.cs = cs;
 
-	res->callback        = 0;
+	res->callback        = CBID_NO_CALLBACK;
 	res->callback_param1 = 0;
 	res->callback_param2 = 0;
 	res->last_value      = 0;
@@ -81,7 +81,7 @@
 }
 
 
-uint16 GetCargoCallback(uint16 callback, uint32 param1, uint32 param2, const CargoSpec *cs)
+uint16 GetCargoCallback(CallbackID callback, uint32 param1, uint32 param2, const CargoSpec *cs)
 {
 	ResolverObject object;
 	const SpriteGroup *group;
--- a/src/newgrf_cargo.h
+++ b/src/newgrf_cargo.h
@@ -5,6 +5,8 @@
 #ifndef NEWGRF_CARGO_H
 #define NEWGRF_CARGO_H
 
+#include "newgrf_callbacks.h"
+
 enum {
 	CC_NOAVAILABLE  = 0,
 	CC_PASSENGERS   = 1 << 0,
@@ -26,7 +28,7 @@
 struct GRFFile;
 
 SpriteID GetCustomCargoSprite(const CargoSpec *cs);
-uint16 GetCargoCallback(uint16 callback, uint32 param1, uint32 param2, const CargoSpec *cs);
+uint16 GetCargoCallback(CallbackID callback, uint32 param1, uint32 param2, const CargoSpec *cs);
 CargoID GetCargoTranslation(uint8 cargo, const GRFFile *grffile);
 uint8 GetReverseCargoTranslation(CargoID cargo, const GRFFile *grffile);
 
--- a/src/newgrf_engine.cpp
+++ b/src/newgrf_engine.cpp
@@ -838,7 +838,7 @@
 
 	res->info_view = false;
 
-	res->callback        = 0;
+	res->callback        = CBID_NO_CALLBACK;
 	res->callback_param1 = 0;
 	res->callback_param2 = 0;
 	res->last_value      = 0;
@@ -938,7 +938,7 @@
  * @param v        The vehicle to evaluate the callback for, or NULL if it doesnt exist yet
  * @return The value the callback returned, or CALLBACK_FAILED if it failed
  */
-uint16 GetVehicleCallback(uint16 callback, uint32 param1, uint32 param2, EngineID engine, const Vehicle *v)
+uint16 GetVehicleCallback(CallbackID callback, uint32 param1, uint32 param2, EngineID engine, const Vehicle *v)
 {
 	const SpriteGroup *group;
 	ResolverObject object;
@@ -965,7 +965,7 @@
  * @param parent   The vehicle to use for parent scope
  * @return The value the callback returned, or CALLBACK_FAILED if it failed
  */
-uint16 GetVehicleCallbackParent(uint16 callback, uint32 param1, uint32 param2, EngineID engine, const Vehicle *v, const Vehicle *parent)
+uint16 GetVehicleCallbackParent(CallbackID callback, uint32 param1, uint32 param2, EngineID engine, const Vehicle *v, const Vehicle *parent)
 {
 	const SpriteGroup *group;
 	ResolverObject object;
--- a/src/newgrf_engine.h
+++ b/src/newgrf_engine.h
@@ -30,8 +30,8 @@
 const struct GRFFile *GetEngineGRF(EngineID engine);
 uint32 GetEngineGRFID(EngineID engine);
 
-uint16 GetVehicleCallback(uint16 callback, uint32 param1, uint32 param2, EngineID engine, const Vehicle *v);
-uint16 GetVehicleCallbackParent(uint16 callback, uint32 param1, uint32 param2, EngineID engine, const Vehicle *v, const Vehicle *parent);
+uint16 GetVehicleCallback(CallbackID callback, uint32 param1, uint32 param2, EngineID engine, const Vehicle *v);
+uint16 GetVehicleCallbackParent(CallbackID callback, uint32 param1, uint32 param2, EngineID engine, const Vehicle *v, const Vehicle *parent);
 bool UsesWagonOverride(const Vehicle *v);
 #define GetCustomVehicleSprite(v, direction) GetCustomEngineSprite(v->engine_type, v, direction)
 #define GetCustomVehicleIcon(et, direction) GetCustomEngineSprite(et, NULL, direction)
--- a/src/newgrf_house.cpp
+++ b/src/newgrf_house.cpp
@@ -274,7 +274,7 @@
 	res->u.house.town     = town;
 	res->u.house.house_id = house_id;
 
-	res->callback        = 0;
+	res->callback        = CBID_NO_CALLBACK;
 	res->callback_param1 = 0;
 	res->callback_param2 = 0;
 	res->last_value      = 0;
@@ -282,7 +282,7 @@
 	res->reseed          = 0;
 }
 
-uint16 GetHouseCallback(uint16 callback, uint32 param1, uint32 param2, HouseID house_id, Town *town, TileIndex tile)
+uint16 GetHouseCallback(CallbackID callback, uint32 param1, uint32 param2, HouseID house_id, Town *town, TileIndex tile)
 {
 	ResolverObject object;
 	const SpriteGroup *group;
--- a/src/newgrf_house.h
+++ b/src/newgrf_house.h
@@ -6,6 +6,7 @@
 #define NEWGRF_HOUSE_H
 
 #include "town.h"
+#include "newgrf_callbacks.h"
 
 /**
  * Makes class IDs unique to each GRF file.
@@ -38,7 +39,7 @@
 void AnimateNewHouseTile(TileIndex tile);
 void ChangeHouseAnimationFrame(TileIndex tile, uint16 callback_result);
 
-uint16 GetHouseCallback(uint16 callback, uint32 param1, uint32 param2, HouseID house_id, Town *town, TileIndex tile);
+uint16 GetHouseCallback(CallbackID callback, uint32 param1, uint32 param2, HouseID house_id, Town *town, TileIndex tile);
 
 bool CanDeleteHouse(TileIndex tile);
 
--- a/src/newgrf_industries.cpp
+++ b/src/newgrf_industries.cpp
@@ -275,7 +275,7 @@
 	res->u.industry.ind  = indus;
 	res->u.industry.gfx  = INVALID_INDUSTRYTILE;
 
-	res->callback        = 0;
+	res->callback        = CBID_NO_CALLBACK;
 	res->callback_param1 = 0;
 	res->callback_param2 = 0;
 	res->last_value      = 0;
@@ -283,7 +283,7 @@
 	res->reseed          = 0;
 }
 
-uint16 GetIndustryCallback(uint16 callback, uint32 param1, uint32 param2, Industry *industry, IndustryType type, TileIndex tile)
+uint16 GetIndustryCallback(CallbackID callback, uint32 param1, uint32 param2, Industry *industry, IndustryType type, TileIndex tile)
 {
 	ResolverObject object;
 	const SpriteGroup *group;
--- a/src/newgrf_industries.h
+++ b/src/newgrf_industries.h
@@ -10,7 +10,7 @@
 
 /* in newgrf_industry.cpp */
 uint32 IndustryGetVariable(const ResolverObject *object, byte variable, byte parameter, bool *available);
-uint16 GetIndustryCallback(uint16 callback, uint32 param1, uint32 param2, Industry *industry, IndustryType type, TileIndex tile);
+uint16 GetIndustryCallback(CallbackID callback, uint32 param1, uint32 param2, Industry *industry, IndustryType type, TileIndex tile);
 uint32 GetIndustryIDAtOffset(TileIndex new_tile, TileIndex old_tile, const Industry *i);
 void IndustryProductionCallback(Industry *ind, int reason);
 bool CheckIfCallBackAllowsCreation(TileIndex tile, IndustryType type, uint itspec_index);
--- a/src/newgrf_industrytiles.cpp
+++ b/src/newgrf_industrytiles.cpp
@@ -142,7 +142,7 @@
 	res->u.industry.ind  = indus;
 	res->u.industry.gfx  = gfx;
 
-	res->callback        = 0;
+	res->callback        = CBID_NO_CALLBACK;
 	res->callback_param1 = 0;
 	res->callback_param2 = 0;
 	res->last_value      = 0;
@@ -188,7 +188,7 @@
 	}
 }
 
-uint16 GetIndustryTileCallback(uint16 callback, uint32 param1, uint32 param2, IndustryGfx gfx_id, Industry *industry, TileIndex tile)
+uint16 GetIndustryTileCallback(CallbackID callback, uint32 param1, uint32 param2, IndustryGfx gfx_id, Industry *industry, TileIndex tile)
 {
 	ResolverObject object;
 	const SpriteGroup *group;
--- a/src/newgrf_industrytiles.h
+++ b/src/newgrf_industrytiles.h
@@ -14,7 +14,7 @@
 };
 
 bool DrawNewIndustryTile(TileInfo *ti, Industry *i, IndustryGfx gfx, const IndustryTileSpec *inds);
-uint16 GetIndustryTileCallback(uint16 callback, uint32 param1, uint32 param2, IndustryGfx gfx_id, Industry *industry, TileIndex tile);
+uint16 GetIndustryTileCallback(CallbackID callback, uint32 param1, uint32 param2, IndustryGfx gfx_id, Industry *industry, TileIndex tile);
 bool PerformIndustryTileSlopeCheck(TileIndex tile, const IndustryTileSpec *its, IndustryType type, IndustryGfx gfx);
 
 void AnimateNewIndustryTile(TileIndex tile);
--- a/src/newgrf_spritegroup.h
+++ b/src/newgrf_spritegroup.h
@@ -188,7 +188,7 @@
 
 
 struct ResolverObject {
-	uint16 callback;
+	CallbackID callback;
 	uint32 callback_param1;
 	uint32 callback_param2;
 
--- a/src/newgrf_station.cpp
+++ b/src/newgrf_station.cpp
@@ -555,7 +555,7 @@
 	res->u.station.statspec = statspec;
 	res->u.station.tile     = tile;
 
-	res->callback        = 0;
+	res->callback        = CBID_NO_CALLBACK;
 	res->callback_param1 = 0;
 	res->callback_param2 = 0;
 	res->last_value      = 0;
@@ -627,7 +627,7 @@
 }
 
 
-uint16 GetStationCallback(uint16 callback, uint32 param1, uint32 param2, const StationSpec *statspec, const Station *st, TileIndex tile)
+uint16 GetStationCallback(CallbackID callback, uint32 param1, uint32 param2, const StationSpec *statspec, const Station *st, TileIndex tile)
 {
 	const SpriteGroup *group;
 	ResolverObject object;
--- a/src/newgrf_station.h
+++ b/src/newgrf_station.h
@@ -6,6 +6,7 @@
 #define NEWGRF_STATION_H
 
 #include "engine.h"
+#include "newgrf_callbacks.h"
 #include "newgrf_cargo.h"
 #include "helpers.hpp"
 
@@ -117,7 +118,7 @@
  * for variational sprite groups. */
 SpriteID GetCustomStationRelocation(const StationSpec *statspec, const Station *st, TileIndex tile);
 SpriteID GetCustomStationGroundRelocation(const StationSpec *statspec, const Station *st, TileIndex tile);
-uint16 GetStationCallback(uint16 callback, uint32 param1, uint32 param2, const StationSpec *statspec, const Station *st, TileIndex tile);
+uint16 GetStationCallback(CallbackID callback, uint32 param1, uint32 param2, const StationSpec *statspec, const Station *st, TileIndex tile);
 
 /* Check if a rail station tile is traversable. */
 bool IsStationTileBlocked(TileIndex tile);