rnd-19980928-4
authorHolger Schemel <info@artsoft.org>
Mon, 28 Sep 1998 16:30:50 +0000 (18:30 +0200)
committerHolger Schemel <info@artsoft.org>
Sat, 30 Aug 2014 08:30:48 +0000 (10:30 +0200)
src/events.c
src/files.c
src/game.c
src/joystick.h
src/main.h
src/tape.c
src/tape.h

index 771efb2837ca6958db89dd8f5c25140e43ae52d4..ff86409e640952345561ebeacf78ece8163d1eb3 100644 (file)
@@ -273,7 +273,7 @@ void HandleButton(int mx, int my, int button)
     int sx = (mx - SX) / TILEX;
     int sy = (my - SY) / TILEY;
 
-    if (IN_SCR_FIELD(sx,sy))
+    if (IN_VIS_FIELD(sx,sy))
     {
       int x = LEVELX(sx);
       int y = LEVELY(sy);
@@ -728,7 +728,12 @@ void HandleJoystick()
 {
   int joystick = Joystick();
   int keyboard = key_joystick_mapping;
+
+  /*
   int joy      = (tape.playing ? TapePlayAction() : (joystick | keyboard));
+  */
+
+  int joy      = (joystick | keyboard);
   int left     = joy & JOY_LEFT;
   int right    = joy & JOY_RIGHT;
   int up       = joy & JOY_UP;
index e3ad459fb57c59393cf3847fe073add1bcc8bdd6..284ed51fc0c7a8099d7834c099b903756e8de1b2 100644 (file)
@@ -220,6 +220,7 @@ void LoadLevelTape(int level_nr)
   char filename[MAX_FILENAME];
   char cookie[MAX_FILENAME];
   FILE *file;
+  BOOL levelrec_10 = FALSE;
 
 #ifndef MSDOS
   sprintf(filename,"%s/%s/%d.tape",
@@ -233,7 +234,9 @@ void LoadLevelTape(int level_nr)
   {
     fgets(cookie,LEVELREC_COOKIE_LEN,file);
     fgetc(file);
-    if (strcmp(cookie,LEVELREC_COOKIE))        /* ungültiges Format? */
+    if (!strcmp(cookie,LEVELREC_COOKIE_10))    /* old 1.0 tape format */
+      levelrec_10 = TRUE;
+    else if (strcmp(cookie,LEVELREC_COOKIE))   /* unknown tape format */
     {
       fprintf(stderr,"%s: wrong format of level recording file '%s'!\n",
              progname,filename);
@@ -262,10 +265,23 @@ void LoadLevelTape(int level_nr)
 
   for(i=0;i<tape.length;i++)
   {
-    if (i>=MAX_TAPELEN)
+    int j;
+
+    if (i >= MAX_TAPELEN)
       break;
-    tape.pos[i].joystickdata = fgetc(file);
-    tape.pos[i].delay        = fgetc(file);
+
+    for(j=0; j<MAX_PLAYERS; j++)
+    {
+      if (levelrec_10 && j>0)
+      {
+       tape.pos[i].joystickdata[j] = MV_NO_MOVING;
+       continue;
+      }
+      tape.pos[i].joystickdata[j] = fgetc(file);
+    }
+
+    tape.pos[i].delay = fgetc(file);
+
     if (feof(file))
       break;
   }
@@ -571,7 +587,11 @@ void SaveLevelTape(int level_nr)
 
   for(i=0;i<tape.length;i++)
   {
-    fputc(tape.pos[i].joystickdata,file);
+    int j;
+
+    for(j=0; j<MAX_PLAYERS; j++)
+      fputc(tape.pos[i].joystickdata[j],file);
+
     fputc(tape.pos[i].delay,file);
   }
 
index 8e6c8a9c115e4d2c089d860701903a315f807af0..86d83660ce7baec0059ee2edc0219758492807b2 100644 (file)
@@ -2710,6 +2710,8 @@ void CheckForDragon(int x, int y)
 
 void PlayerActions(struct PlayerInfo *player, int player_action)
 {
+  static int stored_player_action[MAX_PLAYERS];
+  static int num_stored_actions = 0;
   BOOL moved = FALSE, snapped = FALSE, bombed = FALSE;
   int jx = player->jx, jy = player->jy;
   int left     = player_action & JOY_LEFT;
@@ -2721,6 +2723,9 @@ void PlayerActions(struct PlayerInfo *player, int player_action)
   int dx       = (left ? -1    : right ? 1     : 0);
   int dy       = (up   ? -1    : down  ? 1     : 0);
 
+  stored_player_action[player->nr] = 0;
+  num_stored_actions++;
+
   if (!player->active || player->gone)
     return;
 
@@ -2741,7 +2746,15 @@ void PlayerActions(struct PlayerInfo *player, int player_action)
     {
       if (bombed && !moved)
        player_action &= JOY_BUTTON;
-      TapeRecordAction(player_action);
+
+      stored_player_action[player->nr] = player_action;
+
+      /* this allows cycled sequences of PlayerActions() */
+      if (num_stored_actions >= MAX_PLAYERS)
+      {
+       TapeRecordAction(stored_player_action);
+       num_stored_actions = 0;
+      }
     }
     else if (tape.playing && snapped)
       SnapField(player, 0,0);                  /* stop snapping */
@@ -2757,7 +2770,8 @@ void PlayerActions(struct PlayerInfo *player, int player_action)
   if (tape.playing && !tape.pausing && !player_action &&
       tape.counter < tape.length)
   {
-    int next_joy = tape.pos[tape.counter].joystickdata & (JOY_LEFT|JOY_RIGHT);
+    int next_joy =
+      tape.pos[tape.counter].joystickdata[player->nr] & (JOY_LEFT|JOY_RIGHT);
 
     if (next_joy == JOY_LEFT || next_joy == JOY_RIGHT)
     {
@@ -2785,6 +2799,7 @@ void GameActions(int player_action)
   long action_delay_value;
   int sieb_x = 0, sieb_y = 0;
   int i, x,y, element;
+  int *recorded_player_action;
 
   if (game_status != PLAYING)
     return;
@@ -2800,16 +2815,25 @@ void GameActions(int player_action)
   /* main game synchronization point */
   WaitUntilDelayReached(&action_delay, action_delay_value);
 
+  if (tape.playing)
+    recorded_player_action = TapePlayAction();
+  else
+    recorded_player_action = NULL;
+
   for(i=0; i<MAX_PLAYERS; i++)
   {
+    int actual_player_action = player_action;
     /* TEST TEST TEST */
 
     if (i != TestPlayer && !stored_player[i].MovPos)
-      continue;
+      actual_player_action = 0;
 
     /* TEST TEST TEST */
 
-    PlayerActions(&stored_player[i], player_action);
+    if (recorded_player_action)
+      actual_player_action = recorded_player_action[i];
+
+    PlayerActions(&stored_player[i], actual_player_action);
     ScrollFigure(&stored_player[i], SCROLL_GO_ON);
   }
 
index 64a8166d5cc95115802130b5f8a6edaa0da03f32..205f51f8ac6b37fb3e4dc8f830a10042723e2339 100644 (file)
@@ -41,8 +41,8 @@
 #define JOY_RIGHT              MV_RIGHT
 #define JOY_UP                 MV_UP
 #define JOY_DOWN               MV_DOWN
-#define JOY_BUTTON_1           16
-#define JOY_BUTTON_2           32
+#define JOY_BUTTON_1           (1<<4)
+#define JOY_BUTTON_2           (1<<5)
 #define JOY_BUTTON             (JOY_BUTTON_1 | JOY_BUTTON_2)
 #define JOY_BUTTON_NOT_PRESSED 0
 #define JOY_BUTTON_PRESSED     1
index a9fba3709e76aec839bd4bda48b0a9aa4a87bfab..54efac83aa175866bed1e1db2b7ea93f0da1f1b5 100644 (file)
@@ -288,7 +288,7 @@ struct RecordingInfo
   BOOL changed;
   struct
   {
-    unsigned char joystickdata;
+    unsigned char joystickdata[MAX_PLAYERS];
     unsigned char delay;
   } pos[MAX_TAPELEN];
 };
@@ -956,10 +956,10 @@ extern char               *progname;
 
 /* directions for moving */
 #define MV_NO_MOVING           0
-#define MV_LEFT                        1
-#define MV_RIGHT               2
-#define MV_UP                  4
-#define MV_DOWN                        8
+#define MV_LEFT                        (1<<0)
+#define MV_RIGHT               (1<<1)
+#define MV_UP                  (1<<2)
+#define MV_DOWN                        (1<<3)
 
 /* font types */
 #define FS_SMALL               0
@@ -1038,12 +1038,13 @@ extern char             *progname;
 
 /* old cookies */
 #define NAMES_COOKIE_10                "ROCKSNDIAMONDS_NAMES_FILE_VERSION_1.0"
+#define LEVELREC_COOKIE_10     "ROCKSNDIAMONDS_LEVELREC_FILE_VERSION_1.0"
 
 #define LEVEL_COOKIE           "ROCKSNDIAMONDS_LEVEL_FILE_VERSION_1.0"
 #define SCORE_COOKIE           "ROCKSNDIAMONDS_SCORE_FILE_VERSION_1.0"
 #define NAMES_COOKIE           "ROCKSNDIAMONDS_NAMES_FILE_VERSION_1.1"
 #define LEVELDIR_COOKIE                "ROCKSNDIAMONDS_LEVELDIR_FILE_VERSION_1.0"
-#define LEVELREC_COOKIE                "ROCKSNDIAMONDS_LEVELREC_FILE_VERSION_1.0"
+#define LEVELREC_COOKIE                "ROCKSNDIAMONDS_LEVELREC_FILE_VERSION_1.2"
 #define JOYSTICK_COOKIE                "ROCKSNDIAMONDS_JOYSTICK_FILE_VERSION_1.0"
 #define LEVEL_COOKIE_LEN       (strlen(LEVEL_COOKIE)+1)
 #define SCORE_COOKIE_LEN       (strlen(SCORE_COOKIE)+1)
index 33713069c4da4302fe7bddfe685a2ef27612b0ac..9c2668455a4092570a7bf53c1ab2c4fcfcc27e2d 100644 (file)
@@ -42,10 +42,14 @@ void TapeStartRecording()
 
 void TapeStopRecording()
 {
+  int i;
+
   if (!tape.recording)
     return;
 
-  tape.pos[tape.counter].joystickdata = 0;
+  for(i=0; i<MAX_PLAYERS; i++)
+    tape.pos[tape.counter].joystickdata[i] = 0;
+
   tape.counter++;
   tape.length = tape.counter;
   tape.length_seconds = GetTapeLength();
@@ -54,8 +58,10 @@ void TapeStopRecording()
   DrawVideoDisplay(VIDEO_STATE_REC_OFF,0);
 }
 
-void TapeRecordAction(int joy)
+void TapeRecordAction(int joy[MAX_PLAYERS])
 {
+  int i;
+
   if (!tape.recording || tape.pausing)
     return;
 
@@ -65,16 +71,17 @@ void TapeRecordAction(int joy)
     return;
   }
 
-  if (joy)
-  {
-    tape.pos[tape.counter].joystickdata = joy;
-    tape.counter++;
-    tape.pos[tape.counter].delay = 0;
-  }
+  for(i=0; i<MAX_PLAYERS; i++)
+    tape.pos[tape.counter].joystickdata[i] = joy[i];
+
+  tape.counter++;
+  tape.pos[tape.counter].delay = 0;
 }
 
 void TapeRecordDelay()
 {
+  int i;
+
   if (!tape.recording || tape.pausing)
     return;
 
@@ -86,9 +93,11 @@ void TapeRecordDelay()
 
   tape.pos[tape.counter].delay++;
 
-  if (tape.pos[tape.counter].delay>=255)
+  if (tape.pos[tape.counter].delay >= 255)
   {
-    tape.pos[tape.counter].joystickdata = 0;
+    for(i=0; i<MAX_PLAYERS; i++)
+      tape.pos[tape.counter].joystickdata[i] = 0;
+
     tape.counter++;
     tape.pos[tape.counter].delay = 0;
   }
@@ -139,25 +148,32 @@ void TapeStopPlaying()
   DrawVideoDisplay(VIDEO_STATE_PLAY_OFF,0);
 }
 
-int TapePlayAction()
+int *TapePlayAction()
 {
+  static int joy[MAX_PLAYERS];
+  int i;
+
   if (!tape.playing || tape.pausing)
-    return(0);
+    return(NULL);
 
   if (tape.counter>=tape.length)
   {
     TapeStop();
-    return(0);
+    return(NULL);
   }
 
   if (tape.delay_played == tape.pos[tape.counter].delay)
   {
     tape.delay_played = 0;
     tape.counter++;
-    return(tape.pos[tape.counter-1].joystickdata);
+
+    for(i=0; i<MAX_PLAYERS; i++)
+      joy[i] = tape.pos[tape.counter-1].joystickdata[i];
+
+    return(joy);
   }
-  else
-    return(0);
+
+  return(NULL);
 }
 
 BOOL TapePlayDelay()
index ca085e0067d1bb6bd8203f1ec9033d73f9661d85..ee0a98e34866a64180b5eb25fd5307a032ca34b0 100644 (file)
 
 void TapeStartRecording(void);
 void TapeStopRecording(void);
-void TapeRecordAction(int);
+void TapeRecordAction(int *);
 void TapeRecordDelay(void);
 void TapeTogglePause(void);
 void TapeStartPlaying(void);
 void TapeStopPlaying(void);
-int TapePlayAction(void);
+int *TapePlayAction(void);
 BOOL TapePlayDelay(void);
 void TapeStop(void);
 void TapeErase(void);