(svn r4446) - Add function to determine if a Sprite ID exists.
authorpeter1138
Sun, 16 Apr 2006 11:26:23 +0000
changeset 3565 ef0a9ef56fa0
parent 3564 ce1862c6cc7f
child 3566 21db83574baf
(svn r4446) - Add function to determine if a Sprite ID exists.
spritecache.c
spritecache.h
--- a/spritecache.c	Sun Apr 16 10:26:46 2006 +0000
+++ b/spritecache.c	Sun Apr 16 11:26:23 2006 +0000
@@ -71,6 +71,13 @@
 	return true;
 }
 
+/* Check if the given Sprite ID exists */
+bool SpriteExists(SpriteID id)
+{
+	/* Special case for Sprite ID zero -- its position is also 0... */
+	return _sprite_file_pos[id] != 0 || id == 0;
+}
+
 static void* AllocSprite(size_t);
 
 static void* ReadSprite(SpriteID id)
@@ -80,7 +87,7 @@
 
 	DEBUG(spritecache, 9) ("load sprite %d", id);
 
-	if (_sprite_file_pos[id] == 0 && id != 0) {
+	if (!SpriteExists(id)) {
 		error(
 			"Tried to load non-existing sprite #%d.\n"
 			"Probable cause: Wrong/missing NewGRFs",
--- a/spritecache.h	Sun Apr 16 10:26:46 2006 +0000
+++ b/spritecache.h	Sun Apr 16 11:26:23 2006 +0000
@@ -13,6 +13,7 @@
 } Sprite;
 
 const void *GetRawSprite(SpriteID sprite);
+bool SpriteExists(SpriteID sprite);
 
 static inline const Sprite *GetSprite(SpriteID sprite)
 {