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 a780952b9749960b09146a81745a8dbf496be539..12397d5c4f262cf5367957a8c78e32c06f37f081 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 c5f563b2397ca4012d752b959becd298e89f86df..d61e33eec5db472f1f55df60d9bad4b77221fe8b 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 90957d69bf0a04a266260cdb7dc84ac2592baafc..45cbd2503908eefb81ed4369089b67bd95f7950a 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 cea29bb22a9db0e072181f7a86ddcbd065a80444..b390ad916e71dfeec0f108d8fa38d81edbdd9b7b 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 8fc7ada1d9e91dcafebc7982380d7427d0d68d74..70f6797c88e38030fabacdcfec58249e5f8ae8a0 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;