fixed empty default level according to default game engine type
authorHolger Schemel <info@artsoft.org>
Wed, 10 Apr 2024 16:46:52 +0000 (18:46 +0200)
committerHolger Schemel <info@artsoft.org>
Wed, 10 Apr 2024 16:47:20 +0000 (18:47 +0200)
src/files.c
src/tools.c
src/tools.h

index 38f142585ac07cf49157ae22cd4050149e1e5796..2694c2d9a71cecb946c02e882bc9944300600f66 100644 (file)
@@ -2334,6 +2334,11 @@ void setElementChangeInfoToDefaults(struct ElementChangeInfo *change)
 
 static void setLevelInfoToDefaults_Level(struct LevelInfo *level)
 {
+  boolean add_border = FALSE;
+  int x1 = 0;
+  int y1 = 0;
+  int x2 = STD_LEV_FIELDX - 1;
+  int y2 = STD_LEV_FIELDY - 1;
   int i, x, y;
 
   li = *level;         // copy level data into temporary buffer
@@ -2372,15 +2377,35 @@ static void setLevelInfoToDefaults_Level(struct LevelInfo *level)
   // set default game engine type
   level->game_engine_type = setup.default_game_engine_type;
 
+  // some game engines should have a default playfield with border elements
+  if (level->game_engine_type == GAME_ENGINE_TYPE_BD ||
+      level->game_engine_type == GAME_ENGINE_TYPE_EM ||
+      level->game_engine_type == GAME_ENGINE_TYPE_SP)
+  {
+    add_border = TRUE;
+    x1++;
+    y1++;
+    x2--;
+    y2--;
+  }
+
   // set level playfield to playable default level with player and exit
   for (x = 0; x < MAX_LEV_FIELDX; x++)
+  {
     for (y = 0; y < MAX_LEV_FIELDY; y++)
-      level->field[x][y] = EL_SAND;
+    {
+      if (add_border && (x == 0 || x == STD_LEV_FIELDX - 1 ||
+                        y == 0 || y == STD_LEV_FIELDY - 1))
+       level->field[x][y] = getEngineElement(EL_STEELWALL);
+      else
+       level->field[x][y] = getEngineElement(EL_SAND);
+    }
+  }
 
-  level->field[0][0] = EL_PLAYER_1;
-  level->field[STD_LEV_FIELDX - 1][STD_LEV_FIELDY - 1] = EL_EXIT_CLOSED;
+  level->field[x1][y1] = getEngineElement(EL_PLAYER_1);
+  level->field[x2][y2] = getEngineElement(EL_EXIT_CLOSED);
 
-  BorderElement = EL_STEELWALL;
+  BorderElement = getEngineElement(EL_STEELWALL);
 
   // detect custom elements when loading them
   level->file_has_custom_elements = FALSE;
index d83cb75aada4810bf6a2b235d695e45d54976c10..1fe6fccc6306529554ed1f797cee6f8c8cd8373e 100644 (file)
@@ -6012,6 +6012,88 @@ static void HandleToolButtons(struct GadgetInfo *gi)
   request_gadget_id = gi->custom_id;
 }
 
+static int getEngineElement_Ext(int element, int game_engine_type, boolean is_drawing_element)
+{
+  int el_empty;
+  int el_player;
+  int el_sand;
+  int el_wall;
+  int el_steelwall;
+  int el_exit_closed;
+
+  if (game_engine_type == -1)
+    game_engine_type = level.game_engine_type;
+
+  if (level.game_engine_type == GAME_ENGINE_TYPE_BD)
+  {
+    el_empty           = EL_EMPTY;
+    el_player          = EL_BD_PLAYER;
+    el_sand            = EL_BD_SAND;
+    el_wall            = EL_BD_WALL;
+    el_steelwall       = EL_BD_STEELWALL;
+    el_exit_closed     = EL_BD_EXIT_CLOSED;
+  }
+  else if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
+  {
+    el_empty           = EL_EMPTY;
+    el_player          = EL_PLAYER_1;
+    el_sand            = EL_SAND;
+    el_wall            = EL_WALL;
+    el_steelwall       = EL_STEELWALL;
+    el_exit_closed     = EL_EM_EXIT_CLOSED;
+  }
+  else if (level.game_engine_type == GAME_ENGINE_TYPE_SP)
+  {
+    el_empty           = EL_EMPTY;
+    el_player          = EL_SP_MURPHY;
+    el_sand            = EL_SP_BASE;
+    el_wall            = EL_SP_CHIP_SINGLE;
+    el_steelwall       = EL_SP_HARDWARE_GRAY;
+    el_exit_closed     = EL_SP_EXIT_CLOSED;
+  }
+  else if (level.game_engine_type == GAME_ENGINE_TYPE_MM)
+  {
+    el_empty           = EL_EMPTY;
+    el_player          = EL_MM_MCDUFFIN_DOWN;
+    el_sand            = EL_EMPTY;
+    el_wall            = EL_MM_WOODEN_WALL;
+    el_steelwall       = EL_MM_STEEL_WALL;
+    el_exit_closed     = EL_MM_EXIT_CLOSED;
+
+    if (is_drawing_element)
+    {
+      el_wall          = EL_MM_MIRROR_START;
+      el_sand          = EL_MM_WOODEN_WALL;
+    }
+  }
+  else
+  {
+    el_empty           = EL_EMPTY;
+    el_player          = EL_PLAYER_1;
+    el_sand            = EL_SAND;
+    el_wall            = EL_WALL;
+    el_steelwall       = EL_STEELWALL;
+    el_exit_closed     = EL_EXIT_CLOSED;
+  }
+
+  return (element == EL_EMPTY          ? el_empty :
+         element == EL_PLAYER_1        ? el_player :
+         element == EL_SAND            ? el_sand :
+         element == EL_WALL            ? el_wall :
+         element == EL_STEELWALL       ? el_steelwall :
+         element == EL_EXIT_CLOSED     ? el_exit_closed : EL_EMPTY);
+}
+
+int getEngineElement(int element)
+{
+  return getEngineElement_Ext(element, -1, FALSE);
+}
+
+int getDrawingElement(int element)
+{
+  return getEngineElement_Ext(element, -1, TRUE);
+}
+
 static struct Mapping_BD_to_RND_object
 {
   int element_bd;
index afad2e37948a973739006a7dcd05143f0745c2c1..cc503c0ae922c6fa332693885efdaa4df2ca4192 100644 (file)
@@ -229,6 +229,9 @@ void UndrawSpecialEditorDoor(void);
 void CreateToolButtons(void);
 void FreeToolButtons(void);
 
+int getEngineElement(int);
+int getDrawingElement(int);
+
 int map_element_RND_to_BD_cave(int);
 int map_element_RND_to_BD_effect(int, int);
 int map_element_BD_to_RND_cave(int);