added flags for "level solved" and "game over" to EM engine
authorHolger Schemel <info@artsoft.org>
Tue, 30 Oct 2018 19:55:42 +0000 (20:55 +0100)
committerHolger Schemel <info@artsoft.org>
Tue, 30 Oct 2018 19:58:30 +0000 (20:58 +0100)
src/game.c
src/game_em/convert.c
src/game_em/export.h
src/game_em/synchro_1.c
src/game_em/synchro_2.c

index a780952..12397d5 100644 (file)
@@ -11117,19 +11117,17 @@ static void CheckLevelSolved(void)
 {
   if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
   {
-    if (level.native_em_level->lev->home == 0) // all players at home
+    if (game_em.level_solved &&
+       !game_em.game_over)                             // game won
     {
       PlayerWins(local_player);
 
-      AllPlayersGone = TRUE;
+      game_em.game_over = TRUE;
 
-      level.native_em_level->lev->home = -1;
+      AllPlayersGone = TRUE;
     }
 
-    if (level.native_em_level->ply[0]->alive == 0 &&
-       level.native_em_level->ply[1]->alive == 0 &&
-       level.native_em_level->ply[2]->alive == 0 &&
-       level.native_em_level->ply[3]->alive == 0)      // all dead
+    if (game_em.game_over)                             // game lost
       AllPlayersGone = TRUE;
   }
   else if (level.game_engine_type == GAME_ENGINE_TYPE_SP)
@@ -15041,7 +15039,7 @@ boolean checkGameFailed(void)
     return FALSE;
 
   if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
-    return (level.native_em_level->lev->home > 0);
+    return (game_em.game_over && !game_em.level_solved);
   else if (level.game_engine_type == GAME_ENGINE_TYPE_SP)
     return (game_sp.game_over && !game_sp.level_solved);
   else if (level.game_engine_type == GAME_ENGINE_TYPE_MM)
index c5f563b..d61e33e 100644 (file)
@@ -1115,6 +1115,9 @@ void prepare_em_level(void)
   // - game_em.use_single_button (default: TRUE)
   // - game_em.use_snap_key_bug (default: FALSE)
 
+  game_em.level_solved = FALSE;
+  game_em.game_over = FALSE;
+
   game_em.any_player_moving = FALSE;
   game_em.any_player_snapping = FALSE;
 
index 90957d6..45cbd25 100644 (file)
@@ -664,6 +664,9 @@ struct GlobalInfo_EM
 
 struct GameInfo_EM
 {
+  boolean level_solved;
+  boolean game_over;
+
   boolean any_player_moving;
   boolean any_player_snapping;
 
index cea29bb..b390ad9 100644 (file)
@@ -1069,6 +1069,9 @@ static boolean player_digfield(struct PLAYER *ply, int dx, int dy)
       case Xexit_3:
        lev.home--;
 
+       if (lev.home == 0)
+         game_em.level_solved = TRUE;
+
        ply->anim = SPR_walk + anim;
        ply->x = x;
        ply->y = y;
index 8fc7ada..70f6797 100644 (file)
@@ -4867,6 +4867,8 @@ void synchro_2(void)
 
   if (ply[0].alive || ply[1].alive || ply[2].alive || ply[3].alive)
     lev.score += score;                /* only add a score if someone is alive */
+  else
+    game_em.game_over = TRUE;
 
   RandomEM = random;