Exemple #1
0
void read_global_data( Clib::ConfigElem& elem )
{
  ResourceDef* rd = find_resource_def( elem.rest() );
  if ( rd == nullptr )
  {
    ERROR_PRINT << "Error reading RESOURCE.DAT: Unable to find resource type " << elem.rest()
                << "\n";
    throw std::runtime_error( "Data file error" );
  }

  rd->read_data( elem );
}
Exemple #2
0
	void load_circle_data()
	{
	  if ( !Clib::FileExists( "config/circles.cfg" ) )
	  {
		if ( config.loglevel > 1 )
		  INFO_PRINT << "File config/circles not found, skipping.\n";
		return;
	  }

      Clib::ConfigFile cf( "config/circles.cfg", "Circle" );
      Clib::ConfigElem elem;

	  while ( cf.read( elem ) )
	  {
		int index = strtoul( elem.rest(), NULL, 0 ) - 1;
		if ( index < 0 || index >= 100 )
		{
          ERROR_PRINT << "Error in CIRCLES.CFG: Circle must fall between 1 and 100\n";
		  throw std::runtime_error( "Config file error" );
		}

		spellcircles.resize( index + 1, NULL );

		if ( spellcircles[index] != NULL )
		{
          ERROR_PRINT << "Error in CIRCLES.CFG: Circle " << index + 1 << " is multiply defined.\n";
		  throw std::runtime_error( "Config file error" );
		}

		spellcircles[index] = new SpellCircle( elem );
	  }
	}
Exemple #3
0
UOSkill::UOSkill( const Plib::Package* pkg, Clib::ConfigElem& elem )
    : inited( true ),
      skillid( strtoul( elem.rest(), nullptr, 10 ) ),
      attributename( elem.remove_string( "Attribute", "" ) ),
      pAttr( nullptr ),
      pkg( pkg )
{
  if ( skillid >= 500 )
    elem.throw_error( "SkillID must be < 500" );

  if ( !attributename.empty() )
  {
    bool required = false;
    if ( attributename[0] == '+' )
    {
      required = true;
      attributename = attributename.substr( 1, std::string::npos );
    }
    pAttr = Mobile::Attribute::FindAttribute( attributename );
    if ( !pAttr )
    {
      if ( required )
      {
        elem.throw_error( "Attribute " + attributename + " not found." );
      }
      else
      {
        elem.warn( "Attribute " + attributename + " not found." );
      }
    }
  }
}
Exemple #4
0
	JusticeRegion::JusticeRegion( Clib::ConfigElem& elem, RegionId id ) :
	  Region( elem, id ),
	  guarded_( elem.remove_bool( "Guarded", false ) ),
	  nocombat_( elem.remove_bool( "NoCombat", false ) ),
	  region_name_( elem.rest() ),
	  entertext_( elem.remove_string( "EnterText", "" ) ),
	  leavetext_( elem.remove_string( "LeaveText", "" ) ),
	  enter_script_( elem.remove_string( "EnterScript", "" ) ),
	  leave_script_( elem.remove_string( "LeaveScript", "" ) )
	{}
Exemple #5
0
void read_region_data( Clib::ConfigElem& elem )
{
  ResourceDef* rd = find_resource_def( elem.rest() );
  if ( rd == nullptr )
  {
    ERROR_PRINT << "Error reading RESOURCE.DAT: Unable to find resource type " << elem.rest()
                << "\n";
    throw std::runtime_error( "Data file error" );
  }
  std::string regionname = elem.remove_string( "Name" );
  ResourceRegion* rgn = rd->getregion( regionname );
  if ( rgn == nullptr )
  {
    ERROR_PRINT << "Error reading RESOURCE.DAT: Unable to find region " << regionname
                << " in resource " << elem.rest() << "\n";
    throw std::runtime_error( "Data file error" );
  }
  rgn->read_data( elem );
}
Exemple #6
0
void process_package_cmds_cfg( Plib::Package* pkg )
{
  // ConfigFile cf( (pkg->dir() + "cmds.cfg").c_str(), "Commands" );
  Clib::ConfigFile cf( GetPackageCfgPath( pkg, "cmds.cfg" ).c_str(), "Commands" );
  Clib::ConfigElem elem;
  while ( cf.read( elem ) )
  {
    CmdLevel* cmdlevel = find_cmdlevel( elem.rest() );
    if ( !cmdlevel )
    {
      elem.throw_error( std::string( "Command Level " ) + elem.rest() + " not found." );
    }

    std::string tmp;
    while ( elem.remove_prop( "DIR", &tmp ) )
    {
      Clib::mklower( tmp );
      cmdlevel->add_searchdir_front( pkg, Clib::normalized_dir_form( pkg->dir() + tmp ) );
    }
  }
}
	void read_multidefs()
	{
      Clib::ConfigFile cf( "config/multis.cfg", "BOAT HOUSE STAIRS" );
      Clib::ConfigElem elem;
	  while ( cf.read( elem ) )
	  {
		u16 multiid = static_cast<u16>( strtoul( elem.rest(), NULL, 0 ) );

		MultiDef* mdef = new MultiDef( elem, multiid );
		mdef->init();

		multidef_buffer.multidefs_by_multiid[mdef->multiid] = mdef;
	  }
	}
Exemple #8
0
	NpcTemplate::NpcTemplate( const Clib::ConfigElem& elem, const Plib::Package* pkg ) :
	  intrinsic_weapon( Items::find_intrinsic_weapon( elem.rest() ) ),
	  pkg( pkg ),
	  // script( elem.read_string( "SCRIPT" ) ),
	  alignment( static_cast<ALIGNMENT>( translate( elem.read_string( "ALIGNMENT", "neutral" ), xlate_align ) ) ),
	  method_script( NULL )
	{
	  if ( pkg == NULL )
	  {
		name = elem.rest();
	  }
	  else
	  {
		if ( elem.rest()[0] == ':' )
		{
		  name = elem.rest();
		}
		else
		{
		  name = ":" + pkg->name() + ":" + elem.rest();
		}
	  }

	  if ( elem.has_prop( "MethodScript" ) )
	  {
		std::string temp = elem.read_string( "MethodScript" );
		if ( !temp.empty() )
		{
		  ExportScript* shs = new ExportScript( pkg, temp );
		  if ( shs->Initialize() )
			method_script = shs;
		  else
			delete shs;
		}
	  }
	}
Exemple #9
0
CmdLevel::CmdLevel( Clib::ConfigElem& elem, int cmdlevelnum )
    : name( elem.rest() ), cmdlevel( static_cast<unsigned char>( cmdlevelnum ) )
{
  Clib::mklower( name );
  std::string tmp;
  while ( elem.remove_prop( "DIR", &tmp ) )
  {
    Clib::mklower( tmp );
    add_searchdir( nullptr, Clib::normalized_dir_form( tmp ) );
  }
  while ( elem.remove_prop( "ALIAS", &tmp ) )
  {
    Clib::mklower( tmp );
    aliases.push_back( tmp );
  }
}
Exemple #10
0
void load_system_hooks()
{
  /*
    system_hooks.clear();
    while (!export_scripts.empty())
    {
    delete export_scripts.back();
    export_scripts.pop_back();
    }
    */
  for ( Plib::Packages::const_iterator citr = Plib::systemstate.packages.begin( ); citr != Plib::systemstate.packages.end( ); ++citr )
  {
    Plib::Package* pkg = ( *citr );
    //string fname = pkg->dir() + "syshook.cfg";
    std::string fname = Plib::GetPackageCfgPath(pkg, "syshook.cfg");
    if ( Clib::FileExists( fname.c_str() ) )
    {
      Clib::ConfigFile cf( fname.c_str( ), "SystemHookScript" );
      Clib::ConfigElem elem;
      while ( cf.read( elem ) )
      {
        ExportScript* shs = new ExportScript( pkg, elem.rest() );
        if ( shs->Initialize() )
        {
          gamestate.export_scripts.push_back( shs );
          std::string hookname, exfuncname;
          while ( elem.remove_first_prop( &hookname, &exfuncname ) )
          {
            if ( exfuncname.empty() )
              exfuncname = hookname;
            hook( shs, hookname, exfuncname );
          }
        }
        else
        {
          delete shs;
        }
      }
    }
  }
}
Exemple #11
0
Vital::Vital( const Plib::Package* pkg, Clib::ConfigElem& elem ) :
  pkg( pkg ),
  name( elem.rest() ),
  aliases(),
  vitalid( 0 ),
  next( NULL ),
  get_regenrate_func( FindExportedFunction( elem, pkg, elem.remove_string( "RegenRateFunction" ), 1 ) ),
  get_maximum_func( FindExportedFunction( elem, pkg, elem.remove_string( "MaximumFunction" ), 1 ) ),
  underflow_func( NULL ),
  regen_while_dead( elem.remove_bool( "RegenWhileDead", false ) )
{
  aliases.push_back( name );
  std::string tmp;
  while ( elem.remove_prop( "Alias", &tmp ) )
    aliases.push_back( tmp );

  if ( elem.remove_prop( "UnderflowFunction", &tmp ) )
  {
    underflow_func = FindExportedFunction( elem, pkg, tmp, 2 );
  }
}
Exemple #12
0
Attribute::Attribute( const Plib::Package* pkg, Clib::ConfigElem& elem ) :
  pkg( pkg ),
  name( elem.rest() ),
  attrid( 0 ),
  aliases(),
  next( NULL ),
  getintrinsicmod_func( nullptr ),
  delay_seconds( elem.remove_ushort( "DELAY", 0 ) ),
  unhides( elem.remove_bool( "UNHIDES", true ) ),
  disable_core_checks( elem.remove_bool( "DisableCoreChecks", false ) ),
  default_cap( elem.remove_ushort( "DefaultCap", Core::settingsManager.ssopt.default_attribute_cap ) ),
  script_( elem.remove_string( "SCRIPT", "" ), pkg, "scripts/skills/" )
{
  aliases.push_back( name );
  std::string tmp;
  while ( elem.remove_prop( "Alias", &tmp ) )
    aliases.push_back( tmp );

  if ( elem.remove_prop( "GetIntrinsicModFunction", &tmp ) )
  {
    getintrinsicmod_func = Core::FindExportedFunction( elem, pkg, tmp, 1 );
  }
}
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 );
    }
  }
}
// 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;
}