rnd-20070409-1-src
authorHolger Schemel <info@artsoft.org>
Mon, 9 Apr 2007 00:42:39 +0000 (02:42 +0200)
committerHolger Schemel <info@artsoft.org>
Sat, 30 Aug 2014 08:55:32 +0000 (10:55 +0200)
* fixed displaying of game panel values for Emerald Mine game engine
* fixed displaying end-of-level time and score values on new game panel

ChangeLog
src/conftime.h
src/files.c
src/game.c
src/game.h

index 89903c15f1bb2d4e347ddb875de2ba2e31357169..b5f7dc49d1a0bba94c5ca5ab3d0c84c7de9d543b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,7 @@
 2007-04-08
        * added support for accessing native Diamond Caves II level packages
+       * fixed displaying of game panel values for Emerald Mine game engine
+       * fixed displaying end-of-level time and score values on new game panel
 
 2007-04-07
        * added game panel control to display arbitrary elements on game panel
index 90fd11bbb04d77e1243e0cebe5d4cf0f78399e75..4099a36a81cb322fa9afc66336d49ff033f4efea 100644 (file)
@@ -1 +1 @@
-#define COMPILE_DATE_STRING "2007-04-08 17:08"
+#define COMPILE_DATE_STRING "2007-04-09 02:39"
index aa9cdb4cc5558fd4122b90e53eb1fec18ab8f4a2..01548e646f2af752fda3f7b9ac4f2ca895f07648 100644 (file)
@@ -1694,7 +1694,8 @@ static int getFileTypeFromBasename(char *basename)
     return LEVEL_FILE_TYPE_SP;
 
   /* check for typical filename of a Diamond Caves II level package file */
-  if (strEqualSuffix(basename, ".dc2"))
+  if (strEqualSuffix(basename, ".dc") ||
+      strEqualSuffix(basename, ".dc2"))
     return LEVEL_FILE_TYPE_DC;
 
   /* ---------- try to determine file type from filesize ---------- */
@@ -5758,12 +5759,10 @@ static void LoadLevelFromFileInfo_DC(struct LevelInfo *level,
     return;
   }
 
+  // fseek(file, 0x0000, SEEK_SET);
+
   if (level_file_info->packed)
   {
-    int position_first_level = 0x00fa;
-    int extra_bytes = 4;
-    int skip_bytes;
-
     /* read "magic bytes" from start of file */
     fgets(magic_bytes, num_magic_bytes + 1, file);
 
@@ -5772,38 +5771,56 @@ static void LoadLevelFromFileInfo_DC(struct LevelInfo *level,
     {
       level->no_valid_file = TRUE;
 
-      Error(ERR_WARN, "unknown level file '%s' -- using empty level", filename);
+      Error(ERR_WARN, "unknown DC level file '%s' -- using empty level",
+           filename);
 
       return;
     }
 
-    /* advance file stream to first level inside the level package */
-    skip_bytes = position_first_level - num_magic_bytes - extra_bytes;
+    if (strEqualPrefix(magic_bytes, "DC2Win95") ||
+       strEqualPrefix(magic_bytes, "DC2Win98"))
+    {
+      int position_first_level = 0x00fa;
+      int extra_bytes = 4;
+      int skip_bytes;
 
-    /* each block of level data is followed by block of non-level data */
-    num_levels_to_skip *= 2;
+      /* advance file stream to first level inside the level package */
+      skip_bytes = position_first_level - num_magic_bytes - extra_bytes;
 
-    /* at least skip header bytes, therefore use ">= 0" instead of "> 0" */
-    while (num_levels_to_skip >= 0)
-    {
-      /* advance file stream to next level inside the level package */
-      if (fseek(file, skip_bytes, SEEK_CUR) != 0)
+      /* each block of level data is followed by block of non-level data */
+      num_levels_to_skip *= 2;
+
+      /* at least skip header bytes, therefore use ">= 0" instead of "> 0" */
+      while (num_levels_to_skip >= 0)
       {
-       level->no_valid_file = TRUE;
+       /* advance file stream to next level inside the level package */
+       if (fseek(file, skip_bytes, SEEK_CUR) != 0)
+       {
+         level->no_valid_file = TRUE;
 
-       Error(ERR_WARN, "cannot fseek in file '%s' -- using empty level",
-             filename);
+         Error(ERR_WARN, "cannot fseek in file '%s' -- using empty level",
+               filename);
 
-       return;
-      }
+         return;
+       }
 
-      /* skip apparently unused extra bytes following each level */
-      ReadUnusedBytesFromFile(file, extra_bytes);
+       /* skip apparently unused extra bytes following each level */
+       ReadUnusedBytesFromFile(file, extra_bytes);
 
-      /* read size of next level in level package */
-      skip_bytes = getFile32BitLE(file);
+       /* read size of next level in level package */
+       skip_bytes = getFile32BitLE(file);
 
-      num_levels_to_skip--;
+       num_levels_to_skip--;
+      }
+    }
+    else
+    {
+      level->no_valid_file = TRUE;
+
+      Error(ERR_WARN, "unknown DC2 level file '%s' -- using empty level",
+           filename);
+
+      return;
     }
   }
 
index 3f6ec77b97628b366a671484bc2c9f203ebc4886..d24c62f6b324b0d815eebff9581e847b997ac451 100644 (file)
@@ -2013,16 +2013,27 @@ void InitGameControlValues()
 void UpdateGameControlValues()
 {
   int i, k;
-  int time = (level.time == 0 ? TimePlayed : TimeLeft);
-  int score = (local_player->LevelSolved ? local_player->score_final :
+  int time = (local_player->LevelSolved ?
+             local_player->LevelSolved_CountingTime :
+             level.game_engine_type == GAME_ENGINE_TYPE_EM ?
+             level.native_em_level->lev->time :
+             level.time == 0 ? TimePlayed : TimeLeft);
+  int score = (local_player->LevelSolved ?
+              local_player->LevelSolved_CountingScore :
+              level.game_engine_type == GAME_ENGINE_TYPE_EM ?
+              level.native_em_level->lev->score :
               local_player->score);
-  int exit_closed = (local_player->gems_still_needed > 0 ||
+  int gems = (level.game_engine_type == GAME_ENGINE_TYPE_EM ?
+             level.native_em_level->lev->required :
+             local_player->gems_still_needed);
+  int exit_closed = (level.game_engine_type == GAME_ENGINE_TYPE_EM ?
+                    level.native_em_level->lev->required > 0 :
+                    local_player->gems_still_needed > 0 ||
                     local_player->sokobanfields_still_needed > 0 ||
                     local_player->lights_still_needed > 0);
 
   game_panel_controls[GAME_PANEL_LEVEL_NUMBER].value = level_nr;
-  game_panel_controls[GAME_PANEL_GEMS].value =
-    local_player->gems_still_needed;
+  game_panel_controls[GAME_PANEL_GEMS].value = gems;
 
   game_panel_controls[GAME_PANEL_INVENTORY_COUNT].value = 0;
   for (i = 0; i < MAX_NUM_KEYS; i++)
@@ -2035,12 +2046,24 @@ void UpdateGameControlValues()
     for (i = 0; i < MAX_PLAYERS; i++)
     {
       for (k = 0; k < MAX_NUM_KEYS; k++)
-       if (stored_player[i].key[k])
+      {
+       if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
+       {
+         if (level.native_em_level->ply[i]->keys & (1 << k))
+           game_panel_controls[GAME_PANEL_KEY_1 + k].value =
+             get_key_element_from_nr(k);
+       }
+       else if (stored_player[i].key[k])
          game_panel_controls[GAME_PANEL_KEY_1 + k].value =
            get_key_element_from_nr(k);
+      }
 
-      game_panel_controls[GAME_PANEL_INVENTORY_COUNT].value +=
-       stored_player[i].inventory_size;
+      if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
+       game_panel_controls[GAME_PANEL_INVENTORY_COUNT].value +=
+         level.native_em_level->ply[i]->dynamite;
+      else
+       game_panel_controls[GAME_PANEL_INVENTORY_COUNT].value +=
+         stored_player[i].inventory_size;
 
       if (stored_player[i].num_white_keys > 0)
        game_panel_controls[GAME_PANEL_KEY_WHITE].value =
@@ -2055,12 +2078,24 @@ void UpdateGameControlValues()
     int player_nr = game.centered_player_nr;
 
     for (k = 0; k < MAX_NUM_KEYS; k++)
-      if (stored_player[player_nr].key[k])
+    {
+      if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
+      {
+       if (level.native_em_level->ply[player_nr]->keys & (1 << k))
+         game_panel_controls[GAME_PANEL_KEY_1 + k].value =
+           get_key_element_from_nr(k);
+      }
+      else if (stored_player[player_nr].key[k])
        game_panel_controls[GAME_PANEL_KEY_1 + k].value =
          get_key_element_from_nr(k);
+    }
 
-    game_panel_controls[GAME_PANEL_INVENTORY_COUNT].value +=
-      stored_player[player_nr].inventory_size;
+    if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
+      game_panel_controls[GAME_PANEL_INVENTORY_COUNT].value +=
+       level.native_em_level->ply[player_nr]->dynamite;
+    else
+      game_panel_controls[GAME_PANEL_INVENTORY_COUNT].value +=
+       stored_player[player_nr].inventory_size;
 
     if (stored_player[player_nr].num_white_keys > 0)
       game_panel_controls[GAME_PANEL_KEY_WHITE].value = EL_DC_KEY_WHITE;
@@ -3526,6 +3561,8 @@ void InitGame()
     player->LevelSolved_PanelOff = FALSE;
     player->LevelSolved_SaveTape = FALSE;
     player->LevelSolved_SaveScore = FALSE;
+    player->LevelSolved_CountingTime = 0;
+    player->LevelSolved_CountingScore = 0;
   }
 
   network_player_action_received = FALSE;
@@ -4281,6 +4318,9 @@ static void PlayerWins(struct PlayerInfo *player)
 
   player->score_final = (level.game_engine_type == GAME_ENGINE_TYPE_EM ?
                         level.native_em_level->lev->score : player->score);
+
+  player->LevelSolved_CountingTime = (level.time == 0 ? TimePlayed : TimeLeft);
+  player->LevelSolved_CountingScore = player->score_final;
 }
 
 void GameWon()
@@ -4336,6 +4376,9 @@ void GameWon()
       score = score_final;
 
 #if 1
+      local_player->LevelSolved_CountingTime = time;
+      local_player->LevelSolved_CountingScore = score;
+
       game_panel_controls[GAME_PANEL_TIME].value = time;
       game_panel_controls[GAME_PANEL_SCORE].value = score;
 
@@ -4418,6 +4461,9 @@ void GameWon()
     score += time_count_steps * level.score[SC_TIME_BONUS];
 
 #if 1
+    local_player->LevelSolved_CountingTime = time;
+    local_player->LevelSolved_CountingScore = score;
+
     game_panel_controls[GAME_PANEL_TIME].value = time;
     game_panel_controls[GAME_PANEL_SCORE].value = score;
 
index ac2496e1bae9949340b3f2284bdebe75ab0c27d5..5b2b46a95d8b6a0eaf901672efff41d0dada1cc0 100644 (file)
@@ -214,6 +214,8 @@ struct PlayerInfo
   boolean LevelSolved_PanelOff;
   boolean LevelSolved_SaveTape;
   boolean LevelSolved_SaveScore;
+  int LevelSolved_CountingTime;
+  int LevelSolved_CountingScore;
 
   int last_move_dir;