#include <ctype.h>
#include <sys/stat.h>
+#include <math.h>
#include "libgame/libgame.h"
strcpy(level->author, PROGRAM_AUTHOR_STRING);
break;
- case LEVELCLASS_CONTRIBUTION:
- strncpy(level->author, leveldir_current->name,MAX_LEVEL_AUTHOR_LEN);
+ case LEVELCLASS_CONTRIB:
+ strncpy(level->author, leveldir_current->name, MAX_LEVEL_AUTHOR_LEN);
level->author[MAX_LEVEL_AUTHOR_LEN] = '\0';
break;
- case LEVELCLASS_USER:
+ case LEVELCLASS_PRIVATE:
strncpy(level->author, getRealName(), MAX_LEVEL_AUTHOR_LEN);
level->author[MAX_LEVEL_AUTHOR_LEN] = '\0';
break;
if (leveldir_current == NULL) /* only when dumping level */
return;
+#if 0
+ printf("::: sort_priority: %d\n", leveldir_current->sort_priority);
+#endif
+
/* determine correct game engine version of current level */
- if (IS_LEVELCLASS_CONTRIBUTION(leveldir_current) ||
- IS_LEVELCLASS_USER(leveldir_current))
+#if 1
+ if (!leveldir_current->latest_engine)
+#else
+ if (IS_LEVELCLASS_CONTRIB(leveldir_current) ||
+ IS_LEVELCLASS_PRIVATE(leveldir_current) ||
+ IS_LEVELCLASS_UNDEFINED(leveldir_current))
+#endif
{
#if 0
printf("\n::: This level is private or contributed: '%s'\n", filename);
#endif
- /* For user contributed and private levels, use the version of
- the game engine the levels were created for.
+#if 0
+ printf("\n::: Use the stored game engine version for this level\n");
+#endif
+
+ /* For all levels which are not forced to use the latest game engine
+ version (normally user contributed, private and undefined levels),
+ use the version of the game engine the levels were created for.
+
Since 2.0.1, the game engine version is now directly stored
in the level file (chunk "VERS"), so there is no need anymore
to set the game version from the file version (except for old,
/* do some special adjustments to support older level versions */
if (level->file_version == FILE_VERSION_1_0)
{
- Error(ERR_WARN, "level file '%s'has version number 1.0", filename);
+ Error(ERR_WARN, "level file '%s' has version number 1.0", filename);
Error(ERR_WARN, "using high speed movement for player");
/* player was faster than monsters in (pre-)1.0 levels */
}
/* Default behaviour for EM style gems was "slippery" only in 2.0.1 */
- if (level->game_version == VERSION_IDENT(2,0,1))
+ if (level->game_version == VERSION_IDENT(2,0,1,0))
level->em_slippery_gems = TRUE;
}
else
leveldir_current->sort_priority, filename);
#endif
- /* Always use the latest version of the game engine for all but
- user contributed and private levels; this allows for actual
- corrections in the game engine to take effect for existing,
- converted levels (from "classic" or other existing games) to
- make the game emulation more accurate, while (hopefully) not
- breaking existing levels created from other players. */
+#if 0
+ printf("\n::: Use latest game engine version for this level.\n");
+#endif
+
+ /* For all levels which are forced to use the latest game engine version
+ (normally all but user contributed, private and undefined levels), set
+ the game engine version to the actual version; this allows for actual
+ corrections in the game engine to take effect for existing, converted
+ levels (from "classic" or other existing games) to make the emulation
+ of the corresponding game more accurate, while (hopefully) not breaking
+ existing levels created from other players. */
+
+#if 0
+ printf("::: changing engine from %d to %d\n",
+ level->game_version, GAME_VERSION_ACTUAL);
+#endif
level->game_version = GAME_VERSION_ACTUAL;
if (level->file_version < FILE_VERSION_2_0)
level->em_slippery_gems = TRUE;
}
+
+#if 0
+ printf("::: => %d\n", level->game_version);
+#endif
}
static void LoadLevel_InitElements(struct LevelInfo *level, char *filename)
/* map custom element change events that have changed in newer versions
(these following values were accidentally changed in version 3.0.1) */
- if (level->game_version <= VERSION_IDENT(3,0,0))
+ if (level->game_version <= VERSION_IDENT(3,0,0,0))
{
for (i=0; i < NUM_CUSTOM_ELEMENTS; i++)
{
}
/* initialize "can_change" field for old levels with only one change page */
- if (level->game_version <= VERSION_IDENT(3,0,2))
+ if (level->game_version <= VERSION_IDENT(3,0,2,0))
{
for (i=0; i < NUM_CUSTOM_ELEMENTS; i++)
{
}
}
- /* set default push delay values (corrected since version 3.0.7) */
- if (level->game_version < VERSION_IDENT(3,0,7))
+#if 0
+ /* set default push delay values (corrected since version 3.0.7-1) */
+ if (level->game_version < VERSION_IDENT(3,0,7,1))
{
game.default_push_delay_fixed = 2;
game.default_push_delay_random = 8;
if (element_info[element].push_delay_random == -1)
element_info[element].push_delay_random = game.default_push_delay_random;
}
+#endif
/* initialize element properties for level editor etc. */
InitElementPropertiesEngine(level->game_version);
{
int element = level->field[x][y];
- if (level->game_version <= VERSION_IDENT(2,2,0))
+ if (level->game_version <= VERSION_IDENT(2,2,0,0))
{
/* map game font elements */
element = (element == EL_CHAR('[') ? EL_CHAR_AUMLAUT :
element == EL_CHAR('^') ? EL_CHAR_COPYRIGHT : element);
}
- if (level->game_version < VERSION_IDENT(3,0,0))
+ if (level->game_version < VERSION_IDENT(3,0,0,0))
{
/* map Supaplex gravity tube elements */
element = (element == EL_SP_GRAVITY_PORT_LEFT ? EL_SP_PORT_LEFT :
tape.length_seconds = GetTapeLength();
#if 0
- printf("tape game version: %d\n", tape.game_version);
- printf("tape engine version: %d\n", tape.engine_version);
+ printf("::: tape game version: %d\n", tape.game_version);
+ printf("::: tape engine version: %d\n", tape.engine_version);
#endif
}
#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
+}