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:
break;
case LEVELED:
- LevelEd(mx,my,button);
+ LevelEd(mx,my, button);
break;
case HELPSCREEN:
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:
#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;
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
{
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()
return;
}
- HandleGameActions();
break;
default:
#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;
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);
tape.playing = FALSE;
tape.pausing = FALSE;
- for(i=0;i<tape.length;i++)
+ for(i=0; i<tape.length; i++)
{
int j;
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);
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);
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++)
/* 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);
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")))
{
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);
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")))
{
#include "main.h"
-boolean LoadLevelInfo(void);
+void InitUserdataDirectory();
+boolean LoadLevelInfo(void);
void LoadLevel(int);
void SaveLevel(int);
-
void LoadLevelTape(int);
void SaveLevelTape(int);
void LoadSetup(void);
void SaveSetup(void);
-
void LoadLevelSetup(void);
void SaveLevelSetup(void);
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;
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);
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);
exit(0);
}
+ InitUserdataDirectory();
InitLevelAndPlayerInfo();
InitCounter();
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;
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;
#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
#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"
gettimeofday(¤t_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(¤t_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)
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 *, ...);
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)
{