예제 #1
0
/**
 * 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
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 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;
}
예제 #4
0
void net_load_config_file(void)
{
    TbFileHandle handle;
    char *fname;
    // Try to load the config file
    fname = prepare_file_path(FGrp_Save,keeper_netconf_file);
    handle = LbFileOpen(fname, Lb_FILE_MODE_READ_ONLY);
    if (handle != -1)
    {
      if (LbFileRead(handle, &net_config_info, sizeof(net_config_info)) == sizeof(net_config_info))
      {
        LbFileClose(handle);
        return;
      }
      LbFileClose(handle);
    }
    // If can't load, then use default config
    LbMemoryCopy(&net_config_info, &default_net_config_info, sizeof(net_config_info));
    LbStringCopy(net_config_info.str_u2, get_string(GUIStr_MnuNoName), 20);
}
예제 #5
0
//Returns disk size of file
long LbFileLength(const char *fname)
{
  TbFileHandle handle;
  handle = LbFileOpen(fname, Lb_FILE_MODE_READ_ONLY);
  long result = handle;
  if ( handle != -1 )
  {
    result = filelength(handle);
    LbFileClose(handle);
  }
  return result;
}
예제 #6
0
TbBool load_ceiling_table(void)
{
    char *fname;
    TbFileHandle fh;
    unsigned short *value_array;
    char nchr;
    char numstr[8];
    TbBool do_next;
    long i,n;
    //_DK_load_ceiling_table(); return true;
    // Prepare filename and open the file
    wait_for_cd_to_be_available();
    fname = prepare_file_path(FGrp_StdData,"ceiling.txt");
    fh = LbFileOpen(fname, Lb_FILE_MODE_READ_ONLY);
    if (fh == -1) {
        return false;
    }

    value_array = &floor_to_ceiling_map[0];
    n = 0;
    do_next = 1;
    while (do_next == 1)
    {
        {
            do_next = LbFileRead(fh, &nchr, 1);
            if (do_next != 1)
                break;
            if ( (nchr == 10) || (nchr == 44) || (nchr == 32) || (nchr == 9) || (nchr == 13) )
                continue;
        }
        LbMemorySet(numstr, 0, sizeof(numstr));
        for (i=0; i < sizeof(numstr); i++)
        {
            numstr[i] = nchr;
            do_next = LbFileRead(fh, &nchr, 1);
            if (do_next != 1)
                break;
            if ( (nchr == 10) || (nchr == 44) || (nchr == 32) || (nchr == 9) || (nchr == 13) )
                break;
        }
        value_array[n] = atol(numstr);
        n++;
        if (n >= sizeof(floor_to_ceiling_map)/sizeof(floor_to_ceiling_map[0]))
        {
            do_next = 0;
        }
    }
    LbFileClose(fh);
    memcpy(_DK_floor_to_ceiling_map,floor_to_ceiling_map,sizeof(floor_to_ceiling_map));
    return true;
}
예제 #7
0
void net_write_config_file(void)
{
    TbFileHandle handle;
    char *fname;
    // Try to load the config file
    fname = prepare_file_path(FGrp_Save,keeper_netconf_file);
    handle = LbFileOpen(fname, Lb_FILE_MODE_NEW);
    if (handle != -1)
    {
        strupr(net_config_info.str_atz);
        strupr(net_config_info.str_ath);
        strupr(net_config_info.str_atdt);
        strupr(net_config_info.str_ats);
        LbFileWrite(handle, &net_config_info, sizeof(net_config_info));
        LbFileClose(handle);
    }
}
예제 #8
0
short read_continue_game_part(unsigned char *buf,long pos,long buf_len)
{
  TbFileHandle fh;
  short result;
  char *fname;
  fname = prepare_file_path(FGrp_Save,continue_game_filename);
  if (LbFileLength(fname) != sizeof(struct Game))
  {
    SYNCDBG(7,"No correct .SAV file; there's no continue");
    return false;
  }
  fh = LbFileOpen(fname,Lb_FILE_MODE_READ_ONLY);
  if (fh == -1)
  {
    SYNCDBG(7,"Can't open .SAV file; there's no continue");
    return false;
  }
  LbFileSeek(fh, pos, Lb_FILE_SEEK_BEGINNING);
  result = (LbFileRead(fh, buf, buf_len) == buf_len);
  LbFileClose(fh);
  return result;
}
예제 #9
0
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;
}