fixed removing same player in level editor when drawing new player
authorHolger Schemel <info@artsoft.org>
Sun, 17 Feb 2019 18:35:56 +0000 (19:35 +0100)
committerHolger Schemel <info@artsoft.org>
Sun, 17 Feb 2019 18:35:56 +0000 (19:35 +0100)
Before this fix, this feature did not work with player 2, 3 and 4,
and it also did not work with "sokoban field with player" element.

src/editor.c

index 12562f7671feb4c9f27e3e949e33845bf17e389f..3fa42f10eab74c5accddb47ecc8d90872e340f06 100644 (file)
@@ -12791,13 +12791,37 @@ static void HandleDrawingAreas(struct GadgetInfo *gi)
        {
          SetDrawModeHiRes(new_element);
 
-         if (new_element == EL_PLAYER_1)
+         if (ELEM_IS_PLAYER(new_element))
          {
            // remove player at old position
            for (y = 0; y < lev_fieldy; y++)
+           {
              for (x = 0; x < lev_fieldx; x++)
-               if (Feld[x][y] == EL_PLAYER_1)
-                 SetElement(x, y, EL_EMPTY);
+             {
+               int old_element = Feld[x][y];
+
+               if (ELEM_IS_PLAYER(old_element))
+               {
+                 int replaced_with_element =
+                   (old_element == EL_SOKOBAN_FIELD_PLAYER &&
+                    new_element == EL_PLAYER_1 ? EL_SOKOBAN_FIELD_EMPTY :
+
+                    old_element == EL_SOKOBAN_FIELD_PLAYER &&
+                    new_element == old_element ? EL_SOKOBAN_FIELD_EMPTY :
+
+                    new_element == EL_SOKOBAN_FIELD_PLAYER &&
+                    old_element == EL_PLAYER_1 ? EL_EMPTY :
+
+                    new_element >= EL_PLAYER_1 &&
+                    new_element <= EL_PLAYER_4 &&
+                    new_element == old_element ? EL_EMPTY :
+
+                    old_element);
+
+                 SetElement(x, y, replaced_with_element);
+               }
+             }
+           }
          }
 
          SetElementButton(lx, ly, dx, dy, new_element, button);