rnd-19981209-1
[rocksndiamonds.git] / src / game.c
index c5520d4ae89a754d8a5c638726acb0a7f1801afd..64a7c1aa326f5e01b2ca0b1eb04a1b5992a622d6 100644 (file)
 #include "joystick.h"
 #include "network.h"
 
+/* for DigField() */
+#define DF_NO_PUSH             0
+#define DF_DIG                 1
+#define DF_SNAP                        2
+
+/* for MoveFigure() */
+#define MF_NO_ACTION           0
+#define MF_MOVING              1
+#define MF_ACTION              2
+
+/* for ScrollFigure() */
+#define SCROLL_INIT            0
+#define SCROLL_GO_ON           1
+
+/* for Explode() */
+#define EX_PHASE_START         0
+#define EX_NORMAL              0
+#define EX_CENTER              1
+#define EX_BORDER              2
+
+/* special positions in the game control window (relative to control window) */
+#define XX_LEVEL               37
+#define YY_LEVEL               20
+#define XX_EMERALDS            29
+#define YY_EMERALDS            54
+#define XX_DYNAMITE            29
+#define YY_DYNAMITE            89
+#define XX_KEYS                        18
+#define YY_KEYS                        123
+#define XX_SCORE               15
+#define YY_SCORE               159
+#define XX_TIME                        29
+#define YY_TIME                        194
+
+/* special positions in the game control window (relative to main window) */
+#define DX_LEVEL               (DX + XX_LEVEL)
+#define DY_LEVEL               (DY + YY_LEVEL)
+#define DX_EMERALDS            (DX + XX_EMERALDS)
+#define DY_EMERALDS            (DY + YY_EMERALDS)
+#define DX_DYNAMITE            (DX + XX_DYNAMITE)
+#define DY_DYNAMITE            (DY + YY_DYNAMITE)
+#define DX_KEYS                        (DX + XX_KEYS)
+#define DY_KEYS                        (DY + YY_KEYS)
+#define DX_SCORE               (DX + XX_SCORE)
+#define DY_SCORE               (DY + YY_SCORE)
+#define DX_TIME                        (DX + XX_TIME)
+#define DY_TIME                        (DY + YY_TIME)
+
+#define IS_LOOP_SOUND(s)       ((s)==SND_KLAPPER || (s)==SND_ROEHR ||  \
+                                (s)==SND_NJAM || (s)==SND_MIEP)
+#define IS_MUSIC_SOUND(s)      ((s)==SND_ALCHEMY || (s)==SND_CHASE || \
+                                (s)==SND_NETWORK || (s)==SND_CZARDASZ || \
+                                (s)==SND_TYGER || (s)==SND_VOYAGER || \
+                                (s)==SND_TWILIGHT)
+
+/* score for elements */
+#define SC_EDELSTEIN           0
+#define SC_DIAMANT             1
+#define SC_KAEFER              2
+#define SC_FLIEGER             3
+#define SC_MAMPFER             4
+#define SC_ROBOT               5
+#define SC_PACMAN              6
+#define SC_KOKOSNUSS           7
+#define SC_DYNAMIT             8
+#define SC_SCHLUESSEL          9
+#define SC_ZEITBONUS           10
+
+/* values for game_emulation */
+#define EMU_NONE               0
+#define EMU_BOULDERDASH                1
+#define EMU_SOKOBAN            2
+
+/* to control special behaviour of certain game elements */
+int game_emulation = EMU_NONE;
+
+
+
+
 #ifdef DEBUG
+#if 1
 static unsigned int getStateCheckSum(int counter)
 {
   int x, y;
@@ -70,6 +150,10 @@ static unsigned int getStateCheckSum(int counter)
   return checksum;
 }
 #endif
+#endif
+
+
+
 
 void GetPlayerConfig()
 {
@@ -156,9 +240,11 @@ void InitGame()
 
   network_player_action_received = FALSE;
 
+#ifndef MSDOS
   /* initial null action */
   if (network_playing)
     SendToServer_MovePlayer(MV_NO_MOVING);
+#endif
 
   ZX = ZY = -1;
 
@@ -226,10 +312,13 @@ void InitGame()
 
          StorePlayer[x][y] = Feld[x][y];
 
-         printf("Player %d activated.\n", player->element_nr);
-         printf("[Local player is %d and currently %s.]\n",
-                local_player->element_nr,
-                local_player->active ? "active" : "not active");
+         if (options.verbose)
+         {
+           printf("Player %d activated.\n", player->element_nr);
+           printf("[Local player is %d and currently %s.]\n",
+                  local_player->element_nr,
+                  local_player->active ? "active" : "not active");
+         }
        }
 
        Feld[x][y] = EL_LEERRAUM;
@@ -342,20 +431,38 @@ void InitGame()
     }
   }
 
-  /* when in single player mode, eliminate all but the first active player */
-  if (!options.network && !setup.team_mode)
+  if (tape.playing)
   {
+    /* when playing a tape, eliminate all players who do not participate */
+
+    for (i=0; i<MAX_PLAYERS; i++)
+    {
+      if (stored_player[i].active && !tape.player_participates[i])
+      {
+       struct PlayerInfo *player = &stored_player[i];
+       int jx = player->jx, jy = player->jy;
+
+       player->active = FALSE;
+       StorePlayer[jx][jy] = 0;
+       Feld[jx][jy] = EL_LEERRAUM;
+      }
+    }
+  }
+  else if (!options.network && !setup.team_mode)       /* && !tape.playing */
+  {
+    /* when in single player mode, eliminate all but the first active player */
+
     for (i=0; i<MAX_PLAYERS; i++)
     {
       if (stored_player[i].active)
       {
        for (j=i+1; j<MAX_PLAYERS; j++)
        {
-         struct PlayerInfo *player = &stored_player[j];
-         int jx = player->jx, jy = player->jy;
-
-         if (player->active)
+         if (stored_player[j].active)
          {
+           struct PlayerInfo *player = &stored_player[j];
+           int jx = player->jx, jy = player->jy;
+
            player->active = FALSE;
            StorePlayer[jx][jy] = 0;
            Feld[jx][jy] = EL_LEERRAUM;
@@ -365,19 +472,29 @@ void InitGame()
     }
   }
 
-  for (i=0; i<MAX_PLAYERS; i++)
+  /* when recording the game, store which players take part in the game */
+  if (tape.recording)
   {
-    struct PlayerInfo *player = &stored_player[i];
-
-    printf("Player %d: present == %d, connected == %d, active == %d.\n",
-          i+1,
-          player->present,
-          player->connected,
-          player->active);
-    if (local_player == player)
-      printf("Player %d is local player.\n", i+1);
+    for (i=0; i<MAX_PLAYERS; i++)
+      if (stored_player[i].active)
+       tape.player_participates[i] = TRUE;
   }
 
+  if (options.verbose)
+  {
+    for (i=0; i<MAX_PLAYERS; i++)
+    {
+      struct PlayerInfo *player = &stored_player[i];
+
+      printf("Player %d: present == %d, connected == %d, active == %d.\n",
+            i+1,
+            player->present,
+            player->connected,
+            player->active);
+      if (local_player == player)
+       printf("Player  %d is local player.\n", i+1);
+    }
+  }
 
   game_emulation = (emulate_bd ? EMU_BOULDERDASH :
                    emulate_sb ? EMU_SOKOBAN : EMU_NONE);
@@ -436,11 +553,12 @@ void InitGame()
 
   XAutoRepeatOff(display);
 
-
-  for (i=0; i<4; i++)
-    printf("Spieler %d %saktiv.\n",
-          i+1, (stored_player[i].active ? "" : "nicht "));
-
+  if (options.verbose)
+  {
+    for (i=0; i<4; i++)
+      printf("Spieler %d %saktiv.\n",
+            i+1, (stored_player[i].active ? "" : "nicht "));
+  }
 }
 
 void InitMovDir(int x, int y)
@@ -625,8 +743,8 @@ boolean NewHiScore()
 
   LoadScore(level_nr);
 
-  if (!strcmp(setup.player_name, EMPTY_ALIAS) ||
-      local_player->score < highscore[MAX_SCORE_ENTRIES-1].Score) 
+  if (strcmp(setup.player_name, EMPTY_PLAYER_NAME) == 0 ||
+      local_player->score < highscore[MAX_SCORE_ENTRIES - 1].Score) 
     return -1;
 
   for (k=0; k<MAX_SCORE_ENTRIES; k++) 
@@ -2305,8 +2423,8 @@ void AmoebeUmwandeln2(int ax, int ay, int new_element)
 
 void AmoebeWaechst(int x, int y)
 {
-  static long sound_delay = 0;
-  static int sound_delay_value = 0;
+  static unsigned long sound_delay = 0;
+  static unsigned long sound_delay_value = 0;
 
   if (!MovDelay[x][y])         /* start new growing cycle */
   {
@@ -2995,8 +3113,8 @@ static void PlayerActions(struct PlayerInfo *player, byte player_action)
 
 void GameActions()
 {
-  static long action_delay = 0;
-  long action_delay_value;
+  static unsigned long action_delay = 0;
+  unsigned long action_delay_value;
   int sieb_x = 0, sieb_y = 0;
   int i, x, y, element;
   byte *recorded_player_action;
@@ -3008,8 +3126,40 @@ void GameActions()
   action_delay_value =
     (tape.playing && tape.fast_forward ? FfwdFrameDelay : GameFrameDelay);
 
+  /*
+  if (tape.playing && tape.fast_forward)
+  {
+    char buf[100];
+
+    sprintf(buf, "FFWD: %ld ms", action_delay_value);
+    print_debug(buf);
+  }
+  */
+
+
   /* main game synchronization point */
+
+
+
+
+#if 1
   WaitUntilDelayReached(&action_delay, action_delay_value);
+#else
+
+  while (!DelayReached(&action_delay, action_delay_value))
+  {
+    char buf[100];
+
+    sprintf(buf, "%ld %ld %ld",
+           Counter(), action_delay, action_delay_value);
+    print_debug(buf);
+  }
+  print_debug("done");
+
+#endif
+
+
+
 
   if (network_playing && !network_player_action_received)
   {
@@ -3019,8 +3169,10 @@ void GameActions()
 #endif
     */
 
+#ifndef MSDOS
     /* last chance to get network player actions without main loop delay */
     HandleNetworking();
+#endif
 
     if (game_status != PLAYING)
       return;
@@ -3062,8 +3214,10 @@ void GameActions()
       stored_player[i].effective_action = stored_player[i].action;
   }
 
+#ifndef MSDOS
   if (network_playing)
     SendToServer_MovePlayer(summarized_player_action);
+#endif
 
   if (!options.network && !setup.team_mode)
     local_player->effective_action = summarized_player_action;
@@ -3096,7 +3250,7 @@ void GameActions()
 
 
 #ifdef DEBUG
-  /*
+
   if (TimeFrames == 0 && !local_player->gone)
   {
     extern unsigned int last_RND();
@@ -3106,7 +3260,7 @@ void GameActions()
           last_RND(),
           getStateCheckSum(level.time - TimeLeft));
   }
-  */
+
 #endif
 
 
@@ -3412,11 +3566,11 @@ boolean MoveFigure(struct PlayerInfo *player, int dx, int dy)
 
   if (player->MovPos)
   {
-    /* should only happen if pre-1.0 tape recordings are played */
+    /* should only happen if pre-1.2 tape recordings are played */
     /* this is only for backward compatibility */
 
 #if DEBUG
-    printf("THIS SHOULD ONLY HAPPEN WITH PRE-1.0 LEVEL TAPES.\n");
+    printf("THIS SHOULD ONLY HAPPEN WITH PRE-1.2 LEVEL TAPES.\n");
 #endif
 
     while (player->MovPos)
@@ -3586,7 +3740,7 @@ void ScrollFigure(struct PlayerInfo *player, int mode)
 
 void ScrollScreen(struct PlayerInfo *player, int mode)
 {
-  static long screen_frame_counter = 0;
+  static unsigned long screen_frame_counter = 0;
 
   if (mode == SCROLL_INIT)
   {