rnd-20060828-1-src
authorHolger Schemel <info@artsoft.org>
Mon, 28 Aug 2006 20:49:38 +0000 (22:49 +0200)
committerHolger Schemel <info@artsoft.org>
Sat, 30 Aug 2014 08:53:08 +0000 (10:53 +0200)
* fixed bug in GameWon() when level contains no exit (like in Sokoban)

15 files changed:
ChangeLog
src/conftime.h
src/events.c
src/game.c
src/game.h
src/game_em/export.h
src/game_em/init.c
src/game_em/input.c
src/init.c
src/libgame/misc.c
src/libgame/misc.h
src/libgame/toons.c
src/main.h
src/tape.c
src/tools.c

index ef7d0b250710cfa3b3ab8bd22946b8943afcdff6..e1a10406edd14937680342a2f9b32d29694e00fb 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,6 @@
+2006-08-28
+       * fixed bug in GameWon() when level contains no exit (like in Sokoban)
+
 2006-08-23
        * added engine snapshot functionality for instant tape reloading (this
          only works for the last tape saved using "quick save", and does not
index b906aa53ecd4c24a4957f590d5421893da092236..2d59984d3c07ce02bc76ac69d318d4b96f865535 100644 (file)
@@ -1 +1 @@
-#define COMPILE_DATE_STRING "[2006-08-24 00:46]"
+#define COMPILE_DATE_STRING "[2006-08-28 22:47]"
index d42acf56eff9f1d436eef48395d162c97b1eaa9e..65b06803a9e62f2f7693939f74a6df4ae9f605e6 100644 (file)
@@ -245,7 +245,11 @@ void ClearEventQueue()
        break;
 
       case EVENT_KEYRELEASE:
+#if 1
+       ClearPlayerAction();
+#else
        key_joystick_mapping = 0;
+#endif
        break;
 
       default:
@@ -700,8 +704,14 @@ void HandleKey(Key key, int key_status)
     return;
   }
 
+#if 1
+  if (game_status == GAME_MODE_PLAYING &&
+      local_player->LevelSolved_GameEnd &&
+      (key == KSYM_Return || key == setup.shortcut.toggle_pause))
+#else
   if (game_status == GAME_MODE_PLAYING && AllPlayersGone &&
       (key == KSYM_Return || key == setup.shortcut.toggle_pause))
+#endif
   {
     GameEnd();
 
@@ -1045,7 +1055,11 @@ void HandleJoystick()
       if (tape.playing || keyboard)
        newbutton = ((joy & JOY_BUTTON) != 0);
 
+#if 1
+      if (local_player->LevelSolved_GameEnd && newbutton)
+#else
       if (AllPlayersGone && newbutton)
+#endif
       {
        GameEnd();
 
index 489c476b30e431b297f420e71a904557873a4662..05a0b9ab5f7a5ef41e25f6ba7e9465ffef91e2a7 100644 (file)
 #define GET_DX_FROM_DIR(d)     ((d) == MV_LEFT ? -1 : (d) == MV_RIGHT ? 1 : 0)
 #define GET_DY_FROM_DIR(d)     ((d) == MV_UP   ? -1 : (d) == MV_DOWN  ? 1 : 0)
 
-#define        INIT_GFX_RANDOM()       (SimpleRND(1000000))
+#define        INIT_GFX_RANDOM()       (GetSimpleRandom(1000000))
 
 #define GET_NEW_PUSH_DELAY(e)  (   (element_info[e].push_delay_fixed) + \
                                 RND(element_info[e].push_delay_random))
@@ -2671,12 +2671,14 @@ void GameWon()
   static int game_over_delay = 0;
   int game_over_delay_value = 50;
 
-  /* do not start end game actions before the player stops moving (to exit) */
-  if (local_player->MovPos)
-    return;
-
   if (!local_player->LevelSolved_GameEnd)
   {
+    int i;
+
+    /* do not start end game actions before the player stops moving (to exit) */
+    if (local_player->MovPos)
+      return;
+
     local_player->LevelSolved_GameEnd = TRUE;
     local_player->LevelSolved_SaveTape = tape.recording;
     local_player->LevelSolved_SaveScore = !tape.playing;
@@ -2684,6 +2686,10 @@ void GameWon()
     if (tape.auto_play)                /* tape might already be stopped here */
       tape.auto_play_level_solved = TRUE;
 
+#if 1
+    TapeStop();
+#endif
+
     game_over_delay = game_over_delay_value;
 
     time = time_final = (level.time == 0 ? TimePlayed : TimeLeft);
@@ -2730,6 +2736,19 @@ void GameWon()
       DrawLevelField(ExitX, ExitY);
     }
 
+    for (i = 0; i < MAX_PLAYERS; i++)
+    {
+      struct PlayerInfo *player = &stored_player[i];
+
+      if (player->present)
+      {
+       RemovePlayer(player);
+
+       /* player disappears */
+       DrawLevelField(player->jx, player->jy);
+      }
+    }
+
     PlaySound(SND_GAME_WINNING);
   }
 
@@ -2770,7 +2789,9 @@ void GameEnd()
 
   if (local_player->LevelSolved_SaveTape)
   {
+#if 0
     TapeStop();
+#endif
 
     SaveTape(tape.level_nr);           /* ask to save tape */
   }
@@ -7207,7 +7228,7 @@ void EdelsteinFunkeln(int x, int y)
     return;
 
   if (MovDelay[x][y] == 0)     /* next animation frame */
-    MovDelay[x][y] = 11 * !SimpleRND(500);
+    MovDelay[x][y] = 11 * !GetSimpleRandom(500);
 
   if (MovDelay[x][y] != 0)     /* wait some time before next frame */
   {
@@ -8672,11 +8693,11 @@ static void SetPlayerWaiting(struct PlayerInfo *player, boolean is_waiting)
       player->frame_counter_bored =
        FrameCounter +
        game.player_boring_delay_fixed +
-       SimpleRND(game.player_boring_delay_random);
+       GetSimpleRandom(game.player_boring_delay_random);
       player->frame_counter_sleeping =
        FrameCounter +
        game.player_sleeping_delay_fixed +
-       SimpleRND(game.player_sleeping_delay_random);
+       GetSimpleRandom(game.player_sleeping_delay_random);
 
       InitPlayerGfxAnimation(player, ACTION_WAITING, move_dir);
     }
@@ -8732,10 +8753,10 @@ static void SetPlayerWaiting(struct PlayerInfo *player, boolean is_waiting)
 
          player->anim_delay_counter =
            graphic_info[special_graphic].anim_delay_fixed +
-           SimpleRND(graphic_info[special_graphic].anim_delay_random);
+           GetSimpleRandom(graphic_info[special_graphic].anim_delay_random);
          player->post_delay_counter =
            graphic_info[special_graphic].post_delay_fixed +
-           SimpleRND(graphic_info[special_graphic].post_delay_random);
+           GetSimpleRandom(graphic_info[special_graphic].post_delay_random);
 
          player->special_action_sleeping = special_action;
        }
@@ -8758,16 +8779,16 @@ static void SetPlayerWaiting(struct PlayerInfo *player, boolean is_waiting)
        if (player->anim_delay_counter == 0 && player->post_delay_counter == 0)
        {
          int special_action =
-           ACTION_BORING_1 + SimpleRND(player->num_special_action_bored);
+           ACTION_BORING_1 + GetSimpleRandom(player->num_special_action_bored);
          int special_graphic =
            el_act_dir2img(player->artwork_element, special_action, move_dir);
 
          player->anim_delay_counter =
            graphic_info[special_graphic].anim_delay_fixed +
-           SimpleRND(graphic_info[special_graphic].anim_delay_random);
+           GetSimpleRandom(graphic_info[special_graphic].anim_delay_random);
          player->post_delay_counter =
            graphic_info[special_graphic].post_delay_fixed +
-           SimpleRND(graphic_info[special_graphic].post_delay_random);
+           GetSimpleRandom(graphic_info[special_graphic].post_delay_random);
 
          player->special_action_bored = special_action;
        }
@@ -12413,14 +12434,55 @@ void RequestQuitGame(boolean ask_if_really_quit)
 
 
 /* ------------------------------------------------------------------------- */
-/* game engine snapshot handling                                             */
+/* random generator functions                                                */
+/* ------------------------------------------------------------------------- */
+
+unsigned int InitEngineRandom_RND(long seed)
+{
+  game.num_random_calls = 0;
+
+#if 0
+  unsigned int rnd_seed = InitEngineRandom(seed);
+
+  printf("::: START RND: %d\n", rnd_seed);
+
+  return rnd_seed;
+#else
+
+  return InitEngineRandom(seed);
+
+#endif
+
+}
+
+unsigned int RND(int max)
+{
+  if (max > 0)
+  {
+    game.num_random_calls++;
+
+    return GetEngineRandom(max);
+  }
+
+  return 0;
+}
+
+
+/* ------------------------------------------------------------------------- */
+/* game engine snapshot handling functions                                   */
 /* ------------------------------------------------------------------------- */
 
 #define ARGS_ADDRESS_AND_SIZEOF(x)             (&(x)), (sizeof(x))
 
 struct EngineSnapshotInfo
 {
+  /* runtime values for custom element collect score */
   int collect_score[NUM_CUSTOM_ELEMENTS];
+
+  /* runtime values for group element choice position */
+  int choice_pos[NUM_GROUP_ELEMENTS];
+
+  /* runtime values for belt position animations */
   int belt_graphic[4 * NUM_BELT_PARTS];
   int belt_anim_mode[4 * NUM_BELT_PARTS];
 };
@@ -12459,7 +12521,18 @@ static void SaveEngineSnapshotValues_RND()
   int i, j;
 
   for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
-    engine_snapshot_rnd.collect_score[i] = element_info[i].collect_score;
+  {
+    int element = EL_CUSTOM_START + i;
+
+    engine_snapshot_rnd.collect_score[i] = element_info[element].collect_score;
+  }
+
+  for (i = 0; i < NUM_GROUP_ELEMENTS; i++)
+  {
+    int element = EL_GROUP_START + i;
+
+    engine_snapshot_rnd.choice_pos[i] = element_info[element].group->choice_pos;
+  }
 
   for (i = 0; i < 4; i++)
   {
@@ -12473,14 +12546,30 @@ static void SaveEngineSnapshotValues_RND()
       engine_snapshot_rnd.belt_anim_mode[i * 4 + j] = anim_mode;
     }
   }
+
+#if 0
+  printf("::: SAVE: %d RNDs\n", game.num_random_calls);
+#endif
 }
 
 static void LoadEngineSnapshotValues_RND()
 {
+  unsigned long num_random_calls = game.num_random_calls;
   int i, j;
 
   for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
-    element_info[i].collect_score = engine_snapshot_rnd.collect_score[i];
+  {
+    int element = EL_CUSTOM_START + i;
+
+    element_info[element].collect_score = engine_snapshot_rnd.collect_score[i];
+  }
+
+  for (i = 0; i < NUM_GROUP_ELEMENTS; i++)
+  {
+    int element = EL_GROUP_START + i;
+
+    element_info[element].group->choice_pos = engine_snapshot_rnd.choice_pos[i];
+  }
 
   for (i = 0; i < 4; i++)
   {
@@ -12492,6 +12581,26 @@ static void LoadEngineSnapshotValues_RND()
       graphic_info[graphic].anim_mode = anim_mode;
     }
   }
+
+#if 0
+  printf("::: LOADING ... : %d RNDs\n", num_random_calls);
+#endif
+
+  InitRND(tape.random_seed);
+  for (i = 0; i < num_random_calls; i++)
+    RND(1);
+
+  if (game.num_random_calls != num_random_calls)
+  {
+    Error(ERR_RETURN, "number of random calls out of sync");
+    Error(ERR_RETURN, "number of random calls should be %d", num_random_calls);
+    Error(ERR_RETURN, "number of random calls is %d", game.num_random_calls);
+    Error(ERR_EXIT, "this should not happen -- please debug");
+  }
+
+#if 0
+  printf("::: LOADED: %d RNDs\n", num_random_calls);
+#endif
 }
 
 static void SaveEngineSnapshotBuffer(void *buffer, int size)
index a18b624772fa8da437f9b0709a7d27c2a40b8a24..4532367944b698fb9d1a4396eece66ef9c15d58d 100644 (file)
@@ -86,6 +86,9 @@ struct GameInfo
   int centered_player_nr;
   int centered_player_nr_next;
   boolean set_centered_player;
+
+  /* values for random number generator initialization after snapshot */
+  unsigned long num_random_calls;
 };
 
 struct PlayerInfo
@@ -239,6 +242,9 @@ void RaiseScore(int);
 void RaiseScoreElement(int);
 void RequestQuitGame(boolean);
 
+unsigned int InitEngineRandom_RND(long);
+unsigned int RND(int);
+
 void FreeEngineSnapshot();
 void LoadEngineSnapshot();
 void SaveEngineSnapshot();
index 495aa918769d2e393b5639d36c12a80e8e7d4b9d..209872535a9ab391758c7633f247e15d7620ae49 100644 (file)
@@ -701,6 +701,10 @@ struct EngineSnapshotInfo_EM
   int screen_x;
   int screen_y;
   int frame;
+  short **Boom;
+  short **Cave;
+  short **Next;
+  short **Draw;
 };
 
 
@@ -720,7 +724,7 @@ extern void em_close_all();
 extern void InitGameEngine_EM();
 extern void GameActions_EM(byte *, boolean);
 
-extern unsigned int InitEngineRND_EM(long);
+extern unsigned int InitEngineRandom_EM(long);
 
 extern void setLevelInfoToDefaults_EM();
 extern boolean LoadNativeLevel_EM(char *);
index a756d24a1974aaf99b3353141f3704fc2f036622..b5a0e033bb6a4811c4ae6a37664df5082d3761a2 100644 (file)
@@ -369,11 +369,11 @@ void sound_play(void)
   memset(play, 0, sizeof(play));
 }
 
-unsigned int InitEngineRND_EM(long seed)
+unsigned int InitEngineRandom_EM(long seed)
 {
   if (seed == NEW_RANDOMIZE)
   {
-    int simple_rnd = SimpleRND(1000);
+    int simple_rnd = GetSimpleRandom(1000);
     int i;
 
     for (i = 0; i < simple_rnd || RandomEM == NEW_RANDOMIZE; i++)
index 68ba21f09d7d07ee92ed0d8b0c15ce8448d7173a..cc703ba96cb4ab622f7bec3c2e7f7e5a1dd1b5f1 100644 (file)
@@ -167,12 +167,19 @@ void SaveEngineSnapshotValues_EM()
 {
   int i, j, k;
 
-  engine_snapshot_em.RandomEM = RandomEM;
   engine_snapshot_em.game_em = game_em;
   engine_snapshot_em.lev = lev;
+
+  engine_snapshot_em.RandomEM = RandomEM;
+  engine_snapshot_em.frame = frame;
+
   engine_snapshot_em.screen_x = screen_x;
   engine_snapshot_em.screen_y = screen_y;
-  engine_snapshot_em.frame = frame;
+
+  engine_snapshot_em.Boom = Boom;
+  engine_snapshot_em.Cave = Cave;
+  engine_snapshot_em.Next = Next;
+  engine_snapshot_em.Draw = Draw;
 
   for (i = 0; i < 4; i++)
     engine_snapshot_em.ply[i] = ply[i];
@@ -181,18 +188,25 @@ void SaveEngineSnapshotValues_EM()
     for (j = 0; j < HEIGHT; j++)
       for (k = 0; k < WIDTH; k++)
        engine_snapshot_em.Array[i][j][k] = Array[i][j][k];
-
 }
 
 void LoadEngineSnapshotValues_EM()
 {
   int i, j, k;
 
-  RandomEM = engine_snapshot_em.RandomEM;
   game_em = engine_snapshot_em.game_em;
+  lev = engine_snapshot_em.lev;
+
+  RandomEM = engine_snapshot_em.RandomEM;
+  frame = engine_snapshot_em.frame;
+
   screen_x = engine_snapshot_em.screen_x;
   screen_y = engine_snapshot_em.screen_y;
-  frame = engine_snapshot_em.frame;
+
+  Boom = engine_snapshot_em.Boom;
+  Cave = engine_snapshot_em.Cave;
+  Next = engine_snapshot_em.Next;
+  Draw = engine_snapshot_em.Draw;
 
   for (i = 0; i < 4; i++)
     ply[i] = engine_snapshot_em.ply[i];
index f55818968233c212c9537b76b37b8ec2c1998acf..eb6b037454f22a9992f4473e117eaf1e84d12791 100644 (file)
@@ -4762,7 +4762,7 @@ void OpenAll()
   InitCounter();
 
   InitRND(NEW_RANDOMIZE);
-  InitSimpleRND(NEW_RANDOMIZE);
+  InitSimpleRandom(NEW_RANDOMIZE);
 
   InitJoysticks();
 
index ae54541fb3639f5da828a511bf4785d2dfbea943..916ce2bdc4a3fff781f9b546f339adecf39e3443 100644 (file)
@@ -328,8 +328,17 @@ void WaitUntilDelayReached(unsigned long *counter_var, unsigned long delay)
 /* random generator functions                                                */
 /* ------------------------------------------------------------------------- */
 
+#if 0
+static int foo = -1;
+#endif
+
 unsigned int init_random_number(int nr, long seed)
 {
+#if 0
+  if (nr == 0)
+    foo = 0;
+#endif
+
   if (seed == NEW_RANDOMIZE)
   {
 #if defined(TARGET_SDL)
@@ -349,7 +358,26 @@ unsigned int init_random_number(int nr, long seed)
 
 unsigned int get_random_number(int nr, int max)
 {
+#if 0
+  if (max > 0)
+  {
+    long int rnd_raw = random_linux_libc(nr);
+    unsigned int rnd = rnd_raw % max;
+
+    if (nr == 0)
+    {
+      printf("::: %d: %d [%d MOD %d]\n", foo++, rnd, rnd_raw, max);
+    }
+
+    return rnd;
+  }
+  else
+  {
+    return 0;
+  }
+#else
   return (max > 0 ? random_linux_libc(nr) % max : 0);
+#endif
 }
 
 
index 1bafb463efe04bdd3a3661b7067075996b862079..009350c025afb7eb9c1823f29bf8c0759a110c7e 100644 (file)
 /* values for InitRND() */
 #define NEW_RANDOMIZE                  -1
 
-#define InitEngineRND(seed)            init_random_number(0, seed)
-#define InitSimpleRND(seed)            init_random_number(1, seed)
-#define RND(max)                       get_random_number(0, max)
-#define SimpleRND(max)                 get_random_number(1, max)
+#define RANDOM_ENGINE                  0
+#define RANDOM_SIMPLE                  1
+
+#define InitEngineRandom(seed)         init_random_number(RANDOM_ENGINE, seed)
+#define InitSimpleRandom(seed)         init_random_number(RANDOM_SIMPLE, seed)
+#define GetEngineRandom(max)           get_random_number(RANDOM_ENGINE, max)
+#define GetSimpleRandom(max)           get_random_number(RANDOM_SIMPLE, max)
 
 /* values for Error() */
 #define ERR_RETURN                     0
index 0b7ca5522c8db2391bb2751b50a3d2d35ae6e812..c5f1ff39bbdd0de17040a8208f9cd171c638e91f 100644 (file)
@@ -65,7 +65,7 @@ int getAnimationFrame(int num_frames, int delay, int mode, int start_frame,
     /* note: expect different frames for the same delay cycle! */
 
     if (gfx.anim_random_frame < 0)
-      frame = SimpleRND(num_frames);
+      frame = GetSimpleRandom(num_frames);
     else
       frame = gfx.anim_random_frame % num_frames;
   }
@@ -182,11 +182,11 @@ boolean AnimateToon(int toon_nr, boolean restart)
       else if (strEqual(anim->position, "bottom"))
        pos_y = pos_bottom;
       else if (strEqual(anim->position, "upper"))
-       pos_y = SimpleRND(pos_bottom / 2);
+       pos_y = GetSimpleRandom(pos_bottom / 2);
       else if (strEqual(anim->position, "lower"))
-       pos_y = pos_bottom / 2 + SimpleRND(pos_bottom / 2);
+       pos_y = pos_bottom / 2 + GetSimpleRandom(pos_bottom / 2);
       else
-       pos_y = SimpleRND(pos_bottom);
+       pos_y = GetSimpleRandom(pos_bottom);
 
       if (direction == MV_RIGHT)
       {
@@ -210,7 +210,7 @@ boolean AnimateToon(int toon_nr, boolean restart)
       else if (strEqual(anim->position, "right"))
        pos_x = pos_right;
       else
-       pos_x = SimpleRND(pos_right);
+       pos_x = GetSimpleRandom(pos_right);
 
       if (direction == MV_DOWN)
       {
@@ -354,7 +354,7 @@ void HandleAnimation(int mode)
   if (reset_delay)
   {
     animstart_delay = Counter();
-    animstart_delay_value = SimpleRND(3000);
+    animstart_delay_value = GetSimpleRandom(3000);
     reset_delay = FALSE;
   }
 
@@ -363,7 +363,7 @@ void HandleAnimation(int mode)
     if (!DelayReached(&animstart_delay, animstart_delay_value))
       return;
 
-    toon_nr = SimpleRND(screen_info.num_toons);
+    toon_nr = GetSimpleRandom(screen_info.num_toons);
   }
 
   anim_restart = reset_delay = AnimateToon(toon_nr, anim_restart);
index f2b284423594be7c637b2d2fe4c00b1568f7bd21..a88e12b8b3ea1c4f4773be6ae487255f6a44d7d3 100644 (file)
@@ -2397,8 +2397,6 @@ extern int                        ExitX, ExitY;
 extern int                     AllPlayersGone;
 
 extern int                     TimeFrames, TimePlayed, TimeLeft, TapeTime;
-extern boolean                 SiebAktiv;
-extern int                     SiebCount;
 
 extern boolean                 network_player_action_received;
 
index 90435c48179e2ffd7952f53b2f66a8651c256d64..a7bd35ee2f94196452216d1adcd08749b5119e5e 100644 (file)
@@ -677,6 +677,9 @@ void TapeTogglePause(boolean toggle_manual)
       tape.quick_resume = FALSE;
 
       TapeAppendRecording();
+
+      if (!CheckEngineSnapshot())
+       SaveEngineSnapshot();
     }
   }
 }
@@ -945,7 +948,7 @@ void TapeQuickLoad()
   if (game_status != GAME_MODE_PLAYING && game_status != GAME_MODE_MAIN)
     return;
 
-  if (CheckEngineSnapshot())
+  if (1 && CheckEngineSnapshot())
   {
     TapeStartGamePlaying();
 
index 298a98bf45d893dba034070266f6296c269104c0..23a255108812d00a7028e4d171f69cc6f408bdd7 100644 (file)
@@ -2226,6 +2226,10 @@ void WaitForEventToContinue()
 
   button_status = MB_RELEASED;
 
+#if 1
+  ClearEventQueue();
+#endif
+
   while (still_wait)
   {
     if (PendingEvent())
@@ -5306,9 +5310,9 @@ int getGameFrameDelay_EM(int native_em_game_frame_delay)
 unsigned int InitRND(long seed)
 {
   if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
-    return InitEngineRND_EM(seed);
+    return InitEngineRandom_EM(seed);
   else
-    return InitEngineRND(seed);
+    return InitEngineRandom_RND(seed);
 }
 
 void InitGraphicInfo_EM(void)