rnd-20030722-1-src
[rocksndiamonds.git] / src / libgame / misc.c
index 10656e46a208fdcc0cf746b226c3345374eece9f..f487175728d274d820630ec09a205d9d7a2c846e 100644 (file)
@@ -324,7 +324,7 @@ unsigned int init_random_number(int nr, long seed)
 
 unsigned int get_random_number(int nr, unsigned int max)
 {
-  return (random_linux_libc(nr) % max);
+  return (max > 0 ? random_linux_libc(nr) % max : 0);
 }
 
 
@@ -981,26 +981,28 @@ void putFileChunk(FILE *file, char *chunk_name, int chunk_size,
 
 int getFileVersion(FILE *file)
 {
-  int version_major, version_minor, version_patch;
+  int version_major, version_minor, version_patch, version_release;
 
-  version_major = fgetc(file);
-  version_minor = fgetc(file);
-  version_patch = fgetc(file);
-  fgetc(file);         /* not used */
+  version_major   = fgetc(file);
+  version_minor   = fgetc(file);
+  version_patch   = fgetc(file);
+  version_release = fgetc(file);
 
-  return VERSION_IDENT(version_major, version_minor, version_patch);
+  return RELEASE_IDENT(version_major, version_minor, version_patch,
+                      version_release);
 }
 
 void putFileVersion(FILE *file, int version)
 {
-  int version_major = VERSION_MAJOR(version);
-  int version_minor = VERSION_MINOR(version);
-  int version_patch = VERSION_PATCH(version);
+  int version_major   = VERSION_MAJOR(version);
+  int version_minor   = VERSION_MINOR(version);
+  int version_patch   = VERSION_PATCH(version);
+  int version_release = VERSION_RELEASE(version);
 
-  fputc(version_major, file);
-  fputc(version_minor, file);
-  fputc(version_patch, file);
-  fputc(0, file);      /* not used */
+  fputc(version_major,   file);
+  fputc(version_minor,   file);
+  fputc(version_patch,   file);
+  fputc(version_release, file);
 }
 
 void ReadUnusedBytesFromFile(FILE *file, unsigned long bytes)
@@ -2280,6 +2282,11 @@ static void replaceArtworkListEntry(struct ArtworkListInfo *artwork_info,
   ListNode *node;
   char *filename = getCustomArtworkFilename(basename, artwork_info->type);
 
+#if 1
+    if (strcmp(basename, "RocksScreen.pcx") == 0)
+      printf("::: got filename '%s'\n", filename);
+#endif
+
   if (filename == NULL)
   {
     int error_mode = ERR_WARN;
@@ -2299,8 +2306,11 @@ static void replaceArtworkListEntry(struct ArtworkListInfo *artwork_info,
        This usually means that this artwork does not exist in this artwork set
        and a fallback to the existing artwork is done. */
 
-#if 0
-    printf("[artwork '%s' already exists (same list entry)]\n", filename);
+#if 1
+#if 1
+    if (strcmp(basename, "RocksScreen.pcx") == 0)
+#endif
+      printf("[artwork '%s' already exists (same list entry)]\n", filename);
 #endif
 
     return;