src/gfxinit.cpp
branchgamebalance
changeset 9913 e79cd19772dd
parent 9912 1ac8aac92385
--- a/src/gfxinit.cpp	Wed Jun 13 12:05:56 2007 +0000
+++ b/src/gfxinit.cpp	Tue Jun 19 07:21:01 2007 +0000
@@ -53,13 +53,15 @@
 static uint LoadGrfFile(const char* filename, uint load_index, int file_index)
 {
 	uint load_index_org = load_index;
+	uint sprite_id = 0;
 
 	FioOpenFile(file_index, filename);
 
 	DEBUG(sprite, 2, "Reading grf-file '%s'", filename);
 
-	while (LoadNextSprite(load_index, file_index)) {
+	while (LoadNextSprite(load_index, file_index, sprite_id)) {
 		load_index++;
+		sprite_id++;
 		if (load_index >= MAX_SPRITES) {
 			error("Too many sprites. Recompile with higher MAX_SPRITES value or remove some custom GRF files.");
 		}
@@ -73,6 +75,7 @@
 static void LoadGrfIndexed(const char* filename, const SpriteID* index_tbl, int file_index)
 {
 	uint start;
+	uint sprite_id = 0;
 
 	FioOpenFile(file_index, filename);
 
@@ -83,14 +86,16 @@
 
 		if (start == SKIP) { // skip sprites (amount in second var)
 			SkipSprites(end);
+			sprite_id += end;
 		} else { // load sprites and use indexes from start to end
 			do {
 			#ifdef NDEBUG
-				LoadNextSprite(start, file_index);
+				LoadNextSprite(start, file_index, sprite_id);
 			#else
-				bool b = LoadNextSprite(start, file_index);
+				bool b = LoadNextSprite(start, file_index, sprite_id);
 				assert(b);
 			#endif
+				sprite_id++;
 			} while (++start <= end);
 		}
 	}
@@ -109,33 +114,7 @@
  * returns true if the checksum is correct */
 static bool FileMD5(const MD5File file, bool warn)
 {
-	FILE *f;
-	char buf[MAX_PATH];
-
-	/* open file */
-	snprintf(buf, lengthof(buf), "%s%s", _paths.data_dir, file.filename);
-	f = fopen(buf, "rb");
-
-#if !defined(WIN32)
-	if (f == NULL) {
-		strtolower(buf + strlen(_paths.data_dir) - 1);
-		f = fopen(buf, "rb");
-	}
-#endif
-
-#if defined SECOND_DATA_DIR
-	/* If we failed to find the file in the first data directory, we will try the other one */
-
-	if (f == NULL) {
-		snprintf(buf, lengthof(buf), "%s%s", _paths.second_data_dir, file.filename);
-		f = fopen(buf, "rb");
-
-		if (f == NULL) {
-			strtolower(buf + strlen(_paths.second_data_dir) - 1);
-			f = fopen(buf, "rb");
-		}
-	}
-#endif
+	FILE *f = FioFOpenFile(file.filename);
 
 	if (f != NULL) {
 		md5_state_t filemd5state;
@@ -147,7 +126,7 @@
 		while ((len = fread(buffer, 1, sizeof(buffer), f)) != 0)
 			md5_append(&filemd5state, buffer, len);
 
-		if (ferror(f) && warn) ShowInfoF("Error Reading from %s \n", buf);
+		if (ferror(f) && warn) ShowInfoF("Error Reading from %s \n", file.filename);
 		fclose(f);
 
 		md5_finish(&filemd5state, digest);