+2007-03-01
+ * added new (special) "include: <filename>" directive that works in all
+ configuration files (like "graphicsinfo.conf") and that has the same
+ effect as if that directive would be replaced with the content of the
+ specified file (this can be useful to split large configuration files
+ into several smaller ones and include them from one main file, or to
+ store configuration settings that always stay the same into a separate
+ file, while including it and only add those parts that really change)
+
2007-02-24
* fixed minor bug (screen redraw of player tiles) in EMC graphics engine
-#define COMPILE_DATE_STRING "2007-02-26 02:31"
+#define COMPILE_DATE_STRING "2007-03-02 00:13"
extern void PlayLevelSound_EM(int, int, int, int);
extern void InitGraphicInfo_EM(void);
-void getGraphicSourceObjectExt_EM(int, int, Bitmap **, int *, int *);
+void getGraphicSourceObjectExt_EM(int, int, Bitmap **, int *, int *, int, int);
void getGraphicSourcePlayerExt_EM(int, int, int, Bitmap **, int *, int *);
#endif /* ENGINES_H */
{
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);
+ Error(ERR_INFO_LINE, "-");
+ Error(ERR_INFO, "warning: unknown token(s) found in config file:");
+ Error(ERR_INFO, "- config file: '%s'", filename);
num_unknown_tokens++;
}
- Error(ERR_RETURN, "- token: '%s'", list->token);
+ Error(ERR_INFO, "- token: '%s'", list->token);
}
}
if (num_unknown_tokens > 0)
- Error(ERR_RETURN_LINE, "-");
+ Error(ERR_INFO_LINE, "-");
while (*num_elements % 4) /* pad with empty elements, if needed */
(*elements)[(*num_elements)++] = EL_EMPTY;
{
if (token_nr == 0)
{
- Error(ERR_RETURN_LINE, "-");
- Error(ERR_RETURN, "warning: unknown token(s) found in config file:");
- Error(ERR_RETURN, "- config file: '%s'", filename);
+ Error(ERR_INFO_LINE, "-");
+ Error(ERR_INFO, "warning: unknown token(s) found in config file:");
+ Error(ERR_INFO, "- config file: '%s'", filename);
}
- Error(ERR_RETURN, "- token: '%s'", token);
+ Error(ERR_INFO, "- token: '%s'", token);
}
void print_unknown_token_end(int token_nr)
{
if (token_nr > 0)
- Error(ERR_RETURN_LINE, "-");
+ Error(ERR_INFO_LINE, "-");
}
void LoadHelpAnimInfo()
if (game.num_random_calls != num_random_calls)
{
- Error(ERR_RETURN, "number of random calls out of sync");
- Error(ERR_RETURN, "number of random calls should be %d", num_random_calls);
- Error(ERR_RETURN, "number of random calls is %d", game.num_random_calls);
+ Error(ERR_INFO, "number of random calls out of sync");
+ Error(ERR_INFO, "number of random calls should be %d", num_random_calls);
+ Error(ERR_INFO, "number of random calls is %d", game.num_random_calls);
Error(ERR_EXIT, "this should not happen -- please debug");
}
}
struct GraphicInfo_EM *g = &graphic_info_em_object[tile][frame];
#if 1
- getGraphicSourceObjectExt_EM(tile, frame, &g->bitmap, &g->src_x, &g->src_y);
+ getGraphicSourceObjectExt_EM(tile, frame, &g->bitmap, &g->src_x, &g->src_y,
+ x - 2, y - 2);
#endif
int src_x = g->src_x + g->src_offset_x;
for (i = 0; i < MAX_NUM_ELEMENTS; i++)
if (element_info[i].graphic[ACTION_DEFAULT] == IMG_UNKNOWN &&
i != EL_UNKNOWN)
- Error(ERR_RETURN, "warning: no graphic for element '%s' (%d)",
+ Error(ERR_INFO, "warning: no graphic for element '%s' (%d)",
element_info[i].token_name, i);
}
#endif
if (num_references_followed >= max_num_images)
{
- Error(ERR_RETURN_LINE, "-");
- Error(ERR_RETURN, "warning: error found in config file:");
- Error(ERR_RETURN, "- config file: '%s'", getImageConfigFilename());
- Error(ERR_RETURN, "- config token: '%s'", getTokenFromImageID(graphic));
- Error(ERR_RETURN, "error: loop discovered when resolving cloned graphics");
- Error(ERR_RETURN, "custom graphic rejected for this element/action");
+ Error(ERR_INFO_LINE, "-");
+ Error(ERR_INFO, "warning: error found in config file:");
+ Error(ERR_INFO, "- config file: '%s'", getImageConfigFilename());
+ Error(ERR_INFO, "- config token: '%s'", getTokenFromImageID(graphic));
+ Error(ERR_INFO, "error: loop discovered when resolving cloned graphics");
+ Error(ERR_INFO, "custom graphic rejected for this element/action");
if (graphic == fallback_graphic)
Error(ERR_EXIT, "fatal error: no fallback graphic available");
- Error(ERR_RETURN, "fallback done to 'char_exclam' for this graphic");
- Error(ERR_RETURN_LINE, "-");
+ Error(ERR_INFO, "fallback done to 'char_exclam' for this graphic");
+ Error(ERR_INFO_LINE, "-");
graphic_info[graphic] = graphic_info[fallback_graphic];
}
src_x + width > src_bitmap_width ||
src_y + height > src_bitmap_height)
{
- Error(ERR_RETURN_LINE, "-");
- Error(ERR_RETURN, "warning: error found in config file:");
- Error(ERR_RETURN, "- config file: '%s'", getImageConfigFilename());
- Error(ERR_RETURN, "- config token: '%s'", getTokenFromImageID(i));
- Error(ERR_RETURN, "- image file: '%s'", src_bitmap->source_filename);
- Error(ERR_RETURN,
+ Error(ERR_INFO_LINE, "-");
+ Error(ERR_INFO, "warning: error found in config file:");
+ Error(ERR_INFO, "- config file: '%s'", getImageConfigFilename());
+ Error(ERR_INFO, "- config token: '%s'", getTokenFromImageID(i));
+ Error(ERR_INFO, "- image file: '%s'", src_bitmap->source_filename);
+ Error(ERR_INFO,
"error: first animation frame out of bounds (%d, %d) [%d, %d]",
src_x, src_y, src_bitmap_width, src_bitmap_height);
- Error(ERR_RETURN, "custom graphic rejected for this element/action");
+ Error(ERR_INFO, "custom graphic rejected for this element/action");
if (i == fallback_graphic)
Error(ERR_EXIT, "fatal error: no fallback graphic available");
- Error(ERR_RETURN, "fallback done to 'char_exclam' for this graphic");
- Error(ERR_RETURN_LINE, "-");
+ Error(ERR_INFO, "fallback done to 'char_exclam' for this graphic");
+ Error(ERR_INFO_LINE, "-");
graphic_info[i] = graphic_info[fallback_graphic];
}
src_x + width > src_bitmap_width ||
src_y + height > src_bitmap_height)
{
- Error(ERR_RETURN_LINE, "-");
- Error(ERR_RETURN, "warning: error found in config file:");
- Error(ERR_RETURN, "- config file: '%s'", getImageConfigFilename());
- Error(ERR_RETURN, "- config token: '%s'", getTokenFromImageID(i));
- Error(ERR_RETURN, "- image file: '%s'", src_bitmap->source_filename);
- Error(ERR_RETURN,
+ Error(ERR_INFO_LINE, "-");
+ Error(ERR_INFO, "warning: error found in config file:");
+ Error(ERR_INFO, "- config file: '%s'", getImageConfigFilename());
+ Error(ERR_INFO, "- config token: '%s'", getTokenFromImageID(i));
+ Error(ERR_INFO, "- image file: '%s'", src_bitmap->source_filename);
+ Error(ERR_INFO,
"error: last animation frame (%d) out of bounds (%d, %d) [%d, %d]",
last_frame, src_x, src_y, src_bitmap_width, src_bitmap_height);
- Error(ERR_RETURN, "custom graphic rejected for this element/action");
+ Error(ERR_INFO, "custom graphic rejected for this element/action");
if (i == fallback_graphic)
Error(ERR_EXIT, "fatal error: no fallback graphic available");
- Error(ERR_RETURN, "fallback done to 'char_exclam' for this graphic");
- Error(ERR_RETURN_LINE, "-");
+ Error(ERR_INFO, "fallback done to 'char_exclam' for this graphic");
+ Error(ERR_INFO_LINE, "-");
graphic_info[i] = graphic_info[fallback_graphic];
}
if (!private_cmap)
{
if (options.verbose)
- Error(ERR_RETURN, "switching to private colormap");
+ Error(ERR_INFO, "switching to private colormap");
/* we just filled up the default colormap -- get a private one
which contains all already allocated colors */
break;
default:
- Error(ERR_RETURN,"DirectColor, TrueColor or PseudoColor display needed");
+ Error(ERR_INFO,"DirectColor, TrueColor or PseudoColor display needed");
SetError(error, "display class not supported");
return NULL;
}
default:
- Error(ERR_RETURN, "RGB or TrueColor image needed");
+ Error(ERR_INFO, "RGB or TrueColor image needed");
SetError(error, "image type not supported");
return NULL;
}
default:
- Error(ERR_RETURN,"DirectColor, TrueColor or PseudoColor display needed");
+ Error(ERR_INFO,"DirectColor, TrueColor or PseudoColor display needed");
SetError(error, "display class not supported");
return NULL;
if (mode & ERR_WARN && !options.verbose)
return;
- if (mode == ERR_RETURN_LINE)
+ if (mode == ERR_INFO_LINE)
{
if (!last_line_was_separator)
fprintf_line(program.error_file, format, 79);
!strEqual(&config_list[i].value[len_config_value - 4], ".wav") &&
!strEqual(config_list[i].value, UNDEFINED_FILENAME))
{
- Error(ERR_RETURN, "Configuration directive '%s' -> '%s':",
+ Error(ERR_INFO, "Configuration directive '%s' -> '%s':",
config_list[i].token, config_list[i].value);
Error(ERR_EXIT, "This seems to be no valid definition -- please fix");
}
num_file_list_entries_found = list_pos + 1;
if (num_file_list_entries_found != num_file_list_entries)
{
- Error(ERR_RETURN_LINE, "-");
- Error(ERR_RETURN, "inconsistant config list information:");
- Error(ERR_RETURN, "- should be: %d (according to 'src/conf_xxx.h')",
+ Error(ERR_INFO_LINE, "-");
+ Error(ERR_INFO, "inconsistant config list information:");
+ Error(ERR_INFO, "- should be: %d (according to 'src/conf_xxx.h')",
num_file_list_entries);
- Error(ERR_RETURN, "- found to be: %d (according to 'src/conf_xxx.c')",
+ Error(ERR_INFO, "- found to be: %d (according to 'src/conf_xxx.c')",
num_file_list_entries_found);
Error(ERR_EXIT, "please fix");
}
if (options.debug && dynamic_tokens_found)
{
- Error(ERR_RETURN_LINE, "-");
- Error(ERR_RETURN, "dynamic token(s) found in config file:");
- Error(ERR_RETURN, "- config file: '%s'", filename);
+ Error(ERR_INFO_LINE, "-");
+ Error(ERR_INFO, "dynamic token(s) found in config file:");
+ Error(ERR_INFO, "- config file: '%s'", filename);
for (list = setup_file_list; list != NULL; list = list->next)
{
char *value = getHashEntry(extra_file_hash, list->token);
if (value != NULL && strEqual(value, known_token_value))
- Error(ERR_RETURN, "- dynamic token: '%s'", list->token);
+ Error(ERR_INFO, "- dynamic token: '%s'", list->token);
}
- Error(ERR_RETURN_LINE, "-");
+ Error(ERR_INFO_LINE, "-");
}
if (unknown_tokens_found)
{
- Error(ERR_RETURN_LINE, "-");
- Error(ERR_RETURN, "warning: unknown token(s) found in config file:");
- Error(ERR_RETURN, "- config file: '%s'", filename);
+ Error(ERR_INFO_LINE, "-");
+ Error(ERR_INFO, "warning: unknown token(s) found in config file:");
+ Error(ERR_INFO, "- config file: '%s'", filename);
for (list = setup_file_list; list != NULL; list = list->next)
{
char *value = getHashEntry(extra_file_hash, list->token);
if (value != NULL && !strEqual(value, known_token_value))
- Error(ERR_RETURN, "- dynamic token: '%s'", list->token);
+ Error(ERR_INFO, "- dynamic token: '%s'", list->token);
}
- Error(ERR_RETURN_LINE, "-");
+ Error(ERR_INFO_LINE, "-");
}
if (undefined_values_found)
{
- Error(ERR_RETURN_LINE, "-");
- Error(ERR_RETURN, "warning: undefined values found in config file:");
- Error(ERR_RETURN, "- config file: '%s'", filename);
+ Error(ERR_INFO_LINE, "-");
+ Error(ERR_INFO, "warning: undefined values found in config file:");
+ Error(ERR_INFO, "- config file: '%s'", filename);
for (list = setup_file_list; list != NULL; list = list->next)
{
char *value = getHashEntry(empty_file_hash, list->token);
if (value != NULL)
- Error(ERR_RETURN, "- undefined value for token: '%s'", list->token);
+ Error(ERR_INFO, "- undefined value for token: '%s'", list->token);
}
- Error(ERR_RETURN_LINE, "-");
+ Error(ERR_INFO_LINE, "-");
}
freeSetupFileList(setup_file_list);
#define GetSimpleRandom(max) get_random_number(RANDOM_SIMPLE, max)
/* values for Error() */
-#define ERR_RETURN 0
-#define ERR_RETURN_LINE (1 << 0)
+#define ERR_INFO 0
+#define ERR_INFO_LINE (1 << 0)
#define ERR_WARN (1 << 1)
#define ERR_EXIT (1 << 2)
#define ERR_HELP (1 << 3)
#define ALLOW_TOKEN_VALUE_SEPARATOR_BEING_WHITESPACE 1
#define CHECK_TOKEN_VALUE_SEPARATOR__WARN_IF_MISSING 0
-static void *loadSetupFileData(char *filename, boolean use_hash)
+static void loadSetupFileData(void *setup_file_data, char *filename,
+ boolean top_recursion_level, boolean is_hash)
{
+ static SetupFileHash *include_filename_hash = NULL;
char line[MAX_LINE_LEN], line_raw[MAX_LINE_LEN], previous_line[MAX_LINE_LEN];
char *token, *value, *line_ptr;
- void *setup_file_data, *insert_ptr = NULL;
+ void *insert_ptr = NULL;
boolean read_continued_line = FALSE;
boolean token_value_separator_found;
#if CHECK_TOKEN_VALUE_SEPARATOR__WARN_IF_MISSING
#endif
FILE *file;
int line_nr = 0;
+ int token_count = 0;
if (!(file = fopen(filename, MODE_READ)))
{
Error(ERR_WARN, "cannot open configuration file '%s'", filename);
- return NULL;
+ return;
}
- if (use_hash)
- setup_file_data = newSetupFileHash();
- else
- insert_ptr = setup_file_data = newSetupFileList("", "");
+ /* use "insert pointer" to store list end for constant insertion complexity */
+ if (!is_hash)
+ insert_ptr = setup_file_data;
+
+ /* on top invocation, create hash to mark included files (to prevent loops) */
+ if (top_recursion_level)
+ include_filename_hash = newSetupFileHash();
+
+ /* mark this file as already included (to prevent including it again) */
+ setHashEntry(include_filename_hash, getBaseNamePtr(filename), "true");
while (!feof(file))
{
{
if (!token_value_separator_warning)
{
- Error(ERR_RETURN_LINE, "-");
+ Error(ERR_INFO_LINE, "-");
Error(ERR_WARN, "missing token/value separator(s) in config file:");
- Error(ERR_RETURN, "- config file: '%s'", filename);
+ Error(ERR_INFO, "- config file: '%s'", filename);
token_value_separator_warning = TRUE;
}
- Error(ERR_RETURN, "- line %d: '%s'", line_nr, line_raw);
+ Error(ERR_INFO, "- line %d: '%s'", line_nr, line_raw);
}
#endif
}
if (*token)
{
- if (use_hash)
- setHashEntry((SetupFileHash *)setup_file_data, token, value);
+ if (strEqual(token, "include"))
+ {
+ if (getHashEntry(include_filename_hash, value) == NULL)
+ {
+ char *basepath = getBasePath(filename);
+ char *basename = getBaseName(value);
+ char *filename_include = getPath2(basepath, basename);
+
+#if 0
+ Error(ERR_INFO, "[including file '%s']", filename_include);
+#endif
+
+ loadSetupFileData(setup_file_data, filename_include, FALSE, is_hash);
+
+ free(basepath);
+ free(basename);
+ free(filename_include);
+ }
+ else
+ {
+ Error(ERR_WARN, "ignoring already processed file '%s'", value);
+ }
+ }
else
- insert_ptr = addListEntry((SetupFileList *)insert_ptr, token, value);
+ {
+ if (is_hash)
+ setHashEntry((SetupFileHash *)setup_file_data, token, value);
+ else
+ insert_ptr = addListEntry((SetupFileList *)insert_ptr, token, value);
+
+ token_count++;
+ }
}
}
#if CHECK_TOKEN_VALUE_SEPARATOR__WARN_IF_MISSING
if (token_value_separator_warning)
- Error(ERR_RETURN_LINE, "-");
+ Error(ERR_INFO_LINE, "-");
#endif
- if (use_hash)
- {
- if (hashtable_count((SetupFileHash *)setup_file_data) == 0)
- Error(ERR_WARN, "configuration file '%s' is empty", filename);
- }
- else
- {
- SetupFileList *setup_file_list = (SetupFileList *)setup_file_data;
- SetupFileList *first_valid_list_entry = setup_file_list->next;
-
- /* free empty list header */
- setup_file_list->next = NULL;
- freeSetupFileList(setup_file_list);
- setup_file_data = first_valid_list_entry;
+ if (token_count == 0)
+ Error(ERR_WARN, "configuration file '%s' is empty", filename);
- if (first_valid_list_entry == NULL)
- Error(ERR_WARN, "configuration file '%s' is empty", filename);
- }
-
- return setup_file_data;
+ if (top_recursion_level)
+ freeSetupFileHash(include_filename_hash);
}
void saveSetupFileHash(SetupFileHash *hash, char *filename)
SetupFileList *loadSetupFileList(char *filename)
{
- return (SetupFileList *)loadSetupFileData(filename, FALSE);
+ SetupFileList *setup_file_list = newSetupFileList("", "");
+ SetupFileList *first_valid_list_entry;
+
+ loadSetupFileData(setup_file_list, filename, TRUE, FALSE);
+
+ first_valid_list_entry = setup_file_list->next;
+
+ /* free empty list header */
+ setup_file_list->next = NULL;
+ freeSetupFileList(setup_file_list);
+
+ return first_valid_list_entry;
}
SetupFileHash *loadSetupFileHash(char *filename)
{
- return (SetupFileHash *)loadSetupFileData(filename, TRUE);
+ SetupFileHash *setup_file_hash = newSetupFileHash();
+
+ loadSetupFileData(setup_file_hash, filename, TRUE, TRUE);
+
+ return setup_file_hash;
}
void checkSetupFileHashIdentifier(SetupFileHash *setup_file_hash,
{
if (!mixer[i].active)
{
- Error(ERR_RETURN, "Mixer_InsertSound: Channel %d inactive", i);
- Error(ERR_RETURN, "Mixer_InsertSound: This should never happen!");
+ Error(ERR_INFO, "Mixer_InsertSound: Channel %d inactive", i);
+ Error(ERR_INFO, "Mixer_InsertSound: This should never happen!");
mixer_active_channels--;
}
/* print some debugging information about audio channel usage */
for (i = audio.first_sound_channel; i < audio.num_channels; i++)
{
- Error(ERR_RETURN, "Mixer_InsertSound: %d [%d]: %ld (%ld)",
+ Error(ERR_INFO, "Mixer_InsertSound: %d [%d]: %ld (%ld)",
i, mixer[i].active, mixer[i].data_len, (long)mixer[i].data_ptr);
}
#endif
if (server_frame_counter != FrameCounter)
{
- Error(ERR_RETURN, "client and servers frame counters out of sync");
- Error(ERR_RETURN, "frame counter of client is %d", FrameCounter);
- Error(ERR_RETURN, "frame counter of server is %d", server_frame_counter);
- Error(ERR_RETURN, "this should not happen -- please debug");
+ Error(ERR_INFO, "client and servers frame counters out of sync");
+ Error(ERR_INFO, "frame counter of client is %d", FrameCounter);
+ Error(ERR_INFO, "frame counter of server is %d", server_frame_counter);
+ Error(ERR_INFO, "this should not happen -- please debug");
stop_network_game = TRUE;
}
void getGraphicSourceObjectExt_EM(int tile, int frame_em,
- Bitmap **src_bitmap, int *src_x, int *src_y)
+ Bitmap **src_bitmap, int *src_x, int *src_y,
+ int x, int y)
{
int element = object_mapping[tile].element_rnd;
int action = object_mapping[tile].action;
else
sync_frame = 7 - frame_em;
+ SetRandomAnimationValue(x, y);
+
int frame = getAnimationFrame(g->anim_frames,
g->anim_delay,
g->anim_mode,