1 /***********************************************************
2 * Rocks'n'Diamonds -- McDuffin Strikes Back! *
3 *----------------------------------------------------------*
4 * (c) 1995-2001 Artsoft Entertainment *
6 * Detmolder Strasse 189 *
9 * e-mail: info@artsoft.org *
10 *----------------------------------------------------------*
12 ***********************************************************/
14 #include "libgame/libgame.h"
29 static char *image_filename[NUM_PICTURES] =
43 static void InitSetup(void);
44 static void InitPlayerInfo(void);
45 static void InitLevelInfo(void);
46 static void InitArtworkInfo(void);
47 static void InitNetworkServer(void);
48 static void InitSound(void);
49 static void InitGfx(void);
50 static void InitGfxBackground(void);
51 static void InitGadgets(void);
52 static void InitElementProperties(void);
56 if (options.serveronly)
58 #if defined(PLATFORM_UNIX)
59 NetworkServer(options.server_port, options.serveronly);
61 Error(ERR_WARN, "networking only supported in Unix version");
63 exit(0); /* never reached */
66 InitProgramInfo(UNIX_USERDATA_DIRECTORY,
67 PROGRAM_TITLE_STRING, getWindowTitleString(),
68 ICON_TITLE_STRING, X11_ICON_FILENAME, X11_ICONMASK_FILENAME,
69 MSDOS_POINTER_FILENAME,
70 COOKIE_PREFIX, FILENAME_PREFIX, GAME_VERSION_ACTUAL);
74 InitArtworkInfo(); /* needed before loading gfx, sound & music */
79 InitRND(NEW_RANDOMIZE);
82 InitVideoBuffer(&backbuffer, &window, WIN_XSIZE, WIN_YSIZE, DEFAULT_DEPTH,
85 InitEventFilter(FilterMouseMotionEvents);
88 InitElementProperties(); /* initializes IS_CHAR() for el2gfx() */
91 InitGadgets(); /* needs to know number of level series */
103 LoadSetup(); /* global setup info */
106 void InitPlayerInfo()
110 /* choose default local player */
111 local_player = &stored_player[0];
113 for (i=0; i<MAX_PLAYERS; i++)
114 stored_player[i].connected = FALSE;
116 local_player->connected = TRUE;
121 LoadLevelInfo(); /* global level info */
122 LoadLevelSetup_LastSeries(); /* last played series info */
123 LoadLevelSetup_SeriesInfo(); /* last played level info */
126 void InitArtworkInfo()
131 void InitNetworkServer()
133 #if defined(PLATFORM_UNIX)
137 if (!options.network)
140 #if defined(PLATFORM_UNIX)
141 nr_wanted = Request("Choose player", REQ_PLAYER | REQ_STAY_CLOSED);
143 if (!ConnectToServer(options.server_host, options.server_port))
144 Error(ERR_EXIT, "cannot connect to network game server");
146 SendToServer_PlayerName(setup.player_name);
147 SendToServer_ProtocolVersion();
150 SendToServer_NrWanted(nr_wanted);
160 InitSoundList(NUM_SOUNDS);
162 for(i=0; i<NUM_SOUNDS; i++)
163 LoadSoundToList(sound_name[i], i);
170 void InitTileClipmasks()
172 #if defined(TARGET_X11)
174 XGCValues clip_gc_values;
175 unsigned long clip_gc_valuemask;
177 #if defined(TARGET_X11_NATIVE)
183 tile_needs_clipping[] =
185 { GFX_SPIELER1_UP, 4 },
186 { GFX_SPIELER1_DOWN, 4 },
187 { GFX_SPIELER1_LEFT, 4 },
188 { GFX_SPIELER1_RIGHT, 4 },
189 { GFX_SPIELER1_PUSH_LEFT, 4 },
190 { GFX_SPIELER1_PUSH_RIGHT, 4 },
191 { GFX_SPIELER2_UP, 4 },
192 { GFX_SPIELER2_DOWN, 4 },
193 { GFX_SPIELER2_LEFT, 4 },
194 { GFX_SPIELER2_RIGHT, 4 },
195 { GFX_SPIELER2_PUSH_LEFT, 4 },
196 { GFX_SPIELER2_PUSH_RIGHT, 4 },
197 { GFX_SPIELER3_UP, 4 },
198 { GFX_SPIELER3_DOWN, 4 },
199 { GFX_SPIELER3_LEFT, 4 },
200 { GFX_SPIELER3_RIGHT, 4 },
201 { GFX_SPIELER3_PUSH_LEFT, 4 },
202 { GFX_SPIELER3_PUSH_RIGHT, 4 },
203 { GFX_SPIELER4_UP, 4 },
204 { GFX_SPIELER4_DOWN, 4 },
205 { GFX_SPIELER4_LEFT, 4 },
206 { GFX_SPIELER4_RIGHT, 4 },
207 { GFX_SPIELER4_PUSH_LEFT, 4 },
208 { GFX_SPIELER4_PUSH_RIGHT, 4 },
209 { GFX_SP_MURPHY, 1 },
210 { GFX_MURPHY_GO_LEFT, 3 },
211 { GFX_MURPHY_GO_RIGHT, 3 },
212 { GFX_MURPHY_SNAP_UP, 1 },
213 { GFX_MURPHY_SNAP_DOWN, 1 },
214 { GFX_MURPHY_SNAP_RIGHT, 1 },
215 { GFX_MURPHY_SNAP_LEFT, 1 },
216 { GFX_MURPHY_PUSH_RIGHT, 1 },
217 { GFX_MURPHY_PUSH_LEFT, 1 },
218 { GFX_GEBLUBBER, 4 },
221 { GFX_EXPLOSION, 8 },
222 { GFX_SOKOBAN_OBJEKT, 1 },
223 { GFX_FUNKELN_BLAU, 3 },
224 { GFX_FUNKELN_WEISS, 3 },
225 { GFX2_SHIELD_PASSIVE, 3 },
226 { GFX2_SHIELD_ACTIVE, 3 },
229 #endif /* TARGET_X11_NATIVE */
230 #endif /* TARGET_X11 */
234 /* initialize pixmap array for special X11 tile clipping to Pixmap 'None' */
235 for(i=0; i<NUM_TILES; i++)
236 tile_clipmask[i] = None;
238 #if defined(TARGET_X11)
239 /* This stuff is needed because X11 (XSetClipOrigin(), to be precise) is
240 often very slow when preparing a masked XCopyArea() for big Pixmaps.
241 To prevent this, create small (tile-sized) mask Pixmaps which will then
242 be set much faster with XSetClipOrigin() and speed things up a lot. */
244 clip_gc_values.graphics_exposures = False;
245 clip_gc_valuemask = GCGraphicsExposures;
247 XCreateGC(display, window->drawable, clip_gc_valuemask, &clip_gc_values);
249 for(i=0; i<NUM_BITMAPS; i++)
251 if (pix[i]->clip_mask)
253 clip_gc_values.graphics_exposures = False;
254 clip_gc_values.clip_mask = pix[i]->clip_mask;
255 clip_gc_valuemask = GCGraphicsExposures | GCClipMask;
256 pix[i]->stored_clip_gc = XCreateGC(display, window->drawable,
257 clip_gc_valuemask, &clip_gc_values);
261 #if defined(TARGET_X11_NATIVE)
263 /* create graphic context structures needed for clipping */
264 clip_gc_values.graphics_exposures = False;
265 clip_gc_valuemask = GCGraphicsExposures;
267 XCreateGC(display, pix[PIX_BACK]->clip_mask,
268 clip_gc_valuemask, &clip_gc_values);
270 /* create only those clipping Pixmaps we really need */
271 for(i=0; tile_needs_clipping[i].start>=0; i++)
275 for(j=0; j<tile_needs_clipping[i].count; j++)
277 int tile = tile_needs_clipping[i].start + j;
283 getGraphicSource(graphic, &pixmap_nr, &src_x, &src_y);
284 src_pixmap = pix[pixmap_nr]->clip_mask;
286 tile_clipmask[tile] = XCreatePixmap(display, window->drawable,
289 XCopyArea(display, src_pixmap, tile_clipmask[tile], copy_clipmask_gc,
290 src_x, src_y, TILEX, TILEY, 0, 0);
294 XFreeGC(display, copy_clipmask_gc);
296 #endif /* TARGET_X11_NATIVE */
297 #endif /* TARGET_X11 */
300 void FreeTileClipmasks()
302 #if defined(TARGET_X11)
305 for(i=0; i<NUM_TILES; i++)
307 if (tile_clipmask[i] != None)
309 XFreePixmap(display, tile_clipmask[i]);
310 tile_clipmask[i] = None;
315 XFreeGC(display, tile_clip_gc);
318 for(i=0; i<NUM_BITMAPS; i++)
320 if (pix[i]->stored_clip_gc)
322 XFreeGC(display, pix[i]->stored_clip_gc);
323 pix[i]->stored_clip_gc = None;
326 #endif /* TARGET_X11 */
333 /* initialize some global variables */
334 global.frames_per_second = 0;
335 global.fps_slowdown = FALSE;
336 global.fps_slowdown_factor = 1;
338 /* initialize screen properties */
339 InitGfxFieldInfo(SX, SY, SXSIZE, SYSIZE,
340 REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE);
341 InitGfxDoor1Info(DX, DY, DXSIZE, DYSIZE);
342 InitGfxDoor2Info(VX, VY, VXSIZE, VYSIZE);
343 InitGfxScrollbufferInfo(FXSIZE, FYSIZE);
345 /* create additional image buffers for double-buffering */
346 pix[PIX_DB_DOOR] = CreateBitmap(3 * DXSIZE, DYSIZE + VYSIZE, DEFAULT_DEPTH);
347 pix[PIX_DB_FIELD] = CreateBitmap(FXSIZE, FYSIZE, DEFAULT_DEPTH);
349 pix[PIX_SMALLFONT] = LoadCustomImage(image_filename[PIX_SMALLFONT]);
351 InitFontInfo(NULL, NULL, pix[PIX_SMALLFONT]);
353 DrawInitText(WINDOW_TITLE_STRING, 20, FC_YELLOW);
354 DrawInitText(WINDOW_SUBTITLE_STRING, 50, FC_RED);
355 #if defined(PLATFORM_MSDOS)
356 DrawInitText(PROGRAM_DOS_PORT_STRING, 210, FC_BLUE);
359 DrawInitText("Loading graphics:",120,FC_GREEN);
361 for(i=0; i<NUM_PICTURES; i++)
363 if (i != PIX_SMALLFONT)
365 DrawInitText(image_filename[i], 150, FC_YELLOW);
367 pix[i] = LoadCustomImage(image_filename[i]);
371 InitFontInfo(pix[PIX_BIGFONT], pix[PIX_MEDIUMFONT], pix[PIX_SMALLFONT]);
376 void InitGfxBackground()
381 fieldbuffer = pix[PIX_DB_FIELD];
382 SetDrawtoField(DRAW_BACKBUFFER);
384 BlitBitmap(pix[PIX_BACK], backbuffer, 0, 0, WIN_XSIZE, WIN_YSIZE, 0, 0);
385 ClearRectangle(backbuffer, REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE);
386 ClearRectangle(pix[PIX_DB_DOOR], 0, 0, 3 * DXSIZE, DYSIZE + VYSIZE);
388 for(x=0; x<MAX_BUF_XSIZE; x++)
389 for(y=0; y<MAX_BUF_YSIZE; y++)
392 redraw_mask = REDRAW_ALL;
395 void ReloadCustomArtwork()
397 if (artwork.graphics_set_current != artwork.gfx_current->name)
401 ClearRectangle(window, 0, 0, WIN_XSIZE, WIN_YSIZE);
403 for(i=0; i<NUM_PICTURES; i++)
405 DrawInitText(image_filename[i], 150, FC_YELLOW);
406 ReloadCustomImage(pix[i], image_filename[i]);
413 SetDoorState(DOOR_OPEN_1 | DOOR_CLOSE_2);
415 artwork.graphics_set_current = artwork.gfx_current->name;
418 if (artwork.sounds_set_current != artwork.snd_current->name)
420 InitReloadSounds(artwork.snd_current->name);
422 artwork.sounds_set_current = artwork.snd_current->name;
425 if (artwork.music_set_current != artwork.mus_current->name)
427 InitReloadMusic(artwork.mus_current->name);
429 artwork.music_set_current = artwork.mus_current->name;
435 CreateLevelEditorGadgets();
439 CreateScreenGadgets();
442 void InitElementProperties()
446 static int ep_amoebalive[] =
453 static int ep_amoebalive_num = SIZEOF_ARRAY_INT(ep_amoebalive);
455 static int ep_amoeboid[] =
463 static int ep_amoeboid_num = SIZEOF_ARRAY_INT(ep_amoeboid);
465 static int ep_schluessel[] =
476 static int ep_schluessel_num = SIZEOF_ARRAY_INT(ep_schluessel);
478 static int ep_pforte[] =
497 EL_SWITCHGATE_CLOSED,
512 static int ep_pforte_num = SIZEOF_ARRAY_INT(ep_pforte);
514 static int ep_solid[] =
534 EL_QUICKSAND_FILLING,
535 EL_QUICKSAND_EMPTYING,
540 EL_MAGIC_WALL_BD_OFF,
541 EL_MAGIC_WALL_BD_EMPTY,
542 EL_MAGIC_WALL_BD_FULL,
543 EL_MAGIC_WALL_BD_DEAD,
570 EL_BELT1_SWITCH_LEFT,
571 EL_BELT1_SWITCH_MIDDLE,
572 EL_BELT1_SWITCH_RIGHT,
573 EL_BELT2_SWITCH_LEFT,
574 EL_BELT2_SWITCH_MIDDLE,
575 EL_BELT2_SWITCH_RIGHT,
576 EL_BELT3_SWITCH_LEFT,
577 EL_BELT3_SWITCH_MIDDLE,
578 EL_BELT3_SWITCH_RIGHT,
579 EL_BELT4_SWITCH_LEFT,
580 EL_BELT4_SWITCH_MIDDLE,
581 EL_BELT4_SWITCH_RIGHT,
582 EL_SWITCHGATE_SWITCH_1,
583 EL_SWITCHGATE_SWITCH_2,
586 EL_TIMEGATE_SWITCH_OFF,
587 EL_TIMEGATE_SWITCH_ON,
589 EL_SIGN_RADIOACTIVITY,
628 static int ep_solid_num = SIZEOF_ARRAY_INT(ep_solid);
630 static int ep_massive[] =
656 EL_SWITCHGATE_CLOSED,
671 EL_BELT1_SWITCH_LEFT,
672 EL_BELT1_SWITCH_MIDDLE,
673 EL_BELT1_SWITCH_RIGHT,
674 EL_BELT2_SWITCH_LEFT,
675 EL_BELT2_SWITCH_MIDDLE,
676 EL_BELT2_SWITCH_RIGHT,
677 EL_BELT3_SWITCH_LEFT,
678 EL_BELT3_SWITCH_MIDDLE,
679 EL_BELT3_SWITCH_RIGHT,
680 EL_BELT4_SWITCH_LEFT,
681 EL_BELT4_SWITCH_MIDDLE,
682 EL_BELT4_SWITCH_RIGHT,
686 EL_SIGN_RADIOACTIVITY,
715 static int ep_massive_num = SIZEOF_ARRAY_INT(ep_massive);
717 static int ep_slippery[] =
752 static int ep_slippery_num = SIZEOF_ARRAY_INT(ep_slippery);
754 static int ep_enemy[] =
767 static int ep_enemy_num = SIZEOF_ARRAY_INT(ep_enemy);
769 static int ep_mauer[] =
832 static int ep_mauer_num = SIZEOF_ARRAY_INT(ep_mauer);
834 static int ep_can_fall[] =
849 EL_MAGIC_WALL_BD_FULL,
860 static int ep_can_fall_num = SIZEOF_ARRAY_INT(ep_can_fall);
862 static int ep_can_smash[] =
893 static int ep_can_smash_num = SIZEOF_ARRAY_INT(ep_can_smash);
895 static int ep_can_change[] =
906 static int ep_can_change_num = SIZEOF_ARRAY_INT(ep_can_change);
908 static int ep_can_move[] =
928 static int ep_can_move_num = SIZEOF_ARRAY_INT(ep_can_move);
930 static int ep_could_move[] =
953 static int ep_could_move_num = SIZEOF_ARRAY_INT(ep_could_move);
955 static int ep_dont_touch[] =
962 static int ep_dont_touch_num = SIZEOF_ARRAY_INT(ep_dont_touch);
964 static int ep_dont_go_to[] =
982 static int ep_dont_go_to_num = SIZEOF_ARRAY_INT(ep_dont_go_to);
984 static int ep_mampf2[] =
1009 static int ep_mampf2_num = SIZEOF_ARRAY_INT(ep_mampf2);
1011 static int ep_bd_element[] =
1020 EL_MAGIC_WALL_BD_OFF,
1038 static int ep_bd_element_num = SIZEOF_ARRAY_INT(ep_bd_element);
1040 static int ep_sb_element[] =
1045 EL_SOKOBAN_FELD_LEER,
1046 EL_SOKOBAN_FELD_VOLL,
1050 static int ep_sb_element_num = SIZEOF_ARRAY_INT(ep_sb_element);
1052 static int ep_gem[] =
1061 static int ep_gem_num = SIZEOF_ARRAY_INT(ep_gem);
1063 static int ep_inactive[] =
1100 EL_DYNAMITE_INACTIVE,
1112 EL_SOKOBAN_FELD_LEER,
1113 EL_SOKOBAN_FELD_VOLL,
1123 EL_MAGIC_WALL_BD_OFF,
1124 EL_MAGIC_WALL_BD_DEAD,
1160 EL_BELT1_SWITCH_LEFT,
1161 EL_BELT1_SWITCH_MIDDLE,
1162 EL_BELT1_SWITCH_RIGHT,
1163 EL_BELT2_SWITCH_LEFT,
1164 EL_BELT2_SWITCH_MIDDLE,
1165 EL_BELT2_SWITCH_RIGHT,
1166 EL_BELT3_SWITCH_LEFT,
1167 EL_BELT3_SWITCH_MIDDLE,
1168 EL_BELT3_SWITCH_RIGHT,
1169 EL_BELT4_SWITCH_LEFT,
1170 EL_BELT4_SWITCH_MIDDLE,
1171 EL_BELT4_SWITCH_RIGHT,
1172 EL_SIGN_EXCLAMATION,
1173 EL_SIGN_RADIOACTIVITY,
1185 EL_EMC_STEEL_WALL_1,
1186 EL_EMC_STEEL_WALL_2,
1187 EL_EMC_STEEL_WALL_3,
1188 EL_EMC_STEEL_WALL_4,
1198 static int ep_inactive_num = SIZEOF_ARRAY_INT(ep_inactive);
1200 static int ep_explosive[] =
1204 EL_DYNAMITE_INACTIVE,
1205 EL_DYNABOMB_ACTIVE_1,
1206 EL_DYNABOMB_ACTIVE_2,
1207 EL_DYNABOMB_ACTIVE_3,
1208 EL_DYNABOMB_ACTIVE_4,
1225 static int ep_explosive_num = SIZEOF_ARRAY_INT(ep_explosive);
1227 static int ep_mampf3[] =
1238 static int ep_mampf3_num = SIZEOF_ARRAY_INT(ep_mampf3);
1240 static int ep_pushable[] =
1247 EL_SOKOBAN_FELD_VOLL,
1257 static int ep_pushable_num = SIZEOF_ARRAY_INT(ep_pushable);
1259 static int ep_player[] =
1267 static int ep_player_num = SIZEOF_ARRAY_INT(ep_player);
1269 static int ep_has_content[] =
1277 static int ep_has_content_num = SIZEOF_ARRAY_INT(ep_has_content);
1279 static int ep_eatable[] =
1287 static int ep_eatable_num = SIZEOF_ARRAY_INT(ep_eatable);
1289 static int ep_sp_element[] =
1331 /* additional elements that appeared in newer Supaplex levels */
1333 /* more than one murphy in a level results in an inactive clone */
1336 static int ep_sp_element_num = SIZEOF_ARRAY_INT(ep_sp_element);
1338 static int ep_quick_gate[] =
1362 static int ep_quick_gate_num = SIZEOF_ARRAY_INT(ep_quick_gate);
1364 static int ep_over_player[] =
1389 static int ep_over_player_num = SIZEOF_ARRAY_INT(ep_over_player);
1391 static int ep_active_bomb[] =
1394 EL_DYNABOMB_ACTIVE_1,
1395 EL_DYNABOMB_ACTIVE_2,
1396 EL_DYNABOMB_ACTIVE_3,
1397 EL_DYNABOMB_ACTIVE_4
1399 static int ep_active_bomb_num = SIZEOF_ARRAY_INT(ep_active_bomb);
1401 static int ep_belt[] =
1416 static int ep_belt_num = SIZEOF_ARRAY_INT(ep_belt);
1418 static int ep_belt_switch[] =
1420 EL_BELT1_SWITCH_LEFT,
1421 EL_BELT1_SWITCH_MIDDLE,
1422 EL_BELT1_SWITCH_RIGHT,
1423 EL_BELT2_SWITCH_LEFT,
1424 EL_BELT2_SWITCH_MIDDLE,
1425 EL_BELT2_SWITCH_RIGHT,
1426 EL_BELT3_SWITCH_LEFT,
1427 EL_BELT3_SWITCH_MIDDLE,
1428 EL_BELT3_SWITCH_RIGHT,
1429 EL_BELT4_SWITCH_LEFT,
1430 EL_BELT4_SWITCH_MIDDLE,
1431 EL_BELT4_SWITCH_RIGHT,
1433 static int ep_belt_switch_num = SIZEOF_ARRAY_INT(ep_belt_switch);
1435 static int ep_tube[] =
1449 static int ep_tube_num = SIZEOF_ARRAY_INT(ep_tube);
1451 static long ep1_bit[] =
1485 static long ep2_bit[] =
1491 static int *ep1_array[] =
1525 static int *ep2_array[] =
1531 static int *ep1_num[] =
1558 &ep_has_content_num,
1562 &ep_over_player_num,
1565 static int *ep2_num[] =
1568 &ep_belt_switch_num,
1571 static int num_properties1 = SIZEOF_ARRAY(ep1_num, int *);
1572 static int num_properties2 = SIZEOF_ARRAY(ep2_num, int *);
1574 for(i=0; i<MAX_ELEMENTS; i++)
1576 Elementeigenschaften1[i] = 0;
1577 Elementeigenschaften2[i] = 0;
1580 for(i=0; i<num_properties1; i++)
1581 for(j=0; j<*(ep1_num[i]); j++)
1582 Elementeigenschaften1[(ep1_array[i])[j]] |= ep1_bit[i];
1583 for(i=0; i<num_properties2; i++)
1584 for(j=0; j<*(ep2_num[i]); j++)
1585 Elementeigenschaften2[(ep2_array[i])[j]] |= ep2_bit[i];
1587 for(i=EL_CHAR_START; i<=EL_CHAR_END; i++)
1588 Elementeigenschaften1[i] |= (EP_BIT_CHAR | EP_BIT_INACTIVE);
1591 void CloseAllAndExit(int exit_value)
1600 FreeTileClipmasks();
1601 for(i=0; i<NUM_BITMAPS; i++)
1604 CloseVideoDisplay();
1605 ClosePlatformDependantStuff();