33 #ifdef WRITEGALAXYCOORDS
37 using namespace XMLSupport;
38 using namespace VSFileSystem;
77 std::vector< std::string >
stak;
79 void beginElement(
void *userdata,
const XML_Char *nam,
const XML_Char **atts )
81 AttributeList::const_iterator iter;
82 XML *xml = (
XML*) userdata;
96 xml->
stak.push_back(
"<planets>" );
103 for (iter = attributes.begin(); iter != attributes.end(); ++iter) {
108 name = (*iter).value;
114 xml->
stak.push_back( name );
119 for (iter = attributes.begin(); iter != attributes.end(); ++iter) {
124 name = (*iter).value;
127 value = (*iter).value;
141 XML *xml = (
XML*) userdata;
155 xml->
stak.pop_back();
163 using namespace GalaxyXML;
177 }
else if (subheirarchy) {
184 SGalaxy::SGalaxy(
const SGalaxy &g ) : data( g.data )
196 sprintf( coord,
"%lf %lf %lf", coords.i, coords.j, coords.k );
198 if (ret.length() == 0)
203 #ifdef WRITEGALAXYCOORDS
205 while ( !si.
done() ) {
214 for (
unsigned int i = 0;
i < tabs; ++
i)
219 StringMap::const_iterator dat;
220 for (dat =
data.begin(); dat !=
data.end(); ++dat)
221 if ( (*dat).first !=
"jumps" ) {
223 f.
Fprintf(
"<var name=\"%s\" value=\"%s\"/>\n", (*dat).first.c_str(), (*dat).second.c_str() );
225 dat =
data.find( std::string(
"jumps" ) );
226 if ( dat !=
data.end() ) {
228 f.
Fprintf(
"<var name=\"jumps\" value=\"%s\"/>\n", (*dat).second.c_str() );
232 if (&(*it).second != planet_types) {
234 f.
Fprintf(
"<%s name=\"%s\">\n", sectorType.c_str(), (*it).first.c_str() );
235 (*it).second.writeSector( f, tabs+1, sectorType, planet_types );
237 f.
Fprintf(
"</%s>\n", sectorType.c_str() );
243 f.
Fprintf(
"<galaxy>\n<systems>\n" );
251 f.
Fprintf(
"<galaxy>\n<systems>\n" );
264 using namespace VSFileSystem;
272 XML_Parser parser = XML_ParserCreate( NULL );
273 XML_SetUserData( parser, &x );
275 XML_Parse( parser, (
f.ReadFull() ).c_str(),
f.Size(), 1 );
278 XML_ParserFree( parser );
280 std::cerr<<
"!!! ERROR : couldn't find galaxy file : "<<configfile<<std::endl;
295 const string &default_value )
const
298 for (
unsigned int i = 0;
i < section.size(); ++
i) {
300 SubHeirarchy::const_iterator sub =
subheirarchy->find( section[
i] );
303 else return default_value;
304 }
else {
return default_value; }}
305 StringMap::const_iterator dat =
data.find( name );
306 if ( dat !=
data.end() )
307 return (*dat).second;
308 return default_value;
318 for (
unsigned int i = 0;
i < section.size(); ++
i)
319 temp = &( (*temp)[section[
i]].getHeirarchy() );
324 for (
unsigned int i = 0;
i < section.size(); ++
i)
326 g->
data[name] = value;
337 bool SGalaxy::setVariable(
const string §ion,
const string &subsection,
const string &name,
const string &value )
339 getHeirarchy()[section].getHeirarchy()[subsection].data[name] = value;
346 const SGalaxy §or = (*subheirarchy)[sect];
350 int which = rand()%
size;
351 SubHeirarchy::const_iterator
i =
362 const string &subsection,
364 const string &defaultvalue )
const
366 #ifdef WRITEGALAXYCOORDS
367 static bool blah =
false;
375 SubHeirarchy::const_iterator
i;
377 i = s->find( section );
378 if ( i != s->end() ) {
379 s = (*i).second.subheirarchy;
381 i = s->find( subsection );
382 if ( i != s->end() ) {
384 StringMap::const_iterator
j = g->
data.find( name );
385 if ( j != g->
data.end() )
394 const string&
SGalaxy::getVariable(
const string §ion,
const string &name,
const string &defaultvalue )
const
397 SubHeirarchy::const_iterator
i;
399 i = s->find( section );
400 if ( i != s->end() ) {
402 StringMap::const_iterator
j = g->
data.find( name );
403 if ( j != g->
data.end() )
414 planet_types->data[name] = value;
422 planet_types->getHeirarchy()[section].data[name] = value;
430 SubHeirarchy::const_iterator
i;
433 return getPlanetVariable( name, defaultvalue );
436 StringMap::const_iterator
j = g->
data.find( name );
437 if ( j == g->
data.end() )
438 return getPlanetVariable( name, defaultvalue );
449 StringMap::const_iterator
j = planet_types->data.find( name );
450 if ( j != planet_types->data.end() )
455 SGalaxy* Galaxy::getInitialPlanetTypes()
458 SubHeirarchy::iterator iter =
subheirarchy->find(
"<planets>" );
462 return &(*iter).second;
466 void Galaxy::setupPlanetTypeMaps()
469 SubHeirarchy::iterator
i = planet_types->getHeirarchy().begin();
470 for (; i != planet_types->getHeirarchy().end(); ++i) {
471 string name = (*i).first;
476 static const string _unit(
"unit");
477 const string &unit = (*i).second[_unit];
482 static const string _texture(
"texture");
483 const string &tex = (*i).second[_texture];
490 string::size_type pipe = val.find_first_of(
'|');
491 if (pipe != string::npos)
492 val = val.substr( 0, pipe );
493 string::size_type slash = val.find_last_of(
'/');
494 if (slash != string::npos)
495 val = val.substr( slash+1 );
496 string::size_type dot = val.find_last_of(
'.');
497 if (dot != string::npos)
498 val = val.substr( 0, dot );
500 static const string numtag =
"#num#";
501 static const string::size_type numtaglen = numtag.length();
502 string::size_type tagpos;
503 while (string::npos != (tagpos = val.find(numtag)))
504 val.erase(tagpos, numtaglen);
509 if ( texture2name.find( val ) != texture2name.end() ) {
510 printf(
"name conflict %s has texture %s and %s has texture %s\n",
513 texture2name[val].c_str(),
516 texture2name[val] = name;
518 val = (*i).second[
"initial"];
519 if ( initial2name.find( val ) != initial2name.end() ) {
520 printf(
"name conflict %s has initial %s and %s has initial %s\n",
523 initial2name[val].c_str(),
526 initial2name[val] = name;
530 if ( initial2name.empty() || texture2name.empty() )
531 fprintf( stderr,
"Warning, galaxy contains no overarching planet info\n" );
535 planet_types = getInitialPlanetTypes();
536 setupPlanetTypeMaps();
540 planet_types = getInitialPlanetTypes();
541 setupPlanetTypeMaps();