moved initial player position to level structure for EM engine
authorHolger Schemel <info@artsoft.org>
Thu, 13 Feb 2020 00:27:05 +0000 (01:27 +0100)
committerHolger Schemel <info@artsoft.org>
Tue, 19 May 2020 16:19:55 +0000 (18:19 +0200)
src/files.c
src/game_em/cave.c
src/game_em/convert.c
src/game_em/emerald.h
src/game_em/export.h
src/game_em/reademc.c

index 4590665ecfe94e65d9d87eb3f1dc765661f59bb8..1052d7fc6ae7d7c0c8fb3eb4e7d40a2e3f6124ce 100644 (file)
@@ -3516,7 +3516,6 @@ static void CopyNativeLevel_RND_to_EM(struct LevelInfo *level)
   };
   struct LevelInfo_EM *level_em = level->native_em_level;
   struct LEVEL *lev = level_em->lev;
-  struct PLAYER **ply = level_em->ply;
   int i, j, x, y;
 
   lev->width  = MIN(level->fieldx, MAX_PLAYFIELD_WIDTH);
@@ -3591,8 +3590,8 @@ static void CopyNativeLevel_RND_to_EM(struct LevelInfo *level)
 
   for (i = 0; i < MAX_PLAYERS; i++)
   {
-    ply[i]->x_initial = -1;
-    ply[i]->y_initial = -1;
+    lev->player_x[i] = -1;
+    lev->player_y[i] = -1;
   }
 
   // initialize player positions and delete players from the playfield
@@ -3602,8 +3601,8 @@ static void CopyNativeLevel_RND_to_EM(struct LevelInfo *level)
     {
       int player_nr = GET_PLAYER_NR(level->field[x][y]);
 
-      ply[player_nr]->x_initial = x;
-      ply[player_nr]->y_initial = y;
+      lev->player_x[player_nr] = x;
+      lev->player_y[player_nr] = y;
 
       level_em->cave[x][y] = map_element_RND_to_EM(EL_EMPTY);
     }
@@ -3625,7 +3624,6 @@ static void CopyNativeLevel_EM_to_RND(struct LevelInfo *level)
   };
   struct LevelInfo_EM *level_em = level->native_em_level;
   struct LEVEL *lev = level_em->lev;
-  struct PLAYER **ply = level_em->ply;
   int i, j, x, y;
 
   level->fieldx = MIN(lev->width,  MAX_LEV_FIELDX);
@@ -3698,8 +3696,8 @@ static void CopyNativeLevel_EM_to_RND(struct LevelInfo *level)
   {
     // in case of all players set to the same field, use the first player
     int nr = MAX_PLAYERS - i - 1;
-    int jx = ply[nr]->x_initial;
-    int jy = ply[nr]->y_initial;
+    int jx = lev->player_x[nr];
+    int jy = lev->player_y[nr];
 
     if (jx != -1 && jy != -1)
       level->field[jx][jy] = EL_PLAYER_1 + nr;
index 585bfd2f0de6c10435be6d33dce4453bb8997d1d..7788ae70748bfb49eaa4a7112627be1686d6a829 100644 (file)
@@ -13,10 +13,7 @@ void setLevelInfoToDefaults_EM(void)
   int i;
 
   native_em_level.file_version = FILE_VERSION_EM_ACTUAL;
-
   native_em_level.lev = &lev;
-  for (i = 0; i < MAX_PLAYERS; i++)
-    native_em_level.ply[i] = &ply[i];
 
   game_em.lev = &lev;
   for (i = 0; i < MAX_PLAYERS; i++)
@@ -27,8 +24,8 @@ void setLevelInfoToDefaults_EM(void)
 
   for (i = 0; i < MAX_PLAYERS; i++)
   {
-    ply[i].x_initial = -1;
-    ply[i].y_initial = -1;
+    lev.player_x[i] = -1;
+    lev.player_y[i] = -1;
   }
 
   lev.lenses_cnt_initial = 0;
index 4ce1611104a57311201cfde05918c1e517ec4ee0..581c93eec2baf21fa797f2269a1afff8e74a29d7 100644 (file)
@@ -83,7 +83,8 @@ void prepare_em_level(void)
     ply[i].exists = 0;
     ply[i].alive_initial = FALSE;
 
-    if (ply[i].x_initial != -1 && ply[i].y_initial != -1)
+    if (lev.player_x[i] != -1 &&
+       lev.player_y[i] != -1)
     {
       ply[i].exists = 1;
 
@@ -110,8 +111,8 @@ void prepare_em_level(void)
       }
       else
       {
-       int x = ply[i].x_initial;
-       int y = ply[i].y_initial;
+       int x = lev.player_x[i];
+       int y = lev.player_y[i];
 
        native_em_level.cave[x][y] = Xblank;
 
@@ -130,8 +131,8 @@ void prepare_em_level(void)
     ply[i].dynamite_cnt = 0;
     ply[i].keys = 0;
     ply[i].anim = 0;
-    ply[i].oldx = ply[i].x = ply[i].x_initial + lev.left;
-    ply[i].oldy = ply[i].y = ply[i].y_initial + lev.top;
+    ply[i].oldx = ply[i].x = lev.player_x[i] + lev.left;
+    ply[i].oldy = ply[i].y = lev.player_y[i] + lev.top;
     ply[i].last_move_dir = MV_NONE;
     ply[i].joy_n = ply[i].joy_e = ply[i].joy_s = ply[i].joy_w = 0;
     ply[i].joy_snap  = ply[i].joy_drop = 0;
index 37b75c66e4be259c95280bcb399c2eb87f05b814..8394414859493a04646233469049fc06a778bc22 100644 (file)
@@ -632,6 +632,9 @@ struct LEVEL
   int right;                   /* playfield right edge */
   int bottom;                  /* playfield bottom edge */
 
+  int player_x[MAX_PLAYERS];   /* player x pos */
+  int player_y[MAX_PLAYERS];   /* player y pos */
+
   int time_seconds;            /* available time (seconds) */
   int time_initial;            /* available time (initial) */
   int time;                    /* time remaining (runtime) */
@@ -730,8 +733,6 @@ struct PLAYER
   int keys;
   int anim;
 
-  int x_initial;
-  int y_initial;
   int x;
   int y;
   int oldx;
index acd000b55d44408cbb3406306093e58294749726..6fac56aec45f93bb768b04a2b01b3b7e3777731f 100644 (file)
@@ -50,7 +50,6 @@ struct LevelInfo_EM
   short cave[CAVE_WIDTH][CAVE_HEIGHT];
 
   struct LEVEL *lev;
-  struct PLAYER *ply[MAX_PLAYERS];
 };
 
 struct GraphicInfo_EM
index 0c9e663e9ecc448676b24da36fa193f97af72ccd..f8f101242368bd9056c950732b8ff2aeaa3ae14e 100644 (file)
@@ -447,8 +447,8 @@ void convert_em_level(unsigned char *src, int file_version)
   {
     temp = GET_BE16(src[2096 + i * 2]);
 
-    ply[i].x_initial = (temp & 63);
-    ply[i].y_initial = (temp >> 6 & 31);
+    lev.player_x[i] = (temp & 63);
+    lev.player_y[i] = (temp >> 6 & 31);
   }
 
   /* cave */
@@ -467,7 +467,7 @@ void convert_em_level(unsigned char *src, int file_version)
   /* at last, set the two players at their positions in the playfield */
   /* (native EM[C] levels always have exactly two players in a level) */
   for (i = 0; i < 2; i++)
-    native_em_level.cave[ply[i].x_initial][ply[i].y_initial] = Zplayer;
+    native_em_level.cave[lev.player_x[i]][lev.player_y[i]] = Zplayer;
 
   native_em_level.file_version = file_version;
 }