コード例 #1
0
ファイル: game_saves.c プロジェクト: ommmmmmm/keeperfx
/**
 * Saves the game state file (savegame).
 * @note fill_game_catalogue_entry() should be called before to fill level information.
 *
 * @param slot_num
 * @return
 */
TbBool save_game(long slot_num)
{
    char *fname;
    TbFileHandle handle;
    if (!save_game_save_catalogue())
        return false;
/*  game.version_major = VersionMajor;
    game.version_minor = VersionMinor;
    game.load_restart_level = get_loaded_level_number();*/
    fname = prepare_file_fmtpath(FGrp_Save, saved_game_filename, slot_num);
    handle = LbFileOpen(fname,Lb_FILE_MODE_NEW);
    if (handle == -1)
    {
        WARNMSG("Cannot open file to save, \"%s\".",fname);
        return false;
    }
    if (!save_game_chunks(handle,&save_game_catalogue[slot_num]))
    {
        LbFileClose(handle);
        WARNMSG("Cannot write to save file, \"%s\".",fname);
        return false;
    }
    LbFileClose(handle);
    return true;
}
コード例 #2
0
ファイル: game_saves.c プロジェクト: ommmmmmm/keeperfx
TbBool load_game_save_catalogue(void)
{
    long slot_num;
    char *fname;
    TbFileHandle fh;
    struct FileChunkHeader hdr;
    struct CatalogueEntry *centry;
    long saves_found;
    //return load_game_catalogue(save_game_catalogue);
    saves_found = 0;
    for (slot_num=0; slot_num < TOTAL_SAVE_SLOTS_COUNT; slot_num++)
    {
        centry = &save_game_catalogue[slot_num];
        LbMemorySet(centry, 0, sizeof(struct CatalogueEntry));
        fname = prepare_file_fmtpath(FGrp_Save, saved_game_filename, slot_num);
        fh = LbFileOpen(fname,Lb_FILE_MODE_READ_ONLY);
        if (fh == -1)
            continue;
        if (LbFileRead(fh, &hdr, sizeof(struct FileChunkHeader)) == sizeof(struct FileChunkHeader))
        {
            if (load_catalogue_entry(fh,&hdr,centry))
                saves_found++;
        }
        LbFileClose(fh);
    }
    return (saves_found > 0);
}
コード例 #3
0
TbBool load_slab_tng_file(void)
{
    char *fname;
    SYNCDBG(5,"Starting");
    fname = prepare_file_fmtpath(FGrp_StdData,"slabs.tng");
    wait_for_cd_to_be_available();
    if ( LbFileExists(fname) )
      LbFileLoadAt(fname, &game.slabobjs_num);
    else
      ERRORLOG("Could not load slab object set");
    return true;
}
コード例 #4
0
/**
 * Loads map file with given level number and file extension.
 * @return Returns NULL if the file doesn't exist or is smaller than ldsize;
 * on success, returns a buffer which should be freed after use,
 * and sets ldsize into its size.
 */
unsigned char *load_single_map_file_to_buffer(LevelNumber lvnum,const char *fext,long *ldsize,unsigned short flags)
{
  unsigned char *buf;
  char *fname;
  long fsize;
  short fgroup;
  fgroup = get_level_fgroup(lvnum);
  fname = prepare_file_fmtpath(fgroup,"map%05lu.%s",lvnum,fext);
  wait_for_cd_to_be_available();
  fsize = LbFileLengthRnc(fname);
  if (fsize < *ldsize)
  {
    if ((flags & LMFF_Optional) == 0)
      WARNMSG("Map file \"map%05lu.%s\" doesn't exist or is too small.",lvnum,fext);
    else
      SYNCMSG("Optional file \"map%05lu.%s\" doesn't exist or is too small.",lvnum,fext);
    return NULL;
  }
  if (fsize > ANY_MAP_FILE_MAX_SIZE)
  {
    if ((flags & LMFF_Optional) == 0)
      WARNMSG("Map file \"map%05lu.%s\" exceeds max size of %d; loading failed.",lvnum,fext,ANY_MAP_FILE_MAX_SIZE);
    else
      SYNCMSG("Optional file \"map%05lu.%s\" exceeds max size of %d; not loading.",lvnum,fext,ANY_MAP_FILE_MAX_SIZE);
    return NULL;
  }
  buf = LbMemoryAlloc(fsize+16);
  if (buf == NULL)
  {
    if ((flags & LMFF_Optional) == 0)
      WARNMSG("Can't allocate %ld bytes to load \"map%05lu.%s\".",fsize,lvnum,fext);
    else
      SYNCMSG("Can't allocate %ld bytes to load \"map%05lu.%s\".",fsize,lvnum,fext);
    return NULL;
  }
  fsize = LbFileLoadAt(fname,buf);
  if (fsize < *ldsize)
  {
    if ((flags & LMFF_Optional) == 0)
      WARNMSG("Reading map file \"map%05lu.%s\" failed.",lvnum,fext);
    else
      SYNCMSG("Reading optional file \"map%05lu.%s\" failed.",lvnum,fext);
    LbMemoryFree(buf);
    return NULL;
  }
  *ldsize = fsize;
  SYNCDBG(7,"Map file \"map%05lu.%s\" loaded.",lvnum,fext);
  return buf;
}
コード例 #5
0
TbBool load_texture_map_file(unsigned long tmapidx, unsigned char n)
{
    char *fname;
    SYNCDBG(7,"Starting");
#ifdef SPRITE_FORMAT_V2
    fname = prepare_file_fmtpath(FGrp_StdData,"tmapa%03d-%d.dat",tmapidx,32);
#else
    fname = prepare_file_fmtpath(FGrp_StdData,"tmapa%03d.dat",tmapidx);
#endif
    if (!wait_for_cd_to_be_available())
        return false;
    if (!LbFileExists(fname))
    {
        WARNMSG("Texture file \"%s\" doesn't exits.",fname);
        return false;
    }
    // The texture file has always over 500kb
    if (LbFileLoadAt(fname, block_mem) < 65536)
    {
        WARNMSG("Texture file \"%s\" can't be loaded or is too small.",fname);
        return false;
    }
    return true;
}
コード例 #6
0
short load_level_file(LevelNumber lvnum)
{
    char *fname;
    short fgroup;
    short result;
    fgroup = get_level_fgroup(lvnum);
    fname = prepare_file_fmtpath(fgroup,"map%05lu.slb",(unsigned long)lvnum);
    wait_for_cd_to_be_available();
    if (LbFileExists(fname))
    {
        result = true;
        load_map_data_file(lvnum);
        load_map_flag_file(lvnum);
        load_column_file(lvnum);
        init_whole_blocks();
        load_slab_file();
        init_columns();
        load_static_light_file(lvnum);
        if (!load_map_ownership_file(lvnum))
          result = false;
        load_map_wibble_file(lvnum);
        load_and_setup_map_info(lvnum);
        load_texture_map_file(game.texture_id, 2);
        load_action_point_file(lvnum);
        if (!load_map_slab_file(lvnum))
          result = false;
        if (!load_thing_file(lvnum))
          result = false;
        reinitialise_map_rooms();
        ceiling_init(0, 1);
    } else
    {
        ERRORLOG("The level \"map%05lu\" doesn't exist; creating empty map.",lvnum);
        init_whole_blocks();
        load_slab_file();
        init_columns();
        game.texture_id = 0;
        load_texture_map_file(game.texture_id, 2);
        init_top_texture_to_cube_table();
        result = false;
    }
    return result;
}
コード例 #7
0
ファイル: game_saves.c プロジェクト: ommmmmmm/keeperfx
TbBool is_save_game_loadable(long slot_num)
{
    char *fname;
    TbFileHandle fh;
    struct FileChunkHeader hdr;
    // Prepare filename and open the file
    fname = prepare_file_fmtpath(FGrp_Save,saved_game_filename,slot_num);
    fh = LbFileOpen(fname, Lb_FILE_MODE_READ_ONLY);
    if (fh != -1)
    {
        // Let's try to read the file, just to be sure
        if (LbFileRead(fh, &hdr, sizeof(struct FileChunkHeader)) == sizeof(struct FileChunkHeader))
        {
            LbFileClose(fh);
            return true;
        }
        LbFileClose(fh);
    }
    return false;
}
コード例 #8
0
ファイル: config_strings.c プロジェクト: joaocc/keeperfx-git
/**
 * Loads the language-specific strings data for game interface.
 */
TbBool setup_gui_strings_data(void)
{
  char *strings_data_end;
  char *fname;
  short result;
  long filelen;
  long loaded_size;
  SYNCDBG(8,"Starting");

  fname = prepare_file_fmtpath(FGrp_FxData,"gtext_%s.dat",get_language_lwrstr(install_info.lang_id));
  filelen = LbFileLengthRnc(fname);
  if (filelen <= 0)
  {
    ERRORLOG("GUI Strings file does not exist or can't be opened");
    SYNCLOG("Strings file name is \"%s\"",fname);
    return false;
  }
  gui_strings_data = (char *)LbMemoryAlloc(filelen + 256);
  if (gui_strings_data == NULL)
  {
    ERRORLOG("Can't allocate memory for GUI Strings data");
    SYNCLOG("Strings file name is \"%s\"",fname);
    return false;
  }
  strings_data_end = gui_strings_data+filelen+255;
  loaded_size = LbFileLoadAt(fname, gui_strings_data);
  if (loaded_size < 16)
  {
    ERRORLOG("GUI Strings file couldn't be loaded or is too small");
    return false;
  }
  // Resetting all values to empty strings
  reset_strings(gui_strings);
  // Analyzing strings data and filling correct values
  result = create_strings_list(gui_strings, gui_strings_data, strings_data_end);
  // Updating strings inside the DLL
  LbMemoryCopy(_DK_strings, gui_strings, DK_STRINGS_MAX*sizeof(char *));
  SYNCDBG(19,"Finished");
  return result;
}
コード例 #9
0
ファイル: game_saves.c プロジェクト: ommmmmmm/keeperfx
TbBool load_game(long slot_num)
{
    TbFileHandle fh;
    long file_len;
    struct PlayerInfo *player;
    struct Dungeon *dungeon;
    struct CatalogueEntry *centry;
//  unsigned char buf[14];
//  char cmpgn_fname[CAMPAIGN_FNAME_LEN];
    SYNCDBG(6,"Starting");
    reset_eye_lenses();
    {
        // Use fname only here - it is overwritten by next use of prepare_file_fmtpath()
        char *fname;
        fname = prepare_file_fmtpath(FGrp_Save,saved_game_filename,slot_num);
        if (!wait_for_cd_to_be_available())
          return false;
        fh = LbFileOpen(fname,Lb_FILE_MODE_READ_ONLY);
        if (fh == -1)
        {
          WARNMSG("Cannot open saved game file \"%s\".",fname);
          save_catalogue_slot_disable(slot_num);
          return false;
        }
    }
    file_len = LbFileLengthHandle(fh);
    if (is_primitive_save_version(file_len))
    {
        //if (LbFileRead(handle, buf, sizeof(buf)) != sizeof(buf))
        {
          LbFileClose(fh);
          save_catalogue_slot_disable(slot_num);
          return false;
        }
        /*LbFileSeek(fh, (char *)&game.campaign_fname[0] - (char *)&game, Lb_FILE_SEEK_BEGINNING);
        LbFileRead(fh, cmpgn_fname, CAMPAIGN_FNAME_LEN);
        cmpgn_fname[CAMPAIGN_FNAME_LEN-1] = '\0';
        if (!change_campaign(cmpgn_fname))
        {
          ERRORLOG("Unable to load campaign associated with saved game");
        }
        LbFileClose(fh);
        WARNMSG("Saved game file \"%s\" has incompatible version; restarting level.",fname);
        player = get_my_player();
        player->field_7 = 0;
        my_player_number = default_loc_player;
        player = get_my_player();
        game.flagfield_14EA4A = 2;
        set_flag_byte(&game.system_flags,GSF_NetworkActive,false);
        player->field_2C = 1;
        set_selected_level_number(((struct Game *)buf)->load_restart_level);
        set_continue_level_number(((struct Game *)buf)->continue_level_number);
        startup_network_game();
        return true;*/
    }
    centry = &save_game_catalogue[slot_num];
    LbFileSeek(fh, 0, Lb_FILE_SEEK_BEGINNING);
    // Here is the actual loading
    if (load_game_chunks(fh,centry) != GLoad_SavedGame)
    {
        LbFileClose(fh);
        WARNMSG("Couldn't correctly load saved game in slot %d.",(int)slot_num);
        init_lookups();
        return false;
    }
    LbFileClose(fh);
    LbStringCopy(game.campaign_fname,campaign.fname,sizeof(game.campaign_fname));
    reinit_level_after_load();
    output_message(SMsg_GameLoaded, 0, true);
    pannel_map_update(0, 0, map_subtiles_x+1, map_subtiles_y+1);
    calculate_moon_phase(false,false);
    update_extra_levels_visibility();
    player = get_my_player();
    set_flag_byte(&player->field_3,0x08,false);
    set_flag_byte(&player->field_3,0x04,false);
    player->field_4C1 = 0;
    player->field_4C5 = 0;
    player->field_7 = 0;
    PaletteSetPlayerPalette(player, engine_palette);
    reinitialise_eye_lens(game.numfield_1B);
    // Update the lights system state
    light_import_system_state(&gameadd.lightst);
    // Victory state
    if (player->victory_state != VicS_Undecided)
    {
      frontstats_initialise();
      dungeon = get_players_dungeon(player);
      dungeon->lvstats.player_score = 0;
      dungeon->lvstats.allow_save_score = 1;
    }
    game.loaded_swipe_idx = -1;
    return true;
}
コード例 #10
0
ファイル: front_torture.c プロジェクト: ommmmmmm/keeperfx
void fronttorture_load(void)
{
    struct PlayerInfo *player;
    char *fname;
    unsigned char *ptr;
    long i,k;
    wait_for_cd_to_be_available();
    frontend_load_data_from_cd();
    memcpy(frontend_backup_palette, &frontend_palette, PALETTE_SIZE);
    // Texture blocks memory isn't used here, so reuse it instead of allocating
    ptr = block_mem;
    // Load RAW/PAL background
    fname = prepare_file_path(FGrp_LoData,"torture.raw");
    torture_background = ptr;
    i = LbFileLoadAt(fname, ptr);
    ptr += i;
    fname = prepare_file_path(FGrp_LoData,"torture.pal");
    torture_palette = ptr;
    i = LbFileLoadAt(fname, ptr);
    ptr += i;

    // Load DAT/TAB sprites for doors
    k = 0;
    {
        fname = prepare_file_fmtpath(FGrp_LoData,"door%02d.dat",k+1);
        i = LbFileLoadAt(fname, ptr);
        doors[k].data = ptr;
        ptr += i;
        doors[k].data_end = ptr;

        fname = prepare_file_fmtpath(FGrp_LoData,"door%02d.tab",k+1);
        i = LbFileLoadAt(fname, ptr);
        doors[k].sprites = (struct TbSprite *)ptr;
        ptr += i;
        doors[k].sprites_end =(struct TbSprite *) ptr;
    }
    ptr = &game.land_map_start;
    for (k=1; k < 8; k++)
    {
        fname = prepare_file_fmtpath(FGrp_LoData,"door%02d.dat",k+1);
        i = LbFileLoadAt(fname, ptr);
        doors[k].data = ptr;
        ptr += i;
        doors[k].data_end = ptr;
        fname = prepare_file_fmtpath(FGrp_LoData,"door%02d.tab",k+1);
        i = LbFileLoadAt(fname, ptr);
        doors[k].sprites = (struct TbSprite *)ptr;
        ptr += i;
        doors[k].sprites_end = (struct TbSprite *)ptr;
    }
    ptr = poly_pool;
    k = 8;
    {
        fname = prepare_file_fmtpath(FGrp_LoData,"door%02d.dat",k+1);
        i = LbFileLoadAt(fname, ptr);
        doors[k].data = ptr;
        ptr += i;
        doors[k].data_end = ptr;
        fname = prepare_file_fmtpath(FGrp_LoData,"door%02d.tab",k+1);
        i = LbFileLoadAt(fname, ptr);
        doors[k].sprites = (struct TbSprite *)ptr;
        ptr += i;
        doors[k].sprites_end = (struct TbSprite *)ptr;
    }

    if ( LbDataLoadAll(torture_load_files) )
        ERRORLOG("Unable to load torture load files");
    LbSpriteSetupAll(setup_torture_sprites);
    frontend_load_data_reset();
    memcpy(&frontend_palette, torture_palette, PALETTE_SIZE);
    torture_state.action = 0;
    torture_door_selected = -1;
    torture_end_sprite = -1;
    torture_sprite_direction = 0;
    LbMemorySet(door_sound_state, 0, TORTURE_DOORS_COUNT*sizeof(struct DoorSoundState));

    player = get_my_player();
    if (player->victory_state == VicS_WonLevel)
    {
        LbMouseChangeSpriteAndHotspot(&fronttor_sprites[1], 0, 0);
    } else
    {
        LbMouseChangeSpriteAndHotspot(0, 0, 0);
    }
    torture_left_button = 0;
}
コード例 #11
0
TbBool setup_heaps(void)
{
    TbBool low_memory;
    char snd_fname[2048];
    char *spc_fname;
    long i;
    SYNCDBG(8,"Starting");
    low_memory = false;
    if (!SoundDisabled)
    {
      StopAllSamples();
      close_sound_heap();
      if (sound_heap_memory != NULL)
      {
        LbMemoryFree(sound_heap_memory);
        sound_heap_memory = NULL;
      }
    }
    if (heap != NULL)
    {
      ERRORLOG("Graphics heap already allocated");
      LbMemoryFree(heap);
      heap = NULL;
    }
    // Allocate sound heap
    if (!SoundDisabled)
    {
      i = mem_size;
      while (sound_heap_memory == NULL)
      {
        sound_heap_size = get_best_sound_heap_size(i);
        i = get_smaller_memory_amount(i);
        sound_heap_memory = LbMemoryAlloc(sound_heap_size);
        if ((i <= 8) && (sound_heap_memory == NULL))
        {
          low_memory = true;
          break;
        }
      }
    }
    // Allocate graphics heap
    i = mem_size;
    while (heap == NULL)
    {
      heap_size = get_best_sound_heap_size(i);
      i = get_smaller_memory_amount(i);
      heap = LbMemoryAlloc(heap_size);
      if ((i <= 8) && (heap == NULL))
      {
        low_memory = true;
        break;
      }
    }
    SYNCMSG("GraphicsHeap Size %d", heap_size);

    if (low_memory)
    {
      SYNCDBG(8,"Low memory mode entered on heap allocation.");
      while (heap != NULL)
      {
        if ((!SoundDisabled) && (sound_heap_memory == NULL))
        {
          break;
        }
        if (!SoundDisabled)
        {
          if (sound_heap_size < heap_size)
          {
            heap_size -= 16384;
          } else
          if (sound_heap_size == heap_size)
          {
            heap_size -= 16384;
            sound_heap_size -= 16384;
          } else
          {
            sound_heap_size -= 16384;
          }
          if (sound_heap_size < 524288)
          {
            ERRORLOG("Unable to allocate heaps (small_mem)");
            return false;
          }
        } else
        {
          heap_size -= 16384;
        }
        if (heap_size < 524288)
        {
          if (sound_heap_memory != NULL)
          {
            LbMemoryFree(sound_heap_memory);
            sound_heap_memory = NULL;
          }
          ERRORLOG("Unable to allocate heaps (small_mem)");
          return false;
          }
        }
        if (sound_heap_memory != NULL)
        {
          LbMemoryFree(sound_heap_memory);
          sound_heap_memory = NULL;
        }
        if (heap != NULL)
        {
          LbMemoryFree(heap);
          heap = NULL;
        }
        if (!SoundDisabled)
        {
          sound_heap_memory = LbMemoryAlloc(sound_heap_size);
        }
        heap = LbMemoryAlloc(heap_size);
    }
    if (!SoundDisabled)
    {
      SYNCMSG("SoundHeap Size %d", sound_heap_size);
      // Prepare sound sample bank file names
      prepare_file_path_buf(snd_fname,FGrp_LrgSound,sound_fname);
      // language-specific speech file
      spc_fname = prepare_file_fmtpath(FGrp_LrgSound,"speech_%s.dat",get_language_lwrstr(install_info.lang_id));
      // default speech file
      if (!LbFileExists(spc_fname))
        spc_fname = prepare_file_path(FGrp_LrgSound,speech_fname);
      // speech file for english
      if (!LbFileExists(spc_fname))
        spc_fname = prepare_file_fmtpath(FGrp_LrgSound,"speech_%s.dat",get_language_lwrstr(1));
      // Initialize sample banks
      if (!init_sound_heap_two_banks(sound_heap_memory, sound_heap_size, snd_fname, spc_fname, 1622))
      {
        LbMemoryFree(sound_heap_memory);
        sound_heap_memory = NULL;
        SoundDisabled = true;
        ERRORLOG("Unable to initialize sound heap. Sound disabled.");
      }
    }
    return true;
}