/* map buttons to select level */
counter_id = ED_COUNTER_ID_SELECT_LEVEL;
ModifyEditorCounterLimits(counter_id,
- leveldir[leveldir_nr].first_level,
- leveldir[leveldir_nr].last_level);
+ leveldir_current->first_level,
+ leveldir_current->last_level);
ModifyEditorCounter(counter_id, *counterbutton_info[counter_id].value);
MapCounterButtons(counter_id);
}
break;
case GADGET_ID_SAVE:
- if (leveldir[leveldir_nr].readonly)
+ if (leveldir_current->readonly)
{
Request("This level is read only !", REQ_CONFIRM);
break;
free(filename);
sprintf(basename, "%03d.%s", nr, LEVELFILE_EXTENSION);
- filename = getPath3((leveldir[leveldir_nr].user_defined ?
+ filename = getPath3((leveldir_current->user_defined ?
getUserLevelDir("") :
options.level_directory),
- leveldir[leveldir_nr].filename,
+ leveldir_current->filename,
basename);
return filename;
free(filename);
sprintf(basename, "%03d.%s", nr, TAPEFILE_EXTENSION);
- filename = getPath2(getTapeDir(leveldir[leveldir_nr].filename), basename);
+ filename = getPath2(getTapeDir(leveldir_current->filename), basename);
return filename;
}
free(filename);
sprintf(basename, "%03d.%s", nr, SCOREFILE_EXTENSION);
- filename = getPath2(getScoreDir(leveldir[leveldir_nr].filename), basename);
+ filename = getPath2(getScoreDir(leveldir_current->filename), basename);
return filename;
}
BorderElement = EL_BETON;
/* try to determine better author name than 'anonymous' */
- if (strcmp(leveldir[leveldir_nr].author, ANONYMOUS_NAME) != 0)
+ if (strcmp(leveldir_current->author, ANONYMOUS_NAME) != 0)
{
- strncpy(level.author, leveldir[leveldir_nr].author, MAX_LEVEL_AUTHOR_LEN);
+ strncpy(level.author, leveldir_current->author, MAX_LEVEL_AUTHOR_LEN);
level.author[MAX_LEVEL_AUTHOR_LEN] = '\0';
}
else
{
- switch (LEVELCLASS(&leveldir[leveldir_nr]))
+ switch (LEVELCLASS(leveldir_current))
{
case LEVELCLASS_TUTORIAL:
strcpy(level.author, PROGRAM_AUTHOR_STRING);
break;
case LEVELCLASS_CONTRIBUTION:
- strncpy(level.author, leveldir[leveldir_nr].name,MAX_LEVEL_AUTHOR_LEN);
+ strncpy(level.author, leveldir_current->name,MAX_LEVEL_AUTHOR_LEN);
level.author[MAX_LEVEL_AUTHOR_LEN] = '\0';
break;
/* player was faster than monsters in pre-1.0 levels */
if (file_version == FILE_VERSION_1_0 &&
- IS_LEVELCLASS_CONTRIBUTION(&leveldir[leveldir_nr]))
+ IS_LEVELCLASS_CONTRIBUTION(leveldir_current))
{
Error(ERR_WARN, "level file '%s' has version number 1.0", filename);
Error(ERR_WARN, "using high speed movement for player");
byte store_participating_players;
int num_participating_players;
- InitTapeDirectory(leveldir[leveldir_nr].filename);
+ InitTapeDirectory(leveldir_current->filename);
/* if a tape still exists, ask to overwrite it */
if (access(filename, F_OK) == 0)
char *filename = getScoreFilename(level_nr);
FILE *file;
- InitScoreDirectory(leveldir[leveldir_nr].filename);
+ InitScoreDirectory(leveldir_current->filename);
if (!(file = fopen(filename, "w")))
{
}
}
-int getLevelSeriesNrFromLevelSeriesName(char *level_series_name)
+struct LevelDirInfo *getLevelDirInfoFromLevelDirName(char *level_dir_name)
{
- int i;
+ struct LevelDirInfo *leveldir_node = leveldir_first;
+
+ if (level_dir_name == NULL)
+ return NULL;
- if (!level_series_name)
- return 0;
+ while (leveldir_node)
+ {
+ if (strcmp(level_dir_name, leveldir_node->name) == 0)
+ return leveldir_node; /* return success value */
- for (i=0; i<num_leveldirs; i++)
- if (strcmp(level_series_name, leveldir[i].filename) == 0)
- return i;
+ leveldir_node = leveldir_node->next;
+ }
- return 0;
+ return NULL;
}
static int compareLevelDirInfoEntries(const void *object1, const void *object2)
{
- const struct LevelDirInfo *entry1 = object1;
- const struct LevelDirInfo *entry2 = object2;
+ const struct LevelDirInfo *entry1 = *((struct LevelDirInfo **)object1);
+ const struct LevelDirInfo *entry2 = *((struct LevelDirInfo **)object2);
int compare_result;
if (entry1->sort_priority == entry2->sort_priority)
return compare_result;
}
-static int LoadLevelInfoFromLevelDir(char *level_directory, int start_entry)
+static void LoadLevelInfoFromLevelDir(char *level_directory)
{
DIR *dir;
- struct stat file_status;
- char *directory = NULL;
- char *filename = NULL;
- struct SetupFileList *setup_file_list = NULL;
struct dirent *dir_entry;
- int i, current_entry = start_entry;
+ boolean valid_entry_found = FALSE;
if ((dir = opendir(level_directory)) == NULL)
{
Error(ERR_WARN, "cannot read level directory '%s'", level_directory);
- return current_entry;
+ return;
}
- while (current_entry < MAX_LEVDIR_ENTRIES)
+ while ((dir_entry = readdir(dir)) != NULL) /* loop until last dir entry */
{
- if ((dir_entry = readdir(dir)) == NULL) /* last directory entry */
- break;
+ struct stat file_status;
+ char *directory = NULL;
+ char *filename = NULL;
+ struct SetupFileList *setup_file_list = NULL;
/* skip entries for current and parent directory */
if (strcmp(dir_entry->d_name, ".") == 0 ||
if (setup_file_list)
{
-#if 0
- DrawInitText(dir_entry->d_name, 150, FC_YELLOW);
-#endif
+ struct LevelDirInfo *leveldir_new = newLevelDirInfo();
+ int i;
checkSetupFileListIdentifier(setup_file_list, LEVELINFO_COOKIE);
- setLevelDirInfoToDefaults(&leveldir[current_entry]);
+ setLevelDirInfoToDefaults(leveldir_new);
- ldi = leveldir[current_entry];
+ ldi = *leveldir_new;
for (i=FIRST_LEVELINFO_TOKEN; i<=LAST_LEVELINFO_TOKEN; i++)
setSetupInfo(i, getTokenValue(setup_file_list, token_info[i].text));
- leveldir[current_entry] = ldi;
+ *leveldir_new = ldi;
-#if 1
- DrawInitText(leveldir[current_entry].name, 150, FC_YELLOW);
-#endif
+ DrawInitText(leveldir_new->name, 150, FC_YELLOW);
+
+ if (leveldir_new->name_short == NULL)
+ leveldir_new->name_short = getStringCopy(leveldir_new->name);
- if (leveldir[current_entry].name_short == NULL)
- leveldir[current_entry].name_short =
- getStringCopy(leveldir[current_entry].name);
+ if (leveldir_new->name_sorting == NULL)
+ leveldir_new->name_sorting = getStringCopy(leveldir_new->name);
- if (leveldir[current_entry].name_sorting == NULL)
- leveldir[current_entry].name_sorting =
- getStringCopy(leveldir[current_entry].name);
+ leveldir_new->filename = getStringCopy(dir_entry->d_name);
- leveldir[current_entry].filename = getStringCopy(dir_entry->d_name);
- leveldir[current_entry].last_level =
- leveldir[current_entry].first_level +
- leveldir[current_entry].levels - 1;
- leveldir[current_entry].user_defined =
+ if (leveldir_new->levels < 1)
+ leveldir_new->levels = 1;
+
+ leveldir_new->last_level =
+ leveldir_new->first_level + leveldir_new->levels - 1;
+
+ leveldir_new->user_defined =
(level_directory == options.level_directory ? FALSE : TRUE);
- leveldir[current_entry].color = LEVELCOLOR(&leveldir[current_entry]);
- leveldir[current_entry].class_desc =
- getLevelClassDescription(&leveldir[current_entry]);
-#if 0
- leveldir[current_entry].handicap_level =
- leveldir[current_entry].first_level; /* default value */
-#else
- leveldir[current_entry].handicap_level =
- (leveldir[current_entry].user_defined ?
- leveldir[current_entry].last_level :
- leveldir[current_entry].first_level);
-#endif
+ leveldir_new->color = LEVELCOLOR(leveldir_new);
+ leveldir_new->class_desc = getLevelClassDescription(leveldir_new);
+
+ leveldir_new->handicap_level = /* set handicap to default value */
+ (leveldir_new->user_defined ?
+ leveldir_new->last_level :
+ leveldir_new->first_level);
+
+ pushLevelDirInfo(leveldir_new); /* add new LevelDirInfo to list */
freeSetupFileList(setup_file_list);
- current_entry++;
+ valid_entry_found = TRUE;
}
else
Error(ERR_WARN, "ignoring level directory '%s'", directory);
closedir(dir);
- if (current_entry == MAX_LEVDIR_ENTRIES)
- {
- Error(ERR_WARN, "maximum of %d level directories reached", current_entry);
- Error(ERR_WARN, "remaining level directories ignored in directory '%s'",
- level_directory);
- }
- else if (current_entry == start_entry)
+ if (!valid_entry_found)
Error(ERR_WARN, "cannot find any valid level series in directory '%s'",
level_directory);
-
- return current_entry;
}
void LoadLevelInfo()
{
InitUserLevelDirectory(getLoginName());
- num_leveldirs = 0;
- leveldir_nr = 0;
-
DrawInitText("Loading level series:", 120, FC_GREEN);
- num_leveldirs = LoadLevelInfoFromLevelDir(options.level_directory,
- num_leveldirs);
- num_leveldirs = LoadLevelInfoFromLevelDir(getUserLevelDir(""),
- num_leveldirs);
+ LoadLevelInfoFromLevelDir(options.level_directory);
+ LoadLevelInfoFromLevelDir(getUserLevelDir(""));
+
+ num_leveldirs = numLevelDirInfo(leveldir_first);
+ leveldir_current = leveldir_first;
if (num_leveldirs == 0)
Error(ERR_EXIT, "cannot find any valid level series in any directory");
+#if 0
if (num_leveldirs > 1)
qsort(leveldir, num_leveldirs, sizeof(struct LevelDirInfo),
compareLevelDirInfoEntries);
+#else
+ if (num_leveldirs > 1)
+ sortLevelDirInfo(&leveldir_first, compareLevelDirInfoEntries);
+#endif
}
static void SaveUserLevelInfo()
struct SetupFileList *level_setup_list = NULL;
/* always start with reliable default values */
- leveldir_nr = 0;
+ leveldir_current = leveldir_first;
/* ----------------------------------------------------------------------- */
/* ~/.rocksndiamonds/levelsetup.conf */
char *last_level_series =
getTokenValue(level_setup_list, TOKEN_STR_LAST_LEVEL_SERIES);
- leveldir_nr = getLevelSeriesNrFromLevelSeriesName(last_level_series);
+ leveldir_current = getLevelDirInfoFromLevelDirName(last_level_series);
+ if (leveldir_current == NULL)
+ leveldir_current = leveldir_first;
checkSetupFileListIdentifier(level_setup_list, LEVELSETUP_COOKIE);
void SaveLevelSetup_LastSeries()
{
char *filename;
- char *level_subdir = leveldir[leveldir_nr].filename;
+ char *level_subdir = leveldir_current->filename;
FILE *file;
/* ----------------------------------------------------------------------- */
chmod(filename, SETUP_PERMS);
}
-static void checkSeriesInfo(int leveldir_nr)
+static void checkSeriesInfo()
{
static char *level_directory = NULL;
DIR *dir;
/* check for more levels besides the 'levels' field of 'levelinfo.conf' */
- level_directory = getPath2((leveldir[leveldir_nr].user_defined ?
+ level_directory = getPath2((leveldir_current->user_defined ?
getUserLevelDir("") :
options.level_directory),
- leveldir[leveldir_nr].filename);
+ leveldir_current->filename);
if ((dir = opendir(level_directory)) == NULL)
{
levelnum_value = atoi(levelnum_str);
- if (levelnum_value < leveldir[leveldir_nr].first_level)
+ if (levelnum_value < leveldir_current->first_level)
{
Error(ERR_WARN, "additional level %d found", levelnum_value);
- leveldir[leveldir_nr].first_level = levelnum_value;
+ leveldir_current->first_level = levelnum_value;
}
- else if (levelnum_value > leveldir[leveldir_nr].last_level)
+ else if (levelnum_value > leveldir_current->last_level)
{
Error(ERR_WARN, "additional level %d found", levelnum_value);
- leveldir[leveldir_nr].last_level = levelnum_value;
+ leveldir_current->last_level = levelnum_value;
}
}
}
closedir(dir);
}
-void LoadLevelSetup_SeriesInfo(int leveldir_nr)
+void LoadLevelSetup_SeriesInfo()
{
char *filename;
struct SetupFileList *level_setup_list = NULL;
- char *level_subdir = leveldir[leveldir_nr].filename;
+ char *level_subdir = leveldir_current->filename;
/* always start with reliable default values */
-#if 0
- level_nr = 0;
- leveldir[leveldir_nr].handicap_level = 0;
-#else
- level_nr = leveldir[leveldir_nr].first_level;
-#endif
+ level_nr = leveldir_current->first_level;
- checkSeriesInfo(leveldir_nr);
+ checkSeriesInfo(leveldir_current);
/* ----------------------------------------------------------------------- */
/* ~/.rocksndiamonds/levelsetup/<level series>/levelsetup.conf */
/* ----------------------------------------------------------------------- */
- level_subdir = leveldir[leveldir_nr].filename;
+ level_subdir = leveldir_current->filename;
filename = getPath2(getLevelSetupDir(level_subdir), LEVELSETUP_FILENAME);
{
level_nr = atoi(token_value);
- if (level_nr < leveldir[leveldir_nr].first_level)
- level_nr = leveldir[leveldir_nr].first_level;
- if (level_nr > leveldir[leveldir_nr].last_level)
- level_nr = leveldir[leveldir_nr].last_level;
+ if (level_nr < leveldir_current->first_level)
+ level_nr = leveldir_current->first_level;
+ if (level_nr > leveldir_current->last_level)
+ level_nr = leveldir_current->last_level;
}
token_value = getTokenValue(level_setup_list, TOKEN_STR_HANDICAP_LEVEL);
{
int level_nr = atoi(token_value);
- if (level_nr < leveldir[leveldir_nr].first_level)
- level_nr = leveldir[leveldir_nr].first_level;
- if (level_nr > leveldir[leveldir_nr].last_level + 1)
- level_nr = leveldir[leveldir_nr].last_level;
+ if (level_nr < leveldir_current->first_level)
+ level_nr = leveldir_current->first_level;
+ if (level_nr > leveldir_current->last_level + 1)
+ level_nr = leveldir_current->last_level;
- if (leveldir[leveldir_nr].user_defined)
- level_nr = leveldir[leveldir_nr].last_level;
+ if (leveldir_current->user_defined)
+ level_nr = leveldir_current->last_level;
- leveldir[leveldir_nr].handicap_level = level_nr;
+ leveldir_current->handicap_level = level_nr;
}
checkSetupFileListIdentifier(level_setup_list, LEVELSETUP_COOKIE);
free(filename);
}
-void SaveLevelSetup_SeriesInfo(int leveldir_nr)
+void SaveLevelSetup_SeriesInfo()
{
char *filename;
- char *level_subdir = leveldir[leveldir_nr].filename;
+ char *level_subdir = leveldir_current->filename;
char *level_nr_str = int2str(level_nr, 0);
- char *handicap_level_str = int2str(leveldir[leveldir_nr].handicap_level, 0);
+ char *handicap_level_str = int2str(leveldir_current->handicap_level, 0);
FILE *file;
/* ----------------------------------------------------------------------- */
void LoadScore(int);
void SaveScore(int);
-int getLastPlayedLevelOfLevelSeries(char *);
+struct LevelDirInfo *getLevelDirInfoFromLevelDirName(char *);
void LoadLevelInfo(void);
void LoadSetup(void);
void SaveSetup(void);
void LoadLevelSetup_LastSeries(void);
void SaveLevelSetup_LastSeries(void);
-void LoadLevelSetup_SeriesInfo(int);
-void SaveLevelSetup_SeriesInfo(int);
+void LoadLevelSetup_SeriesInfo(void);
+void SaveLevelSetup_SeriesInfo(void);
#ifdef MSDOS
void initErrorFile();
SaveTape(tape.level_nr); /* Ask to save tape */
}
- if (level_nr == leveldir[leveldir_nr].handicap_level)
+ if (level_nr == leveldir_current->handicap_level)
{
- leveldir[leveldir_nr].handicap_level++;
- SaveLevelSetup_SeriesInfo(leveldir_nr);
+ leveldir_current->handicap_level++;
+ SaveLevelSetup_SeriesInfo();
- if (level_nr < leveldir[leveldir_nr].last_level)
+ if (level_nr < leveldir_current->last_level)
raise_level = TRUE;
}
LoadLevelInfo(); /* global level info */
LoadSetup(); /* global setup info */
LoadLevelSetup_LastSeries(); /* last played series info */
- LoadLevelSetup_SeriesInfo(leveldir_nr); /* last played level info */
+ LoadLevelSetup_SeriesInfo(); /* last played level info */
}
void InitNetworkServer()
unsigned long Elementeigenschaften1[MAX_ELEMENTS];
unsigned long Elementeigenschaften2[MAX_ELEMENTS];
-int level_nr, leveldir_nr, num_leveldirs;
+int level_nr, num_leveldirs;
int lev_fieldx,lev_fieldy, scroll_x,scroll_y;
int FX = SX, FY = SY, ScrollStepSize;
boolean network_player_action_received = FALSE;
-struct LevelDirInfo leveldir[MAX_LEVDIR_ENTRIES];
+struct LevelDirInfo *leveldir_first = NULL, *leveldir_current = NULL;
struct LevelInfo level;
struct PlayerInfo stored_player[MAX_PLAYERS], *local_player = NULL;
struct HiScore highscore[MAX_SCORE_ENTRIES];
#define MAX_LEVEL_NAME_LEN 32
#define MAX_LEVEL_AUTHOR_LEN 32
#define MAX_TAPELEN (1000 * 50) /* max. time * framerate */
-#define MAX_LEVDIR_ENTRIES 250 /* max. level directories */
#define MAX_SCORE_ENTRIES 100
#define MAX_ELEMENTS 700 /* 500 static + 200 runtime */
#define MAX_NUM_AMOEBA 100
int color; /* color to use on selection screen for this level */
char *class_desc; /* description of level series class */
int handicap_level; /* number of the lowest unsolved level */
+
+ struct LevelDirInfo *next;
};
struct TapeInfo
extern unsigned long Elementeigenschaften1[MAX_ELEMENTS];
extern unsigned long Elementeigenschaften2[MAX_ELEMENTS];
-extern int level_nr, leveldir_nr, num_leveldirs;
+extern int level_nr, num_leveldirs;
extern int lev_fieldx,lev_fieldy, scroll_x,scroll_y;
extern int FX,FY, ScrollStepSize;
extern boolean network_player_action_received;
-extern struct LevelDirInfo leveldir[];
+extern struct LevelDirInfo *leveldir_first, *leveldir_current;
extern struct LevelInfo level;
extern struct PlayerInfo stored_player[], *local_player;
extern struct HiScore highscore[];
return joystick_nr;
}
-/* ----------------------------------------------------------------- */
-/* the following is only for debugging purpose and normally not used */
-/* ----------------------------------------------------------------- */
+/* ------------------------------------------------------------------------- */
+/* some functions to handle lists of level directories */
+/* ------------------------------------------------------------------------- */
+
+struct LevelDirInfo *newLevelDirInfo()
+{
+ return checked_calloc(sizeof(struct LevelDirInfo));
+}
+
+void pushLevelDirInfo(struct LevelDirInfo *node)
+{
+ node->next = leveldir_first;
+ leveldir_first = node;
+}
+
+int numLevelDirInfo(struct LevelDirInfo *node)
+{
+ int num = 0;
+
+ while (node)
+ {
+ num++;
+ node = node->next;
+ }
+
+ return num;
+}
+
+int posLevelDirInfo(struct LevelDirInfo *node)
+{
+ struct LevelDirInfo *node_cmp = leveldir_first;
+ int pos = 0;
+
+ while (node_cmp)
+ {
+ if (node_cmp == node)
+ return pos;
+
+ pos++;
+ node_cmp = node_cmp->next;
+ }
+
+ return 0;
+}
+
+struct LevelDirInfo *getLevelDirInfoFromPos(struct LevelDirInfo *node, int pos)
+{
+ struct LevelDirInfo *node_default = node;
+ int pos_cmp = 0;
+
+ while (node)
+ {
+ if (pos_cmp == pos)
+ return node;
+
+ pos_cmp++;
+ node = node->next;
+ }
+
+ return node_default;
+}
+
+void sortLevelDirInfo(struct LevelDirInfo **node_first,
+ int (*compare_function)(const void *, const void *))
+{
+ int num_nodes = numLevelDirInfo(*node_first);
+ struct LevelDirInfo **sort_array;
+ struct LevelDirInfo *node = *node_first;
+ int i = 0;
+
+ if (num_nodes < 2) /* a list with only one element is always sorted... */
+ return;
+
+ /* allocate array for sorting structure pointers */
+ sort_array = checked_calloc(num_nodes * sizeof(struct LevelDirInfo *));
+
+ /* writing structure pointers to sorting array */
+ while (i < num_nodes && node) /* double boundary check... */
+ {
+ sort_array[i] = node;
+
+ i++;
+ node = node->next;
+ }
+
+ /* sorting the structure pointers in the sorting array */
+ qsort(sort_array, num_nodes, sizeof(struct LevelDirInfo *),
+ compare_function);
+
+ /* update the linkage of list elements with the sorted node array */
+ for (i=0; i<num_nodes - 1; i++)
+ sort_array[i]->next = sort_array[i + 1];
+ sort_array[num_nodes - 1]->next = NULL;
+
+ /* update the linkage of the main list anchor pointer */
+ *node_first = sort_array[0];
+
+ free(sort_array);
+}
+
+
+/* ------------------------------------------------------------------------- */
+/* the following is only for debugging purpose and normally not used */
+/* ------------------------------------------------------------------------- */
#define DEBUG_NUM_TIMESTAMPS 3
int getJoySymbolFromJoyName(char *);
int getJoystickNrFromDeviceName(char *);
+struct LevelDirInfo *newLevelDirInfo();
+void pushLevelDirInfo(struct LevelDirInfo *);
+int numLevelDirInfo(struct LevelDirInfo *);
+int posLevelDirInfo(struct LevelDirInfo *);
+struct LevelDirInfo *getLevelDirInfoFromPos(struct LevelDirInfo *, int);
+void sortLevelDirInfo(struct LevelDirInfo **,
+ int (*compare_function)(const void *, const void *));
+
void debug_print_timestamp(int, char *);
-void print_debug(char *);
#endif /* MISC_H */
{
unsigned long new_random_seed = InitRND(NEW_RANDOMIZE);
+ int dummy = 0; /* !!! HAS NO MEANING ANYMORE !!! */
+ /* the name of the level must be enough */
+
buffer[1] = OP_START_PLAYING;
buffer[2] = (byte)(level_nr >> 8);
buffer[3] = (byte)(level_nr & 0xff);
- buffer[4] = (byte)(leveldir_nr >> 8);
- buffer[5] = (byte)(leveldir_nr & 0xff);
+ buffer[4] = (byte)(dummy >> 8);
+ buffer[5] = (byte)(dummy & 0xff);
buffer[6] = (unsigned char)((new_random_seed >> 24) & 0xff);
buffer[7] = (unsigned char)((new_random_seed >> 16) & 0xff);
buffer[8] = (unsigned char)((new_random_seed >> 8) & 0xff);
buffer[9] = (unsigned char)((new_random_seed >> 0) & 0xff);
- strcpy((char *)&buffer[10], leveldir[leveldir_nr].name);
+ strcpy((char *)&buffer[10], leveldir_current->name);
- SendBufferToServer(10 + strlen(leveldir[leveldir_nr].name)+1);
+ SendBufferToServer(10 + strlen(leveldir_current->name) + 1);
}
void SendToServer_PausePlaying()
static void Handle_OP_START_PLAYING()
{
- int new_level_nr, new_leveldir_nr;
+ struct LevelDirInfo *new_leveldir;
+ int new_level_nr;
+ int dummy; /* !!! HAS NO MEANING ANYMORE !!! */
unsigned long new_random_seed;
char *new_leveldir_name;
new_level_nr = (buffer[2] << 8) + buffer[3];
- new_leveldir_nr = (buffer[4] << 8) + buffer[5];
+ dummy = (buffer[4] << 8) + buffer[5];
new_random_seed =
(buffer[6] << 24) | (buffer[7] << 16) | (buffer[8] << 8) | (buffer[9]);
new_leveldir_name = (char *)&buffer[10];
+ new_leveldir = getLevelDirInfoFromLevelDirName(new_leveldir_name);
+ if (new_leveldir == NULL)
+ {
+ Error(ERR_WARN, "no such level directory: '%s'", new_leveldir_name);
+
+ new_leveldir = leveldir_first;
+ Error(ERR_WARN, "using default level directory: '%s'", new_leveldir->name);
+ }
+
printf("OP_START_PLAYING: %d\n", buffer[0]);
Error(ERR_NETWORK_CLIENT,
- "client %d starts game [level %d from levedir %d (%s)]\n",
- buffer[0], new_level_nr, new_leveldir_nr, new_leveldir_name);
-
- if (strcmp(leveldir[new_leveldir_nr].name, new_leveldir_name) != 0)
- Error(ERR_WARN, "no such level directory: '%s'",new_leveldir_name);
+ "client %d starts game [level %d from leveldir '%s']\n",
+ buffer[0], new_level_nr, new_leveldir->name);
- leveldir_nr = new_leveldir_nr;
+ leveldir_current = new_leveldir;
level_nr = new_level_nr;
TapeErase();
MapTapeButtons();
/* level_nr may have set to value over handicap with level editor */
- if (setup.handicap && level_nr > leveldir[leveldir_nr].handicap_level)
- level_nr = leveldir[leveldir_nr].handicap_level;
+ if (setup.handicap && level_nr > leveldir_current->handicap_level)
+ level_nr = leveldir_current->handicap_level;
GetPlayerConfig();
LoadLevel(level_nr);
DrawText(SX + 6*32, SY + 2*32, setup.player_name, FS_BIG, FC_RED);
DrawText(SX + 32, SY + 3*32, "Level:", FS_BIG, FC_GREEN);
DrawText(SX + 11*32, SY + 3*32, int2str(level_nr,3), FS_BIG,
- (leveldir[leveldir_nr].readonly ? FC_RED : FC_YELLOW));
+ (leveldir_current->readonly ? FC_RED : FC_YELLOW));
DrawText(SX + 32, SY + 4*32, "Hall Of Fame", FS_BIG, FC_GREEN);
DrawText(SX + 32, SY + 5*32, "Level Creator", FS_BIG, FC_GREEN);
DrawText(SY + 32, SY + 6*32, "Info Screen", FS_BIG, FC_GREEN);
DrawMicroLevel(MICROLEV_XPOS, MICROLEV_YPOS, TRUE);
DrawTextF(7*32 + 6, 3*32 + 9, FC_RED, "%d-%d",
- leveldir[leveldir_nr].first_level,
- leveldir[leveldir_nr].last_level);
+ leveldir_current->first_level,
+ leveldir_current->last_level);
- if (leveldir[leveldir_nr].readonly)
+ if (leveldir_current->readonly)
{
DrawTextF(15*32 + 6, 3*32 + 9 - 7, FC_RED, "READ");
DrawTextF(15*32 + 6, 3*32 + 9 + 7, FC_RED, "ONLY");
DrawText(SX + 56, SY + 326, "A Game by Artsoft Entertainment",
FS_SMALL, FC_RED);
- if (leveldir[leveldir_nr].name)
+ if (leveldir_current->name)
{
- int len = strlen(leveldir[leveldir_nr].name);
+ int len = strlen(leveldir_current->name);
int lxpos = SX + (SXSIZE - len * FONT4_XSIZE) / 2;
int lypos = SY + 352;
- DrawText(lxpos, lypos, leveldir[leveldir_nr].name, FS_SMALL, FC_SPECIAL2);
+ DrawText(lxpos, lypos, leveldir_current->name, FS_SMALL, FC_SPECIAL2);
}
FadeToFront();
y = choice;
}
- if (y == 4 && ((x == 11 && level_nr > leveldir[leveldir_nr].first_level) ||
- (x == 15 && level_nr < leveldir[leveldir_nr].last_level)) &&
+ if (y == 4 && ((x == 11 && level_nr > leveldir_current->first_level) ||
+ (x == 15 && level_nr < leveldir_current->last_level)) &&
button)
{
static unsigned long level_delay = 0;
int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
int new_level_nr, old_level_nr = level_nr;
- int font_color = (leveldir[leveldir_nr].readonly ? FC_RED : FC_YELLOW);
+ int font_color = (leveldir_current->readonly ? FC_RED : FC_YELLOW);
new_level_nr = level_nr + (x == 11 ? -step : +step);
- if (new_level_nr < leveldir[leveldir_nr].first_level)
- new_level_nr = leveldir[leveldir_nr].first_level;
- if (new_level_nr > leveldir[leveldir_nr].last_level)
- new_level_nr = leveldir[leveldir_nr].last_level;
+ if (new_level_nr < leveldir_current->first_level)
+ new_level_nr = leveldir_current->first_level;
+ if (new_level_nr > leveldir_current->last_level)
+ new_level_nr = leveldir_current->last_level;
- if (setup.handicap && new_level_nr > leveldir[leveldir_nr].handicap_level)
- new_level_nr = leveldir[leveldir_nr].handicap_level;
+ if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
+ new_level_nr = leveldir_current->handicap_level;
if (old_level_nr == new_level_nr ||
!DelayReached(&level_delay, GADGET_FRAME_DELAY))
{
if (y != choice)
{
- DrawGraphic(0, y-1, GFX_KUGEL_ROT);
+ DrawGraphic(0, y - 1, GFX_KUGEL_ROT);
DrawGraphic(0, choice - 1, GFX_KUGEL_BLAU);
choice = y;
}
{
game_status = CHOOSELEVEL;
SaveLevelSetup_LastSeries();
- SaveLevelSetup_SeriesInfo(leveldir_nr);
+ SaveLevelSetup_SeriesInfo();
DrawChooseLevel();
}
}
}
else if (y == 6)
{
- if (leveldir[leveldir_nr].readonly &&
+ if (leveldir_current->readonly &&
strcmp(setup.player_name, "Artsoft") != 0)
Request("This level is read only !", REQ_CONFIRM);
game_status = LEVELED;
else if (y == 10)
{
SaveLevelSetup_LastSeries();
- SaveLevelSetup_SeriesInfo(leveldir_nr);
+ SaveLevelSetup_SeriesInfo();
if (Request("Do you really want to quit ?", REQ_ASK | REQ_STAY_CLOSED))
game_status = EXITGAME;
}
for(i=0; i<num_page_entries; i++)
{
-#if 0
- strncpy(buffer, leveldir[first_entry + i].name_short , SCR_FIELDX - 1);
- buffer[SCR_FIELDX - 1] = '\0';
-#else
- strncpy(buffer, leveldir[first_entry + i].name , max_buffer_len);
+ struct LevelDirInfo *leveldir_node;
+ int leveldir_pos = first_entry + i;
+
+ leveldir_node = getLevelDirInfoFromPos(leveldir_first, leveldir_pos);
+ strncpy(buffer, leveldir_node->name , max_buffer_len);
buffer[max_buffer_len] = '\0';
-#endif
- DrawText(SX + 32, SY + (i + 2) * 32, buffer,
- FS_MEDIUM, leveldir[first_entry + i].color);
+ DrawText(SX + 32, SY + (i + 2) * 32, buffer, FS_MEDIUM,
+ leveldir_node->color);
DrawGraphic(0, i + 2, GFX_KUGEL_BLAU);
}
DrawGraphic(0, MAX_LEVEL_SERIES_ON_SCREEN + 1, GFX_ARROW_BLUE_DOWN);
}
-static void drawChooseLevelInfo(int leveldir_nr)
+static void drawChooseLevelInfo(int leveldir_pos)
{
+ struct LevelDirInfo *leveldir_node;
int x, last_redraw_mask = redraw_mask;
+ leveldir_node = getLevelDirInfoFromPos(leveldir_first, leveldir_pos);
+
XFillRectangle(display, drawto, gc, SX + 32, SY + 32, SXSIZE - 64, 32);
-#if 0
- DrawTextFCentered(40, FC_RED, "%3d levels (%s)",
- leveldir[leveldir_nr].levels,
- leveldir[leveldir_nr].readonly ? "readonly" : "writable");
-#else
DrawTextFCentered(40, FC_RED, "%3d levels (%s)",
- leveldir[leveldir_nr].levels,
- leveldir[leveldir_nr].class_desc);
-#endif
+ leveldir_node->levels,
+ leveldir_node->class_desc);
/* let BackToFront() redraw only what is needed */
redraw_mask = last_redraw_mask | REDRAW_TILES;
if (button == MB_MENU_INITIALIZE)
{
+ int leveldir_pos = posLevelDirInfo(leveldir_current);
+
if (first_entry == -1)
{
- first_entry = MAX(0, leveldir_nr - num_page_entries + 1);
- choice = leveldir_nr - first_entry + 3;
+ first_entry = MAX(0, leveldir_pos - num_page_entries + 1);
+ choice = leveldir_pos - first_entry + 3;
AdjustChooseLevelScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, first_entry);
}
first_entry = dy;
drawChooseLevelList(first_entry, num_page_entries);
- drawChooseLevelInfo(leveldir_nr);
+ drawChooseLevelInfo(leveldir_pos);
redraw = TRUE;
}
}
else
{
- leveldir_nr = first_entry + y - 3;
- LoadLevelSetup_SeriesInfo(leveldir_nr);
+ int leveldir_pos = first_entry + y - 3;
+
+ leveldir_current = getLevelDirInfoFromPos(leveldir_first, leveldir_pos);
+
+ LoadLevelSetup_SeriesInfo();
SaveLevelSetup_LastSeries();
- SaveLevelSetup_SeriesInfo(leveldir_nr);
+ SaveLevelSetup_SeriesInfo();
TapeErase();
+
+ printf("first_level == %d, last_level == %d, levels == %d\n",
+ leveldir_current->first_level,
+ leveldir_current->last_level,
+ leveldir_current->levels);
+
+
game_status = MAINMENU;
DrawMainMenu();
redraw = TRUE;
mode == MICROLABEL_LEVEL_AUTHOR ? level.author :
mode == MICROLABEL_IMPORTED_FROM ? "imported from" :
mode == MICROLABEL_LEVEL_IMPORT_INFO ?
- leveldir[leveldir_nr].imported_from : ""),
+ leveldir_current->imported_from : ""),
MAX_MICROLABEL_SIZE);
label_text[MAX_MICROLABEL_SIZE] = '\0';
/* redraw micro level label, if needed */
if (strcmp(level.name, NAMELESS_LEVEL_NAME) != 0 &&
strcmp(level.author, ANONYMOUS_NAME) != 0 &&
- strcmp(level.author, leveldir[leveldir_nr].name) != 0 &&
+ strcmp(level.author, leveldir_current->name) != 0 &&
DelayReached(&label_delay, MICROLEVEL_LABEL_DELAY))
{
int max_label_counter = 23;
- if (leveldir[leveldir_nr].imported_from != NULL)
+ if (leveldir_current->imported_from != NULL)
max_label_counter += 14;
label_counter = (label_counter + 1) % max_label_counter;