From: Holger Schemel Date: Tue, 18 Nov 2003 21:38:53 +0000 (+0100) Subject: rnd-20031118-1-src X-Git-Tag: 3.0.8^2~22 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=d292f0ad61b32968ca4a6750b93ac7e5b99ff00d;p=rocksndiamonds.git rnd-20031118-1-src --- diff --git a/src/conftime.h b/src/conftime.h index b65f6583..fb7ddff0 100644 --- a/src/conftime.h +++ b/src/conftime.h @@ -1 +1 @@ -#define COMPILE_DATE_STRING "[2003-11-16 22:37]" +#define COMPILE_DATE_STRING "[2003-11-18 22:35]" diff --git a/src/editor.c b/src/editor.c index 5c3298f8..20994b8d 100644 --- a/src/editor.c +++ b/src/editor.c @@ -1922,6 +1922,8 @@ static int editor_el_boulderdash[] = EL_BD_FIREFLY_DOWN, EL_EMPTY, }; +static int *editor_hl_boulderdash_ptr = editor_hl_boulderdash; +static int *editor_el_boulderdash_ptr = editor_el_boulderdash; static int num_editor_hl_boulderdash = SIZEOF_ARRAY_INT(editor_hl_boulderdash); static int num_editor_el_boulderdash = SIZEOF_ARRAY_INT(editor_el_boulderdash); @@ -2027,6 +2029,8 @@ static int editor_el_emerald_mine[] = EL_EM_GATE_3_GRAY, EL_EM_GATE_4_GRAY, }; +static int *editor_hl_emerald_mine_ptr = editor_hl_emerald_mine; +static int *editor_el_emerald_mine_ptr = editor_el_emerald_mine; static int num_editor_hl_emerald_mine=SIZEOF_ARRAY_INT(editor_hl_emerald_mine); static int num_editor_el_emerald_mine=SIZEOF_ARRAY_INT(editor_el_emerald_mine); @@ -2135,6 +2139,8 @@ static int editor_el_more[] = EL_EMC_WALL_6, EL_EMC_WALL_7, }; +static int *editor_hl_more_ptr = editor_hl_more; +static int *editor_el_more_ptr = editor_el_more; static int num_editor_hl_more = SIZEOF_ARRAY_INT(editor_hl_more); static int num_editor_el_more = SIZEOF_ARRAY_INT(editor_el_more); @@ -2158,6 +2164,8 @@ static int editor_el_sokoban[] = EL_SOKOBAN_FIELD_FULL, EL_STEELWALL, }; +static int *editor_hl_sokoban_ptr = editor_hl_sokoban; +static int *editor_el_sokoban_ptr = editor_el_sokoban; static int num_editor_hl_sokoban = SIZEOF_ARRAY_INT(editor_hl_sokoban); static int num_editor_el_sokoban = SIZEOF_ARRAY_INT(editor_el_sokoban); @@ -2230,6 +2238,8 @@ static int editor_el_supaplex[] = EL_SP_CHIP_TOP, EL_SP_CHIP_BOTTOM, }; +static int *editor_hl_supaplex_ptr = editor_hl_supaplex; +static int *editor_el_supaplex_ptr = editor_el_supaplex; static int num_editor_hl_supaplex = SIZEOF_ARRAY_INT(editor_hl_supaplex); static int num_editor_el_supaplex = SIZEOF_ARRAY_INT(editor_el_supaplex); @@ -2323,6 +2333,8 @@ static int editor_el_diamond_caves[] = EL_EXTRA_TIME, EL_EMPTY, }; +static int *editor_hl_diamond_caves_ptr = editor_hl_diamond_caves; +static int *editor_el_diamond_caves_ptr = editor_el_diamond_caves; static int num_editor_hl_diamond_caves = SIZEOF_ARRAY_INT(editor_hl_diamond_caves); static int num_editor_el_diamond_caves = SIZEOF_ARRAY_INT(editor_el_diamond_caves); @@ -2371,6 +2383,8 @@ static int editor_el_dx_boulderdash[] = EL_EMPTY, EL_EMPTY }; +static int *editor_hl_dx_boulderdash_ptr = editor_hl_dx_boulderdash; +static int *editor_el_dx_boulderdash_ptr = editor_el_dx_boulderdash; static int num_editor_hl_dx_boulderdash = SIZEOF_ARRAY_INT(editor_hl_dx_boulderdash); static int num_editor_el_dx_boulderdash = SIZEOF_ARRAY_INT(editor_el_dx_boulderdash); @@ -2474,6 +2488,8 @@ static int editor_el_chars[] = EL_CHAR(FONT_ASCII_CURSOR), EL_CHAR(' ') }; +static int *editor_hl_chars_ptr = editor_hl_chars; +static int *editor_el_chars_ptr = editor_el_chars; static int num_editor_hl_chars = SIZEOF_ARRAY_INT(editor_hl_chars); static int num_editor_el_chars = SIZEOF_ARRAY_INT(editor_el_chars); @@ -2662,6 +2678,8 @@ static int editor_el_custom[] = EL_CUSTOM_START + 126, EL_CUSTOM_START + 127 }; +static int *editor_hl_custom_ptr = editor_hl_custom; +static int *editor_el_custom_ptr = editor_el_custom; static int num_editor_hl_custom = SIZEOF_ARRAY_INT(editor_hl_custom); static int num_editor_el_custom = SIZEOF_ARRAY_INT(editor_el_custom); @@ -2831,9 +2849,44 @@ static int editor_el_custom_more[] = EL_CUSTOM_START + 254, EL_CUSTOM_START + 255 }; +static int *editor_hl_custom_more_ptr = editor_hl_custom_more; +static int *editor_el_custom_more_ptr = editor_el_custom_more; static int num_editor_hl_custom_more = SIZEOF_ARRAY_INT(editor_hl_custom_more); static int num_editor_el_custom_more = SIZEOF_ARRAY_INT(editor_el_custom_more); +static int editor_hl_user_defined[] = +{ + EL_CHAR('U'), + EL_CHAR('S'), + EL_CHAR('E'), + EL_CHAR('R'), + + EL_CHAR('D'), + EL_CHAR('E'), + EL_CHAR('F'), + EL_CHAR('I'), + + EL_CHAR('-'), + EL_CHAR('N'), + EL_CHAR('E'), + EL_CHAR('D'), +}; + +static int *editor_hl_user_defined_ptr = editor_hl_user_defined; +static int *editor_el_user_defined_ptr = NULL; +static int num_editor_hl_user_defined=SIZEOF_ARRAY_INT(editor_hl_user_defined); +static int num_editor_el_user_defined = 0; + +static int editor_hl_empty[] = { }; +static int editor_el_empty[ED_NUM_ELEMENTLIST_BUTTONS]; + +static int *editor_hl_empty_ptr = editor_hl_empty; +static int *editor_el_empty_ptr = editor_el_empty; +static int num_editor_hl_empty = 0; +static int num_editor_el_empty = 0; /* dynamically determined, if needed */ + +static boolean use_el_empty = FALSE; + static int *editor_elements = NULL; /* dynamically allocated */ static int num_editor_elements = 0; /* dynamically determined */ @@ -2841,10 +2894,10 @@ static struct { boolean *setup_value; - int *headline_list; + int **headline_list; int *headline_list_size; - int *element_list; + int **element_list; int *element_list_size; boolean last_setup_value; @@ -2853,53 +2906,63 @@ editor_elements_info[] = { { &setup.editor.el_boulderdash, - editor_hl_boulderdash, &num_editor_hl_boulderdash, - editor_el_boulderdash, &num_editor_el_boulderdash + &editor_hl_boulderdash_ptr, &num_editor_hl_boulderdash, + &editor_el_boulderdash_ptr, &num_editor_el_boulderdash }, { &setup.editor.el_emerald_mine, - editor_hl_emerald_mine, &num_editor_hl_emerald_mine, - editor_el_emerald_mine, &num_editor_el_emerald_mine + &editor_hl_emerald_mine_ptr, &num_editor_hl_emerald_mine, + &editor_el_emerald_mine_ptr, &num_editor_el_emerald_mine }, { &setup.editor.el_more, - editor_hl_more, &num_editor_hl_more, - editor_el_more, &num_editor_el_more + &editor_hl_more_ptr, &num_editor_hl_more, + &editor_el_more_ptr, &num_editor_el_more }, { &setup.editor.el_sokoban, - editor_hl_sokoban, &num_editor_hl_sokoban, - editor_el_sokoban, &num_editor_el_sokoban + &editor_hl_sokoban_ptr, &num_editor_hl_sokoban, + &editor_el_sokoban_ptr, &num_editor_el_sokoban }, { &setup.editor.el_supaplex, - editor_hl_supaplex, &num_editor_hl_supaplex, - editor_el_supaplex, &num_editor_el_supaplex + &editor_hl_supaplex_ptr, &num_editor_hl_supaplex, + &editor_el_supaplex_ptr, &num_editor_el_supaplex }, { &setup.editor.el_diamond_caves, - editor_hl_diamond_caves, &num_editor_hl_diamond_caves, - editor_el_diamond_caves, &num_editor_el_diamond_caves + &editor_hl_diamond_caves_ptr, &num_editor_hl_diamond_caves, + &editor_el_diamond_caves_ptr, &num_editor_el_diamond_caves }, { &setup.editor.el_dx_boulderdash, - editor_hl_dx_boulderdash, &num_editor_hl_dx_boulderdash, - editor_el_dx_boulderdash, &num_editor_el_dx_boulderdash + &editor_hl_dx_boulderdash_ptr, &num_editor_hl_dx_boulderdash, + &editor_el_dx_boulderdash_ptr, &num_editor_el_dx_boulderdash }, { &setup.editor.el_chars, - editor_hl_chars, &num_editor_hl_chars, - editor_el_chars, &num_editor_el_chars + &editor_hl_chars_ptr, &num_editor_hl_chars, + &editor_el_chars_ptr, &num_editor_el_chars }, { &setup.editor.el_custom, - editor_hl_custom, &num_editor_hl_custom, - editor_el_custom, &num_editor_el_custom + &editor_hl_custom_ptr, &num_editor_hl_custom, + &editor_el_custom_ptr, &num_editor_el_custom }, { &setup.editor.el_custom_more, - editor_hl_custom_more, &num_editor_hl_custom_more, - editor_el_custom_more, &num_editor_el_custom_more + &editor_hl_custom_more_ptr, &num_editor_hl_custom_more, + &editor_el_custom_more_ptr, &num_editor_el_custom_more + }, + { + &setup.editor.el_user_defined, + &editor_hl_user_defined_ptr, &num_editor_hl_user_defined, + &editor_el_user_defined_ptr, &num_editor_el_user_defined + }, + { + &use_el_empty, + &editor_hl_empty_ptr, &num_editor_hl_empty, + &editor_el_empty_ptr, &num_editor_el_empty, }, { NULL, @@ -2970,14 +3033,22 @@ static void ReinitializeElementList() if (editor_elements != NULL) free(editor_elements); - /* do some sanity check for each element from element list at startup */ if (!initialized) { + /* initialize optional user defined element list */ + LoadUserDefinedEditorElementList(&editor_el_user_defined_ptr, + &num_editor_el_user_defined); + + /* initialize list of empty elements (used for padding, if needed) */ + for (i=0; i < ED_NUM_ELEMENTLIST_BUTTONS; i++) + editor_el_empty[i] = EL_EMPTY; + + /* do some sanity checks for each element from element list */ for (i=0; editor_elements_info[i].setup_value != NULL; i++) { for (j=0; j < *editor_elements_info[i].element_list_size; j++) { - int element = editor_elements_info[i].element_list[j]; + int element = (*editor_elements_info[i].element_list)[j]; if (element >= NUM_FILE_ELEMENTS) Error(ERR_WARN, "editor element %d is runtime element", element); @@ -2991,6 +3062,7 @@ static void ReinitializeElementList() } num_editor_elements = 0; + use_el_empty = FALSE; /* determine size of element list */ for (i=0; editor_elements_info[i].setup_value != NULL; i++) @@ -3006,11 +3078,11 @@ static void ReinitializeElementList() if (num_editor_elements < ED_NUM_ELEMENTLIST_BUTTONS) { - /* workaround: offer at least as many elements as element buttons exist */ - int list_nr = 1; /* see above: editor_elements_info for Emerald Mine */ + /* offer at least as many elements as element buttons exist */ + use_el_empty = TRUE; + num_editor_el_empty = ED_NUM_ELEMENTLIST_BUTTONS - num_editor_elements; - *editor_elements_info[list_nr].setup_value = TRUE; - num_editor_elements += *editor_elements_info[list_nr].element_list_size; + num_editor_elements += num_editor_el_empty; } editor_elements = checked_malloc(num_editor_elements * sizeof(int)); @@ -3022,10 +3094,10 @@ static void ReinitializeElementList() { if (setup.editor.el_headlines) for (j=0; j < *editor_elements_info[i].headline_list_size; j++) - editor_elements[pos++] = editor_elements_info[i].headline_list[j]; + editor_elements[pos++] = (*editor_elements_info[i].headline_list)[j]; for (j=0; j < *editor_elements_info[i].element_list_size; j++) - editor_elements[pos++] = editor_elements_info[i].element_list[j]; + editor_elements[pos++] = (*editor_elements_info[i].element_list)[j]; } } diff --git a/src/files.c b/src/files.c index 813ce976..f8b49839 100644 --- a/src/files.c +++ b/src/files.c @@ -13,6 +13,7 @@ #include #include +#include #include "libgame/libgame.h" @@ -2299,8 +2300,9 @@ void SaveScore(int level_nr) #define SETUP_TOKEN_EDITOR_EL_CUSTOM 8 #define SETUP_TOKEN_EDITOR_EL_CUSTOM_MORE 9 #define SETUP_TOKEN_EDITOR_EL_HEADLINES 10 +#define SETUP_TOKEN_EDITOR_EL_USER_DEFINED 11 -#define NUM_EDITOR_SETUP_TOKENS 11 +#define NUM_EDITOR_SETUP_TOKENS 12 /* shortcut setup */ #define SETUP_TOKEN_SHORTCUT_SAVE_GAME 0 @@ -2387,6 +2389,7 @@ static struct TokenInfo editor_setup_tokens[] = { TYPE_SWITCH, &sei.el_custom, "editor.el_custom" }, { TYPE_SWITCH, &sei.el_custom_more, "editor.el_custom_more" }, { TYPE_SWITCH, &sei.el_headlines, "editor.el_headlines" }, + { TYPE_SWITCH, &sei.el_user_defined, "editor.el_user_defined" }, }; static struct TokenInfo shortcut_setup_tokens[] = @@ -2485,6 +2488,7 @@ static void setSetupInfoToDefaults(struct SetupInfo *si) si->editor.el_custom_more = FALSE; si->editor.el_headlines = TRUE; + si->editor.el_user_defined = FALSE; si->shortcut.save_game = DEFAULT_KEY_SAVE_GAME; si->shortcut.load_game = DEFAULT_KEY_LOAD_GAME; @@ -2756,3 +2760,87 @@ void LoadSpecialMenuDesignSettings() freeSetupFileHash(setup_file_hash); } + +static char *itoa(unsigned int i) +{ + static char *a = NULL; + + if (a != NULL) + free(a); + + if (i > 2147483647) /* yes, this is a kludge */ + i = 2147483647; + + a = checked_malloc(10 + 1); + + sprintf(a, "%d", i); + + return a; +} + +void LoadUserDefinedEditorElementList(int **elements, int *num_elements) +{ + char *filename = getEditorSetupFilename(); + SetupFileList *setup_file_list, *list; + SetupFileHash *element_hash; + int num_unknown_tokens = 0; + int i; + + if ((setup_file_list = loadSetupFileList(filename)) == NULL) + return; + + element_hash = newSetupFileHash(); + + for (i=0; i < NUM_FILE_ELEMENTS; i++) + setHashEntry(element_hash, element_info[i].token_name, itoa(i)); + + /* determined size may be larger than needed (due to unknown elements) */ + *num_elements = 0; + for (list = setup_file_list; list != NULL; list = list->next) + (*num_elements)++; + + /* add space for up to 3 more elements for padding that may be needed */ + *num_elements += 3; + + *elements = checked_malloc(*num_elements * sizeof(int)); + + *num_elements = 0; + for (list = setup_file_list; list != NULL; list = list->next) + { + char *value = getHashEntry(element_hash, list->token); + + if (value) + { + (*elements)[(*num_elements)++] = atoi(value); + } + else + { + if (num_unknown_tokens == 0) + { + Error(ERR_RETURN_LINE, "-"); + Error(ERR_RETURN, "warning: unknown token(s) found in config file:"); + Error(ERR_RETURN, "- config file: '%s'", filename); + + num_unknown_tokens++; + } + + Error(ERR_RETURN, "- token: '%s'", list->token); + } + } + + if (num_unknown_tokens > 0) + Error(ERR_RETURN_LINE, "-"); + + while (*num_elements % 4) /* pad with empty elements, if needed */ + (*elements)[(*num_elements)++] = EL_EMPTY; + + freeSetupFileList(setup_file_list); + freeSetupFileHash(element_hash); + +#if 0 + /* TEST-ONLY */ + for (i=0; i < *num_elements; i++) + printf("editor: element '%s' [%d]\n", + element_info[(*elements)[i]].token_name, (*elements)[i]); +#endif +} diff --git a/src/files.h b/src/files.h index 1ae371db..6ad50a6c 100644 --- a/src/files.h +++ b/src/files.h @@ -40,5 +40,6 @@ void SaveSetup(); void LoadCustomElementDescriptions(); void LoadSpecialMenuDesignSettings(); +void LoadUserDefinedEditorElementList(int **, int *); #endif /* FILES_H */ diff --git a/src/libgame/setup.c b/src/libgame/setup.c index 8ba46e0b..3ba6745d 100644 --- a/src/libgame/setup.c +++ b/src/libgame/setup.c @@ -405,6 +405,18 @@ char *getSetupFilename() return filename; } +char *getEditorSetupFilename() +{ + static char *filename = NULL; + + if (filename != NULL) + free(filename); + + filename = getPath2(getSetupDir(), EDITORSETUP_FILENAME); + + return filename; +} + static char *getCorrectedArtworkBasename(char *basename) { char *basename_corrected = basename; @@ -1275,6 +1287,9 @@ SetupFileHash *newSetupFileHash() SetupFileHash *new_hash = create_hashtable(16, 0.75, get_hash_from_key, keys_are_equal); + if (new_hash == NULL) + Error(ERR_EXIT, "create_hashtable() failed -- out of memory"); + return new_hash; } @@ -1387,7 +1402,11 @@ static void *loadSetupFileData(char *filename, boolean use_hash) if (line_ptr < line + line_len) value = line_ptr + 1; else +#if 1 + value = "true"; /* treat tokens without value as "true" */ +#else value = "\0"; +#endif /* cut leading whitespaces from value */ for (; *value; value++) @@ -2618,17 +2637,15 @@ char *getSetupLine(struct TokenInfo *token_info, char *prefix, int token_nr) void LoadLevelSetup_LastSeries() { - char *filename; - SetupFileHash *level_setup_hash = NULL; - - /* always start with reliable default values */ - leveldir_current = getFirstValidTreeInfoEntry(leveldir_first); - /* ----------------------------------------------------------------------- */ /* ~/./levelsetup.conf */ /* ----------------------------------------------------------------------- */ - filename = getPath2(getSetupDir(), LEVELSETUP_FILENAME); + char *filename = getPath2(getSetupDir(), LEVELSETUP_FILENAME); + SetupFileHash *level_setup_hash = NULL; + + /* always start with reliable default values */ + leveldir_current = getFirstValidTreeInfoEntry(leveldir_first); if ((level_setup_hash = loadSetupFileHash(filename))) { @@ -2652,17 +2669,15 @@ void LoadLevelSetup_LastSeries() void SaveLevelSetup_LastSeries() { - char *filename; - char *level_subdir = leveldir_current->filename; - FILE *file; - /* ----------------------------------------------------------------------- */ /* ~/./levelsetup.conf */ /* ----------------------------------------------------------------------- */ - InitUserDataDirectory(); + char *filename = getPath2(getSetupDir(), LEVELSETUP_FILENAME); + char *level_subdir = leveldir_current->filename; + FILE *file; - filename = getPath2(getSetupDir(), LEVELSETUP_FILENAME); + InitUserDataDirectory(); if (!(file = fopen(filename, MODE_WRITE))) { diff --git a/src/libgame/setup.h b/src/libgame/setup.h index 2498fe7d..9bc5fd90 100644 --- a/src/libgame/setup.h +++ b/src/libgame/setup.h @@ -196,6 +196,7 @@ char *getLevelFilename(int); char *getTapeFilename(int); char *getScoreFilename(int); char *getSetupFilename(void); +char *getEditorSetupFilename(void); char *getImageFilename(char *); char *getCustomImageFilename(char *); char *getCustomSoundFilename(char *); diff --git a/src/libgame/system.h b/src/libgame/system.h index ae847346..ec1b5250 100644 --- a/src/libgame/system.h +++ b/src/libgame/system.h @@ -227,6 +227,7 @@ #define LEVELSETUP_DIRECTORY "levelsetup" #define SETUP_FILENAME "setup.conf" #define LEVELSETUP_FILENAME "levelsetup.conf" +#define EDITORSETUP_FILENAME "editorsetup.conf" #define LEVELINFO_FILENAME "levelinfo.conf" #define GRAPHICSINFO_FILENAME "graphicsinfo.conf" #define SOUNDSINFO_FILENAME "soundsinfo.conf" @@ -238,6 +239,7 @@ #define LEVELSETUP_DIRECTORY "lvlsetup" #define SETUP_FILENAME "setup.cnf" #define LEVELSETUP_FILENAME "lvlsetup.cnf" +#define EDITORSETUP_FILENAME "edsetup.conf" #define LEVELINFO_FILENAME "lvlinfo.cnf" #define GRAPHICSINFO_FILENAME "gfxinfo.cnf" #define SOUNDSINFO_FILENAME "sndinfo.cnf" @@ -539,6 +541,7 @@ struct SetupEditorInfo boolean el_chars; boolean el_custom; boolean el_custom_more; + boolean el_user_defined; boolean el_headlines; }; diff --git a/src/screens.c b/src/screens.c index d82f3bd2..92e3838c 100644 --- a/src/screens.c +++ b/src/screens.c @@ -1824,6 +1824,7 @@ static struct TokenInfo setup_info_editor[] = { TYPE_SWITCH, &setup.editor.el_custom, "Custom:" }, { TYPE_SWITCH, &setup.editor.el_custom_more, "More Custom:" }, { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" }, + { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined:" }, { TYPE_EMPTY, NULL, "" }, { TYPE_LEAVE_MENU, execSetupMain, "Back" }, { 0, NULL, NULL }