(svn r3530) - NewGRF: Move station resolver to newgrf_station
authorpeter1138
Fri, 03 Feb 2006 23:02:01 +0000
changeset 2967 4208a82bf0d9
parent 2966 7f382cfeb93d
child 2968 b17821f292cb
(svn r3530) - NewGRF: Move station resolver to newgrf_station
newgrf_station.c
newgrf_station.h
station.h
station_cmd.c
--- a/newgrf_station.c	Fri Feb 03 21:51:42 2006 +0000
+++ b/newgrf_station.c	Fri Feb 03 23:02:01 2006 +0000
@@ -6,6 +6,7 @@
 #include "openttd.h"
 #include "debug.h"
 #include "sprite.h"
+#include "station.h"
 #include "newgrf_station.h"
 
 static StationClass station_classes[STAT_CLASS_MAX];
@@ -113,3 +114,85 @@
 	// probably was not loaded.
 	return NULL;
 }
+
+static const RealSpriteGroup *ResolveStationSpriteGroup(const SpriteGroup *spg, const Station *st)
+{
+	switch (spg->type) {
+		case SGT_REAL:
+			return &spg->g.real;
+
+		case SGT_DETERMINISTIC: {
+			const DeterministicSpriteGroup *dsg = &spg->g.determ;
+			SpriteGroup *target;
+			int value = -1;
+
+			if ((dsg->variable >> 6) == 0) {
+				/* General property */
+				value = GetDeterministicSpriteValue(dsg->variable);
+			} else {
+				if (st == NULL) {
+					/* We are in a build dialog of something,
+					 * and we are checking for something undefined.
+					 * That means we should get the first target
+					 * (NOT the default one). */
+					if (dsg->num_ranges > 0) {
+						target = dsg->ranges[0].group;
+					} else {
+						target = dsg->default_group;
+					}
+					return ResolveStationSpriteGroup(target, NULL);
+				}
+
+				/* Station-specific property. */
+				if (dsg->var_scope == VSG_SCOPE_PARENT) {
+					/* TODO: Town structure. */
+
+				} else /* VSG_SELF */ {
+					if (dsg->variable == 0x40 || dsg->variable == 0x41) {
+						/* FIXME: This is ad hoc only
+						 * for waypoints. */
+						value = 0x01010000;
+					} else {
+						/* TODO: Only small fraction done. */
+						// TTDPatch runs on little-endian arch;
+						// Variable is 0x70 + offset in the TTD's station structure
+						switch (dsg->variable - 0x70) {
+							case 0x80: value = st->facilities;             break;
+							case 0x81: value = st->airport_type;           break;
+							case 0x82: value = st->truck_stops->status;    break;
+							case 0x83: value = st->bus_stops->status;      break;
+							case 0x86: value = st->airport_flags & 0xFFFF; break;
+							case 0x87: value = st->airport_flags & 0xFF;   break;
+							case 0x8A: value = st->build_date;             break;
+						}
+					}
+				}
+			}
+
+			target = value != -1 ? EvalDeterministicSpriteGroup(dsg, value) : dsg->default_group;
+			return ResolveStationSpriteGroup(target, st);
+		}
+
+		default:
+		case SGT_RANDOMIZED:
+			DEBUG(grf, 6)("I don't know how to handle random spritegroups yet!");
+			return NULL;
+	}
+}
+
+uint32 GetCustomStationRelocation(const StationSpec *spec, const Station *st, byte ctype)
+{
+	const RealSpriteGroup *rsg = ResolveStationSpriteGroup(spec->spritegroup[ctype], st);
+
+	if (rsg->sprites_per_set != 0) {
+		if (rsg->loading_count != 0) return rsg->loading[0]->g.result.result;
+		if (rsg->loaded_count != 0) return rsg->loaded[0]->g.result.result;
+	}
+
+	DEBUG(grf, 6)("Custom station 0x%08x::0x%02x has no sprites associated.",
+		spec->grfid, spec->localidx);
+	/* This is what gets subscribed of dtss->image in newgrf.c,
+	 * so it's probably kinda "default offset". Try to use it as
+	 * emergency measure. */
+	return 0;
+}
--- a/newgrf_station.h	Fri Feb 03 21:51:42 2006 +0000
+++ b/newgrf_station.h	Fri Feb 03 23:02:01 2006 +0000
@@ -74,4 +74,9 @@
 void SetCustomStation(StationSpec *spec);
 const StationSpec *GetCustomStation(StationClassID sclass, uint station);
 
+/* Get sprite offset for a given custom station and station structure (may be
+ * NULL if ctype is set - that means we are in a build dialog). The station
+ * structure is used for variational sprite groups. */
+uint32 GetCustomStationRelocation(const StationSpec *spec, const Station *st, byte ctype);
+
 #endif /* NEWGRF_STATION_H */
--- a/station.h	Fri Feb 03 21:51:42 2006 +0000
+++ b/station.h	Fri Feb 03 23:02:01 2006 +0000
@@ -196,11 +196,6 @@
 
 void StationPickerDrawSprite(int x, int y, RailType railtype, int image);
 
-/* Get sprite offset for a given custom station and station structure (may be
- * NULL if ctype is set - that means we are in a build dialog). The station
- * structure is used for variational sprite groups. */
-uint32 GetCustomStationRelocation(const StationSpec *spec, const Station *st, byte ctype);
-
 RoadStop * GetRoadStopByTile(TileIndex tile, RoadStopType type);
 static inline int GetRoadStopType(TileIndex tile)
 {
--- a/station_cmd.c	Fri Feb 03 21:51:42 2006 +0000
+++ b/station_cmd.c	Fri Feb 03 23:02:01 2006 +0000
@@ -1196,88 +1196,6 @@
 	return len - 1;
 }
 
-static const RealSpriteGroup *ResolveStationSpriteGroup(const SpriteGroup *spg, const Station *st)
-{
-	switch (spg->type) {
-		case SGT_REAL:
-			return &spg->g.real;
-
-		case SGT_DETERMINISTIC: {
-			const DeterministicSpriteGroup *dsg = &spg->g.determ;
-			SpriteGroup *target;
-			int value = -1;
-
-			if ((dsg->variable >> 6) == 0) {
-				/* General property */
-				value = GetDeterministicSpriteValue(dsg->variable);
-			} else {
-				if (st == NULL) {
-					/* We are in a build dialog of something,
-					 * and we are checking for something undefined.
-					 * That means we should get the first target
-					 * (NOT the default one). */
-					if (dsg->num_ranges > 0) {
-						target = dsg->ranges[0].group;
-					} else {
-						target = dsg->default_group;
-					}
-					return ResolveStationSpriteGroup(target, NULL);
-				}
-
-				/* Station-specific property. */
-				if (dsg->var_scope == VSG_SCOPE_PARENT) {
-					/* TODO: Town structure. */
-
-				} else /* VSG_SELF */ {
-					if (dsg->variable == 0x40 || dsg->variable == 0x41) {
-						/* FIXME: This is ad hoc only
-						 * for waypoints. */
-						value = 0x01010000;
-					} else {
-						/* TODO: Only small fraction done. */
-						// TTDPatch runs on little-endian arch;
-						// Variable is 0x70 + offset in the TTD's station structure
-						switch (dsg->variable - 0x70) {
-							case 0x80: value = st->facilities;             break;
-							case 0x81: value = st->airport_type;           break;
-							case 0x82: value = st->truck_stops->status;    break;
-							case 0x83: value = st->bus_stops->status;      break;
-							case 0x86: value = st->airport_flags & 0xFFFF; break;
-							case 0x87: value = st->airport_flags & 0xFF;   break;
-							case 0x8A: value = st->build_date;             break;
-						}
-					}
-				}
-			}
-
-			target = value != -1 ? EvalDeterministicSpriteGroup(dsg, value) : dsg->default_group;
-			return ResolveStationSpriteGroup(target, st);
-		}
-
-		default:
-		case SGT_RANDOMIZED:
-			error("I don't know how to handle random spritegroups yet!");
-			return NULL;
-	}
-}
-
-uint32 GetCustomStationRelocation(const StationSpec *spec, const Station *st, byte ctype)
-{
-	const RealSpriteGroup *rsg = ResolveStationSpriteGroup(spec->spritegroup[ctype], st);
-
-	if (rsg->sprites_per_set != 0) {
-		if (rsg->loading_count != 0) return rsg->loading[0]->g.result.result;
-		if (rsg->loaded_count != 0) return rsg->loaded[0]->g.result.result;
-	}
-
-	error("Custom station 0x%08x::0x%02x has no sprites associated.",
-		spec->grfid, spec->localidx);
-	/* This is what gets subscribed of dtss->image in newgrf.c,
-	 * so it's probably kinda "default offset". Try to use it as
-	 * emergency measure. */
-	return SPR_RAIL_PLATFORM_Y_FRONT;
-}
-
 static int32 RemoveRailroadStation(Station *st, TileIndex tile, uint32 flags)
 {
 	int w,h;