rnd-19981108-1
authorHolger Schemel <info@artsoft.org>
Sun, 8 Nov 1998 11:59:33 +0000 (12:59 +0100)
committerHolger Schemel <info@artsoft.org>
Sat, 30 Aug 2014 08:31:34 +0000 (10:31 +0200)
src/events.c
src/files.c
src/files.h
src/game.c
src/init.c
src/main.h
src/misc.c
src/misc.h
src/screens.c

index ed76f9a655beac4341b36a1cb80bb4cfda26b5fb..15f7205117ff592c9fac0de054796a5f2ae2a5df 100644 (file)
@@ -272,23 +272,23 @@ void HandleButton(int mx, int my, int button)
     old_mx = mx;
     old_my = my;
 
-    HandleVideoButtons(mx,my,button);
-    HandleSoundButtons(mx,my,button);
-    HandleGameButtons(mx,my,button);
+    HandleVideoButtons(mx,my, button);
+    HandleSoundButtons(mx,my, button);
+    HandleGameButtons(mx,my, button);
   }
 
   switch(game_status)
   {
     case MAINMENU:
-      HandleMainMenu(mx,my,0,0,button);
+      HandleMainMenu(mx,my, 0,0, button);
       break;
 
     case TYPENAME:
-      HandleTypeName(0,XK_Return);
+      HandleTypeName(0, XK_Return);
       break;
 
     case CHOOSELEVEL:
-      HandleChooseLevel(mx,my,0,0,button);
+      HandleChooseLevel(mx,my, 0,0, button);
       break;
 
     case HALLOFFAME:
@@ -296,7 +296,7 @@ void HandleButton(int mx, int my, int button)
       break;
 
     case LEVELED:
-      LevelEd(mx,my,button);
+      LevelEd(mx,my, button);
       break;
 
     case HELPSCREEN:
@@ -304,11 +304,11 @@ void HandleButton(int mx, int my, int button)
       break;
 
     case SETUP:
-      HandleSetupScreen(mx,my,0,0,button);
+      HandleSetupScreen(mx,my, 0,0, button);
       break;
 
     case SETUPINPUT:
-      HandleSetupInputScreen(mx,my,0,0,button);
+      HandleSetupInputScreen(mx,my, 0,0, button);
       break;
 
     case PLAYING:
@@ -545,80 +545,6 @@ void HandleKey(KeySym key, int key_status)
 
 #if 0
 
-       case XK_x:
-
-         {
-           int i,j,k, num_steps = 8, step_size = TILEX / num_steps;
-           static long scroll_delay=0;
-           long scroll_delay_value = 4*4 / num_steps;
-
-           printf("Scroll test\n");
-
-           for(i=0;i<3;i++)
-           {
-             for(j=0;j<SCR_FIELDX;j++)
-             {
-               for(k=0;k<num_steps;k++)
-               {
-                 int xxx = j*TILEX+k*step_size;
-                 int done = 0;
-
-                 while(!done)
-                 {
-                   if (DelayReached(&scroll_delay, scroll_delay_value))
-                   {
-                     XCopyArea(display,fieldbuffer,window,gc,
-                               SX+xxx,SY,
-                               SXSIZE-xxx,SYSIZE,
-                               SX,SY);
-                     XCopyArea(display,fieldbuffer,window,gc,
-                               SX,SY,
-                               xxx,SYSIZE,
-                               SX+SXSIZE-xxx,SY);
-  
-                     XFlush(display);
-                     XSync(display,FALSE);
-
-                     done = 1;
-                   }
-                   else
-                   {
-                     Delay(1);
-                   }
-                 }
-  
-                 /*
-                 Delay(160 / num_steps);
-                 */
-                 /*
-                 Delay(120 / num_steps);
-                 */
-               }
-             }
-           }
-         }
-
-         break;
-
-       case XK_y:
-         /*
-         {
-           printf("FX = %d, FY = %d\n", FX,FY);
-
-           XCopyArea(display,fieldbuffer,window,gc,
-                     0,0,
-                     MIN(WIN_XSIZE,FXSIZE),MIN(WIN_YSIZE,FYSIZE),
-                     0,0);
-           XFlush(display);
-           XSync(display,FALSE);
-           Delay(1000);
-         }
-         */
-
-         printf("direct_draw == %d\n", setup.direct_draw);
-
-         break;
-
        case XK_z:
          {
            int i;
@@ -634,20 +560,6 @@ void HandleKey(KeySym key, int key_status)
            printf("\n");
          }
 
-         break;
-
-       case XK_t:
-         {
-           char *color[] = { "yellow", "red", "green", "blue" };
-
-           do
-             TestPlayer = (TestPlayer + 1) % MAX_PLAYERS;
-           while(!stored_player[TestPlayer].active);
-
-           printf("TestPlayer = %d (%s player)\n",
-                  TestPlayer, color[TestPlayer]);
-         }
-
          break;
 #endif
 #endif
@@ -666,36 +578,17 @@ void HandleNoXEvent()
 {
   if (button_status && game_status != PLAYING)
   {
-    HandleButton(-1,-1,button_status);
+    HandleButton(-1,-1, button_status);
     return;
   }
 
   if (options.network)
     HandleNetworking();
 
-  switch(game_status)
-  {
-    case MAINMENU:
-    case CHOOSELEVEL:
-    case HALLOFFAME:
-    case HELPSCREEN:
-    case SETUP:
-    case SETUPINPUT:
-      HandleJoystick();
-      break;
-
-    case PLAYING:
-      HandleJoystick();
-
-      /*
-      HandleGameActions(0);
-      */
-
-      break;
+  HandleJoystick();
 
-    default:
-      break;
-  }
+  if (game_status == PLAYING)
+    HandleGameActions();
 }
 
 static int HandleJoystickForAllPlayers()
@@ -777,7 +670,6 @@ void HandleJoystick()
        return;
       }
 
-      HandleGameActions();
       break;
 
     default:
index d96e3bf23000d25d6d112ed6b6c6c6c285d57833..bdd8b54319ae9c94b82876953d10d7a9760f01d9 100644 (file)
 #include "tape.h"
 #include "joystick.h"
 
+static char *getUserdataDir()
+{
+  static char *userdata_dir = NULL;
+
+  if (!userdata_dir)
+  {
+    char *home_dir = getHomeDir();
+    char *data_dir = USERDATA_DIRECTORY;
+
+    userdata_dir = checked_malloc(strlen(home_dir) + strlen(data_dir) + 2);
+    sprintf(userdata_dir, "%s/%s", home_dir, data_dir);
+  }
+
+  return userdata_dir;
+}
+
+static char *getSetupDir()
+{
+  return getUserdataDir();
+}
+
+static char *getTapeDir(char *level_subdir)
+{
+  static char *tape_dir = NULL;
+  char *data_dir = getUserdataDir();
+  char *tape_subdir = TAPEDATA_DIRECTORY;
+
+  if (tape_dir)
+    free(tape_dir);
+
+  tape_dir = checked_malloc(strlen(data_dir) + strlen(tape_subdir) +
+                           strlen(level_subdir) + 3);
+  sprintf(tape_dir, "%s/%s%s%s", data_dir, tape_subdir,
+         (strlen(level_subdir) > 0 ? "/" : ""), level_subdir);
+
+  return tape_dir;
+}
+
+static void createDirectory(char *dir, char *text)
+{
+  if (access(dir, F_OK) != 0)
+    if (mkdir(dir, USERDATA_DIR_MODE) != 0)
+      Error(ERR_WARN, "cannot create %s directory '%s'", text, dir);
+}
+
+void InitUserdataDirectory()
+{
+  createDirectory(getUserdataDir(), "user data");
+}
+
+static void InitTapeDirectory(char *level_subdir)
+{
+  createDirectory(getTapeDir(""), "main tape data");
+  createDirectory(getTapeDir(level_subdir), "level tape data");
+}
+
 boolean LoadLevelInfo()
 {
   int i;
@@ -213,21 +269,17 @@ void LoadLevelTape(int level_nr)
   FILE *file;
   boolean levelrec_10 = FALSE;
 
-#ifndef MSDOS
-  sprintf(filename,"%s/%s/%d.tape",
-         level_directory,leveldir[leveldir_nr].filename,level_nr);
-#else
-  sprintf(filename,"%s/%s/%d.tap",
-         level_directory,leveldir[leveldir_nr].filename,level_nr);
-#endif
+  sprintf(filename, "%s/%d.%s",
+         getTapeDir(leveldir[leveldir_nr].filename),
+         level_nr, TAPEFILE_EXTENSION);
 
-  if ((file=fopen(filename,"r")))
+  if ((file = fopen(filename, "r")))
   {
-    fgets(cookie,LEVELREC_COOKIE_LEN,file);
+    fgets(cookie, LEVELREC_COOKIE_LEN, file);
     fgetc(file);
-    if (!strcmp(cookie,LEVELREC_COOKIE_10))    /* old 1.0 tape format */
+    if (!strcmp(cookie, LEVELREC_COOKIE_10))   /* old 1.0 tape format */
       levelrec_10 = TRUE;
-    else if (strcmp(cookie,LEVELREC_COOKIE))   /* unknown tape format */
+    else if (strcmp(cookie, LEVELREC_COOKIE))  /* unknown tape format */
     {
       Error(ERR_WARN, "wrong format of level recording file '%s'", filename);
       fclose(file);
@@ -253,7 +305,7 @@ void LoadLevelTape(int level_nr)
   tape.playing = FALSE;
   tape.pausing = FALSE;
 
-  for(i=0;i<tape.length;i++)
+  for(i=0; i<tape.length; i++)
   {
     int j;
 
@@ -319,32 +371,30 @@ void SaveLevelTape(int level_nr)
   FILE *file;
   boolean new_tape = TRUE;
 
-#ifndef MSDOS
-  sprintf(filename,"%s/%s/%d.tape",
-         level_directory,leveldir[leveldir_nr].filename,level_nr);
-#else
-  sprintf(filename,"%s/%s/%d.tap",
-         level_directory,leveldir[leveldir_nr].filename,level_nr);
-#endif
+  sprintf(filename, "%s/%d.%s",
+         getTapeDir(leveldir[leveldir_nr].filename),
+         level_nr, TAPEFILE_EXTENSION);
+
+  InitTapeDirectory(leveldir[leveldir_nr].filename);
 
   /* Testen, ob bereits eine Aufnahme existiert */
-  if ((file=fopen(filename,"r")))
+  if ((file = fopen(filename, "r")))
   {
     new_tape = FALSE;
     fclose(file);
 
-    if (!Request("Replace old tape ?",REQ_ASK))
+    if (!Request("Replace old tape ?", REQ_ASK))
       return;
   }
 
-  if (!(file=fopen(filename,"w")))
+  if (!(file = fopen(filename, "w")))
   {
     Error(ERR_WARN, "cannot save level recording file '%s'", filename);
     return;
   }
 
-  fputs(LEVELREC_COOKIE,file);         /* Formatkennung */
-  fputc(0x0a,file);
+  fputs(LEVELREC_COOKIE, file);                /* Formatkennung */
+  fputc(0x0a, file);
 
   fputc((tape.random_seed >> 24) & 0xff,file);
   fputc((tape.random_seed >> 16) & 0xff,file);
@@ -361,14 +411,14 @@ void SaveLevelTape(int level_nr)
   fputc((tape.length >>   8) & 0xff,file);
   fputc((tape.length >>   0) & 0xff,file);
 
-  for(i=0;i<tape.length;i++)
+  for(i=0; i<tape.length; i++)
   {
     int j;
 
     for(j=0; j<MAX_PLAYERS; j++)
-      fputc(tape.pos[i].action[j],file);
+      fputc(tape.pos[i].action[j], file);
 
-    fputc(tape.pos[i].delay,file);
+    fputc(tape.pos[i].delay, file);
   }
 
   fclose(file);
@@ -862,9 +912,9 @@ static void setSetupInfoToDefaults(struct SetupInfo *si)
   si->autorecord = FALSE;
   si->quick_doors = FALSE;
 
-  strncpy(si->login_name, GetLoginName(), MAX_NAMELEN-1);
+  strncpy(si->login_name, getLoginName(), MAX_NAMELEN-1);
   si->login_name[MAX_NAMELEN-1] = '\0';
-  strncpy(si->alias_name, GetLoginName(), MAX_NAMELEN-1);
+  strncpy(si->alias_name, getLoginName(), MAX_NAMELEN-1);
   si->alias_name[MAX_NAMELEN-1] = '\0';
 
   for (i=0; i<MAX_PLAYERS; i++)
@@ -1001,7 +1051,7 @@ void LoadSetup()
   /* always start with reliable default setup values */
   setSetupInfoToDefaults(&setup);
 
-  sprintf(filename, "%s/%s", SETUP_PATH, SETUP_FILENAME);
+  sprintf(filename, "%s/%s", getSetupDir(), SETUP_FILENAME);
 
   setup_file_list = loadSetupFileList(filename);
 
@@ -1087,7 +1137,7 @@ void SaveSetup()
   char filename[MAX_FILENAME_LEN];
   FILE *file;
 
-  sprintf(filename, "%s/%s", SETUP_PATH, SETUP_FILENAME);
+  sprintf(filename, "%s/%s", getSetupDir(), SETUP_FILENAME);
 
   if (!(file = fopen(filename, "w")))
   {
@@ -1137,7 +1187,7 @@ void LoadLevelSetup()
   leveldir_nr = 0;
   level_nr = 0;
 
-  sprintf(filename, "%s/%s", SETUP_PATH, LEVELSETUP_FILENAME);
+  sprintf(filename, "%s/%s", getSetupDir(), LEVELSETUP_FILENAME);
 
   if (level_setup_list)
     freeSetupFileList(level_setup_list);
@@ -1170,7 +1220,7 @@ void SaveLevelSetup()
   setTokenValue(level_setup_list,
                leveldir[leveldir_nr].filename, int2str(level_nr, 0));
 
-  sprintf(filename, "%s/%s", SETUP_PATH, LEVELSETUP_FILENAME);
+  sprintf(filename, "%s/%s", getSetupDir(), LEVELSETUP_FILENAME);
 
   if (!(file = fopen(filename, "w")))
   {
index ec510e32c0c86cd460ff791089510acbee94b20b..2c1acbd2fbb5b7d92732ac54374ce46c75a2634d 100644 (file)
 
 #include "main.h"
 
-boolean LoadLevelInfo(void);
+void InitUserdataDirectory();
 
+boolean LoadLevelInfo(void);
 void LoadLevel(int);
 void SaveLevel(int);
-
 void LoadLevelTape(int);
 void SaveLevelTape(int);
 
@@ -32,7 +32,6 @@ int getLastPlayedLevelOfLevelSeries(char *);
 
 void LoadSetup(void);
 void SaveSetup(void);
-
 void LoadLevelSetup(void);
 void SaveLevelSetup(void);
 
index b8b43f55c3d51993f7f277c01e19e6789841b97c..d9c9ba2bce2b88622ae81cef27479fbf62533e4d 100644 (file)
@@ -2937,7 +2937,7 @@ void GameActions()
   int sieb_x = 0, sieb_y = 0;
   int i, x,y, element;
   byte *recorded_player_action;
-  byte summarized_player_action;
+  byte summarized_player_action = 0;
 
   if (game_status != PLAYING)
     return;
@@ -3373,8 +3373,8 @@ boolean MoveFigure(struct PlayerInfo *player, int dx, int dy)
          scroll_x = jx-MIDPOSX + (scroll_x < jx-MIDPOSX ? -offset : +offset);
 
        /* don't scroll over playfield boundaries */
-       if (scroll_x < -1 || scroll_x > lev_fieldx - SCR_FIELDX + 2)
-         scroll_x = (scroll_x < -1 ? -1 : lev_fieldx - SCR_FIELDX + 2);
+       if (scroll_x < -1 || scroll_x > lev_fieldx - SCR_FIELDX + 1)
+         scroll_x = (scroll_x < -1 ? -1 : lev_fieldx - SCR_FIELDX + 1);
 
        /* don't scroll more than one field at a time */
        scroll_x = old_scroll_x + SIGN(scroll_x - old_scroll_x);
@@ -3391,8 +3391,8 @@ boolean MoveFigure(struct PlayerInfo *player, int dx, int dy)
          scroll_y = jy-MIDPOSY + (scroll_y < jy-MIDPOSY ? -offset : +offset);
 
        /* don't scroll over playfield boundaries */
-       if (scroll_y < -1 || scroll_y > lev_fieldy - SCR_FIELDY + 2)
-         scroll_y = (scroll_y < -1 ? -1 : lev_fieldy - SCR_FIELDY + 2);
+       if (scroll_y < -1 || scroll_y > lev_fieldy - SCR_FIELDY + 1)
+         scroll_y = (scroll_y < -1 ? -1 : lev_fieldy - SCR_FIELDY + 1);
 
        /* don't scroll more than one field at a time */
        scroll_y = old_scroll_y + SIGN(scroll_y - old_scroll_y);
index 7a5f5eeb521a651bff36cf587fed803df82831df..52facada8273910720c004a61d9f963cebabcf52 100644 (file)
@@ -65,6 +65,7 @@ void OpenAll(int argc, char *argv[])
     exit(0);
   }
 
+  InitUserdataDirectory();
   InitLevelAndPlayerInfo();
 
   InitCounter();
@@ -139,7 +140,7 @@ void InitSound()
     return;
 
 #ifndef MSDOS
-  if (access(sound_device_name,W_OK)<0)
+  if (access(sound_device_name, W_OK) != 0)
   {
     Error(ERR_WARN, "cannot access sound device - no sounds");
     sound_status = SOUND_OFF;
@@ -245,7 +246,7 @@ void InitJoysticks()
     if (!setup.input[i].use_joystick)
       continue;
 
-    if (access(device_name, R_OK) < 0)
+    if (access(device_name, R_OK) != 0)
     {
       Error(ERR_WARN, "cannot access joystick device '%s'", device_name);
       continue;
index 955cf84acdac28b1f2956ceccb7b433a03fa0718..d63a289f8d141d83561545651315f96c13ed81cd 100644 (file)
@@ -1099,24 +1099,32 @@ extern int              num_bg_loops;
 #endif
 
 #ifndef MSDOS
+#define USERDATA_DIRECTORY     ".rocksndiamonds"
+#define TAPEDATA_DIRECTORY     "tapes"
 #define SCORE_FILENAME         "ROCKS.score"
-#define NAMES_FILENAME         "ROCKS.names"
 #define LEVDIR_FILENAME                "ROCKS.levelinfo"
 #define JOYDAT_FILENAME                "ROCKS.joystick"
-#define SETUP_FILENAME         "ROCKS.setup"
-#define LEVELSETUP_FILENAME    "ROCKS.levelsetup"
+#define SETUP_FILENAME         "setup"
+#define LEVELSETUP_FILENAME    "setup.level"
+#define TAPEFILE_EXTENSION     "tape"
 #else
+#define USERDATA_DIRECTORY     "userdata"
+#define TAPEDATA_DIRECTORY     "tapes"
 #define SCORE_FILENAME         "ROCKS.sco"
-#define NAMES_FILENAME         "ROCKS.nam"
 #define LEVDIR_FILENAME                "ROCKS.lev"
 #define JOYDAT_FILENAME                "ROCKS.joy"
-#define SETUP_FILENAME         "ROCKS.set"
-#define LEVELSETUP_FILENAME    "ROCKS.lvs"
+#define SETUP_FILENAME         "setup"
+#define LEVELSETUP_FILENAME    "setup.lev"
+#define TAPEFILE_EXTENSION     "rec"
 #endif
 
 #define JOYDAT_FILE            JOYDAT_PATH "/" JOYDAT_FILENAME
 
-#define LEVEL_PERMS    (S_IRUSR|S_IWUSR | S_IRGRP|S_IWGRP | S_IROTH|S_IWOTH)
+#define MODE_R_ALL             (S_IRUSR | S_IRGRP | S_IROTH)
+#define MODE_W_ALL             (S_IWUSR | S_IWGRP | S_IWOTH)
+#define MODE_X_ALL             (S_IXUSR | S_IXGRP | S_IXOTH)
+#define USERDATA_DIR_MODE      (MODE_R_ALL | MODE_X_ALL | S_IWUSR)
+#define LEVEL_PERMS            (MODE_R_ALL | MODE_W_ALL)
 #define SCORE_PERMS            LEVEL_PERMS
 #define NAMES_PERMS            LEVEL_PERMS
 #define LEVDIR_PERMS           LEVEL_PERMS
@@ -1145,7 +1153,7 @@ extern int                num_bg_loops;
 #define SETUP_COOKIE_LEN       (strlen(SETUP_COOKIE)+1)
 #define LEVELSETUP_COOKIE_LEN  (strlen(LEVELSETUP_COOKIE)+1)
 
-#define VERSION_STRING         "1.2"
+#define VERSION_STRING         "1.2 preview 1"
 #define GAMETITLE_STRING       "Rocks'n'Diamonds"
 #define WINDOWTITLE_STRING     GAMETITLE_STRING " " VERSION_STRING
 #define COPYRIGHT_STRING       "Copyright ^1995-98 by Holger Schemel"
index c037e95941d416eaa5ea8a50d60d59bc5afd1686..7d0a7fde159d3fff69de8e447ac15f32c124f4a4 100644 (file)
@@ -155,39 +155,59 @@ unsigned int SimpleRND(unsigned int max)
 
   gettimeofday(&current_time,NULL);
   root = root * 4253261 + current_time.tv_sec + current_time.tv_usec;
-  return(root % max);
+  return (root % max);
 }
 
 unsigned int RND(unsigned int max)
 {
-  return(random_linux_libc() % max);
+  return (random_linux_libc() % max);
 }
 
 unsigned int InitRND(long seed)
 {
   struct timeval current_time;
 
-  if (seed==NEW_RANDOMIZE)
+  if (seed == NEW_RANDOMIZE)
   {
     gettimeofday(&current_time,NULL);
     srandom_linux_libc((unsigned int) current_time.tv_usec);
-    return((unsigned int) current_time.tv_usec);
+    return (unsigned int)current_time.tv_usec;
   }
   else
   {
     srandom_linux_libc((unsigned int) seed);
-    return((unsigned int) seed);
+    return (unsigned int)seed;
   }
 }
 
-char *GetLoginName()
+char *getLoginName()
 {
   struct passwd *pwd;
 
-  if (!(pwd=getpwuid(getuid())))
-    return("ANONYMOUS");
+  if (!(pwd = getpwuid(getuid())))
+    return "ANONYMOUS";
   else
-    return(pwd->pw_name);
+    return pwd->pw_name;
+}
+
+char *getHomeDir()
+{
+  static char *home_dir = NULL;
+
+  if (!home_dir)
+  {
+    if (!(home_dir = getenv("HOME")))
+    {
+      struct passwd *pwd;
+
+      if ((pwd = getpwuid(getuid())))
+       home_dir = pwd->pw_dir;
+      else
+       home_dir = ".";
+    }
+  }
+
+  return home_dir;
 }
 
 void MarkTileDirty(int x, int y)
index 10aae9cec5e8975bf9a4d7beeacf825f1344835c..798e61efe0431933151c8a36c9e1afe1bcb4c09a 100644 (file)
@@ -39,7 +39,8 @@ char *int2str(int, int);
 unsigned int SimpleRND(unsigned int);
 unsigned int RND(unsigned int);
 unsigned int InitRND(long);
-char *GetLoginName(void);
+char *getLoginName(void);
+char *getHomeDir(void);
 void MarkTileDirty(int, int);
 void GetOptions(char **);
 void Error(int, char *, ...);
index 3196704612b8a65bb2d9704af6b5daf08fa70cf3..a0a06dbcebc02697d1721b1bc31b33fa44e6187e 100644 (file)
@@ -71,14 +71,8 @@ void DrawMainMenu()
   DrawGraphic(10,3,GFX_PFEIL_L);
   DrawGraphic(14,3,GFX_PFEIL_R);
 
-  DrawText(SX+40+16,SY+326,"A Game by Artsoft Entertainment",FS_SMALL,FC_BLUE);
-
-  /*
-  DrawText(SX+40+16,SY+344,"Graphics: Deluxe Paint IV Amiga",
-          FS_SMALL,FC_BLUE);
-  DrawText(SX+60+16,SY+362,"Sounds: AudioMaster IV Amiga",
-          FS_SMALL,FC_BLUE);
-  */
+  DrawText(SX+56, SY+326, "A Game by Artsoft Entertainment",
+          FS_SMALL, FC_RED);
 
   if (leveldir[leveldir_nr].name)
   {