rnd-20021223-1-src
authorHolger Schemel <info@artsoft.org>
Sun, 22 Dec 2002 23:38:21 +0000 (00:38 +0100)
committerHolger Schemel <info@artsoft.org>
Sat, 30 Aug 2014 08:39:17 +0000 (10:39 +0200)
src/conftime.h
src/files.c
src/game.c
src/libgame/misc.c
src/libgame/system.h
src/main.h
src/screens.c
src/tape.c
src/tape.h

index 04a3c4c54b4427065c5bcafcea1d74728256ae3d..c572f214750dfb17d41e4138d2a7d06c7786ebba 100644 (file)
@@ -1 +1 @@
-#define COMPILE_DATE_STRING "[2002-12-19 00:19]"
+#define COMPILE_DATE_STRING "[2002-12-23 00:34]"
index e0446de5604e47c9569087d904856e86b508b3d8..fac13d0133719ac331a34f39c707170296958b89 100644 (file)
@@ -125,6 +125,8 @@ static void setLevelInfoToDefaults()
        break;
     }
   }
+
+  level.no_level_file = FALSE;
 }
 
 static int checkLevelElement(int element)
@@ -321,6 +323,8 @@ void LoadLevel(int level_nr)
 
   if (!(file = fopen(filename, MODE_READ)))
   {
+    level.no_level_file = TRUE;
+
     Error(ERR_WARN, "cannot read level '%s' - creating new level", filename);
     return;
   }
index 06edf65091e2acd9dac24734fd34eb66e3d3b586..5a6a248936827043d5a28bf9ec565323df6be7dc 100644 (file)
 #define NUM_GAME_BUTTONS               6
 
 /* forward declaration for internal use */
+static void InitBeltMovement(void);
 static void CloseAllOpenTimegates(void);
 static void CheckGravityMovement(struct PlayerInfo *);
 static void KillHeroUnlessProtected(int, int);
@@ -487,7 +488,7 @@ void DrawGameDoorValues()
     for (j=0; j<4; j++)
       if (stored_player[i].key[j])
        DrawMiniGraphicExt(drawto, DX_KEYS + j * MINI_TILEX, DY_KEYS,
-                          GFX_SCHLUESSEL1 + j);
+                          IMG_KEY1 + j);
 
   DrawText(DX + XX_EMERALDS, DY + YY_EMERALDS,
           int2str(local_player->gems_still_needed, 3), FS_SMALL, FC_YELLOW);
@@ -820,6 +821,8 @@ void InitGame()
     }
   }
 
+  InitBeltMovement();
+
   game.emulation = (emulate_bd ? EMU_BOULDERDASH :
                    emulate_sb ? EMU_SOKOBAN :
                    emulate_sp ? EMU_SUPAPLEX : EMU_NONE);
@@ -1154,6 +1157,9 @@ void GameWon()
   if (local_player->MovPos)
     return;
 
+  if (tape.playing && tape.auto_play)
+    tape.auto_play_level_solved = TRUE;
+
   local_player->LevelSolved = FALSE;
 
   PlaySoundStereo(SND_GAME_WINNING, SOUND_MAX_RIGHT);
@@ -1879,6 +1885,67 @@ void Blurb(int x, int y)
   }
 }
 
+static void InitBeltMovement()
+{
+  static int belt_base_element[4] =
+  {
+    EL_CONVEYOR_BELT1_LEFT,
+    EL_CONVEYOR_BELT2_LEFT,
+    EL_CONVEYOR_BELT3_LEFT,
+    EL_CONVEYOR_BELT4_LEFT
+  };
+  static int belt_base_active_element[4] =
+  {
+    EL_CONVEYOR_BELT1_LEFT_ACTIVE,
+    EL_CONVEYOR_BELT2_LEFT_ACTIVE,
+    EL_CONVEYOR_BELT3_LEFT_ACTIVE,
+    EL_CONVEYOR_BELT4_LEFT_ACTIVE
+  };
+
+  int x, y, i, j;
+
+  /* set frame order for belt animation graphic according to belt direction */
+  for (i=0; i<4; i++)
+  {
+    int belt_nr = i;
+
+    for (j=0; j<3; j++)
+    {
+      int element = belt_base_active_element[belt_nr] + j;
+      int graphic = el2img(element);
+
+      if (game.belt_dir[i] == MV_LEFT)
+       new_graphic_info[graphic].anim_mode &= ~ANIM_REVERSE;
+      else
+       new_graphic_info[graphic].anim_mode |=  ANIM_REVERSE;
+    }
+  }
+
+  for(y=0; y<lev_fieldy; y++)
+  {
+    for(x=0; x<lev_fieldx; x++)
+    {
+      int element = Feld[x][y];
+
+      for (i=0; i<4; i++)
+      {
+       if (IS_BELT(element) && game.belt_dir[i] != MV_NO_MOVING)
+       {
+         int e_belt_nr = getBeltNrFromBeltElement(element);
+         int belt_nr = i;
+
+         if (e_belt_nr == belt_nr)
+         {
+           int belt_part = Feld[x][y] - belt_base_element[belt_nr];
+
+           Feld[x][y] = belt_base_active_element[belt_nr] + belt_part;
+         }
+       }
+      }
+    }
+  }
+}
+
 static void ToggleBeltSwitch(int x, int y)
 {
   static int belt_base_element[4] =
@@ -6098,9 +6165,9 @@ int DigField(struct PlayerInfo *player,
       player->key[key_nr] = TRUE;
       RaiseScoreElement(element);
       DrawMiniGraphicExt(drawto, DX_KEYS + key_nr * MINI_TILEX, DY_KEYS,
-                        GFX_SCHLUESSEL1 + key_nr);
+                        IMG_KEY1 + key_nr);
       DrawMiniGraphicExt(window, DX_KEYS + key_nr * MINI_TILEX, DY_KEYS,
-                        GFX_SCHLUESSEL1 + key_nr);
+                        IMG_KEY1 + key_nr);
       PlaySoundLevel(x, y, SND_KEY_COLLECTING);
       break;
     }
@@ -6116,9 +6183,9 @@ int DigField(struct PlayerInfo *player,
       player->key[key_nr] = TRUE;
       RaiseScoreElement(element);
       DrawMiniGraphicExt(drawto, DX_KEYS + key_nr * MINI_TILEX, DY_KEYS,
-                        GFX_SCHLUESSEL1 + key_nr);
+                        IMG_KEY1 + key_nr);
       DrawMiniGraphicExt(window, DX_KEYS + key_nr * MINI_TILEX, DY_KEYS,
-                        GFX_SCHLUESSEL1 + key_nr);
+                        IMG_KEY1 + key_nr);
       PlaySoundLevel(x, y, SND_KEY_COLLECTING);
       break;
     }
index 6600dfdfc044fbc01116792c2bcbb35cf37350d1..e439e71d6cdbcecdaec8c2c9e245bc65b52ef3ff 100644 (file)
@@ -450,6 +450,7 @@ void GetOptions(char *argv[])
   options.graphics_directory = RO_BASE_PATH "/" GRAPHICS_DIRECTORY;
   options.sounds_directory = RO_BASE_PATH "/" SOUNDS_DIRECTORY;
   options.music_directory = RO_BASE_PATH "/" MUSIC_DIRECTORY;
+  options.autoplay_leveldir = NULL;
   options.serveronly = FALSE;
   options.network = FALSE;
   options.verbose = FALSE;
@@ -500,6 +501,7 @@ void GetOptions(char *argv[])
             "  -g, --graphics <directory>    alternative graphics directory\n"
             "  -s, --sounds <directory>      alternative sounds directory\n"
             "  -m, --music <directory>       alternative music directory\n"
+            "  -a, --autoplay <level series> automatically play level tapes\n"
             "  -n, --network                 network multiplayer game\n"
             "      --serveronly              only start network server\n"
             "  -v, --verbose                 verbose mode\n"
@@ -571,6 +573,15 @@ void GetOptions(char *argv[])
       if (option_arg == next_option)
        options_left++;
     }
+    else if (strncmp(option, "-autoplay", option_len) == 0)
+    {
+      if (option_arg == NULL)
+       Error(ERR_EXIT_HELP, "option '%s' requires an argument", option_str);
+
+      options.autoplay_leveldir = option_arg;
+      if (option_arg == next_option)
+       options_left++;
+    }
     else if (strncmp(option, "-network", option_len) == 0)
     {
       options.network = TRUE;
@@ -1731,7 +1742,7 @@ void FreeCustomArtworkList(struct ArtworkListInfo *artwork_info)
 {
   int i;
 
-  if (artwork_info->artwork_list == NULL)
+  if (artwork_info == NULL || artwork_info->artwork_list == NULL)
     return;
 
 #if 0
index 463d76fcc0b12fbdb23037661757d2ef8c054a6b..a28c03503dbe6ce54de1a8a6d07ba1dbc81f6353 100644 (file)
@@ -240,16 +240,20 @@ struct OptionInfo
   char *display_name;
   char *server_host;
   int server_port;
+
   char *ro_base_directory;
   char *rw_base_directory;
   char *level_directory;
   char *graphics_directory;
   char *sounds_directory;
   char *music_directory;
+  char *autoplay_leveldir;
+
   boolean serveronly;
   boolean network;
   boolean verbose;
   boolean debug;
+
   char *debug_command;
 };
 
index 6c60f8b9482d3075c670e23334453611c46d62be..8b9925115583f297b12396b225040dbe0b62f095 100644 (file)
@@ -1559,6 +1559,8 @@ struct LevelInfo
   boolean double_speed;
   boolean gravity;
   boolean em_slippery_gems;    /* EM style "gems slip from wall" behaviour */
+
+  boolean no_level_file;
 };
 
 struct TapeInfo
@@ -1578,6 +1580,8 @@ struct TapeInfo
   boolean recording, playing, pausing;
   boolean fast_forward;
   boolean index_search;
+  boolean auto_play;
+  boolean auto_play_level_solved;
   boolean quick_resume;
   boolean single_step;
   boolean changed;
index 0532cdd19e2f054e9d42df7059653fe2c0f40faf..ffb15a9f39a52472d0fbed5efd39bf56060e7c98 100644 (file)
@@ -235,6 +235,9 @@ void DrawMainMenu()
 
   OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
 
+  if (options.autoplay_leveldir)
+    AutoPlayTape();
+
 #if 0
   ClearEventQueue();
 #endif
index cc2ad928110c0d5d6e753fa6ab855a5ae7b8d330..8ca52a0335e4e172751344f4cf655346c72a4533 100644 (file)
@@ -14,6 +14,7 @@
 #include "libgame/libgame.h"
 
 #include "tape.h"
+#include "init.h"
 #include "game.h"
 #include "tools.h"
 #include "files.h"
@@ -325,6 +326,8 @@ static void TapeRewind()
   tape.playing = FALSE;
   tape.fast_forward = FALSE;
   tape.index_search = FALSE;
+  tape.auto_play = (options.autoplay_leveldir != NULL);
+  tape.auto_play_level_solved = FALSE;
   tape.quick_resume = FALSE;
   tape.single_step = FALSE;
 
@@ -552,7 +555,7 @@ byte *TapePlayAction()
 
   if (tape.counter >= tape.length)     /* end of tape reached */
   {
-    if (tape.index_search)
+    if (tape.index_search && !tape.auto_play)
       TapeTogglePause(TAPE_TOGGLE_MANUAL);
     else
       TapeStop();
@@ -584,6 +587,9 @@ void TapeStop()
     DrawVideoDisplay(VIDEO_STATE_DATE_ON, tape.date);
     DrawVideoDisplay(VIDEO_STATE_TIME_ON, tape.length_seconds);
   }
+
+  if (tape.auto_play)
+    AutoPlayTape();    /* continue automatically playing next tape */
 }
 
 unsigned int GetTapeLength()
@@ -672,6 +678,74 @@ void TapeQuickLoad()
 }
 
 
+/* ------------------------------------------------------------------------- *
+ * tape autoplay functions
+ * ------------------------------------------------------------------------- */
+
+void AutoPlayTape()
+{
+  static LevelDirTree *autoplay_leveldir = NULL;
+  static boolean autoplay_initialized = FALSE;
+  static int autoplay_level_nr = -1;
+
+  if (autoplay_initialized)
+  {
+    /* just finished auto-playing tape */
+    printf("%s.\n", tape.auto_play_level_solved ? "solved" : "NOT SOLVED");
+  }
+  else
+  {
+    autoplay_leveldir = getTreeInfoFromIdentifier(leveldir_first,
+                                                 options.autoplay_leveldir);
+
+    if (autoplay_leveldir == NULL)
+      Error(ERR_EXIT, "no such level identifier: '%s'",
+           options.autoplay_leveldir);
+
+    leveldir_current = autoplay_leveldir;
+
+    autoplay_level_nr = autoplay_leveldir->first_level;
+
+    printf("Playing tapes of level series '%s'.\n", options.autoplay_leveldir);
+
+    autoplay_initialized = TRUE;
+  }
+
+  while (autoplay_level_nr <= autoplay_leveldir->last_level)
+  {
+    level_nr = autoplay_level_nr++;
+
+    TapeErase();
+
+    printf("Level %03d: ", level_nr);
+
+    LoadLevel(level_nr);
+    if (level.no_level_file)
+    {
+      printf("(no level file)\n");
+      continue;
+    }
+
+    LoadTape(level_nr);
+    if (TAPE_IS_EMPTY(tape))
+    {
+      printf("(no tape file)\n");
+      continue;
+    }
+
+    break;
+  }
+
+  if (autoplay_level_nr >= autoplay_leveldir->last_level)
+    CloseAllAndExit(0);
+
+  printf("playing tape ... ");
+
+  TapeStartGamePlaying();
+  TapeStartIndexSearch();
+}
+
+
 /* ---------- new tape button stuff ---------------------------------------- */
 
 /* graphic position values for tape buttons */
index 6a41a94d8bdf96ae53763d725bc4550aa3d8fbb6..89c56a637ee48152e5b84f5638e9c217df9ca699 100644 (file)
@@ -98,6 +98,8 @@ unsigned int GetTapeLength(void);
 void TapeQuickSave(void);
 void TapeQuickLoad(void);
 
+void AutoPlayTape(void);
+
 void CreateTapeButtons();
 void MapTapeEjectButton();
 void MapTapeIndexButton();