rnd-20050117-1-src
[rocksndiamonds.git] / src / screens.c
index 425c35e86f014dfbc4c079166e7bb76c1d7ccdd7..268cd9c83a1897fd45cd96c1272b3303c30965f3 100644 (file)
@@ -1957,6 +1957,7 @@ static struct TokenInfo setup_info_editor[] =
 #endif
   { TYPE_SWITCH,       &setup.editor.el_boulderdash,   "BoulderDash:"  },
   { TYPE_SWITCH,       &setup.editor.el_emerald_mine,  "Emerald Mine:" },
+  { TYPE_SWITCH,       &setup.editor.el_emerald_mine_club,"E.M. Club:" },
   { TYPE_SWITCH,       &setup.editor.el_more,          "More:"         },
   { TYPE_SWITCH,       &setup.editor.el_sokoban,       "Sokoban:"      },
   { TYPE_SWITCH,       &setup.editor.el_supaplex,      "Supaplex:"     },
@@ -2945,19 +2946,88 @@ void HandleGameActions()
     return;
 
   /* !!! FIX THIS (START) !!! */
-  if (level.file_info.type == LEVEL_FILE_TYPE_EM)
+  if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
   {
+    byte *recorded_player_action;
     byte summarized_player_action = 0;
+    byte tape_action[MAX_PLAYERS];
     int i;
 
+    if (level.native_em_level->lev->home == 0) /* all players at home */
+    {
+      GameWon();
+
+      if (!TAPE_IS_STOPPED(tape))
+       TapeStop();
+
+      if (game_status != GAME_MODE_PLAYING)
+       return;
+    }
+
+    if (level.native_em_level->ply1->alive == 0 &&
+       level.native_em_level->ply2->alive == 0)        /* all dead */
+      AllPlayersGone = TRUE;
+
+    if (AllPlayersGone && !TAPE_IS_STOPPED(tape))
+      TapeStop();
+
+    /* --- game actions --- */
+
+    if (tape.pausing)
+    {
+      /* don't use 100% CPU while in pause mode -- this should better be solved
+        like in the R'n'D game engine! */
+
+      Delay(10);
+
+      return;
+    }
+
+    recorded_player_action = (tape.playing ? TapePlayAction() : NULL);
+
     for (i = 0; i < MAX_PLAYERS; i++)
+    {
       summarized_player_action |= stored_player[i].action;
 
-    if (em_main_handle_game(summarized_player_action) != 0)
+      if (!network_playing)
+       stored_player[i].effective_action = stored_player[i].action;
+    }
+
+    if (!options.network && !setup.team_mode)
+      local_player->effective_action = summarized_player_action;
+
+    if (recorded_player_action != NULL)
+      for (i = 0; i < MAX_PLAYERS; i++)
+       stored_player[i].effective_action = recorded_player_action[i];
+
+    for (i = 0; i < MAX_PLAYERS; i++)
     {
-      game_status = GAME_MODE_MAIN;
-      DrawMainMenu();
+      tape_action[i] = stored_player[i].effective_action;
+
+      /* !!! (this does not happen in the EM engine) !!! */
+      if (tape.recording && tape_action[i] && !tape.player_participates[i])
+       tape.player_participates[i] = TRUE;  /* player just appeared from CE */
     }
+
+    /* only save actions from input devices, but not programmed actions */
+    if (tape.recording)
+      TapeRecordAction(tape_action);
+
+    GameActions_EM(local_player->effective_action);
+
+    if (TimeFrames >= FRAMES_PER_SECOND)
+    {
+      TimeFrames = 0;
+      TapeTime++;
+
+      if (tape.recording || tape.playing)
+       DrawVideoDisplay(VIDEO_STATE_TIME_ON, TapeTime);
+    }
+
+    FrameCounter++;
+    TimeFrames++;
+
+    BackToFront();
   }
   else
   {