Esempio n. 1
0
void read_resources_dat()
{
  std::string resourcefile = Plib::systemstate.config.world_data_path + "resource.dat";

  if ( Clib::FileExists( resourcefile ) )
  {
    Clib::ConfigFile cf( resourcefile, "GLOBALRESOURCEPOOL REGIONALRESOURCEPOOL" );
    Clib::ConfigElem elem;
    while ( cf.read( elem ) )
    {
      if ( elem.type_is( "GlobalResourcePool" ) )
      {
        read_global_data( elem );
      }
      else
      {
        read_region_data( elem );
      }
    }
  }
}
Esempio n. 2
0
void read_resource_cfg( const char* resource )
{
  std::string filename = std::string( "regions/" ) + resource + std::string( ".cfg" );
  Clib::ConfigFile cf( filename.c_str(), "GLOBAL REGION" );
  Clib::ConfigElem elem;

  std::unique_ptr<ResourceDef> rd( new ResourceDef( resource ) );

  while ( cf.read( elem ) )
  {
    if ( elem.type_is( "global" ) )
    {
      rd->read_config( elem );
    }
    else
    {
      rd->read_region( elem );
    }
  }

  gamestate.resourcedefs[resource] = rd.release();
}
Esempio n. 3
0
void read_npc_templates( Plib::Package* pkg )
{
  std::string filename = GetPackageCfgPath( pkg, "npcdesc.cfg" );
  if ( !Clib::FileExists( filename ) )
    return;

  Clib::ConfigFile cf( filename.c_str() );
  Clib::ConfigElem elem;
  while ( cf.read( elem ) )
  {
    if ( elem.type_is( "NpcTemplate" ) )
    {
      // first determine the NPC template name.
      std::string namebase;
      const char* rest = elem.rest();
      if ( rest != NULL && *rest != '\0' )
      {
        namebase = rest;
      }
      else
      {
        namebase = elem.remove_string( "TemplateName" );
      }
      std::string descname;
      if ( pkg != NULL )
      {
        descname = ":" + pkg->name() + ":" + namebase;
        elem.set_rest( descname.c_str() );
      }
      else
        descname = namebase;

      gamestate.npc_template_elems[descname] = NpcTemplateElem( cf, elem );
    }
  }
}
Esempio n. 4
0
// FIXME inefficient.  Templates should be read in once, and reused.
bool FindNpcTemplate( const char* template_name, Clib::ConfigFile& cf, Clib::ConfigElem& elem )
{
  try
  {
    const Plib::Package* pkg;
    std::string npctemplate;
    if ( !Plib::pkgdef_split( template_name, NULL, &pkg, &npctemplate ) )
      return false;

    std::string filename =
        Plib::GetPackageCfgPath( const_cast<Plib::Package*>( pkg ), "npcdesc.cfg" );

    cf.open( filename.c_str() );
    while ( cf.read( elem ) )
    {
      if ( !elem.type_is( "NpcTemplate" ) )
        continue;

      std::string orig_rest = elem.rest();
      if ( pkg != NULL )
      {
        std::string newrest = ":" + pkg->name() + ":" + npctemplate;
        elem.set_rest( newrest.c_str() );
      }
      const char* rest = elem.rest();
      if ( rest != NULL && *rest != '\0' )
      {
        if ( stricmp( orig_rest.c_str(), npctemplate.c_str() ) == 0 )
          return true;
      }
      else
      {
        std::string tname = elem.remove_string( "TemplateName" );
        if ( stricmp( tname.c_str(), npctemplate.c_str() ) == 0 )
          return true;
      }
    }
    return false;
  }
  catch ( const char* msg )
  {
    ERROR_PRINT << "NPC Creation (" << template_name << ") Failed: " << msg << "\n";
  }
  catch ( std::string& str )
  {
    ERROR_PRINT << "NPC Creation (" << template_name << ") Failed: " << str << "\n";
  }                                 // egcs has some trouble realizing 'exception' should catch
  catch ( std::runtime_error& re )  // runtime_errors, so...
  {
    ERROR_PRINT << "NPC Creation (" << template_name << ") Failed: " << re.what() << "\n";
  }
  catch ( std::exception& ex )
  {
    ERROR_PRINT << "NPC Creation (" << template_name << ") Failed: " << ex.what() << "\n";
  }
#ifndef WIN32
  catch ( ... )
  {
  }
#endif
  return false;
}
Esempio n. 5
0
int UoConvertMain::main()
{
  const std::vector<std::string>& binArgs = programArgs();

  /**********************************************
   * show help
   **********************************************/
  if ( binArgs.size() == 1 )
  {
    showHelp();
    return 0;  // return "okay"
  }

  /**********************************************
   * TODO: rework the following cruft from former uoconvert.cpp
   **********************************************/
  Plib::systemstate.config.max_tile_id = UOBJ_DEFAULT_MAX;  // default
  std::string argvalue = programArgsFindEquals( "uodata=", "" );
  if ( !argvalue.empty() )
  {
    Plib::systemstate.config.uo_datafile_root = argvalue;
    Plib::systemstate.config.uo_datafile_root =
        Clib::normalized_dir_form( Plib::systemstate.config.uo_datafile_root );
  }
  else
  {
    INFO_PRINT << "Reading pol.cfg.\n";
    Clib::ConfigFile cf( "pol.cfg" );
    Clib::ConfigElem elem;

    cf.readraw( elem );
    Plib::systemstate.config.uo_datafile_root = elem.remove_string( "UoDataFileRoot" );
    Plib::systemstate.config.uo_datafile_root =
        Clib::normalized_dir_form( Plib::systemstate.config.uo_datafile_root );

    unsigned short max_tile = elem.remove_ushort( "MaxTileID", UOBJ_DEFAULT_MAX );

    if ( max_tile == UOBJ_DEFAULT_MAX || max_tile == UOBJ_SA_MAX || max_tile == UOBJ_HSA_MAX )
      Plib::systemstate.config.max_tile_id = max_tile;
  }

  unsigned short max_tile =
      static_cast<unsigned short>( programArgsFindEquals( "maxtileid=", UOBJ_DEFAULT_MAX, true ) );
  if ( max_tile == UOBJ_DEFAULT_MAX || max_tile == UOBJ_SA_MAX || max_tile == UOBJ_HSA_MAX )
    Plib::systemstate.config.max_tile_id = max_tile;


  std::string main_cfg = "uoconvert.cfg";
  if ( Clib::FileExists( main_cfg.c_str() ) )
  {
    std::string temp;
    Clib::ConfigElem elem;
    INFO_PRINT << "Reading uoconvert.cfg.\n";
    Clib::ConfigFile cf_main( main_cfg.c_str() );
    while ( cf_main.read( elem ) )
    {
      if ( elem.type_is( "MultiTypes" ) )
      {
        temp = elem.remove_string( "Boats" );
        ISTRINGSTREAM is_boats( temp );
        std::string graphicnum;
        while ( is_boats >> graphicnum )
          UoConvert::BoatTypes.insert( strtoul( graphicnum.c_str(), NULL, 0 ) );

        temp = elem.remove_string( "Houses" );
        ISTRINGSTREAM is_houses( temp );
        while ( is_houses >> graphicnum )
          UoConvert::HouseTypes.insert( strtoul( graphicnum.c_str(), NULL, 0 ) );

        temp = elem.remove_string( "Stairs" );
        ISTRINGSTREAM is_stairs( temp );
        while ( is_stairs >> graphicnum )
          UoConvert::StairTypes.insert( strtoul( graphicnum.c_str(), NULL, 0 ) );
      }
      else if ( elem.type_is( "LOSOptions" ) )