#include "network.h"
#include "netserv.h"
#include "cartoons.h"
-#include "config.h"
#include "conf_e2g.c" /* include auto-generated data structure definitions */
#include "conf_esg.c" /* include auto-generated data structure definitions */
#include "conf_e2s.c" /* include auto-generated data structure definitions */
#include "conf_fnt.c" /* include auto-generated data structure definitions */
-#define CONFIG_TOKEN_FONT_INITIAL "font.initial"
-
-struct FontBitmapInfo font_initial[NUM_INITIAL_FONTS];
-
-static void InitGlobal();
-static void InitSetup();
-static void InitPlayerInfo();
-static void InitLevelInfo();
-static void InitArtworkInfo();
-static void InitLevelArtworkInfo();
-static void InitNetworkServer();
-static void InitArtworkConfig();
-static void InitImages();
-static void InitMixer();
-static void InitSound();
-static void InitMusic();
-static void InitGfx();
-static void InitGfxBackground();
-static void InitGadgets();
-static void InitFontGraphicInfo();
-static void InitElementSmallImages();
-static void InitElementGraphicInfo();
-static void InitElementSpecialGraphicInfo();
-static void InitElementSoundInfo();
-static void InitElementProperties();
-static void InitGraphicInfo();
-static void InitSoundInfo();
-static void Execute_Command(char *);
-
-void OpenAll()
-{
- InitGlobal(); /* initialize some global variables */
-
- if (options.execute_command)
- Execute_Command(options.execute_command);
-
- if (options.serveronly)
- {
-#if defined(PLATFORM_UNIX)
- NetworkServer(options.server_port, options.serveronly);
-#else
- Error(ERR_WARN, "networking only supported in Unix version");
-#endif
- exit(0); /* never reached */
- }
-
- InitProgramInfo(UNIX_USERDATA_DIRECTORY,
- PROGRAM_TITLE_STRING, getWindowTitleString(),
- ICON_TITLE_STRING, X11_ICON_FILENAME, X11_ICONMASK_FILENAME,
- MSDOS_POINTER_FILENAME,
- COOKIE_PREFIX, FILENAME_PREFIX, GAME_VERSION_ACTUAL);
-
- InitSetup();
- InitPlayerInfo();
- InitArtworkInfo(); /* needed before loading gfx, sound & music */
- InitArtworkConfig(); /* needed before forking sound child process */
- InitMixer();
-
- InitCounter();
-
- InitJoysticks();
- InitRND(NEW_RANDOMIZE);
-
- InitVideoDisplay();
- InitVideoBuffer(&backbuffer, &window, WIN_XSIZE, WIN_YSIZE, DEFAULT_DEPTH,
- setup.fullscreen);
-
- InitEventFilter(FilterMouseMotionEvents);
-
- InitElementProperties();
-
- InitGfx();
-
- InitLevelInfo();
- InitLevelArtworkInfo();
-
- InitImages(); /* needs to know current level directory */
- InitSound(); /* needs to know current level directory */
- InitMusic(); /* needs to know current level directory */
-
- InitGfxBackground();
-
- if (global.autoplay_leveldir)
- {
- AutoPlayTape();
- return;
- }
-
- game_status = MAINMENU;
-
- DrawMainMenu();
-
- InitNetworkServer();
-}
-
-static void InitGlobal()
-{
- global.autoplay_leveldir = NULL;
-
- global.frames_per_second = 0;
- global.fps_slowdown = FALSE;
- global.fps_slowdown_factor = 1;
-}
-
-static void InitSetup()
-{
- LoadSetup(); /* global setup info */
-}
-
-static void InitPlayerInfo()
-{
- int i;
-
- /* choose default local player */
- local_player = &stored_player[0];
-
- for (i=0; i<MAX_PLAYERS; i++)
- stored_player[i].connected = FALSE;
-
- local_player->connected = TRUE;
-}
-
-static void InitLevelInfo()
-{
- LoadLevelInfo(); /* global level info */
- LoadLevelSetup_LastSeries(); /* last played series info */
- LoadLevelSetup_SeriesInfo(); /* last played level info */
-}
-
-static void InitArtworkInfo()
-{
- LoadArtworkInfo();
-}
-
-static char *get_element_class_token(int element)
-{
- char *element_class_name = element_info[element].class_name;
- char *element_class_token = checked_malloc(strlen(element_class_name) + 3);
-
- sprintf(element_class_token, "[%s]", element_class_name);
-
- return element_class_token;
-}
-
-static void InitArtworkConfig()
-{
- static char *image_id_prefix[MAX_NUM_ELEMENTS + NUM_FONTS + 1];
- static char *sound_id_prefix[MAX_NUM_ELEMENTS + MAX_NUM_ELEMENTS + 1];
- static char *action_id_suffix[NUM_ACTIONS + 1];
- static char *direction_id_suffix[NUM_DIRECTIONS + 1];
- static char *special_id_suffix[NUM_SPECIAL_GFX_ARGS + 1];
- static char *dummy[1] = { NULL };
- static char *ignore_image_tokens[] =
- {
- "name",
- "sort_priority",
- "global.num_toons",
- NULL
- };
- static char *ignore_sound_tokens[] =
- {
- "name",
- "sort_priority",
- NULL
- };
- int i;
-
- for (i=0; i<MAX_NUM_ELEMENTS; i++)
- image_id_prefix[i] = element_info[i].token_name;
- for (i=0; i<NUM_FONTS; i++)
- image_id_prefix[MAX_NUM_ELEMENTS + i] = font_info[i].token_name;
- image_id_prefix[MAX_NUM_ELEMENTS + NUM_FONTS] = NULL;
-
- for (i=0; i<MAX_NUM_ELEMENTS; i++)
- sound_id_prefix[i] = element_info[i].token_name;
- for (i=0; i<MAX_NUM_ELEMENTS; i++)
- sound_id_prefix[MAX_NUM_ELEMENTS + i] = get_element_class_token(i);
- sound_id_prefix[MAX_NUM_ELEMENTS + MAX_NUM_ELEMENTS] = NULL;
-
- for (i=0; i<NUM_ACTIONS; i++)
- action_id_suffix[i] = element_action_info[i].suffix;
- action_id_suffix[NUM_ACTIONS] = NULL;
-
- for (i=0; i<NUM_DIRECTIONS; i++)
- direction_id_suffix[i] = element_direction_info[i].suffix;
- direction_id_suffix[NUM_DIRECTIONS] = NULL;
-
- for (i=0; i<NUM_SPECIAL_GFX_ARGS; i++)
- special_id_suffix[i] = special_suffix_info[i].suffix;
- special_id_suffix[NUM_SPECIAL_GFX_ARGS] = NULL;
-
- InitImageList(image_config, NUM_IMAGE_FILES, image_config_suffix,
- image_id_prefix, action_id_suffix, direction_id_suffix,
- special_id_suffix, ignore_image_tokens);
- InitSoundList(sound_config, NUM_SOUND_FILES, sound_config_suffix,
- sound_id_prefix, action_id_suffix, dummy,
- dummy, ignore_sound_tokens);
-}
-
-void InitLevelArtworkInfo()
-{
- LoadLevelArtworkInfo();
-}
-
-void InitNetworkServer()
-{
-#if defined(PLATFORM_UNIX)
- int nr_wanted;
-#endif
-
- if (!options.network)
- return;
-
-#if defined(PLATFORM_UNIX)
- nr_wanted = Request("Choose player", REQ_PLAYER | REQ_STAY_CLOSED);
-
- if (!ConnectToServer(options.server_host, options.server_port))
- Error(ERR_EXIT, "cannot connect to network game server");
-
- SendToServer_PlayerName(setup.player_name);
- SendToServer_ProtocolVersion();
-
- if (nr_wanted)
- SendToServer_NrWanted(nr_wanted);
-#endif
-}
-
-static void InitMixer()
-{
- OpenAudio();
- StartMixer();
-}
-
-static void ReinitializeGraphics()
-{
- InitElementGraphicInfo(); /* element game graphic mapping */
- InitElementSpecialGraphicInfo(); /* element special graphic mapping */
- InitGraphicInfo(); /* graphic properties mapping */
-
- InitElementSmallImages(); /* create editor and preview images */
- InitFontGraphicInfo(); /* initialize text drawing functions */
-
- SetMainBackgroundImage(IMG_BACKGROUND);
- SetDoorBackgroundImage(IMG_BACKGROUND_DOOR);
-
- InitGadgets();
- InitToons();
-}
-
-static void ReinitializeSounds()
-{
- InitElementSoundInfo(); /* element game sound mapping */
- InitSoundInfo(); /* sound properties mapping */
-
-#if 1
- InitElementSoundInfo(); /* element game sound mapping */
-#endif
-
- InitPlaySoundLevel(); /* internal game sound settings */
-}
-
-static void ReinitializeMusic()
-{
- /* currently nothing to do */
-}
-
-static void InitImages()
-{
- ReloadCustomImages();
- LoadCustomElementDescriptions();
- LoadSpecialMenuDesignSettings();
+#define CONFIG_TOKEN_FONT_INITIAL "font.initial"
- ReinitializeGraphics();
-}
-static void InitSound()
-{
- InitReloadCustomSounds(artwork.snd_current->identifier);
- ReinitializeSounds();
-}
+struct FontBitmapInfo font_initial[NUM_INITIAL_FONTS];
-static void InitMusic()
-{
- InitReloadCustomMusic(artwork.mus_current->identifier);
- ReinitializeMusic();
-}
static void InitTileClipmasks()
{
#endif
}
-void InitGfx()
-{
- char *filename_font_initial = NULL;
- Bitmap *bitmap_font_initial = NULL;
- int i, j;
-
- /* determine settings for initial font (for displaying startup messages) */
- for (i=0; image_config[i].token != NULL; i++)
- {
- for (j=0; j < NUM_INITIAL_FONTS; j++)
- {
- char font_token[128];
- int len_font_token;
-
- sprintf(font_token, "%s_%d", CONFIG_TOKEN_FONT_INITIAL, j + 1);
- len_font_token = strlen(font_token);
-
- if (strcmp(image_config[i].token, font_token) == 0)
- filename_font_initial = image_config[i].value;
- else if (strlen(image_config[i].token) > len_font_token &&
- strncmp(image_config[i].token, font_token, len_font_token) == 0)
- {
- if (strcmp(&image_config[i].token[len_font_token], ".x") == 0)
- font_initial[j].src_x = atoi(image_config[i].value);
- else if (strcmp(&image_config[i].token[len_font_token], ".y") == 0)
- font_initial[j].src_y = atoi(image_config[i].value);
- else if (strcmp(&image_config[i].token[len_font_token], ".width") == 0)
- font_initial[j].width = atoi(image_config[i].value);
- else if (strcmp(&image_config[i].token[len_font_token],".height") == 0)
- font_initial[j].height = atoi(image_config[i].value);
- }
- }
- }
-
- if (filename_font_initial == NULL) /* should not happen */
- Error(ERR_EXIT, "cannot get filename for '%s'", CONFIG_TOKEN_FONT_INITIAL);
-
- /* initialize screen properties */
- InitGfxFieldInfo(SX, SY, SXSIZE, SYSIZE,
- REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE);
- InitGfxDoor1Info(DX, DY, DXSIZE, DYSIZE);
- InitGfxDoor2Info(VX, VY, VXSIZE, VYSIZE);
- InitGfxScrollbufferInfo(FXSIZE, FYSIZE);
-
- /* create additional image buffers for double-buffering */
- bitmap_db_field = CreateBitmap(FXSIZE, FYSIZE, DEFAULT_DEPTH);
- bitmap_db_door = CreateBitmap(3 * DXSIZE, DYSIZE + VYSIZE, DEFAULT_DEPTH);
-
- bitmap_font_initial = LoadCustomImage(filename_font_initial);
-
- for (j=0; j < NUM_INITIAL_FONTS; j++)
- font_initial[j].bitmap = bitmap_font_initial;
-
- InitFontGraphicInfo();
-
- DrawInitText(WINDOW_TITLE_STRING, 20, FC_YELLOW);
- DrawInitText(WINDOW_SUBTITLE_STRING, 50, FC_RED);
-
- DrawInitText("Loading graphics:", 120, FC_GREEN);
-
- InitTileClipmasks();
-}
-
-void InitGfxBackground()
-{
- int x, y;
-
- drawto = backbuffer;
- fieldbuffer = bitmap_db_field;
- SetDrawtoField(DRAW_BACKBUFFER);
-
- BlitBitmap(graphic_info[IMG_GLOBAL_BORDER].bitmap, backbuffer,
- 0, 0, WIN_XSIZE, WIN_YSIZE, 0, 0);
- ClearRectangle(backbuffer, REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE);
- ClearRectangle(bitmap_db_door, 0, 0, 3 * DXSIZE, DYSIZE + VYSIZE);
-
- for (x=0; x<MAX_BUF_XSIZE; x++)
- for (y=0; y<MAX_BUF_YSIZE; y++)
- redraw[x][y] = 0;
- redraw_tiles = 0;
- redraw_mask = REDRAW_ALL;
-}
-
-void ReloadCustomArtwork()
-{
- static char *leveldir_current_identifier = NULL;
- static boolean last_override_level_graphics = FALSE;
- static boolean last_override_level_sounds = FALSE;
- static boolean last_override_level_music = FALSE;
- /* identifier for new artwork; default: artwork configured in setup */
- char *gfx_new_identifier = artwork.gfx_current->identifier;
- char *snd_new_identifier = artwork.snd_current->identifier;
- char *mus_new_identifier = artwork.mus_current->identifier;
- boolean redraw_screen = FALSE;
-
- if (leveldir_current_identifier == NULL)
- leveldir_current_identifier = leveldir_current->identifier;
-
-#if 0
- printf("CURRENT GFX: '%s' ['%s']\n", artwork.gfx_current->identifier,
- leveldir_current->graphics_set);
- printf("CURRENT LEV: '%s' / '%s'\n", leveldir_current_identifier,
- leveldir_current->identifier);
-#endif
-
-#if 0
- printf("graphics --> '%s' ('%s')\n",
- artwork.gfx_current_identifier, artwork.gfx_current->filename);
- printf("sounds --> '%s' ('%s')\n",
- artwork.snd_current_identifier, artwork.snd_current->filename);
- printf("music --> '%s' ('%s')\n",
- artwork.mus_current_identifier, artwork.mus_current->filename);
-#endif
-
- /* leveldir_current may be invalid (level group, parent link) */
- if (!validLevelSeries(leveldir_current))
- return;
-
- /* when a new level series was selected, check if there was a change
- in custom artwork stored in level series directory */
- if (leveldir_current_identifier != leveldir_current->identifier)
- {
- char *identifier_old = leveldir_current_identifier;
- char *identifier_new = leveldir_current->identifier;
-
- if (getTreeInfoFromIdentifier(artwork.gfx_first, identifier_old) !=
- getTreeInfoFromIdentifier(artwork.gfx_first, identifier_new))
- gfx_new_identifier = identifier_new;
- if (getTreeInfoFromIdentifier(artwork.snd_first, identifier_old) !=
- getTreeInfoFromIdentifier(artwork.snd_first, identifier_new))
- snd_new_identifier = identifier_new;
- if (getTreeInfoFromIdentifier(artwork.mus_first, identifier_new) !=
- getTreeInfoFromIdentifier(artwork.mus_first, identifier_new))
- mus_new_identifier = identifier_new;
-
- leveldir_current_identifier = leveldir_current->identifier;
- }
-
- /* custom level artwork configured in level series configuration file
- always overrides custom level artwork stored in level series directory
- and (level independant) custom artwork configured in setup menue */
- if (leveldir_current->graphics_set != NULL)
- gfx_new_identifier = leveldir_current->graphics_set;
- if (leveldir_current->sounds_set != NULL)
- snd_new_identifier = leveldir_current->sounds_set;
- if (leveldir_current->music_set != NULL)
- mus_new_identifier = leveldir_current->music_set;
-
- if (strcmp(artwork.gfx_current_identifier, gfx_new_identifier) != 0 ||
- last_override_level_graphics != setup.override_level_graphics)
- {
-#if 0
- printf("RELOADING GRAPHICS '%s' -> '%s' ('%s')\n",
- artwork.gfx_current_identifier,
- artwork.gfx_current->identifier,
- gfx_new_identifier);
-#endif
-
- setLevelArtworkDir(artwork.gfx_first);
-
- ClearRectangle(window, 0, 0, WIN_XSIZE, WIN_YSIZE);
-
- InitImages();
-
- FreeTileClipmasks();
- InitTileClipmasks();
-
- artwork.gfx_current_identifier = artwork.gfx_current->identifier;
- last_override_level_graphics = setup.override_level_graphics;
-
- redraw_screen = TRUE;
- }
-
- if (strcmp(artwork.snd_current_identifier, snd_new_identifier) != 0 ||
- last_override_level_sounds != setup.override_level_sounds)
- {
-#if 0
- printf("RELOADING SOUNDS '%s' -> '%s' ('%s')\n",
- artwork.snd_current_identifier,
- artwork.snd_current->identifier,
- snd_new_identifier);
-#endif
-
- /* set artwork path to send it to the sound server process */
- setLevelArtworkDir(artwork.snd_first);
-
- InitReloadCustomSounds(snd_new_identifier);
- ReinitializeSounds();
-
- artwork.snd_current_identifier = artwork.snd_current->identifier;
- last_override_level_sounds = setup.override_level_sounds;
-
- redraw_screen = TRUE;
- }
-
- if (strcmp(artwork.mus_current_identifier, mus_new_identifier) != 0 ||
- last_override_level_music != setup.override_level_music)
- {
- /* set artwork path to send it to the sound server process */
- setLevelArtworkDir(artwork.mus_first);
-
- InitReloadCustomMusic(mus_new_identifier);
- ReinitializeMusic();
-
- artwork.mus_current_identifier = artwork.mus_current->identifier;
- last_override_level_music = setup.override_level_music;
-
- redraw_screen = TRUE;
- }
-
- if (redraw_screen)
- {
- InitGfxBackground();
-
- /* force redraw of (open or closed) door graphics */
- SetDoorState(DOOR_OPEN_ALL);
- CloseDoor(DOOR_CLOSE_ALL | DOOR_NO_DELAY);
- }
-}
-
void FreeGadgets()
{
FreeLevelEditorGadgets();
int font_bitmap_id = font_info[i].special_bitmap_id[j];
int graphic = font_info[i].special_graphic[j];
+ /* set 'graphic_info' for font entries, if uninitialized (guessed) */
+ if (graphic_info[graphic].anim_frames < MIN_NUM_CHARS_PER_FONT)
+ {
+ graphic_info[graphic].anim_frames = DEFAULT_NUM_CHARS_PER_FONT;
+ graphic_info[graphic].anim_frames_per_line= DEFAULT_NUM_CHARS_PER_LINE;
+ }
+
/* copy font relevant information from graphics information */
font_bitmap_info[font_bitmap_id].bitmap = graphic_info[graphic].bitmap;
font_bitmap_info[font_bitmap_id].src_x = graphic_info[graphic].src_x;
font_bitmap_info[font_bitmap_id].height = graphic_info[graphic].height;
font_bitmap_info[font_bitmap_id].draw_x = graphic_info[graphic].draw_x;
font_bitmap_info[font_bitmap_id].draw_y = graphic_info[graphic].draw_y;
+
+ font_bitmap_info[font_bitmap_id].num_chars =
+ graphic_info[graphic].anim_frames;
+ font_bitmap_info[font_bitmap_id].num_chars_per_line =
+ graphic_info[graphic].anim_frames_per_line;
}
}
int direction = element_to_graphic[i].direction;
int graphic = element_to_graphic[i].graphic;
+ if (graphic_info[graphic].bitmap == NULL)
+ continue;
+
if (action < 0)
action = ACTION_DEFAULT;
int special = property_mapping[i].ext3_index;
int graphic = property_mapping[i].artwork_index;
+ if (graphic_info[graphic].bitmap == NULL)
+ continue;
+
if (element >= MAX_NUM_ELEMENTS || special != -1)
continue;
for (act=0; act<NUM_ACTIONS; act++)
{
+ boolean act_empty = (act == ACTION_DIGGING ||
+ act == ACTION_SNAPPING ||
+ act == ACTION_COLLECTING);
+
for (dir=0; dir<NUM_DIRECTIONS; dir++)
{
int default_direction_graphic = element_info[i].graphic[act];
/* no graphic for current action -- use default direction graphic */
if (default_direction_graphic == -1)
- default_direction_graphic = default_action_direction_graphic[dir];
+ default_direction_graphic =
+ (act_empty ? IMG_EMPTY : default_action_direction_graphic[dir]);
if (element_info[i].direction_graphic[act][dir] == -1)
element_info[i].direction_graphic[act][dir] =
/* no graphic for this specific action -- use default action graphic */
if (element_info[i].graphic[act] == -1)
- element_info[i].graphic[act] = default_action_graphic;
+ element_info[i].graphic[act] =
+ (act_empty ? IMG_EMPTY : default_action_graphic);
}
}
static void set_graphic_parameters(int graphic, char **parameter_raw)
{
Bitmap *src_bitmap = getBitmapFromImageID(graphic);
- int num_xtiles = (src_bitmap ? src_bitmap->width : TILEX) / TILEX;
- int num_ytiles = (src_bitmap ? src_bitmap->height * 2 / 3 : TILEY) / TILEY;
int parameter[NUM_GFX_ARGS];
+ int anim_frames_per_row = 1, anim_frames_per_col = 1;
+ int anim_frames_per_line = 1;
int i;
/* get integer values from string parameters */
if (parameter[GFX_ARG_HEIGHT] != ARG_UNDEFINED_VALUE)
graphic_info[graphic].height = parameter[GFX_ARG_HEIGHT];
+ if (src_bitmap)
+ {
+ anim_frames_per_row = src_bitmap->width / graphic_info[graphic].width;
+ anim_frames_per_col = src_bitmap->height / graphic_info[graphic].height;
+ }
+
/* correct x or y offset dependant of vertical or horizontal frame order */
if (parameter[GFX_ARG_VERTICAL]) /* frames are ordered vertically */
{
- if (parameter[GFX_ARG_OFFSET] != ARG_UNDEFINED_VALUE)
- graphic_info[graphic].offset_y = parameter[GFX_ARG_OFFSET];
- else
- graphic_info[graphic].offset_y = graphic_info[graphic].height;
+ graphic_info[graphic].offset_y =
+ (parameter[GFX_ARG_OFFSET] != ARG_UNDEFINED_VALUE ?
+ parameter[GFX_ARG_OFFSET] : graphic_info[graphic].height);
+ anim_frames_per_line = anim_frames_per_col;
}
else /* frames are ordered horizontally */
{
- if (parameter[GFX_ARG_OFFSET] != ARG_UNDEFINED_VALUE)
- graphic_info[graphic].offset_x = parameter[GFX_ARG_OFFSET];
- else
- graphic_info[graphic].offset_x = graphic_info[graphic].width;
+ graphic_info[graphic].offset_x =
+ (parameter[GFX_ARG_OFFSET] != ARG_UNDEFINED_VALUE ?
+ parameter[GFX_ARG_OFFSET] : graphic_info[graphic].width);
+ anim_frames_per_line = anim_frames_per_row;
}
/* optionally, the x and y offset of frames can be specified directly */
if (parameter[GFX_ARG_FRAMES] != ARG_UNDEFINED_VALUE)
graphic_info[graphic].anim_frames = parameter[GFX_ARG_FRAMES];
else if (parameter[GFX_ARG_XPOS] == 0 && !parameter[GFX_ARG_VERTICAL])
- graphic_info[graphic].anim_frames = num_xtiles;
+ graphic_info[graphic].anim_frames = anim_frames_per_row;
else if (parameter[GFX_ARG_YPOS] == 0 && parameter[GFX_ARG_VERTICAL])
- graphic_info[graphic].anim_frames = num_ytiles;
+ graphic_info[graphic].anim_frames = anim_frames_per_col;
else
graphic_info[graphic].anim_frames = 1;
+ graphic_info[graphic].anim_frames_per_line =
+ (parameter[GFX_ARG_FRAMES_PER_LINE] != ARG_UNDEFINED_VALUE ?
+ parameter[GFX_ARG_FRAMES_PER_LINE] : anim_frames_per_line);
+
graphic_info[graphic].anim_delay = parameter[GFX_ARG_DELAY];
if (graphic_info[graphic].anim_delay == 0) /* delay must be at least 1 */
graphic_info[graphic].anim_delay = 1;
- if (parameter[GFX_ARG_ANIM_MODE] != ANIM_NONE)
- graphic_info[graphic].anim_mode = parameter[GFX_ARG_ANIM_MODE];
- else if (graphic_info[graphic].anim_frames > 1)
- graphic_info[graphic].anim_mode = ANIM_LOOP;
+ graphic_info[graphic].anim_mode = parameter[GFX_ARG_ANIM_MODE];
+ if (graphic_info[graphic].anim_frames == 1)
+ graphic_info[graphic].anim_mode = ANIM_NONE;
/* automatically determine correct start frame, if not defined */
if (parameter[GFX_ARG_START_FRAME] == ARG_UNDEFINED_VALUE)
#endif
}
-void InitElementProperties()
+static void ReinitializeGraphics()
{
- int i, j;
+ InitGraphicInfo(); /* graphic properties mapping */
+ InitElementGraphicInfo(); /* element game graphic mapping */
+ InitElementSpecialGraphicInfo(); /* element special graphic mapping */
- static int ep_amoebalive[] =
- {
- EL_AMOEBA_WET,
- EL_AMOEBA_DRY,
- EL_AMOEBA_FULL,
- EL_BD_AMOEBA
- };
- static int ep_amoebalive_num = SIZEOF_ARRAY_INT(ep_amoebalive);
+ InitElementSmallImages(); /* create editor and preview images */
+ InitFontGraphicInfo(); /* initialize text drawing functions */
- static int ep_amoeboid[] =
- {
- EL_AMOEBA_DEAD,
- EL_AMOEBA_WET,
- EL_AMOEBA_DRY,
- EL_AMOEBA_FULL,
- EL_BD_AMOEBA
- };
- static int ep_amoeboid_num = SIZEOF_ARRAY_INT(ep_amoeboid);
+ SetMainBackgroundImage(IMG_BACKGROUND);
+ SetDoorBackgroundImage(IMG_BACKGROUND_DOOR);
+
+ InitGadgets();
+ InitToons();
+}
+
+static void ReinitializeSounds()
+{
+ InitSoundInfo(); /* sound properties mapping */
+ InitElementSoundInfo(); /* element game sound mapping */
+
+#if 1
+ InitElementSoundInfo(); /* element game sound mapping */
+#endif
+
+ InitPlaySoundLevel(); /* internal game sound settings */
+}
+
+static void ReinitializeMusic()
+{
+ /* currently nothing to do */
+}
+
+void InitElementProperties()
+{
+ int i, j;
+
+ static int ep_amoebalive[] =
+ {
+ EL_AMOEBA_WET,
+ EL_AMOEBA_DRY,
+ EL_AMOEBA_FULL,
+ EL_BD_AMOEBA,
+ -1
+ };
+
+ static int ep_amoeboid[] =
+ {
+ EL_AMOEBA_DEAD,
+ EL_AMOEBA_WET,
+ EL_AMOEBA_DRY,
+ EL_AMOEBA_FULL,
+ EL_BD_AMOEBA,
+ -1
+ };
static int ep_schluessel[] =
{
EL_EM_KEY_1,
EL_EM_KEY_2,
EL_EM_KEY_3,
- EL_EM_KEY_4
+ EL_EM_KEY_4,
+ -1
};
- static int ep_schluessel_num = SIZEOF_ARRAY_INT(ep_schluessel);
static int ep_pforte[] =
{
EL_TUBE_LEFT_UP,
EL_TUBE_LEFT_DOWN,
EL_TUBE_RIGHT_UP,
- EL_TUBE_RIGHT_DOWN
+ EL_TUBE_RIGHT_DOWN,
+ -1
};
- static int ep_pforte_num = SIZEOF_ARRAY_INT(ep_pforte);
static int ep_solid[] =
{
EL_TUBE_LEFT_UP,
EL_TUBE_LEFT_DOWN,
EL_TUBE_RIGHT_UP,
- EL_TUBE_RIGHT_DOWN
+ EL_TUBE_RIGHT_DOWN,
+ -1
};
- static int ep_solid_num = SIZEOF_ARRAY_INT(ep_solid);
static int ep_indestructible[] =
{
EL_TUBE_LEFT_UP,
EL_TUBE_LEFT_DOWN,
EL_TUBE_RIGHT_UP,
- EL_TUBE_RIGHT_DOWN
+ EL_TUBE_RIGHT_DOWN,
+ -1
};
- static int ep_indestructible_num = SIZEOF_ARRAY_INT(ep_indestructible);
static int ep_slippery[] =
{
EL_SPEED_PILL,
EL_STEELWALL_SLANTED,
EL_PEARL,
- EL_CRYSTAL
+ EL_CRYSTAL,
+ -1
};
- static int ep_slippery_num = SIZEOF_ARRAY_INT(ep_slippery);
static int ep_enemy[] =
{
EL_ROBOT,
EL_PACMAN,
EL_SP_SNIKSNAK,
- EL_SP_ELECTRON
+ EL_SP_ELECTRON,
+ -1
};
- static int ep_enemy_num = SIZEOF_ARRAY_INT(ep_enemy);
static int ep_mauer[] =
{
EL_EMC_WALL_5,
EL_EMC_WALL_6,
EL_EMC_WALL_7,
- EL_EMC_WALL_8
+ EL_EMC_WALL_8,
+ -1
};
- static int ep_mauer_num = SIZEOF_ARRAY_INT(ep_mauer);
static int ep_can_fall[] =
{
EL_PEARL,
EL_CRYSTAL,
EL_SPRING,
- EL_DX_SUPABOMB
+ EL_DX_SUPABOMB,
+ -1
};
- static int ep_can_fall_num = SIZEOF_ARRAY_INT(ep_can_fall);
static int ep_can_smash[] =
{
EL_PEARL,
EL_CRYSTAL,
EL_SPRING,
- EL_DX_SUPABOMB
+ EL_DX_SUPABOMB,
+ -1
};
- static int ep_can_smash_num = SIZEOF_ARRAY_INT(ep_can_smash);
static int ep_can_change[] =
{
EL_EMERALD_YELLOW,
EL_EMERALD_RED,
EL_EMERALD_PURPLE,
- EL_DIAMOND
+ EL_DIAMOND,
+ -1
};
- static int ep_can_change_num = SIZEOF_ARRAY_INT(ep_can_change);
static int ep_can_move[] =
{
EL_SP_SNIKSNAK,
EL_SP_ELECTRON,
EL_BALLOON,
- EL_SPRING
+ EL_SPRING,
+ -1
};
- static int ep_can_move_num = SIZEOF_ARRAY_INT(ep_can_move);
static int ep_could_move[] =
{
EL_PACMAN_RIGHT,
EL_PACMAN_UP,
EL_PACMAN_LEFT,
- EL_PACMAN_DOWN
+ EL_PACMAN_DOWN,
+ -1
};
- static int ep_could_move_num = SIZEOF_ARRAY_INT(ep_could_move);
static int ep_dont_touch[] =
{
EL_BUG,
EL_SPACESHIP,
EL_BD_BUTTERFLY,
- EL_BD_FIREFLY
+ EL_BD_FIREFLY,
+ -1
};
- static int ep_dont_touch_num = SIZEOF_ARRAY_INT(ep_dont_touch);
static int ep_dont_go_to[] =
{
EL_SP_ELECTRON,
EL_SP_BUGGY_BASE_ACTIVE,
EL_TRAP_ACTIVE,
- EL_LANDMINE
+ EL_LANDMINE,
+ -1
};
- static int ep_dont_go_to_num = SIZEOF_ARRAY_INT(ep_dont_go_to);
static int ep_mampf2[] =
{
EL_EMERALD_PURPLE,
EL_DIAMOND,
EL_PEARL,
- EL_CRYSTAL
+ EL_CRYSTAL,
+ -1
};
- static int ep_mampf2_num = SIZEOF_ARRAY_INT(ep_mampf2);
static int ep_bd_element[] =
{
EL_BD_BUTTERFLY_3,
EL_BD_BUTTERFLY_4,
EL_BD_AMOEBA,
- EL_CHAR_QUESTION
+ EL_CHAR_QUESTION,
+ -1
};
- static int ep_bd_element_num = SIZEOF_ARRAY_INT(ep_bd_element);
static int ep_sb_element[] =
{
EL_SOKOBAN_FIELD_EMPTY,
EL_SOKOBAN_FIELD_FULL,
EL_PLAYER_1,
- EL_INVISIBLE_STEELWALL
+ EL_INVISIBLE_STEELWALL,
+ -1
};
- static int ep_sb_element_num = SIZEOF_ARRAY_INT(ep_sb_element);
static int ep_gem[] =
{
EL_EMERALD_YELLOW,
EL_EMERALD_RED,
EL_EMERALD_PURPLE,
- EL_DIAMOND
+ EL_DIAMOND,
+ -1
};
- static int ep_gem_num = SIZEOF_ARRAY_INT(ep_gem);
static int ep_inactive[] =
{
EL_EMC_WALL_5,
EL_EMC_WALL_6,
EL_EMC_WALL_7,
- EL_EMC_WALL_8
+ EL_EMC_WALL_8,
+ -1
};
- static int ep_inactive_num = SIZEOF_ARRAY_INT(ep_inactive);
static int ep_explosive[] =
{
EL_SP_DISK_YELLOW,
EL_SP_SNIKSNAK,
EL_SP_ELECTRON,
- EL_DX_SUPABOMB
+ EL_DX_SUPABOMB,
+ -1
};
- static int ep_explosive_num = SIZEOF_ARRAY_INT(ep_explosive);
static int ep_mampf3[] =
{
EL_EMERALD_PURPLE,
EL_DIAMOND,
EL_PEARL,
- EL_CRYSTAL
+ EL_CRYSTAL,
+ -1
};
- static int ep_mampf3_num = SIZEOF_ARRAY_INT(ep_mampf3);
static int ep_pushable[] =
{
EL_SP_DISK_YELLOW,
EL_BALLOON,
EL_SPRING,
- EL_DX_SUPABOMB
+ EL_DX_SUPABOMB,
+ -1
};
- static int ep_pushable_num = SIZEOF_ARRAY_INT(ep_pushable);
static int ep_player[] =
{
EL_PLAYER_1,
EL_PLAYER_2,
EL_PLAYER_3,
- EL_PLAYER_4
+ EL_PLAYER_4,
+ -1
};
- static int ep_player_num = SIZEOF_ARRAY_INT(ep_player);
static int ep_has_content[] =
{
EL_AMOEBA_WET,
EL_AMOEBA_DRY,
EL_AMOEBA_FULL,
- EL_BD_AMOEBA
+ EL_BD_AMOEBA,
+ -1
};
- static int ep_has_content_num = SIZEOF_ARRAY_INT(ep_has_content);
static int ep_eatable[] =
{
EL_SP_BUGGY_BASE_ACTIVATING,
EL_TRAP,
EL_INVISIBLE_SAND,
- EL_INVISIBLE_SAND_ACTIVE
+ EL_INVISIBLE_SAND_ACTIVE,
+ -1
};
- static int ep_eatable_num = SIZEOF_ARRAY_INT(ep_eatable);
static int ep_sp_element[] =
{
/* additional elements that appeared in newer Supaplex levels */
EL_INVISIBLE_WALL,
/* more than one murphy in a level results in an inactive clone */
- EL_SP_MURPHY_CLONE
+ EL_SP_MURPHY_CLONE,
+ -1
};
- static int ep_sp_element_num = SIZEOF_ARRAY_INT(ep_sp_element);
static int ep_quick_gate[] =
{
EL_SP_PORT_VERTICAL,
EL_SP_PORT_ANY,
EL_SWITCHGATE_OPEN,
- EL_TIMEGATE_OPEN
+ EL_TIMEGATE_OPEN,
+ -1
};
- static int ep_quick_gate_num = SIZEOF_ARRAY_INT(ep_quick_gate);
static int ep_over_player[] =
{
EL_TUBE_LEFT_UP,
EL_TUBE_LEFT_DOWN,
EL_TUBE_RIGHT_UP,
- EL_TUBE_RIGHT_DOWN
+ EL_TUBE_RIGHT_DOWN,
+ -1
};
- static int ep_over_player_num = SIZEOF_ARRAY_INT(ep_over_player);
static int ep_active_bomb[] =
{
EL_DYNABOMB_PLAYER_2_ACTIVE,
EL_DYNABOMB_PLAYER_3_ACTIVE,
EL_DYNABOMB_PLAYER_4_ACTIVE,
- EL_SP_DISK_RED_ACTIVE
+ EL_SP_DISK_RED_ACTIVE,
+ -1
};
- static int ep_active_bomb_num = SIZEOF_ARRAY_INT(ep_active_bomb);
static int ep_belt[] =
{
EL_CONVEYOR_BELT_4_LEFT,
EL_CONVEYOR_BELT_4_MIDDLE,
EL_CONVEYOR_BELT_4_RIGHT,
+ -1
};
- static int ep_belt_num = SIZEOF_ARRAY_INT(ep_belt);
static int ep_belt_active[] =
{
EL_CONVEYOR_BELT_4_LEFT_ACTIVE,
EL_CONVEYOR_BELT_4_MIDDLE_ACTIVE,
EL_CONVEYOR_BELT_4_RIGHT_ACTIVE,
+ -1
};
- static int ep_belt_active_num = SIZEOF_ARRAY_INT(ep_belt_active);
static int ep_belt_switch[] =
{
EL_CONVEYOR_BELT_4_SWITCH_LEFT,
EL_CONVEYOR_BELT_4_SWITCH_MIDDLE,
EL_CONVEYOR_BELT_4_SWITCH_RIGHT,
+ -1
};
- static int ep_belt_switch_num = SIZEOF_ARRAY_INT(ep_belt_switch);
static int ep_tube[] =
{
EL_TUBE_LEFT_UP,
EL_TUBE_LEFT_DOWN,
EL_TUBE_RIGHT_UP,
- EL_TUBE_RIGHT_DOWN
- };
- static int ep_tube_num = SIZEOF_ARRAY_INT(ep_tube);
-
- static long ep1_bit[] =
- {
- EP_BIT_AMOEBALIVE,
- EP_BIT_AMOEBOID,
- EP_BIT_SCHLUESSEL,
- EP_BIT_PFORTE,
- EP_BIT_SOLID,
- EP_BIT_INDESTRUCTIBLE,
- EP_BIT_SLIPPERY,
- EP_BIT_ENEMY,
- EP_BIT_MAUER,
- EP_BIT_CAN_FALL,
- EP_BIT_CAN_SMASH,
- EP_BIT_CAN_CHANGE,
- EP_BIT_CAN_MOVE,
- EP_BIT_COULD_MOVE,
- EP_BIT_DONT_TOUCH,
- EP_BIT_DONT_GO_TO,
- EP_BIT_MAMPF2,
- EP_BIT_BD_ELEMENT,
- EP_BIT_SB_ELEMENT,
- EP_BIT_GEM,
- EP_BIT_INACTIVE,
- EP_BIT_EXPLOSIVE,
- EP_BIT_MAMPF3,
- EP_BIT_PUSHABLE,
- EP_BIT_PLAYER,
- EP_BIT_HAS_CONTENT,
- EP_BIT_EATABLE,
- EP_BIT_SP_ELEMENT,
- EP_BIT_QUICK_GATE,
- EP_BIT_OVER_PLAYER,
- EP_BIT_ACTIVE_BOMB
- };
- static long ep2_bit[] =
- {
- EP_BIT_BELT,
- EP_BIT_BELT_ACTIVE,
- EP_BIT_BELT_SWITCH,
- EP_BIT_TUBE
+ EL_TUBE_RIGHT_DOWN,
+ -1
};
- static int *ep1_array[] =
- {
- ep_amoebalive,
- ep_amoeboid,
- ep_schluessel,
- ep_pforte,
- ep_solid,
- ep_indestructible,
- ep_slippery,
- ep_enemy,
- ep_mauer,
- ep_can_fall,
- ep_can_smash,
- ep_can_change,
- ep_can_move,
- ep_could_move,
- ep_dont_touch,
- ep_dont_go_to,
- ep_mampf2,
- ep_bd_element,
- ep_sb_element,
- ep_gem,
- ep_inactive,
- ep_explosive,
- ep_mampf3,
- ep_pushable,
- ep_player,
- ep_has_content,
- ep_eatable,
- ep_sp_element,
- ep_quick_gate,
- ep_over_player,
- ep_active_bomb
- };
- static int *ep2_array[] =
+
+ static int ep_can_be_crumbled[] =
{
- ep_belt,
- ep_belt_active,
- ep_belt_switch,
- ep_tube
- };
- static int *ep1_num[] =
- {
- &ep_amoebalive_num,
- &ep_amoeboid_num,
- &ep_schluessel_num,
- &ep_pforte_num,
- &ep_solid_num,
- &ep_indestructible_num,
- &ep_slippery_num,
- &ep_enemy_num,
- &ep_mauer_num,
- &ep_can_fall_num,
- &ep_can_smash_num,
- &ep_can_change_num,
- &ep_can_move_num,
- &ep_could_move_num,
- &ep_dont_touch_num,
- &ep_dont_go_to_num,
- &ep_mampf2_num,
- &ep_bd_element_num,
- &ep_sb_element_num,
- &ep_gem_num,
- &ep_inactive_num,
- &ep_explosive_num,
- &ep_mampf3_num,
- &ep_pushable_num,
- &ep_player_num,
- &ep_has_content_num,
- &ep_eatable_num,
- &ep_sp_element_num,
- &ep_quick_gate_num,
- &ep_over_player_num,
- &ep_active_bomb_num
+ EL_SAND,
+ EL_LANDMINE,
+ EL_TRAP,
+ EL_TRAP_ACTIVE,
+ -1
};
- static int *ep2_num[] =
+
+ static struct
{
- &ep_belt_num,
- &ep_belt_active_num,
- &ep_belt_switch_num,
- &ep_tube_num
+ int *elements;
+ int property;
+ } element_properties[] =
+ {
+ { ep_amoebalive, EP_AMOEBALIVE },
+ { ep_amoeboid, EP_AMOEBOID },
+ { ep_schluessel, EP_SCHLUESSEL },
+ { ep_pforte, EP_PFORTE },
+ { ep_solid, EP_SOLID },
+ { ep_indestructible, EP_INDESTRUCTIBLE },
+ { ep_slippery, EP_SLIPPERY },
+ { ep_enemy, EP_ENEMY },
+ { ep_mauer, EP_MAUER },
+ { ep_can_fall, EP_CAN_FALL },
+ { ep_can_smash, EP_CAN_SMASH },
+ { ep_can_change, EP_CAN_CHANGE },
+ { ep_can_move, EP_CAN_MOVE },
+ { ep_could_move, EP_COULD_MOVE },
+ { ep_dont_touch, EP_DONT_TOUCH },
+ { ep_dont_go_to, EP_DONT_GO_TO },
+ { ep_mampf2, EP_MAMPF2 },
+ { ep_bd_element, EP_BD_ELEMENT },
+ { ep_sb_element, EP_SB_ELEMENT },
+ { ep_gem, EP_GEM },
+ { ep_inactive, EP_INACTIVE },
+ { ep_explosive, EP_EXPLOSIVE },
+ { ep_mampf3, EP_MAMPF3 },
+ { ep_pushable, EP_PUSHABLE },
+ { ep_player, EP_PLAYER },
+ { ep_has_content, EP_HAS_CONTENT },
+ { ep_eatable, EP_EATABLE },
+ { ep_sp_element, EP_SP_ELEMENT },
+ { ep_quick_gate, EP_QUICK_GATE },
+ { ep_over_player, EP_OVER_PLAYER },
+ { ep_active_bomb, EP_ACTIVE_BOMB },
+ { ep_belt, EP_BELT },
+ { ep_belt_active, EP_BELT_ACTIVE },
+ { ep_belt_switch, EP_BELT_SWITCH },
+ { ep_tube, EP_TUBE },
+ { ep_can_be_crumbled, EP_CAN_BE_CRUMBLED },
+ { NULL, -1 }
};
- static int num_properties1 = SIZEOF_ARRAY(ep1_num, int *);
- static int num_properties2 = SIZEOF_ARRAY(ep2_num, int *);
+ /* always start with reliable default values (no properties) */
for (i=0; i<MAX_NUM_ELEMENTS; i++)
+ for (j=0; j<NUM_EP_BITFIELDS; j++)
+ Properties[i][j] = EP_BITMASK_DEFAULT;
+
+ /* set all predefined element properties from above arrays */
+ for (i=0; element_properties[i].elements != NULL; i++)
+ for (j=0; (element_properties[i].elements)[j] >= 0; j++)
+ SET_PROPERTY((element_properties[i].elements)[j],
+ element_properties[i].property, TRUE);
+
+ /* set properties of character elements */
+ for (i=EL_CHAR_START; i<=EL_CHAR_END; i++)
{
- Properties1[i] = 0;
- Properties2[i] = 0;
+ SET_PROPERTY(i, EP_CHAR, TRUE);
+ SET_PROPERTY(i, EP_INACTIVE, TRUE);
}
+}
- for (i=0; i<num_properties1; i++)
- for (j=0; j<*(ep1_num[i]); j++)
- Properties1[(ep1_array[i])[j]] |= ep1_bit[i];
- for (i=0; i<num_properties2; i++)
- for (j=0; j<*(ep2_num[i]); j++)
- Properties2[(ep2_array[i])[j]] |= ep2_bit[i];
+static void InitGlobal()
+{
+ global.autoplay_leveldir = NULL;
- for (i=EL_CHAR_START; i<=EL_CHAR_END; i++)
- Properties1[i] |= (EP_BIT_CHAR | EP_BIT_INACTIVE);
+ global.frames_per_second = 0;
+ global.fps_slowdown = FALSE;
+ global.fps_slowdown_factor = 1;
}
void Execute_Command(char *command)
}
}
+static void InitSetup()
+{
+ LoadSetup(); /* global setup info */
+
+ /* set some options from setup file */
+
+ if (setup.options.verbose)
+ options.verbose = TRUE;
+}
+
+static void InitPlayerInfo()
+{
+ int i;
+
+ /* choose default local player */
+ local_player = &stored_player[0];
+
+ for (i=0; i<MAX_PLAYERS; i++)
+ stored_player[i].connected = FALSE;
+
+ local_player->connected = TRUE;
+}
+
+static void InitArtworkInfo()
+{
+ LoadArtworkInfo();
+}
+
+static char *get_element_class_token(int element)
+{
+ char *element_class_name = element_info[element].class_name;
+ char *element_class_token = checked_malloc(strlen(element_class_name) + 3);
+
+ sprintf(element_class_token, "[%s]", element_class_name);
+
+ return element_class_token;
+}
+
+static void InitArtworkConfig()
+{
+ static char *image_id_prefix[MAX_NUM_ELEMENTS + NUM_FONTS + 1];
+ static char *sound_id_prefix[MAX_NUM_ELEMENTS + MAX_NUM_ELEMENTS + 1];
+ static char *action_id_suffix[NUM_ACTIONS + 1];
+ static char *direction_id_suffix[NUM_DIRECTIONS + 1];
+ static char *special_id_suffix[NUM_SPECIAL_GFX_ARGS + 1];
+ static char *dummy[1] = { NULL };
+ static char *ignore_image_tokens[] =
+ {
+ "name",
+ "sort_priority",
+ "global.num_toons",
+ "menu.draw_xoffset",
+ "menu.draw_yoffset",
+ "menu.draw_xoffset.MAIN",
+ "menu.draw_yoffset.MAIN",
+ "door.step_offset",
+ "door.step_delay",
+ NULL
+ };
+ static char *ignore_sound_tokens[] =
+ {
+ "name",
+ "sort_priority",
+ NULL
+ };
+ int i;
+
+ for (i=0; i<MAX_NUM_ELEMENTS; i++)
+ image_id_prefix[i] = element_info[i].token_name;
+ for (i=0; i<NUM_FONTS; i++)
+ image_id_prefix[MAX_NUM_ELEMENTS + i] = font_info[i].token_name;
+ image_id_prefix[MAX_NUM_ELEMENTS + NUM_FONTS] = NULL;
+
+ for (i=0; i<MAX_NUM_ELEMENTS; i++)
+ sound_id_prefix[i] = element_info[i].token_name;
+ for (i=0; i<MAX_NUM_ELEMENTS; i++)
+ sound_id_prefix[MAX_NUM_ELEMENTS + i] = get_element_class_token(i);
+ sound_id_prefix[MAX_NUM_ELEMENTS + MAX_NUM_ELEMENTS] = NULL;
+
+ for (i=0; i<NUM_ACTIONS; i++)
+ action_id_suffix[i] = element_action_info[i].suffix;
+ action_id_suffix[NUM_ACTIONS] = NULL;
+
+ for (i=0; i<NUM_DIRECTIONS; i++)
+ direction_id_suffix[i] = element_direction_info[i].suffix;
+ direction_id_suffix[NUM_DIRECTIONS] = NULL;
+
+ for (i=0; i<NUM_SPECIAL_GFX_ARGS; i++)
+ special_id_suffix[i] = special_suffix_info[i].suffix;
+ special_id_suffix[NUM_SPECIAL_GFX_ARGS] = NULL;
+
+ InitImageList(image_config, NUM_IMAGE_FILES, image_config_suffix,
+ image_id_prefix, action_id_suffix, direction_id_suffix,
+ special_id_suffix, ignore_image_tokens);
+ InitSoundList(sound_config, NUM_SOUND_FILES, sound_config_suffix,
+ sound_id_prefix, action_id_suffix, dummy,
+ special_id_suffix, ignore_sound_tokens);
+}
+
+static void InitMixer()
+{
+ OpenAudio();
+ StartMixer();
+}
+
+void InitGfx()
+{
+ char *filename_font_initial = NULL;
+ Bitmap *bitmap_font_initial = NULL;
+ int i, j;
+
+ /* determine settings for initial font (for displaying startup messages) */
+ for (i=0; image_config[i].token != NULL; i++)
+ {
+ for (j=0; j < NUM_INITIAL_FONTS; j++)
+ {
+ char font_token[128];
+ int len_font_token;
+
+ sprintf(font_token, "%s_%d", CONFIG_TOKEN_FONT_INITIAL, j + 1);
+ len_font_token = strlen(font_token);
+
+ if (strcmp(image_config[i].token, font_token) == 0)
+ filename_font_initial = image_config[i].value;
+ else if (strlen(image_config[i].token) > len_font_token &&
+ strncmp(image_config[i].token, font_token, len_font_token) == 0)
+ {
+ if (strcmp(&image_config[i].token[len_font_token], ".x") == 0)
+ font_initial[j].src_x = atoi(image_config[i].value);
+ else if (strcmp(&image_config[i].token[len_font_token], ".y") == 0)
+ font_initial[j].src_y = atoi(image_config[i].value);
+ else if (strcmp(&image_config[i].token[len_font_token], ".width") == 0)
+ font_initial[j].width = atoi(image_config[i].value);
+ else if (strcmp(&image_config[i].token[len_font_token],".height") == 0)
+ font_initial[j].height = atoi(image_config[i].value);
+ }
+ }
+ }
+
+ for (j=0; j < NUM_INITIAL_FONTS; j++)
+ {
+ font_initial[j].num_chars = DEFAULT_NUM_CHARS_PER_FONT;
+ font_initial[j].num_chars_per_line = DEFAULT_NUM_CHARS_PER_LINE;
+ }
+
+ if (filename_font_initial == NULL) /* should not happen */
+ Error(ERR_EXIT, "cannot get filename for '%s'", CONFIG_TOKEN_FONT_INITIAL);
+
+ /* create additional image buffers for double-buffering */
+ bitmap_db_field = CreateBitmap(FXSIZE, FYSIZE, DEFAULT_DEPTH);
+ bitmap_db_door = CreateBitmap(3 * DXSIZE, DYSIZE + VYSIZE, DEFAULT_DEPTH);
+
+ /* initialize screen properties */
+ InitGfxFieldInfo(SX, SY, SXSIZE, SYSIZE,
+ REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE,
+ bitmap_db_field);
+ InitGfxDoor1Info(DX, DY, DXSIZE, DYSIZE);
+ InitGfxDoor2Info(VX, VY, VXSIZE, VYSIZE);
+ InitGfxScrollbufferInfo(FXSIZE, FYSIZE);
+
+ bitmap_font_initial = LoadCustomImage(filename_font_initial);
+
+ for (j=0; j < NUM_INITIAL_FONTS; j++)
+ font_initial[j].bitmap = bitmap_font_initial;
+
+ InitFontGraphicInfo();
+
+ DrawInitText(WINDOW_TITLE_STRING, 20, FC_YELLOW);
+ DrawInitText(WINDOW_SUBTITLE_STRING, 50, FC_RED);
+
+ DrawInitText("Loading graphics:", 120, FC_GREEN);
+
+ InitTileClipmasks();
+}
+
+void InitGfxBackground()
+{
+ int x, y;
+
+ drawto = backbuffer;
+ fieldbuffer = bitmap_db_field;
+ SetDrawtoField(DRAW_BACKBUFFER);
+
+ BlitBitmap(graphic_info[IMG_GLOBAL_BORDER].bitmap, backbuffer,
+ 0, 0, WIN_XSIZE, WIN_YSIZE, 0, 0);
+ ClearRectangle(backbuffer, REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE);
+ ClearRectangle(bitmap_db_door, 0, 0, 3 * DXSIZE, DYSIZE + VYSIZE);
+
+ for (x=0; x<MAX_BUF_XSIZE; x++)
+ for (y=0; y<MAX_BUF_YSIZE; y++)
+ redraw[x][y] = 0;
+ redraw_tiles = 0;
+ redraw_mask = REDRAW_ALL;
+}
+
+static void InitLevelInfo()
+{
+ LoadLevelInfo(); /* global level info */
+ LoadLevelSetup_LastSeries(); /* last played series info */
+ LoadLevelSetup_SeriesInfo(); /* last played level info */
+}
+
+void InitLevelArtworkInfo()
+{
+ LoadLevelArtworkInfo();
+}
+
+static void InitImages()
+{
+ ReloadCustomImages();
+
+ LoadCustomElementDescriptions();
+ LoadSpecialMenuDesignSettings();
+
+ ReinitializeGraphics();
+}
+
+static void InitSound()
+{
+ InitReloadCustomSounds(artwork.snd_current->identifier);
+ ReinitializeSounds();
+}
+
+static void InitMusic()
+{
+ InitReloadCustomMusic(artwork.mus_current->identifier);
+ ReinitializeMusic();
+}
+
+void InitNetworkServer()
+{
+#if defined(PLATFORM_UNIX)
+ int nr_wanted;
+#endif
+
+ if (!options.network)
+ return;
+
+#if defined(PLATFORM_UNIX)
+ nr_wanted = Request("Choose player", REQ_PLAYER | REQ_STAY_CLOSED);
+
+ if (!ConnectToServer(options.server_host, options.server_port))
+ Error(ERR_EXIT, "cannot connect to network game server");
+
+ SendToServer_PlayerName(setup.player_name);
+ SendToServer_ProtocolVersion();
+
+ if (nr_wanted)
+ SendToServer_NrWanted(nr_wanted);
+#endif
+}
+
+void ReloadCustomArtwork()
+{
+ static char *leveldir_current_identifier = NULL;
+ static boolean last_override_level_graphics = FALSE;
+ static boolean last_override_level_sounds = FALSE;
+ static boolean last_override_level_music = FALSE;
+ /* identifier for new artwork; default: artwork configured in setup */
+ char *gfx_new_identifier = artwork.gfx_current->identifier;
+ char *snd_new_identifier = artwork.snd_current->identifier;
+ char *mus_new_identifier = artwork.mus_current->identifier;
+ boolean redraw_screen = FALSE;
+
+ if (leveldir_current_identifier == NULL)
+ leveldir_current_identifier = leveldir_current->identifier;
+
+#if 0
+ printf("CURRENT GFX: '%s' ['%s']\n", artwork.gfx_current->identifier,
+ leveldir_current->graphics_set);
+ printf("CURRENT LEV: '%s' / '%s'\n", leveldir_current_identifier,
+ leveldir_current->identifier);
+#endif
+
+#if 0
+ printf("graphics --> '%s' ('%s')\n",
+ artwork.gfx_current_identifier, artwork.gfx_current->filename);
+ printf("sounds --> '%s' ('%s')\n",
+ artwork.snd_current_identifier, artwork.snd_current->filename);
+ printf("music --> '%s' ('%s')\n",
+ artwork.mus_current_identifier, artwork.mus_current->filename);
+#endif
+
+ /* leveldir_current may be invalid (level group, parent link) */
+ if (!validLevelSeries(leveldir_current))
+ return;
+
+ /* when a new level series was selected, check if there was a change
+ in custom artwork stored in level series directory */
+ if (leveldir_current_identifier != leveldir_current->identifier)
+ {
+ char *identifier_old = leveldir_current_identifier;
+ char *identifier_new = leveldir_current->identifier;
+
+ if (getTreeInfoFromIdentifier(artwork.gfx_first, identifier_old) !=
+ getTreeInfoFromIdentifier(artwork.gfx_first, identifier_new))
+ gfx_new_identifier = identifier_new;
+ if (getTreeInfoFromIdentifier(artwork.snd_first, identifier_old) !=
+ getTreeInfoFromIdentifier(artwork.snd_first, identifier_new))
+ snd_new_identifier = identifier_new;
+ if (getTreeInfoFromIdentifier(artwork.mus_first, identifier_new) !=
+ getTreeInfoFromIdentifier(artwork.mus_first, identifier_new))
+ mus_new_identifier = identifier_new;
+
+ leveldir_current_identifier = leveldir_current->identifier;
+ }
+
+ /* custom level artwork configured in level series configuration file
+ always overrides custom level artwork stored in level series directory
+ and (level independant) custom artwork configured in setup menue */
+ if (leveldir_current->graphics_set != NULL)
+ gfx_new_identifier = leveldir_current->graphics_set;
+ if (leveldir_current->sounds_set != NULL)
+ snd_new_identifier = leveldir_current->sounds_set;
+ if (leveldir_current->music_set != NULL)
+ mus_new_identifier = leveldir_current->music_set;
+
+ if (strcmp(artwork.gfx_current_identifier, gfx_new_identifier) != 0 ||
+ last_override_level_graphics != setup.override_level_graphics)
+ {
+#if 0
+ printf("RELOADING GRAPHICS '%s' -> '%s' ('%s')\n",
+ artwork.gfx_current_identifier,
+ artwork.gfx_current->identifier,
+ gfx_new_identifier);
+#endif
+
+ setLevelArtworkDir(artwork.gfx_first);
+
+ ClearRectangle(window, 0, 0, WIN_XSIZE, WIN_YSIZE);
+
+ InitImages();
+
+ FreeTileClipmasks();
+ InitTileClipmasks();
+
+ artwork.gfx_current_identifier = artwork.gfx_current->identifier;
+ last_override_level_graphics = setup.override_level_graphics;
+
+ redraw_screen = TRUE;
+ }
+
+ if (strcmp(artwork.snd_current_identifier, snd_new_identifier) != 0 ||
+ last_override_level_sounds != setup.override_level_sounds)
+ {
+#if 0
+ printf("RELOADING SOUNDS '%s' -> '%s' ('%s')\n",
+ artwork.snd_current_identifier,
+ artwork.snd_current->identifier,
+ snd_new_identifier);
+#endif
+
+ /* set artwork path to send it to the sound server process */
+ setLevelArtworkDir(artwork.snd_first);
+
+ InitReloadCustomSounds(snd_new_identifier);
+ ReinitializeSounds();
+
+ artwork.snd_current_identifier = artwork.snd_current->identifier;
+ last_override_level_sounds = setup.override_level_sounds;
+
+ redraw_screen = TRUE;
+ }
+
+ if (strcmp(artwork.mus_current_identifier, mus_new_identifier) != 0 ||
+ last_override_level_music != setup.override_level_music)
+ {
+ /* set artwork path to send it to the sound server process */
+ setLevelArtworkDir(artwork.mus_first);
+
+ InitReloadCustomMusic(mus_new_identifier);
+ ReinitializeMusic();
+
+ artwork.mus_current_identifier = artwork.mus_current->identifier;
+ last_override_level_music = setup.override_level_music;
+
+ redraw_screen = TRUE;
+ }
+
+ if (redraw_screen)
+ {
+ InitGfxBackground();
+
+ /* force redraw of (open or closed) door graphics */
+ SetDoorState(DOOR_OPEN_ALL);
+ CloseDoor(DOOR_CLOSE_ALL | DOOR_NO_DELAY);
+ }
+}
+
+
+/* ========================================================================= */
+/* OpenAll() */
+/* ========================================================================= */
+
+void OpenAll()
+{
+ InitGlobal(); /* initialize some global variables */
+
+ if (options.execute_command)
+ Execute_Command(options.execute_command);
+
+ if (options.serveronly)
+ {
+#if defined(PLATFORM_UNIX)
+ NetworkServer(options.server_port, options.serveronly);
+#else
+ Error(ERR_WARN, "networking only supported in Unix version");
+#endif
+ exit(0); /* never reached */
+ }
+
+ InitSetup();
+
+ InitPlayerInfo();
+ InitArtworkInfo(); /* needed before loading gfx, sound & music */
+ InitArtworkConfig(); /* needed before forking sound child process */
+ InitMixer();
+
+ InitCounter();
+
+ InitRND(NEW_RANDOMIZE);
+ InitSimpleRND(NEW_RANDOMIZE);
+
+ InitJoysticks();
+
+ InitVideoDisplay();
+ InitVideoBuffer(&backbuffer, &window, WIN_XSIZE, WIN_YSIZE, DEFAULT_DEPTH,
+ setup.fullscreen);
+
+ InitEventFilter(FilterMouseMotionEvents);
+
+ InitElementProperties();
+
+ InitGfx();
+
+ InitLevelInfo();
+ InitLevelArtworkInfo();
+
+ InitImages(); /* needs to know current level directory */
+ InitSound(); /* needs to know current level directory */
+ InitMusic(); /* needs to know current level directory */
+
+ InitGfxBackground();
+
+ if (global.autoplay_leveldir)
+ {
+ AutoPlayTape();
+ return;
+ }
+
+ game_status = MAINMENU;
+
+ DrawMainMenu();
+
+ InitNetworkServer();
+}
+
void CloseAllAndExit(int exit_value)
{
StopSounds();