14 #include <format/format.h> 15 #include "../clib/cfgelem.h" 16 #include "../clib/cfgfile.h" 17 #include "../clib/clib.h" 18 #include "../clib/fileutil.h" 19 #include "../clib/logfacility.h" 20 #include "../plib/pkg.h" 21 #include "../plib/systemstate.h" 31 : _filename( cf.filename() ), _fileline( cf.element_line_start() ){};
35 return _filename.capacity() +
sizeof(
unsigned int );
40 bool showed_elem_line =
false;
43 tmp << ( error ?
"Error" :
"Warning" ) <<
" reading configuration file " <<
_filename <<
":\n";
45 tmp <<
"\t" << msg <<
"\n";
47 if ( elem !=
nullptr )
49 if ( strlen( elem->
type() ) > 0 )
51 tmp <<
"\tElement: " << elem->
type() <<
" " << elem->
rest();
55 showed_elem_line =
true;
62 tmp <<
"\tElement started on line: " <<
_fileline <<
"\n";
69 : _source( cf ), _elem( elem )
107 std::string npctemplate;
111 std::string filename =
114 cf.
open( filename.c_str() );
115 while ( cf.
read( elem ) )
117 if ( !elem.
type_is(
"NpcTemplate" ) )
120 std::string orig_rest = elem.
rest();
121 if ( pkg !=
nullptr )
123 std::string newrest =
":" + pkg->
name() +
":" + npctemplate;
126 const char* rest = elem.
rest();
127 if ( rest !=
nullptr && *rest !=
'\0' )
129 if ( stricmp( orig_rest.c_str(), npctemplate.c_str() ) == 0 )
135 if ( stricmp( tname.c_str(), npctemplate.c_str() ) == 0 )
141 catch (
const char* msg )
143 ERROR_PRINT <<
"NPC Creation (" << template_name <<
") Failed: " << msg <<
"\n";
145 catch ( std::string& str )
147 ERROR_PRINT <<
"NPC Creation (" << template_name <<
") Failed: " << str <<
"\n";
149 catch ( std::runtime_error& re )
151 ERROR_PRINT <<
"NPC Creation (" << template_name <<
") Failed: " << re.what() <<
"\n";
153 catch ( std::exception& ex )
155 ERROR_PRINT <<
"NPC Creation (" << template_name <<
") Failed: " << ex.what() <<
"\n";
173 while ( cf.read( elem ) )
175 if ( elem.type_is(
"NpcTemplate" ) )
178 std::string namebase;
179 const char* rest = elem.
rest();
180 if ( rest !=
nullptr && *rest !=
'\0' )
186 namebase = elem.remove_string(
"TemplateName" );
188 std::string descname;
189 if ( pkg !=
nullptr )
191 descname =
":" + pkg->
name() +
":" + namebase;
192 elem.set_rest( descname.c_str() );
std::string remove_string(const char *propname)
bool FindNpcTemplate(const char *template_name, Clib::ConfigElem &elem)
const std::string & name() const
void copyto(Clib::ConfigElem &elem) const
size_t estimateSize() const
NpcTemplateConfigSource _source
const char * rest() const
bool pkgdef_split(const std::string &spec, const Package *inpkg, const Package **outpkg, std::string *path)
virtual void display_error(const std::string &msg, bool show_curline=true, const Clib::ConfigElemBase *elem=nullptr, bool error=true) const POL_OVERRIDE
void read_npc_templates()
virtual size_t estimateSize() const POL_OVERRIDE
NpcTemplatesElems npc_template_elems
void open(const char *i_filename)
NpcTemplateConfigSource()
bool type_is(const char *name) const
std::string GetPackageCfgPath(const Package *pkg, const std::string &filename)
void set_source(const ConfigElem &elem)
bool FileExists(const char *filename)
bool read(ConfigElem &elem)
const char * type() const
void set_rest(const char *newrest)
size_t estimateSize() const