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);
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);
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);
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);
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);
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);
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);
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);
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);
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 */
{
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;
{
{
&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,
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);
}
num_editor_elements = 0;
+ use_el_empty = FALSE;
/* determine size of element list */
for (i=0; editor_elements_info[i].setup_value != NULL; i++)
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));
{
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];
}
}
#include <ctype.h>
#include <sys/stat.h>
+#include <math.h>
#include "libgame/libgame.h"
#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
{ 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[] =
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;
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
+}
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;
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;
}
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++)
void LoadLevelSetup_LastSeries()
{
- char *filename;
- SetupFileHash *level_setup_hash = NULL;
-
- /* always start with reliable default values */
- leveldir_current = getFirstValidTreeInfoEntry(leveldir_first);
-
/* ----------------------------------------------------------------------- */
/* ~/.<program>/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)))
{
void SaveLevelSetup_LastSeries()
{
- char *filename;
- char *level_subdir = leveldir_current->filename;
- FILE *file;
-
/* ----------------------------------------------------------------------- */
/* ~/.<program>/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)))
{