X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Finit.c;h=7d0c731ba252e532f0df5cf6ca38a648c8818fb0;hb=234748b5eb0bc4fe29a36fd25a1d25658f53858a;hp=ec0a1c74a26369bf9e7361bc3b3c063552ce73a8;hpb=d0893e6987c21c25ec137438a18cfe1288362139;p=rocksndiamonds.git diff --git a/src/init.c b/src/init.c index ec0a1c74..7d0c731b 100644 --- a/src/init.c +++ b/src/init.c @@ -1,456 +1,2482 @@ /*********************************************************** -* Rocks'n'Diamonds -- McDuffin Strikes Back! * +* Rocks'n'Diamonds -- McDuffin Strikes Back! * *----------------------------------------------------------* -* ©1995 Artsoft Development * -* Holger Schemel * -* 33659 Bielefeld-Senne * -* Telefon: (0521) 493245 * -* eMail: aeglos@valinor.owl.de * -* aeglos@uni-paderborn.de * -* q99492@pbhrzx.uni-paderborn.de * +* (c) 1995-2002 Artsoft Entertainment * +* Holger Schemel * +* Detmolder Strasse 189 * +* 33604 Bielefeld * +* Germany * +* e-mail: info@artsoft.org * *----------------------------------------------------------* -* init.c * -* * -* Letzte Aenderung: 15.06.1995 * +* init.c * ***********************************************************/ +#include "libgame/libgame.h" + #include "init.h" -#include "images.h" -#include "sound.h" +#include "events.h" #include "screens.h" -#include "tools.h" +#include "editor.h" #include "game.h" -#include "misc.h" +#include "tape.h" +#include "tools.h" +#include "files.h" +#include "network.h" +#include "netserv.h" +#include "cartoons.h" +#include "config.h" -#include +#include "conf_e2g.c" /* include auto-generated data structure definitions */ -int sound_process_id=0; -void OpenAll(int argc, char *argv[]) +static char *image_filename[NUM_PICTURES] = { - LoadLevelInfo(); - LoadPlayerInfo(PLAYER_SETUP); - LoadPlayerInfo(PLAYER_LEVEL); +#if 0 + "RocksScreen.pcx", + "RocksDoor.pcx", + "RocksToons.pcx", + "RocksFontBig.pcx", + "RocksFontSmall.pcx", + "RocksFontMedium.pcx", + "RocksFontEM.pcx" +#else + "RocksScreen.pcx", + "RocksElements.pcx", + "RocksDoor.pcx", + "RocksHeroes.pcx", + "RocksToons.pcx", + "RocksSP.pcx", + "RocksDC.pcx", + "RocksMore.pcx", + "RocksFontBig.pcx", + "RocksFontSmall.pcx", + "RocksFontMedium.pcx", + "RocksFontEM.pcx" +#endif +}; + +static void InitSetup(void); +static void InitPlayerInfo(void); +static void InitLevelInfo(void); +static void InitArtworkInfo(void); +static void InitLevelArtworkInfo(void); +static void InitNetworkServer(void); +static void InitImages(void); +static void InitMixer(void); +static void InitSound(void); +static void InitGfx(void); +static void InitGfxBackground(void); +static void InitGadgets(void); +static void InitElementProperties(void); +static void InitElementInfo(void); +static void InitGraphicInfo(void); +static void InitSoundInfo(); +static void Execute_Debug_Command(char *); + +void OpenAll(void) +{ + if (options.debug_command) + { + Execute_Debug_Command(options.debug_command); + + exit(0); + } + + 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 */ InitCounter(); - InitSound(); - InitSoundProcess(); - InitJoystick(); + InitMixer(); + InitJoysticks(); InitRND(NEW_RANDOMIZE); - signal(SIGINT, CloseAll); - signal(SIGTERM, CloseAll); + InitVideoDisplay(); + InitVideoBuffer(&backbuffer, &window, WIN_XSIZE, WIN_YSIZE, DEFAULT_DEPTH, + setup.fullscreen); + + InitEventFilter(FilterMouseMotionEvents); - InitDisplay(argc, argv); - InitWindow(argc, argv); InitGfx(); + InitElementProperties(); /* initializes IS_CHAR() for el2gfx() */ + InitElementInfo(); + + InitLevelInfo(); + InitLevelArtworkInfo(); + InitImages(); /* needs to know current level directory */ + InitSound(); /* needs to know current level directory */ + InitGadgets(); /* needs images + number of level series */ + + InitGfxBackground(); + InitToons(); DrawMainMenu(); - XMapWindow(display, window); - XFlush(display); + InitNetworkServer(); +} + +void InitSetup() +{ + LoadSetup(); /* global setup info */ } -void InitSound() +void InitPlayerInfo() { int i; - if (sound_status==SOUND_OFF) + /* choose default local player */ + local_player = &stored_player[0]; + + for (i=0; iconnected = TRUE; +} + +void InitLevelInfo() +{ + LoadLevelInfo(); /* global level info */ + LoadLevelSetup_LastSeries(); /* last played series info */ + LoadLevelSetup_SeriesInfo(); /* last played level info */ +} + +void InitArtworkInfo() +{ + LoadArtworkInfo(); +} + +void InitLevelArtworkInfo() +{ + LoadLevelArtworkInfo(); +} + +void InitNetworkServer() +{ +#if defined(PLATFORM_UNIX) + int nr_wanted; +#endif + + if (!options.network) return; - if (access(sound_device_name,W_OK)<0) +#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 InitImages() +{ + InitImageList(image_config, image_config_suffix, NUM_IMAGE_FILES); + + /* load custom images */ + ReloadCustomImages(); + + InitGraphicInfo(); +} + +static void InitMixer() +{ + OpenAudio(); + + InitSoundList(sound_config, sound_config_suffix, NUM_SOUND_FILES); + + StartMixer(); +} + +static void InitSound() +{ + /* load custom sounds and music */ + InitReloadSounds(artwork.snd_current->identifier); + InitReloadMusic(artwork.mus_current->identifier); + + InitSoundInfo(); +} + +static void InitTileClipmasks() +{ +#if defined(TARGET_X11) + XGCValues clip_gc_values; + unsigned long clip_gc_valuemask; + +#if defined(TARGET_X11_NATIVE) + +#if 0 + GC copy_clipmask_gc; + + static struct { - fprintf(stderr,"%s: cannot access sound device - no sounds\n",progname); - sound_status=SOUND_OFF; - return; + int start; + int count; } + tile_needs_clipping[] = + { + { GFX_SPIELER1_UP, 4 }, + { GFX_SPIELER1_DOWN, 4 }, + { GFX_SPIELER1_LEFT, 4 }, + { GFX_SPIELER1_RIGHT, 4 }, + { GFX_SPIELER1_PUSH_LEFT, 4 }, + { GFX_SPIELER1_PUSH_RIGHT, 4 }, + { GFX_SPIELER2_UP, 4 }, + { GFX_SPIELER2_DOWN, 4 }, + { GFX_SPIELER2_LEFT, 4 }, + { GFX_SPIELER2_RIGHT, 4 }, + { GFX_SPIELER2_PUSH_LEFT, 4 }, + { GFX_SPIELER2_PUSH_RIGHT, 4 }, + { GFX_SPIELER3_UP, 4 }, + { GFX_SPIELER3_DOWN, 4 }, + { GFX_SPIELER3_LEFT, 4 }, + { GFX_SPIELER3_RIGHT, 4 }, + { GFX_SPIELER3_PUSH_LEFT, 4 }, + { GFX_SPIELER3_PUSH_RIGHT, 4 }, + { GFX_SPIELER4_UP, 4 }, + { GFX_SPIELER4_DOWN, 4 }, + { GFX_SPIELER4_LEFT, 4 }, + { GFX_SPIELER4_RIGHT, 4 }, + { GFX_SPIELER4_PUSH_LEFT, 4 }, + { GFX_SPIELER4_PUSH_RIGHT, 4 }, + { GFX_SP_MURPHY, 1 }, + { GFX_MURPHY_GO_LEFT, 3 }, + { GFX_MURPHY_GO_RIGHT, 3 }, + { GFX_MURPHY_SNAP_UP, 1 }, + { GFX_MURPHY_SNAP_DOWN, 1 }, + { GFX_MURPHY_SNAP_RIGHT, 1 }, + { GFX_MURPHY_SNAP_LEFT, 1 }, + { GFX_MURPHY_PUSH_RIGHT, 1 }, + { GFX_MURPHY_PUSH_LEFT, 1 }, + { GFX_GEBLUBBER, 4 }, + { GFX_DYNAMIT, 7 }, + { GFX_DYNABOMB, 4 }, + { GFX_EXPLOSION, 8 }, + { GFX_SOKOBAN_OBJEKT, 1 }, + { GFX_FUNKELN_BLAU, 3 }, + { GFX_FUNKELN_WEISS, 3 }, + { GFX2_SHIELD_PASSIVE, 3 }, + { GFX2_SHIELD_ACTIVE, 3 }, + { -1, 0 } + }; +#endif + +#endif /* TARGET_X11_NATIVE */ +#endif /* TARGET_X11 */ - if ((sound_device=open(sound_device_name,O_WRONLY))<0) + int i; + + /* initialize pixmap array for special X11 tile clipping to Pixmap 'None' */ + for(i=0; idrawable, + clip_gc_valuemask, &clip_gc_values); + + for(i=0; iclip_mask) + { + clip_gc_values.graphics_exposures = False; + clip_gc_values.clip_mask = pix[i]->clip_mask; + clip_gc_valuemask = GCGraphicsExposures | GCClipMask; + pix[i]->stored_clip_gc = XCreateGC(display, window->drawable, + clip_gc_valuemask, &clip_gc_values); + } } - close(sound_device); - sound_status=SOUND_AVAILABLE; +#if defined(TARGET_X11_NATIVE) -#ifdef VOXWARE - sound_loops_allowed = TRUE; - sound_loops_on = TRUE; -#endif +#if 0 + /* create graphic context structures needed for clipping */ + clip_gc_values.graphics_exposures = False; + clip_gc_valuemask = GCGraphicsExposures; + copy_clipmask_gc = XCreateGC(display, pix[PIX_BACK]->clip_mask, + clip_gc_valuemask, &clip_gc_values); - for(i=0;i=0; i++) { - Sound[i].name = sound_name[i]; - if (!LoadSound(&Sound[i])) + int j; + + for(j=0; jclip_mask; + + tile_clipmask[tile] = XCreatePixmap(display, window->drawable, + TILEX, TILEY, 1); + + XCopyArea(display, src_pixmap, tile_clipmask[tile], copy_clipmask_gc, + src_x, src_y, TILEX, TILEY, 0, 0); } } + + XFreeGC(display, copy_clipmask_gc); +#endif + +#endif /* TARGET_X11_NATIVE */ +#endif /* TARGET_X11 */ } -void InitSoundProcess() +void FreeTileClipmasks() { - if (sound_status==SOUND_OFF) - return; +#if defined(TARGET_X11) + int i; - if (pipe(sound_pipe)<0) + for(i=0; istored_clip_gc) + { + XFreeGC(display, pix[i]->stored_clip_gc); + pix[i]->stored_clip_gc = None; + } + } +#endif /* TARGET_X11 */ } -void InitJoystick() +void InitGfx() { - if (global_joystick_status==JOYSTICK_OFF) - return; + int i; - if (access(joystick_device_name[joystick_nr],R_OK)<0) - { - fprintf(stderr,"%s: cannot access joystick device '%s'\n", - joystick_device_name[joystick_nr],progname); - joystick_status = JOYSTICK_OFF; - return; - } + /* initialize some global variables */ + global.frames_per_second = 0; + global.fps_slowdown = FALSE; + global.fps_slowdown_factor = 1; + + /* 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 */ + pix[PIX_DB_DOOR] = CreateBitmap(3 * DXSIZE, DYSIZE + VYSIZE, DEFAULT_DEPTH); + pix[PIX_DB_FIELD] = CreateBitmap(FXSIZE, FYSIZE, DEFAULT_DEPTH); + + pix[PIX_FONT_SMALL] = LoadCustomImage(image_filename[PIX_FONT_SMALL]); - if ((joystick_device=open(joystick_device_name[joystick_nr],O_RDONLY))<0) + InitFontInfo(NULL, NULL, pix[PIX_FONT_SMALL], NULL); + + DrawInitText(WINDOW_TITLE_STRING, 20, FC_YELLOW); + DrawInitText(WINDOW_SUBTITLE_STRING, 50, FC_RED); + + DrawInitText("Loading graphics:", 120, FC_GREEN); + + for(i=0; iidentifier; + char *snd_new_identifier = artwork.snd_current->identifier; + char *mus_new_identifier = artwork.mus_current->identifier; + +#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; + +#if 0 + printf("--> '%s'\n", artwork.gfx_current_identifier); +#endif - /* get X server to connect to, if given as an argument */ - for (i=1;iidentifier) { - char *dispstr="-display"; - int len=MAX(strlen(dispstr),strlen(argv[i])); + 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 (len<4) - continue; - else if (!strncmp(argv[i],dispstr,len)) + if (strcmp(artwork.gfx_current_identifier, gfx_new_identifier) != 0 || + last_override_level_graphics != setup.override_level_graphics) + { + int i; + + setLevelArtworkDir(artwork.gfx_first); + + ClearRectangle(window, 0, 0, WIN_XSIZE, WIN_YSIZE); + + for(i=0; i -1) + { + int element = element_to_graphic[i].element; + int graphic = element_to_graphic[i].graphic; -void InitGfx() -{ - int i,j,x,y; - int xpm_err, xbm_err; - unsigned int width,height; - int hot_x,hot_y; - XGCValues gc_values; - unsigned long gc_valuemask; - XGCValues clip_gc_values; - unsigned long clip_gc_valuemask; - char filename[256]; - Pixmap shapemask; + element_info[element].graphic[GFX_ACTION_DEFAULT] = graphic; + i++; + } + + /* this initializes special graphics for left/right/up/down directions */ + i = 0; + while (element_to_direction_graphic[i].element > -1) + { + int element = element_to_direction_graphic[i].element; + + element_info[element].direction_graphic[GFX_ACTION_DEFAULT][MV_BIT_LEFT] = + element_to_direction_graphic[i].graphic_left; + element_info[element].direction_graphic[GFX_ACTION_DEFAULT][MV_BIT_RIGHT] = + element_to_direction_graphic[i].graphic_right; + element_info[element].direction_graphic[GFX_ACTION_DEFAULT][MV_BIT_UP] = + element_to_direction_graphic[i].graphic_up; + element_info[element].direction_graphic[GFX_ACTION_DEFAULT][MV_BIT_DOWN] = + element_to_direction_graphic[i].graphic_down; + + element_info[element].has_direction_graphic[GFX_ACTION_DEFAULT] = TRUE; + i++; + } +#else - for(i=0;i -1) { - if (pic[i].picture_filename) + int element = element_to_graphic[i].element; + int direction = element_to_graphic[i].direction; + int action = element_to_graphic[i].action; + int graphic = element_to_graphic[i].graphic; + + if (action > -1) + action = graphics_action_mapping[action]; + else + action = GFX_ACTION_DEFAULT; + + if (direction > -1) { - sprintf(filename,"%s/%s",GFX_PATH,pic[i].picture_filename); + direction = MV_DIR_BIT(direction); - xpm_att[i].valuemask = XpmCloseness; - xpm_att[i].closeness = 20000; - xpm_err = XpmReadFileToPixmap(display,window,filename, - &pix[i],&shapemask,&xpm_att[i]); - switch(xpm_err) - { - case XpmOpenFailed: - fprintf(stderr,"Xpm file open failed on '%s' !\n",filename); - CloseAll(); - exit(-1); - case XpmFileInvalid: - fprintf(stderr,"Invalid Xpm file '%s'!\n",filename); - CloseAll(); - exit(-1); - case XpmNoMemory: - fprintf(stderr,"Not enough memory !\n"); - CloseAll(); - exit(1); - case XpmColorFailed: - fprintf(stderr,"Can`t get any colors...\n"); - CloseAll(); - exit(-1); - default: - break; - } - if (!pix[i]) - { - fprintf(stderr, "%s: cannot read Xpm file '%s'.\n", - progname,filename); - CloseAll(); - exit(-1); - } + element_info[element].direction_graphic[action][direction] = graphic; } + else + element_info[element].graphic[action] = graphic; + + i++; + } + + /* now set all '-1' values to element specific default values */ + for(i=0; i 1) + new_graphic_info[i].anim_mode = ANIM_LOOP; + else + new_graphic_info[i].anim_mode = ANIM_NONE; + + /* set additional flag to play animation frames in reverse order */ + if (parameter[GFX_ARG_MODE_REVERSE]) + new_graphic_info[i].anim_mode |= ANIM_REVERSE; + +#if 1 + /* set first frame of animation after determining animation mode */ + new_graphic_info[i].anim_start_frame = parameter[GFX_ARG_START_FRAME]; + if (new_graphic_info[i].anim_start_frame == -1) + new_graphic_info[i].anim_start_frame = 0; + else if (new_graphic_info[i].anim_mode & ANIM_REVERSE) + new_graphic_info[i].anim_start_frame = + new_graphic_info[i].anim_frames + - new_graphic_info[i].anim_start_frame - 1; +#else + /* set first frame of animation after determining animation mode */ + new_graphic_info[i].anim_start_frame = parameter[GFX_ARG_START_FRAME]; + if (parameter[GFX_ARG_START_FRAME] == -1) /* default: start with ... */ + { + if (parameter[GFX_ARG_MODE_REVERSE]) + new_graphic_info[i].anim_start_frame = + new_graphic_info[i].anim_frames - 1; /* ... last frame */ + else + new_graphic_info[i].anim_start_frame = 0; /* ... first frame */ + } +#endif + + /* animation synchronized with global frame counter, not move position */ + new_graphic_info[i].anim_global_sync = parameter[GFX_ARG_GLOBAL_SYNC]; } - drawto = drawto_field = backbuffer = pix[PIX_DB_BACK]; +#if 0 + printf("D> %d\n", image_files[GFX_BD_DIAMOND].parameter[GFX_ARG_NUM_FRAMES]); + printf("W> %d\n", image_files[GFX_ROBOT_WHEEL].parameter[GFX_ARG_NUM_FRAMES]); - XCopyArea(display,pix[PIX_BACK],backbuffer,gc, - 0,0, WIN_XSIZE,WIN_YSIZE, 0,0); - XFillRectangle(display,backbuffer,gc, - REAL_SX,REAL_SY, FULL_SXSIZE,FULL_SYSIZE); + graphic_info[GFX_ABLENK].bitmap = getBitmapFromImageID(GFX_ROBOT_WHEEL); + graphic_info[GFX_ABLENK].src_x = 0; + graphic_info[GFX_ABLENK].src_y = 0; - for(i=0;i