rnd-20040823-1-src
[rocksndiamonds.git] / src / libgame / system.h
1 /***********************************************************
2 * Artsoft Retro-Game Library                               *
3 *----------------------------------------------------------*
4 * (c) 1994-2002 Artsoft Entertainment                      *
5 *               Holger Schemel                             *
6 *               Detmolder Strasse 189                      *
7 *               33604 Bielefeld                            *
8 *               Germany                                    *
9 *               e-mail: info@artsoft.org                   *
10 *----------------------------------------------------------*
11 * system.h                                                 *
12 ***********************************************************/
13
14 #ifndef SYSTEM_H
15 #define SYSTEM_H
16
17 #include "platform.h"
18 #include "types.h"
19
20
21 #if defined(PLATFORM_MACOSX)
22 #include "macosx.h"
23 #elif defined(PLATFORM_WIN32)
24 #include "windows.h"
25 #elif defined(PLATFORM_MSDOS)
26 #include "msdos.h"
27 #endif
28
29 #if defined(TARGET_SDL)
30 #include "sdl.h"
31 #elif defined(TARGET_X11)
32 #include "x11.h"
33 #endif
34
35
36 /* the additional 'b' is needed for Win32 to open files in binary mode */
37 #define MODE_READ               "rb"
38 #define MODE_WRITE              "wb"
39 #define MODE_APPEND             "ab"
40
41 #define DEFAULT_DEPTH           0
42
43 #define BLIT_OPAQUE             0
44 #define BLIT_MASKED             1
45 #define BLIT_INVERSE            2
46 #define BLIT_ON_BACKGROUND      3
47
48 #define FULLSCREEN_NOT_AVAILABLE FALSE
49 #define FULLSCREEN_AVAILABLE     TRUE
50
51 /* default input keys */
52 #define DEFAULT_KEY_LEFT        KSYM_Left
53 #define DEFAULT_KEY_RIGHT       KSYM_Right
54 #define DEFAULT_KEY_UP          KSYM_Up
55 #define DEFAULT_KEY_DOWN        KSYM_Down
56 #if defined(PLATFORM_MACOSX)
57 #define DEFAULT_KEY_SNAP        KSYM_Control_L
58 #define DEFAULT_KEY_DROP        KSYM_KP_Enter
59 #else
60 #define DEFAULT_KEY_SNAP        KSYM_Control_L
61 #define DEFAULT_KEY_DROP        KSYM_Control_R
62 #endif
63 #define DEFAULT_KEY_OKAY        KSYM_Return
64 #define DEFAULT_KEY_CANCEL      KSYM_Escape
65
66 /* default shortcut keys */
67 #define DEFAULT_KEY_SAVE_GAME   KSYM_F1
68 #define DEFAULT_KEY_LOAD_GAME   KSYM_F2
69 #define DEFAULT_KEY_TOGGLE_PAUSE KSYM_space
70
71 /* values for key_status */
72 #define KEY_NOT_PRESSED         FALSE
73 #define KEY_RELEASED            FALSE
74 #define KEY_PRESSED             TRUE
75
76 /* values for button status */
77 #define MB_NOT_PRESSED          FALSE
78 #define MB_NOT_RELEASED         TRUE
79 #define MB_RELEASED             FALSE
80 #define MB_PRESSED              TRUE
81 #define MB_MENU_CHOICE          FALSE
82 #define MB_MENU_MARK            TRUE
83 #define MB_MENU_INITIALIZE      (-1)
84 #define MB_MENU_LEAVE           (-2)
85 #define MB_LEFTBUTTON           1
86 #define MB_MIDDLEBUTTON         2
87 #define MB_RIGHTBUTTON          3
88
89
90 /* values for move directions */
91 #define MV_BIT_LEFT             0
92 #define MV_BIT_RIGHT            1
93 #define MV_BIT_UP               2
94 #define MV_BIT_DOWN             3
95
96 #define NUM_DIRECTIONS          4
97
98 /* values for special "button" bitmasks */
99 #define BUTTON_1                4
100 #define BUTTON_2                5
101
102 /* values for move direction and special "button" key bitmasks */
103 #define MV_NO_MOVING            0
104 #define MV_LEFT                 (1 << MV_BIT_LEFT)
105 #define MV_RIGHT                (1 << MV_BIT_RIGHT)
106 #define MV_UP                   (1 << MV_BIT_UP)
107 #define MV_DOWN                 (1 << MV_BIT_DOWN)
108
109 #define KEY_BUTTON_1            (1 << BUTTON_1)
110 #define KEY_BUTTON_2            (1 << BUTTON_2)
111 #define KEY_MOTION              (MV_LEFT | MV_RIGHT | MV_UP | MV_DOWN)
112 #define KEY_BUTTON              (KEY_BUTTON_1 | KEY_BUTTON_2)
113 #define KEY_ACTION              (KEY_MOTION | KEY_BUTTON)
114
115 #define MV_DIR_BIT(x)           ((x) == MV_LEFT  ? MV_BIT_LEFT  :       \
116                                  (x) == MV_RIGHT ? MV_BIT_RIGHT :       \
117                                  (x) == MV_UP    ? MV_BIT_UP    : MV_BIT_DOWN)
118
119 #define MV_DIR_OPPOSITE(x)      ((x) == MV_LEFT  ? MV_RIGHT :           \
120                                  (x) == MV_RIGHT ? MV_LEFT  :           \
121                                  (x) == MV_UP    ? MV_DOWN  :           \
122                                  (x) == MV_DOWN  ? MV_UP    : MV_NO_MOVING)
123
124
125 /* values for animation mode (frame order and direction) */
126 #define ANIM_NONE               0
127 #define ANIM_LOOP               (1 << 0)
128 #define ANIM_LINEAR             (1 << 1)
129 #define ANIM_PINGPONG           (1 << 2)
130 #define ANIM_PINGPONG2          (1 << 3)
131 #define ANIM_RANDOM             (1 << 4)
132 #define ANIM_REVERSE            (1 << 5)
133
134 /* values for special (non game element) animation modes */
135 #define ANIM_HORIZONTAL         (1 << 6)
136 #define ANIM_VERTICAL           (1 << 7)
137
138 #define ANIM_DEFAULT            ANIM_LOOP
139
140 /* values for redraw_mask */
141 #define REDRAW_NONE             (0)
142 #define REDRAW_ALL              (1 << 0)
143 #define REDRAW_FIELD            (1 << 1)
144 #define REDRAW_TILES            (1 << 2)
145 #define REDRAW_DOOR_1           (1 << 3)
146 #define REDRAW_VIDEO_1          (1 << 4)
147 #define REDRAW_VIDEO_2          (1 << 5)
148 #define REDRAW_VIDEO_3          (1 << 6)
149 #define REDRAW_MICROLEVEL       (1 << 7)
150 #define REDRAW_MICROLABEL       (1 << 8)
151 #define REDRAW_FROM_BACKBUFFER  (1 << 9)
152 #define REDRAW_DOOR_2           (REDRAW_VIDEO_1 | \
153                                  REDRAW_VIDEO_2 | \
154                                  REDRAW_VIDEO_3)
155 #define REDRAW_DOOR_3           (1 << 10)
156 #define REDRAW_DOORS            (REDRAW_DOOR_1 | \
157                                  REDRAW_DOOR_2 | \
158                                  REDRAW_DOOR_3)
159 #define REDRAW_MAIN             (REDRAW_FIELD | \
160                                  REDRAW_TILES | \
161                                  REDRAW_MICROLEVEL)
162 #define REDRAW_FPS              (1 << 11)
163 #define REDRAWTILES_THRESHOLD   (SCR_FIELDX * SCR_FIELDY / 2)
164
165 #define IN_GFX_SCREEN(x, y)     (x >= gfx.sx && x < gfx.sx + gfx.sxsize && \
166                                  y >= gfx.sy && y < gfx.sy + gfx.sysize)
167 #define IN_GFX_DOOR(x, y)       (x >= gfx.dx && x < gfx.dx + gfx.dxsize && \
168                                  y >= gfx.dy && y < gfx.dy + gfx.dysize)
169 #define IN_GFX_VIDEO(x, y)      (x >= gfx.vx && x < gfx.vx + gfx.vxsize && \
170                                  y >= gfx.vy && y < gfx.vy + gfx.vysize)
171
172 /* values for mouse cursor */
173 #define CURSOR_DEFAULT          0
174 #define CURSOR_PLAYFIELD        1
175
176
177 /* maximum number of parallel players supported by libgame functions */
178 #define MAX_PLAYERS             4
179
180 /* maximum allowed length of player name */
181 #define MAX_PLAYER_NAME_LEN     10
182
183 /* default name for empty highscore entry */
184 #define EMPTY_PLAYER_NAME       "no name"
185
186 /* default name for unknown player names */
187 #define ANONYMOUS_NAME          "anonymous"
188
189 /* default for other unknown names */
190 #define UNKNOWN_NAME            "unknown"
191
192 /* default name for new levels */
193 #define NAMELESS_LEVEL_NAME     "nameless level"
194
195 /* default text for non-existant artwork */
196 #define NOT_AVAILABLE           "(not available)"
197
198 /* default value for undefined filename */
199 #define UNDEFINED_FILENAME      "[NONE]"
200
201 /* default value for undefined parameter */
202 #define ARG_DEFAULT             "[DEFAULT]"
203
204 /* default values for undefined configuration file parameters */
205 #define ARG_UNDEFINED           "-1000000"
206 #define ARG_UNDEFINED_VALUE     (atoi(ARG_UNDEFINED))
207
208 /* definitions for game sub-directories */
209 #ifndef RO_GAME_DIR
210 #define RO_GAME_DIR             "."
211 #endif
212
213 #ifndef RW_GAME_DIR
214 #define RW_GAME_DIR             "."
215 #endif
216
217 #define RO_BASE_PATH            RO_GAME_DIR
218 #define RW_BASE_PATH            RW_GAME_DIR
219
220 /* directory names */
221 #define GRAPHICS_DIRECTORY      "graphics"
222 #define SOUNDS_DIRECTORY        "sounds"
223 #define MUSIC_DIRECTORY         "music"
224 #define LEVELS_DIRECTORY        "levels"
225 #define TAPES_DIRECTORY         "tapes"
226 #define SCORES_DIRECTORY        "scores"
227 #define DOCS_DIRECTORY          "docs"
228
229 #if !defined(PLATFORM_MSDOS)
230 #define GFX_CLASSIC_SUBDIR      "gfx_classic"
231 #define SND_CLASSIC_SUBDIR      "snd_classic"
232 #define MUS_CLASSIC_SUBDIR      "mus_classic"
233 #else
234 #define GFX_CLASSIC_SUBDIR      "gfx_orig"
235 #define SND_CLASSIC_SUBDIR      "snd_orig"
236 #define MUS_CLASSIC_SUBDIR      "mus_orig"
237 #endif
238
239 /* file names and filename extensions */
240 #if !defined(PLATFORM_MSDOS)
241 #define LEVELSETUP_DIRECTORY    "levelsetup"
242 #define SETUP_FILENAME          "setup.conf"
243 #define LEVELSETUP_FILENAME     "levelsetup.conf"
244 #define EDITORSETUP_FILENAME    "editorsetup.conf"
245 #define HELPANIM_FILENAME       "helpanim.conf"
246 #define HELPTEXT_FILENAME       "helptext.conf"
247 #define LEVELINFO_FILENAME      "levelinfo.conf"
248 #define GRAPHICSINFO_FILENAME   "graphicsinfo.conf"
249 #define SOUNDSINFO_FILENAME     "soundsinfo.conf"
250 #define MUSICINFO_FILENAME      "musicinfo.conf"
251 #define LEVELFILE_EXTENSION     "level"
252 #define TAPEFILE_EXTENSION      "tape"
253 #define SCOREFILE_EXTENSION     "score"
254 #else
255 #define LEVELSETUP_DIRECTORY    "lvlsetup"
256 #define SETUP_FILENAME          "setup.cnf"
257 #define LEVELSETUP_FILENAME     "lvlsetup.cnf"
258 #define EDITORSETUP_FILENAME    "edsetup.cnf"
259 #define HELPANIM_FILENAME       "helpanim.cnf"
260 #define HELPTEXT_FILENAME       "helptext.cnf"
261 #define LEVELINFO_FILENAME      "lvlinfo.cnf"
262 #define GRAPHICSINFO_FILENAME   "gfxinfo.cnf"
263 #define SOUNDSINFO_FILENAME     "sndinfo.cnf"
264 #define MUSICINFO_FILENAME      "musinfo.cnf"
265 #define LEVELFILE_EXTENSION     "lvl"
266 #define TAPEFILE_EXTENSION      "tap"
267 #define SCOREFILE_EXTENSION     "sco"
268 #endif
269
270
271 /* areas in bitmap PIX_DOOR */
272 /* meaning in PIX_DB_DOOR: (3 PAGEs)
273    PAGEX1: 1. buffer for DOOR_1
274    PAGEX2: 2. buffer for DOOR_1
275    PAGEX3: buffer for animations
276 */
277
278 /* these values are hard-coded to be able to use them in initialization */
279 #define DOOR_GFX_PAGE_WIDTH     100     /* should be set to "gfx.dxsize" */
280 #define DOOR_GFX_PAGE_HEIGHT    280     /* should be set to "gfx.dysize" */
281
282 #define DOOR_GFX_PAGESIZE       (DOOR_GFX_PAGE_WIDTH)
283 #define DOOR_GFX_PAGEX1         (0 * DOOR_GFX_PAGESIZE)
284 #define DOOR_GFX_PAGEX2         (1 * DOOR_GFX_PAGESIZE)
285 #define DOOR_GFX_PAGEX3         (2 * DOOR_GFX_PAGESIZE)
286 #define DOOR_GFX_PAGEX4         (3 * DOOR_GFX_PAGESIZE)
287 #define DOOR_GFX_PAGEX5         (4 * DOOR_GFX_PAGESIZE)
288 #define DOOR_GFX_PAGEX6         (5 * DOOR_GFX_PAGESIZE)
289 #define DOOR_GFX_PAGEX7         (6 * DOOR_GFX_PAGESIZE)
290 #define DOOR_GFX_PAGEX8         (7 * DOOR_GFX_PAGESIZE)
291 #define DOOR_GFX_PAGEY1         (0)
292 #define DOOR_GFX_PAGEY2         (DOOR_GFX_PAGE_HEIGHT)
293
294
295 /* macros for version handling */
296 #define VERSION_MAJOR(x)        ((x) / 1000000)
297 #define VERSION_MINOR(x)        (((x) % 1000000) / 10000)
298 #define VERSION_PATCH(x)        (((x) % 10000) / 100)
299 #define VERSION_BUILD(x)        ((x) % 100)
300 #define VERSION_IDENT(a,b,c,d)  ((a) * 1000000 + (b) * 10000 + (c) * 100 + (d))
301
302
303 /* macros for parent/child process identification */
304 #if defined(PLATFORM_UNIX)
305 #define IS_PARENT_PROCESS()     (audio.mixer_pid != getpid())
306 #define IS_CHILD_PROCESS()      (audio.mixer_pid == getpid())
307 #define HAS_CHILD_PROCESS()     (audio.mixer_pid > 0)
308 #else
309 #define IS_PARENT_PROCESS()     TRUE
310 #define IS_CHILD_PROCESS()      FALSE
311 #define HAS_CHILD_PROCESS()     FALSE
312 #endif
313
314
315 /* values for artwork type */
316 #define ARTWORK_TYPE_GRAPHICS   0
317 #define ARTWORK_TYPE_SOUNDS     1
318 #define ARTWORK_TYPE_MUSIC      2
319
320 #define NUM_ARTWORK_TYPES       3
321
322
323 /* values for tree type (chosen to match artwork type) */
324 #define TREE_TYPE_UNDEFINED     -1
325 #define TREE_TYPE_GRAPHICS_DIR  ARTWORK_TYPE_GRAPHICS
326 #define TREE_TYPE_SOUNDS_DIR    ARTWORK_TYPE_SOUNDS
327 #define TREE_TYPE_MUSIC_DIR     ARTWORK_TYPE_MUSIC
328 #define TREE_TYPE_LEVEL_DIR     3
329
330 #define NUM_TREE_TYPES          4
331
332
333 /* values for artwork handling */
334 #define LEVELDIR_ARTWORK_SET(leveldir, type)                            \
335                                 ((type) == ARTWORK_TYPE_GRAPHICS ?      \
336                                  (leveldir)->graphics_set :             \
337                                  (type) == ARTWORK_TYPE_SOUNDS ?        \
338                                  (leveldir)->sounds_set :               \
339                                  (leveldir)->music_set)
340
341 #define LEVELDIR_ARTWORK_PATH(leveldir, type)                           \
342                                 ((type) == ARTWORK_TYPE_GRAPHICS ?      \
343                                  (leveldir)->graphics_path :            \
344                                  (type) == ARTWORK_TYPE_SOUNDS ?        \
345                                  (leveldir)->sounds_path :              \
346                                  (leveldir)->music_path)
347
348 #define SETUP_ARTWORK_SET(setup, type)                                  \
349                                 ((type) == ARTWORK_TYPE_GRAPHICS ?      \
350                                  (setup).graphics_set :                 \
351                                  (type) == ARTWORK_TYPE_SOUNDS ?        \
352                                  (setup).sounds_set :                   \
353                                  (setup).music_set)
354
355 #define SETUP_OVERRIDE_ARTWORK(setup, type)                             \
356                                 ((type) == ARTWORK_TYPE_GRAPHICS ?      \
357                                  (setup).override_level_graphics :      \
358                                  (type) == ARTWORK_TYPE_SOUNDS ?        \
359                                  (setup).override_level_sounds :        \
360                                  (setup).override_level_music)
361
362 #define ARTWORK_FIRST_NODE(artwork, type)                               \
363                                 ((type) == ARTWORK_TYPE_GRAPHICS ?      \
364                                  (artwork).gfx_first :  \
365                                  (type) == ARTWORK_TYPE_SOUNDS ?        \
366                                  (artwork).snd_first :  \
367                                  (artwork).mus_first)
368
369 #define ARTWORK_CURRENT_IDENTIFIER(artwork, type)                       \
370                                 ((type) == ARTWORK_TYPE_GRAPHICS ?      \
371                                  (artwork).gfx_current_identifier :     \
372                                  (type) == ARTWORK_TYPE_SOUNDS ?        \
373                                  (artwork).snd_current_identifier :     \
374                                  (artwork).mus_current_identifier)
375
376 #define ARTWORKINFO_FILENAME(type)                                      \
377                                 ((type) == ARTWORK_TYPE_GRAPHICS ?      \
378                                  GRAPHICSINFO_FILENAME :                \
379                                  (type) == ARTWORK_TYPE_SOUNDS ?        \
380                                  SOUNDSINFO_FILENAME :                  \
381                                  (type) == ARTWORK_TYPE_MUSIC ?         \
382                                  MUSICINFO_FILENAME : "")
383
384 #define ARTWORK_DIRECTORY(type)                                         \
385                                 ((type) == ARTWORK_TYPE_GRAPHICS ?      \
386                                  GRAPHICS_DIRECTORY :                   \
387                                  (type) == ARTWORK_TYPE_SOUNDS ?        \
388                                  SOUNDS_DIRECTORY :                     \
389                                  (type) == ARTWORK_TYPE_MUSIC ?         \
390                                  MUSIC_DIRECTORY : "")
391
392 #define OPTIONS_ARTWORK_DIRECTORY(type)                                 \
393                                 ((type) == ARTWORK_TYPE_GRAPHICS ?      \
394                                  options.graphics_directory :           \
395                                  (type) == ARTWORK_TYPE_SOUNDS ?        \
396                                  options.sounds_directory :             \
397                                  (type) == ARTWORK_TYPE_MUSIC ?         \
398                                  options.music_directory : "")
399
400
401 /* type definitions */
402 typedef int (*EventFilter)(const Event *);
403
404
405 /* structure definitions */
406
407 struct ProgramInfo
408 {
409   char *command_basename;
410   char *userdata_directory;
411
412   char *program_title;
413   char *window_title;
414   char *icon_title;
415
416   char *x11_icon_filename;
417   char *x11_iconmask_filename;
418   char *msdos_cursor_filename;
419
420   char *cookie_prefix;
421   char *filename_prefix;        /* prefix to cut off from DOS filenames */
422
423   int version_major;
424   int version_minor;
425   int version_patch;
426
427   void (*exit_function)(int);
428 };
429
430 struct OptionInfo
431 {
432   char *display_name;
433   char *server_host;
434   int server_port;
435
436   char *ro_base_directory;
437   char *rw_base_directory;
438   char *level_directory;
439   char *graphics_directory;
440   char *sounds_directory;
441   char *music_directory;
442   char *docs_directory;
443   char *execute_command;
444
445   boolean serveronly;
446   boolean network;
447   boolean verbose;
448   boolean debug;
449 };
450
451 struct VideoSystemInfo
452 {
453   int default_depth;
454   int width, height, depth;
455   boolean fullscreen_available;
456   boolean fullscreen_enabled;
457 };
458
459 struct AudioSystemInfo
460 {
461   boolean sound_available;
462   boolean loops_available;
463   boolean music_available;
464
465   boolean sound_enabled;
466   boolean sound_deactivated;    /* for temporarily disabling sound */
467
468   int mixer_pipe[2];
469   int mixer_pid;
470   char *device_name;
471   int device_fd;
472
473   int num_channels;
474   int music_channel;
475   int first_sound_channel;
476 };
477
478 struct FontBitmapInfo
479 {
480   Bitmap *bitmap;
481   int src_x, src_y;             /* start position of animation frames */
482   int width, height;            /* width/height of each animation frame */
483   int draw_x, draw_y;           /* offset for drawing font characters */
484   int num_chars;
485   int num_chars_per_line;
486
487 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
488   Pixmap *clip_mask;            /* single-char-only clip mask array for X11 */
489 #endif
490 };
491
492 struct GfxInfo
493 {
494   int sx, sy;
495   int sxsize, sysize;
496   int real_sx, real_sy;
497   int full_sxsize, full_sysize;
498   int scrollbuffer_width, scrollbuffer_height;
499
500   int dx, dy;
501   int dxsize, dysize;
502
503   int vx, vy;
504   int vxsize, vysize;
505
506   int draw_deactivation_mask;
507   int draw_background_mask;
508
509   Bitmap *field_save_buffer;
510
511   Bitmap *background_bitmap;
512   int background_bitmap_mask;
513
514   int num_fonts;
515   struct FontBitmapInfo *font_bitmap_info;
516   int (*select_font_function)(int);
517
518   int anim_random_frame;
519 };
520
521 struct JoystickInfo
522 {
523   int status;
524   int fd[MAX_PLAYERS];          /* file descriptor of player's joystick */
525 };
526
527 struct SetupJoystickInfo
528 {
529   char *device_name;            /* device name of player's joystick */
530
531   int xleft, xmiddle, xright;
532   int yupper, ymiddle, ylower;
533   int snap, drop;
534 };
535
536 struct SetupKeyboardInfo
537 {
538   Key left, right, up, down;
539   Key snap, drop;
540 };
541
542 struct SetupInputInfo
543 {
544   boolean use_joystick;
545   struct SetupJoystickInfo joy;
546   struct SetupKeyboardInfo key;
547 };
548
549 struct SetupEditorInfo
550 {
551   boolean el_boulderdash;
552   boolean el_emerald_mine;
553   boolean el_more;
554   boolean el_sokoban;
555   boolean el_supaplex;
556   boolean el_diamond_caves;
557   boolean el_dx_boulderdash;
558   boolean el_chars;
559   boolean el_custom;
560   boolean el_custom_more;
561   boolean el_user_defined;
562
563   boolean el_headlines;
564 };
565
566 struct SetupShortcutInfo
567 {
568   Key save_game;
569   Key load_game;
570   Key toggle_pause;
571 };
572
573 struct SetupSystemInfo
574 {
575   char *sdl_audiodriver;
576   int audio_fragment_size;
577 };
578
579 struct SetupInfo
580 {
581   char *player_name;
582
583   boolean sound;
584   boolean sound_loops;
585   boolean sound_music;
586   boolean sound_simple;
587   boolean toons;
588   boolean double_buffering;
589   boolean direct_draw;          /* !double_buffering (redundant!) */
590   boolean scroll_delay;
591   boolean soft_scrolling;
592   boolean fading;
593   boolean autorecord;
594   boolean quick_doors;
595   boolean team_mode;
596   boolean handicap;
597   boolean time_limit;
598   boolean fullscreen;
599   boolean ask_on_escape;
600
601   char *graphics_set;
602   char *sounds_set;
603   char *music_set;
604   boolean override_level_graphics;
605   boolean override_level_sounds;
606   boolean override_level_music;
607
608   struct SetupEditorInfo editor;
609   struct SetupShortcutInfo shortcut;
610   struct SetupInputInfo input[MAX_PLAYERS];
611   struct SetupSystemInfo system;
612   struct OptionInfo options;
613 };
614
615 struct TreeInfo
616 {
617   struct TreeInfo **node_top;           /* topmost node in tree */
618   struct TreeInfo *node_parent;         /* parent level directory info */
619   struct TreeInfo *node_group;          /* level group sub-directory info */
620   struct TreeInfo *next;                /* next level series structure node */
621
622   int cl_first;         /* internal control field for setup screen */
623   int cl_cursor;        /* internal control field for setup screen */
624
625   int type;             /* type of tree content */
626
627   /* fields for "type == TREE_TYPE_LEVEL_DIR" */
628
629   char *subdir;         /* tree info sub-directory basename (may be ".") */
630   char *fullpath;       /* complete path relative to tree base directory */
631   char *basepath;       /* absolute base path of tree base directory */
632   char *identifier;     /* identifier string for configuration files */
633   char *name;           /* tree info name, as displayed in selection menues */
634   char *name_sorting;   /* optional sorting name for correct name sorting */
635   char *author;         /* level or artwork author name */
636   char *imported_from;  /* optional comment for imported levels or artwork */
637
638   char *graphics_set;   /* optional custom graphics set (level tree only) */
639   char *sounds_set;     /* optional custom sounds set (level tree only) */
640   char *music_set;      /* optional custom music set (level tree only) */
641   char *graphics_path;  /* path to optional custom graphics set (level only) */
642   char *sounds_path;    /* path to optional custom sounds set (level only) */
643   char *music_path;     /* path to optional custom music set (level only) */
644
645   char *level_filename; /* filename of level file (for packed level file) */
646   char *level_filetype; /* type of levels in level directory or level file */
647
648   int levels;           /* number of levels in level series */
649   int first_level;      /* first level number (to allow start with 0 or 1) */
650   int last_level;       /* last level number (automatically calculated) */
651   int sort_priority;    /* sort levels by 'sort_priority' and then by name */
652
653   boolean latest_engine;/* force level set to use the latest game engine */
654
655   boolean level_group;  /* directory contains more level series directories */
656   boolean parent_link;  /* entry links back to parent directory */
657   boolean user_defined; /* user defined levels are stored in home directory */
658   boolean readonly;     /* readonly levels can not be changed with editor */
659   boolean handicap;     /* level set has no handicap when set to "false" */
660
661   int color;            /* color to use on selection screen for this level */
662   char *class_desc;     /* description of level series class */
663   int handicap_level;   /* number of the lowest unsolved level */
664 };
665
666 typedef struct TreeInfo TreeInfo;
667 typedef struct TreeInfo LevelDirTree;
668 typedef struct TreeInfo ArtworkDirTree;
669 typedef struct TreeInfo GraphicsDirTree;
670 typedef struct TreeInfo SoundsDirTree;
671 typedef struct TreeInfo MusicDirTree;
672
673 struct ArtworkInfo
674 {
675   GraphicsDirTree *gfx_first;
676   GraphicsDirTree *gfx_current;
677   SoundsDirTree *snd_first;
678   SoundsDirTree *snd_current;
679   MusicDirTree *mus_first;
680   MusicDirTree *mus_current;
681
682   char *gfx_current_identifier;
683   char *snd_current_identifier;
684   char *mus_current_identifier;
685 };
686
687 struct ValueTextInfo
688 {
689   int value;
690   char *text;
691 };
692
693 struct ConfigInfo
694 {
695   char *token;
696   char *value;
697 };
698
699 struct ConfigTypeInfo
700 {
701   char *token;
702   char *value;
703   int type;
704 };
705
706 struct TokenIntPtrInfo
707 {
708   char *token;
709   int *value;
710 };
711
712 struct FileInfo
713 {
714   char *token;
715
716   char *default_filename;
717   char *filename;
718
719   char **default_parameter;                     /* array of file parameters */
720   char **parameter;                             /* array of file parameters */
721
722   boolean redefined;
723 };
724
725 struct SetupFileList
726 {
727   char *token;
728   char *value;
729
730   struct SetupFileList *next;
731 };
732
733 struct ListNodeInfo
734 {
735   char *source_filename;                        /* primary key for node list */
736   int num_references;
737 };
738
739 struct PropertyMapping
740 {
741   int base_index;
742   int ext1_index;
743   int ext2_index;
744   int ext3_index;
745
746   int artwork_index;
747 };
748
749 struct ArtworkListInfo
750 {
751   int type;                                     /* type of artwork */
752
753   int num_file_list_entries;
754   int num_dynamic_file_list_entries;
755   struct FileInfo *file_list;                   /* static artwork file array */
756   struct FileInfo *dynamic_file_list;           /* dynamic artwrk file array */
757
758   int num_suffix_list_entries;
759   struct ConfigTypeInfo *suffix_list;           /* parameter suffixes array */
760
761   int num_base_prefixes;
762   int num_ext1_suffixes;
763   int num_ext2_suffixes;
764   int num_ext3_suffixes;
765   char **base_prefixes;                         /* base token prefixes array */
766   char **ext1_suffixes;                         /* property suffixes array 1 */
767   char **ext2_suffixes;                         /* property suffixes array 2 */
768   char **ext3_suffixes;                         /* property suffixes array 3 */
769
770   int num_ignore_tokens;
771   char **ignore_tokens;                         /* file tokens to be ignored */
772
773   int num_property_mapping_entries;
774   struct PropertyMapping *property_mapping;     /* mapping token -> artwork */
775
776   int sizeof_artwork_list_entry;
777
778   struct ListNodeInfo **artwork_list;           /* static artwork node array */
779   struct ListNodeInfo **dynamic_artwork_list;   /* dynamic artwrk node array */
780   struct ListNode *content_list;                /* dynamic artwork node list */
781
782   void *(*load_artwork)(char *);                /* constructor function */
783   void (*free_artwork)(void *);                 /* destructor function */
784 };
785
786
787 /* ========================================================================= */
788 /* exported variables                                                        */
789 /* ========================================================================= */
790
791 extern struct ProgramInfo       program;
792 extern struct OptionInfo        options;
793 extern struct VideoSystemInfo   video;
794 extern struct AudioSystemInfo   audio;
795 extern struct GfxInfo           gfx;
796 extern struct AnimInfo          anim;
797 extern struct ArtworkInfo       artwork;
798 extern struct JoystickInfo      joystick;
799 extern struct SetupInfo         setup;
800
801 extern LevelDirTree            *leveldir_first;
802 extern LevelDirTree            *leveldir_current;
803 extern int                      level_nr;
804
805 extern Display                 *display;
806 extern Visual                  *visual;
807 extern int                      screen;
808 extern Colormap                 cmap;
809
810 extern DrawWindow              *window;
811 extern DrawBuffer              *backbuffer;
812 extern DrawBuffer              *drawto;
813
814 extern int                      button_status;
815 extern boolean                  motion_status;
816
817 extern int                      redraw_mask;
818 extern int                      redraw_tiles;
819
820 extern int                      FrameCounter;
821
822
823 /* function definitions */
824
825 void InitProgramInfo(char *, char *, char *, char *, char *, char *, char *,
826                      char *, char *, char *, int);
827
828 void InitExitFunction(void (*exit_function)(int));
829 void InitPlatformDependentStuff(void);
830 void ClosePlatformDependentStuff(void);
831
832 void InitGfxFieldInfo(int, int, int, int, int, int, int, int, Bitmap *);
833 void InitGfxDoor1Info(int, int, int, int);
834 void InitGfxDoor2Info(int, int, int, int);
835 void InitGfxScrollbufferInfo(int, int);
836 void SetDrawDeactivationMask(int);
837 void SetDrawBackgroundMask(int);
838 void SetMainBackgroundBitmap(Bitmap *);
839 void SetDoorBackgroundBitmap(Bitmap *);
840
841 inline void InitVideoDisplay(void);
842 inline void CloseVideoDisplay(void);
843 inline void InitVideoBuffer(DrawBuffer **,DrawWindow **, int,int,int, boolean);
844 inline Bitmap *CreateBitmapStruct(void);
845 inline Bitmap *CreateBitmap(int, int, int);
846 inline void FreeBitmap(Bitmap *);
847 inline void BlitBitmap(Bitmap *, Bitmap *, int, int, int, int, int, int);
848 inline void FillRectangle(Bitmap *, int, int, int, int, Pixel);
849 inline void ClearRectangle(Bitmap *, int, int, int, int);
850 inline void ClearRectangleOnBackground(Bitmap *, int, int, int, int);
851 inline void SetClipMask(Bitmap *, GC, Pixmap);
852 inline void SetClipOrigin(Bitmap *, GC, int, int);
853 inline void BlitBitmapMasked(Bitmap *, Bitmap *, int, int, int, int, int, int);
854 inline boolean DrawingOnBackground(int, int);
855 inline void BlitBitmapOnBackground(Bitmap *, Bitmap *, int, int, int, int, int,
856                                    int);
857 inline void DrawSimpleWhiteLine(Bitmap *, int, int, int, int);
858 inline void DrawLines(Bitmap *, struct XY *, int, Pixel);
859 inline Pixel GetPixel(Bitmap *, int, int);
860 inline Pixel GetPixelFromRGB(Bitmap *, unsigned int,unsigned int,unsigned int);
861 inline Pixel GetPixelFromRGBcompact(Bitmap *, unsigned int);
862
863 inline void FlushDisplay(void);
864 inline void SyncDisplay(void);
865 inline void KeyboardAutoRepeatOn(void);
866 inline void KeyboardAutoRepeatOff(void);
867 inline boolean PointerInWindow(DrawWindow *);
868 inline boolean SetVideoMode(boolean);
869 inline boolean ChangeVideoModeIfNeeded(boolean);
870
871 Bitmap *LoadImage(char *);
872 Bitmap *LoadCustomImage(char *);
873 void ReloadCustomImage(Bitmap *, char *);
874
875 Bitmap *ZoomBitmap(Bitmap *, int, int);
876 void CreateBitmapWithSmallBitmaps(Bitmap *, int);
877
878 void SetMouseCursor(int);
879
880 inline void OpenAudio(void);
881 inline void CloseAudio(void);
882 inline void SetAudioMode(boolean);
883
884 inline void InitEventFilter(EventFilter);
885 inline boolean PendingEvent(void);
886 inline void NextEvent(Event *event);
887 inline Key GetEventKey(KeyEvent *, boolean);
888 inline KeyMod HandleKeyModState(Key, int);
889 inline KeyMod GetKeyModState();
890 inline boolean CheckCloseWindowEvent(ClientMessageEvent *);
891
892 inline void InitJoysticks();
893 inline boolean ReadJoystick(int, int *, int *, boolean *, boolean *);
894
895 #endif /* SYSTEM_H */